Skip to content

Google Analytics YOURLS Plugin.

A plugin for YOURLS that add Google Analytics tracking code to all your html pages.

How it works:
Add Google Analytics tracking code before your footer. Remember that Shortened address will not be tracked, they are tracked by YOURLS.

How to install:
- Copy plugin files to /user/plugins/ganalytics/ folder.
- Access the administration area and activate the plugin.

Setup:
GANALYTICS_ACCOUNT is the tracking code for your account (UA-XXXXXXX-YY)

Download:
Google Analytics YOURLs Plugin 1.0 beta

20 Comments

  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?

    Thanks!

  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

    2 comments:
    - 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.
    Thanks!

  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.
    Thanks,
    marco.

  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 (http://www.google-analytics.com/__utm.gif) passing along the appropriate parameters in the query string (http://code.google.com/apis/analytics/docs/tracking/gaTrackingTroubleshooting.html). 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 ?

    Thanks

  14. Why is this plugin not working? After installing the plugin the whole YOURL system stopped working and giving fatal errors.

  15. Hi, i think that i saw you visited my weblog thus i got here to go back the prefer?.I am attempting to in finding things to enhance my web site!I guess its ok to use some of your ideas!!

  16. Excellent site you have here but I was wanting to know if you knew of any discussion boards that cover the same topics talked about here? I'd really love to be a part of community where I can get feed-back from other experienced people that share the same interest. If you have any recommendations, please let me know. Kudos!

Leave a Reply

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