Campaign Tracking YOURLS in Google Analytics



yourls google analytics campaign tracking 3 Campaign Tracking YOURLS in Google Analytics

YOURLS is a URL shortening service you can run on your own server, and it comes with a WordPress plugin called YOURLS WordPress to Twitter. In the past I’ve used WP to Twitter, but since it doesn’t support YOURLS I’ve had to switch.

I’ve asked the author of YOURLS WordPress to Twitter to add Google Analytics Campaign Tracking Code with a custom field for authors to add their own identifier, but he has been too busy updating the YOURLS scripts, so I’ve hacked the plugin code to allow us to use Campaign Tracking now.

Note: Only add this Google Analytics Campaign Targeting code if you are using YOURLS for your own internal web site links only. If you also use the short URLs for offsite links, those links will break because of the tracking code.

In the plugin go to the inc/core.php, and open it in a text editor. I prefer to use Notepad++.

On line 74 change the code from:

$url = get_permalink ($post_id);

to

$url = get_permalink ($post_id)."?utm_source=your-identifier&utm_medium=your-identifier&utm_campaign=your-identifier";

On line 107 change the code from:

$shorturl = wp_ozh_yourls_api_call( $service, $url);

to

$shorturl = wp_ozh_yourls_api_call( $service, $url."?utm_source=your-identifier&utm_medium=your-identifier&utm_campaign=your-identifier");

Change “your-identifier” to your custom campaign identifier.

That’s it! Now in your YOURLS reports you will see the Original URL appended with the Google Analytics tracking tag. It will take at least 24 to 48 hours for the Campaign tracking to be posted in Google Analytics. To see the report go to Google Analytics -> View report -> Traffic Sources -> Campaigns, and you’ll see a link with the identifier name you chose.

yourls google analytics campaign tracking 2 Campaign Tracking YOURLS in Google Analytics

If you’re not interested in hacking the core.php file yourself, you can (right-click) click here and choose save as to download a copy already modified for tracking, then just unzip the file, and replace the old core.php file with the new one. If you use the already modified core.php file you will see the Google Analytics Campaign tracking labeled as yourls-camp-track.

Note: The core.php file available for download above will work for YOURLS: WordPress to Twitter Version 1.3.2.



Short Link - http://ngurl.me/2t Posted on October 16, 2009 at 9:44 am (PST)
Tags: | | | | | | | | | |


One comment on “Campaign Tracking YOURLS in Google Analytics

  1. This Article is now outdated for the latest version of YOURLS.

    Im trying to figure out how to get it working with the newer version, but it seems to have been completely recoded by the creators.

    Dan.

Leave a Reply

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

*

14,009 Spam Comments Blocked so far by Spam Free Wordpress

HTML tags are not allowed.

© Copyright Nerd Grind 2009 - 2010. All rights reserved.