Simplified Google Analytics campaign parameter URL tracking builder

A simplified URL parameter builder for use in orgs with multiple staff posting links.

This tool has been designed to let multiple users across an organisation add Google Analytics URL tracking to their links in a consistent way that doesn't require indepth knowledge of Google Analyics. Resulting in clean crisp campaign data in Google Analytics and people not having to worry about whether something is a 'medium' or a 'source'. It's a suped up but simplified version of this. As a bonus it's got built in Bit.ly shortening

Why track links?

Setup instructions

  • Sign up to bit.ly. In the settings section copy the legacy api key and your user name. Open this file (index.html) in a text editor and find and replace the bit.ly account listed with your own account.

    $(document).ready(function()
    {
    function bit_url(url)
    {
    var url=url;

    var username="";
    var key="";


    $.ajax({
    url:"http://api.bit.ly/v3/shorten",
    data:{longUrl:url,apiKey:key,login:username},
    dataType:"jsonp",
    success:function(v)
    {
    var bit_url=v.data.url;
    $("#result").html(''+bit_url+'');
    }
    });
  • Add your source/medium combinations to the placement dropdown by finding this section of code in this file. The optgroup label don't affect any functionality but make it look a bit tidier and help reinforce the link between source and medium.

    <select id="utm_source" name="utm_source" class="input-xlarge" onchange="setmedium(this.value); javascript: changeSubcat(this.options[this.selectedIndex].value);">

    <option>-</option>
    <optgroup label="Social">
    <option value="FacebookPost">Facebook Post</option>
    <option value="FacebookAd">Facebook Ad</option>
    <option value="twitter">Twitter</option>
    <option value="youtube">YouTube</option>
    <option value="pinterest">Pinterest</option>
    <option value="flickr">Flickr</option>

    <optgroup label="Email">
    <option value="email_signature">Email signature</option>
    <option value="general_enews">Monthly Enews</option>
    <option value="single_enews">Single Enews</option>
    <optgroup label="Display">
    <option value="Banner">Banner</option>

    <optgroup label="Outdoor">
    <option value="Poster">Poster</option>

    </select>

  • Find this section of code and create any new rules you need. You'll need to add in any new sources you've added to the placement dropdown and add which medium it should select behind the scenes. In this case FacebookAd, twitter, youtube etc.. are sources and match the placement dropdown values, if they are selected 'social' will be added as the medium. "||" means OR. I.E. If you select FacebookAd or twitter or youtube as the source then the medium is social.

    <script type="text/javascript">
    <!--

    function setmedium(source) {

    mysource = source;

    if (mysource == "FacebookAd" || mysource == "twitter" || mysource == "youtube" || mysource == "flickr" || mysource == "pinterest" || mysource == "FacebookPost") {
    document.ctm.utm_medium.value = "social";}

    else if (mysource == "email_signature" || mysource == "general_enews" || mysource == "single_enews" || mysource == "email_signature") {

    document.ctm.utm_medium.value = "email";}

    else if (mysource == "newsadvert" || mysource == "newsarticle" || mysource == "pressrelease") {

    document.ctm.utm_medium.value = "press";}

    else if (mysource == "poster") {

    document.ctm.utm_medium.value = "outdoor";}

    }
    </script>
  • Add your campaigns to the campaign dropdown. Update as you get new campaigns

    <select id="utm_campaign" name="utm_campaign" class="input-xlarge">
    <option>-</option>
    <option>London Marathon</option>
    <option>Research News</option>
    <option>Ice Bucket Challenge</option>
    <option>Our Great Campaign</option>
    </select>
  • Host the whole folder on a network drive or on an internal server (the bit.ly api key is stored in the open so you don't want this somewhere publically accessible, the trade off in security makes the tool a more portable and easily editable. We put it on a shared network drive)

Using code examples from Google & 9 lessons

Nifty Bootstrap courtesy of Layoutit & Minikomi

Any comments to Owen

Download .zip
Fork on GitHub

Step 1: Paste the URL below.

Step 2: Fill out the details

Separate terms with a "+"

Step 3: Click the button