In my last post, I wrote about the benefits of using YOURLS, a self-hosted link-shortening service. I’m finding that YOURLS is great, but it’s not perfect. Some of the issues I have experience are part of what you get using most URL shortener services.
Some of the downsides of using link shorteners are:
- Google Analytics doesn’t always capture the original referrer (and I have no clue how they do the rest of the time!).
- When generating links using the bookmarklet (or in this case, also the Yourls installation), there’s no easy way to add campaign, source, medium, content, and term tags for Google Analytics to track.
- Yourls doesn’t allow query strings on URLs by default, making overriding existing campaign tags difficult/impossible. For example: `http://katz.si/t?utm_source=2300`
I’m not the only one who wanted these things, so I’ve created a plugin that adds Google Analytics tracking to Yourls. It’s very cool.
Google Analytics Yourls plugin
Download Google Analytics for YOURLS from Github
The plugin features include:
Define default tracking tags
You can define a set of default tags that are added to any link that gets shortened.
- `utm_source`
- `utm_medium`
- `utm_name`
- `utm_term`
- `utm_content`
Override existing tags – you can choose to have your tags replace tags in the long URL that’s being shortened…or not.
Tagging options added directly to the URL form – the best feature in my opinion, you now have an interface to easily add tracking right from the link shortener.
Add query strings to the shortened URL to override or add any tracking tags. This feature has support for abbreviations, too.
If you want to see this in action, check out the links below.
- http://katz.si/t?src=tw expands to `http://www.seodenver.com/yourls-url-shortener/?utm_source=twitter`
- http://katz.si/t?med=em expands to `http://www.seodenver.com/yourls-url-shortener/?utm_medium=email`
- http://katz.si/t?med=blog&src=seodenver&cam=2300 expands to `http://www.seodenver.com/yourls-url-shortener/?utm_medium=blog&utm_source=seodenver&utm_campaign=2300`
Plugin Installation
To install, follow these steps:
- Download the file (updated to correct Github link)
- Upload the `google-analytics` folder into your `users` > `plugins` directory
- Go to your YOURLS plugins page
- Hover over Google Analytics, click “Activate”
- Configure the plugin settings by clicking the Google Analytics link in the menu
55 replies on “Yourls Google Analytics Link Tagging”
your a spammer. Did you put the malicious script in my ftp? I have way to many LD backlinks on my site from THIS SITE!!
jerkoff.
This script creates no backlinks.
I couldn’t get the ZIP to download. And I would like to know whether there is any truth on that claim of this creating backlinks to this site.
Thanks.
I couldn’t get the ZIP to download. And I would like to know whether there is any truth on that claim of this creating backlinks to this site.
Thanks.
Thanks; I forgot to update one of the links in the readme to the new place where the script is hosted (Github). Here’s the link: https://github.com/katzwebservices/google-analytics-for-yourls/zipball/master
No, this script adds no backlinks.
Has anyone implemented this plugin yet?
I found so many entertaining stuff in your blog,especially on this post. Keep up the good work.
Jaipur Web World
Amazing. Thanks. I made 2 plugins that use the geoipcity and geoipregion to plot hits on city and state levels, but I haven’t released to public yet. They were much less complicated then your plugin here. Thanks for sharing!
Hi Jeremy,
Could you post links to your plugins, I have been trying but unsuccessful. Could really use them for my business.
Thanks
Mark
I just started using YOURLS on my short domain name. Thanks for creating such an easy way for me to add GA campaign info to all my shortened URLS. This is a great plug in.
At first I thought it was going to add the campaign info to the end of my shortened URL based on the examples you listed above, which I didn’t want. But after trying it out, I found out it did what I want.
It allows you to place a Long URL and then add GA campaign info to the Long URL prior to shortening it so that your short URL hides it. I don’t want people to see the campaign info when I post the shortened URL.
Terrific Job!
Thanks, I’m glad you like it!
A good and informative post. i am grateful to be here. thanks hope to read more from you.
So how do I add my google account identifier to this?
Why would you need to do this?
Well it should be a google analytics plugin? 😛 Shouldn’t you need someway of tracking to one’s account then? 😛
So, as far as I can tell, this plugin is useless unless we can add our google identifyer code. how do we do this?
Hi guys, your Google Account identifier will be fired back to Google analytics when the js file executes on your site.
What this plug in lets you do is tell the ga action where the visitor came from in terms of the source / medium . campaign etc.
No need for your UA code here
Where or what page or file or setting in YOURLS do we put our GA JS so as to “fire” the JS when a short URL comes through so as to be able to track it in GA?
It is about as clear as mud to me.
If I put any kind of tracking code on the home page via the footer.php file it ONLY tracks the | Home | About | Contact Us | Help | Privacy | Terms | pages and does NOT track any short URLs that come through.
Thanks.
This plugin doesn’t seem to work with version 1.6 of YOURLS.
I found a problem with jQuery live() when toggle the input fields.
But I still can’t get the data in the fields to be added to the URL. Any suggestions?
Not working with version 1.6 (polyglot) either
This plugin now works in 1.6.
This now works in 1.6.
[…] – Google Analytics Yourls plugin: http://www.seodenver.com/add-google-analytics-link-tagging-yourls/ […]
Love the plugin for Yourls!! Great work, but I can not get any stats from google without my google identiifier code. Can you please help us with this? Thanks.
We are creating a series of QR codes for a client to track/compare various POS effectiveness. However the code points to a Facebook share, not to the landing page (a simple way for mobile frictionless sharing). I’m not sure this is accomplished with your plug in as it appears to add tracking info to long URL, so you can see campaigns when using the analytics of that domain. I want to plug a single shortened URL into Google’s tracker tool and create separate QR codes (the URL never visible to the user). So I need to track analytics of my short URL domain. Can this be hacked for that or does anyone have an idea. There seem to be a lot smarter people than me on this blog. Thanks!
I am not getting the plugin to work with YOURLS 1.6. Do you have any updates or fixes. Thank you.
This plugin has been updated to work in 1.6.
Broken in 1.6, any chance for a fix?
The plugin now works in 1.6.
Thanks!
This is not working still. I tried on both FF and Chrome.
Has anyone found a way to make this work with version 1.6 or another plugin that replaces this one?
The plugin has been updated to work in 1.6.
Is it possible to add the tags to the long url before shortening it? adding tags to a shortened url kind of defeats the purpose of shortening it.
Hello! First of all, thanks for your work!
I am trying to use this plugin but I am not able to make it work.
I’ve already activated it but I’m getting this in the address bar when I click on “Show GA Tracking Options”
http://myshortenerdomain/admin/index.php#ga_tracking_options
But the options never appear.
Do you know why is this happening?
I am using Yourls 1.6 and I have installed the last version of your plugin.
Thanks and regards,
Alex.
Here the same problem.
Hey,
I have posted solution above. Hope it works for you.
Have fun, Grega
Use the version from Grega here. That fixes it. http://pastebin.com/6594rGGY
I seem to be getting the same problem everyone else had, when I click to see the google tags nothing happens, please help I really need this to work. Willing to donate.
Hey,
I have posted solution above.
Have fun, Grega
Hi!
I have a problem, i trying use this plugin when I click on “Show GA Tracking Options”, nothing happens D:
Hey,
here is the solution if the plugin doesnt work 🙂
You need to fix the plugin file located in user/plugins/google-analytics-for-yourls-master. Open file named plugin.php.
1. Search for “Show GA Tracking Options”. In the div next to it (div id=”ga_tracking_options”) remove style display: none;
2. Search for: “function add”. Rename it to: function add_link.
3. In the same function near the end you will see “end_loading,…” and “end_disabled….”. Before that add line: add_link_reset();
I hope it helps 😉
Have fun, Grega
Hey,
I did another little fix. I thought it will be easier for you to download the script from the Pastebin.
http://pastebin.com/6594rGGY
Can you please make a pull request on Github? https://github.com/katzwebservices/google-analytics-for-yourls
Thanks Grega! Before, the plugin did not work for me on Yourls 1.6. With your fix, it does!
Yeah Grega, cheers!
Cheers to you too, Zack!
Thanks for this—I’ve udpated the plugin on Github!
Hi This Is The One Of Best Plugins In Yourls.
But I Need One More Additional Feature in it.
That Is for example :- http://katz.si/t?utm_source=2300
the UTM Parameter is adding to this link so this link ‘http://katz.si/t’ redirecting here ‘https://katz.co/add-google-analytics-link-tagging-yourls/’
if i have further additional directory that is ‘https://katz.co/add-google-analytics-link-tagging-yourls/abc’
so how can i add ‘https://katz.co/add-google-analytics-link-tagging-yourls/abc’ to redirect like this ‘http://katz.si/t/abc’
and after that the UTM parameters add and the final link as ‘http://katz.si/t/abc?http://katz.si/t?utm_source=2300‘
so here only only link shorten and directories should be simply add after shorten link so this will help to remove confused link
please let me know how can this happens
The plugin IS still broken for me in 1.6 and 1.7, but with Grega’s code (Thanke!)
http://pastebin.com/6594rGGY
it works for me on both versions.
I’ve udpated the plugin on Github – thanks for your code contribution!
I am wondering… Why does this plugin uses ‘+’ instead of ‘%20’ for spaces? Since that is the original method that Google uses with her own linkbuilder… Google´s link: utm_campaign=de%20introductie%20van%20hem
YOURLS url: utm_campaign=de+introductie+van+hem
Also thank’s for making the plugin! I was wondering would it be possible to create a dropdown list for the utm_source and utm_medium? source for example: socmed / website / newsletter and medium: linkedin / twitter / facebook / gplus etc. That way you don’t get double results by error of a user.
This looks like an interesting plugin, but I’m wondering if you can provide more information before I install it.
Rather than adding the analytics campaign parameters to the shortened URL, could you include the parameters in the long URL before shortening? For example, the long URL:
http://thisismy.very.long/url-that/needs-to-be/shortened?utm_source=twitter&utm_medium=tweet&utm_campaign=test
shortened to http://yourls.co/Fxwaa
Would this behave the same as using this plugin to pass Google Analytics parameters in the short URL?
Thank you for this! Much appreciated. FYI.. edit $power_ga_mp_GAID on line 64 not 48
anybody still alive? 😉
i´m using your plugin and it works fine.. so far. great pice of software!
i create a shortlink in the Admin panel and everything works.
but if i´m using the Bookmarklets, there will be no utm parameter in the final link. maybe the plugin will not work with the comfort function of Bookmarklets.
any idea?