Skip to content

Google Analytics YOURLS Plugin.

NOTA: Plugin desenvolvido com a versão do SVN. Incompatibilidades com versão 1.5+

Um plugin para YOURLS que após configurado adiciona automaticamente o código do google analytics.

Como funciona:
Adiciona o código do Google Analytics em todas as suas páginas que possuem html. Endereços encurtados não serão registrados. Eles são monitorados pelo próprio YOURLs.

Como instalar:
- Copiar os arquivos do plugin para a pasta /user/plugins/ganalytics/
- Acessar area de administração e habilitar o plugin.

GANALYTICS_ACCOUNT é o track code para sua conta do Google Analytics (UA-XXXXXXX-YY)

Google Analytics YOURLs Plugin 1.0 beta


  1. Will Will

    Hey, great plugin! This is just what I was looking for. Just a quick question though, why do you not track the shortened URLs also?


  2. Hello,

    It is possible to track Shortened URLs too. But, if I want to do this, I will need to create an intermediate page that tracks the code and then it is redirected to the real URL. I didn't want to create this because it can be slower with this. But it is possible.

    Do you think it is a nice feature?

  3. Ozh Ozh

    - why "multi-user" folder?
    - it doesn't track clicks on short URL, only stats & admin page views, that should be made clearer for readers (the less tech savvy will get confused)

  4. Ozh,
    - I didn't find any "multi-user" folder in this plugin, at least in the one attached to this post.
    - I agree, I intend to create a version that it can track the shortened URLs too.

  5. Hey Matheus, yes I am interested in seeing GA in the short URLs. I had the same idea about having a redirect page. The thought came to me when I looked at the redirect prompt page in Ozh's plugin example. Perhaps adding the Google Analytics codes into that page and then just quickly passing over that page from the shortlink, to the prompt page with the GA code, and then to the long URL, would be enough for the GA.

    However, my concern is that it wouldn't be enough time for the GA Code (javascript) to run before the page is redirected. Thoughts? Is there another way than what I am thinking?

    I don't have any use for tracking the long URLs, I am only interested in the short URLs. The long URLs defeat the purpose of the excersise.

  6. Will,
    Yes, that is the main problem. If it will run before the page is redirected. That's why it isn't done yet. I'm testing some features, so the page is not redirected before the javascript load and do the request. I think I did it, but I will need to wait until tomorrow to verify if the track worked in Analytics.

  7. Yes I don't like this issue of having to wait 12 hours to test my code. Right now I'm looking for a way to get instant feedback. I know there are ways to do this, I just haven't done the research yet to see which is the best.

    From what I understand, the short URLs are redirected from the /yourls-go.php file. I'm going to try and put the GA Javascript snippet at the top of this php file and see if that works. Ozh maybe you could confirm that it would or would not?

    I'm a Co-op student who's been instructed to figure this out, so I'll be spending the next while figuring this out.

  8. If you discover how to do it, please let me know!

    I'm pretty sure it will not work if you put in the top of the yourls-go.php. But go ahead and try, and let me know. Any new information are welcome! Best regards

  9. Still no luck.

    I've installed Piwik (an open source alternative to Google Analytics) and it loads every 10 seconds new hits. This makes it a lot better for testing.

    yourl-go.php does not work.

    I am trying to write a plugin but it still isn't working!

  10. hi guys,
    have you managed to sort it out?
    Tracking the short url is definitely much more important than the long url.

  11. Chad Chad

    One option to track the short URL is to push the event to GA from the server. So right before sending the redirect to the client, make an HTTP request to GA's tracking pixel ( passing along the appropriate parameters in the query string ( You’ll want to get some of the values from cookies already on the request (e.g. __utma) to better emulate the actual client. This request is what the JavaScript ends up doing anyway, plus it is similar to what Google recommends for mobile sites that may not have JavaScript (generate the URL for the tracking image manually). You’ll also want to include certain values in the destination URL as well; for example the campaign ID should be set so you fully track that request through to potential conversion.

    Couple caveats though: it will look like all of these requests are coming from the IP address of your server and you also won't get the client browser information. Still makes a decent way to get the data into GA and you can set up a segment to filter those requests out of other reports so you don’t skew other numbers.

  12. lpto lpto

    How do I add my account to the plugin?

    ['_setAccount', '" . GANALYTICS_ACCOUNT . "']);

    like this:

    ['_setAccount', '" . UA-XXXXXXX-YY . "']);

    or this?
    ['_setAccount', '"UA-XXXXXXX-YY"']);

  13. Jota Jota

    Should I add that line in the 1st plugin.php line ?


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.