Categories
Plugins Web Development

Yourls Google Analytics Link Tagging

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:

  1. Google Analytics doesn’t always capture the original referrer (and I have no clue how they do the rest of the time!).
  2. 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.
  3. 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 URL tagging options

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.

Plugin Installation

To install, follow these steps:

  1. Download the file (updated to correct Github link)
  2. Upload the `google-analytics` folder into your `users` > `plugins` directory
  3. Go to your YOURLS plugins page
  4. Hover over Google Analytics, click “Activate”
  5. Configure the plugin settings by clicking the Google Analytics link in the menu

By Zack Katz

Zack Katz is the founder of GravityKit and TrustedLogin. He lives in Leverett, Massachusetts with his wife Juniper.

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.

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.

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!

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?

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.

Has anyone found a way to make this work with version 1.6 or another plugin that replaces this one?

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.

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.

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

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

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?

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?

Comments are closed.