The analytics issue with Twitter

Twitter is great for traffic, but just how great it is, well, you’ll never really know. Why not? You’ll ask. Well, the only traffic you’ll see coming from Twitter is traffic that comes through Twitters web interface. And most people I know don’t use the web interface, they use desktop and / or phone clients. Because these clients aren’t browsers, they won’t pass along a referrer, and thus register as “direct traffic”.

I won’t even try to estimate what percentage of Twitter usage goes through the API, although I’ve heard people say it’s up to 80 or even 90%, although Twitter Stats seems to report it as around 50%, and Twitstat.com as 60%. So you’re getting a lot of clicks that look like “direct traffic” in your Analytics, but are in fact, not direct traffic. These people will behave differently than normal people who come to your site directly.

In an effort to improve the reliability of my Google Analytics stats a bit, I’ve decided to start adding Google Analytics campaign, medium and source variables to all my own tweets in which I promote my own posts. I know from cli.gs, the URL shortening service I tend to use, that my tweeted links get up to 300 clicks each, and I’d love to track the behavior of those people on my site.

So I’ve made a small “in between” script that I can use in a bookmarklet. What it does is simple:

  1. it grabs the URL and title from the request
  2. it adds the UTM variables ?utm_campaign=twitter&utm_medium=twitter&utm_source=twitter
  3. it does a request to cli.gs through its API to create a shorturl
  4. it then redirects to twitter.com/home with the status set to that shorturl

Download the script here, and then modify this bookmarklet to use it:

javascript:(function()%7B%20window.open('http://www.example.com/clig.php?url='+encodeURIComponent(location.href)+'&utm&title='+encodeURIComponent(document.title));%20%7D)();

Set example.com to the domain name and path where you uploaded it.

This should allow you to create shorturls with the campaign tags in it, and thus track those tweeted links in your own analytics!

Tags: ,


Yoast.com runs on the Genesis Framework

Genesis theme frameworkThe Genesis Framework empowers you to quickly and easily build incredible websites with WordPress. Whether you're a novice or advanced developer, Genesis provides you with the secure and search-engine-optimized foundation that takes WordPress to places you never thought it could go.

Read our Genesis review or get Genesis now!

71 Responses

  1. Anthony ParkesBy Anthony Parkes on 19 January, 2009

    So you can actually track what those specific people do on your site? wow, that’s pretty powerful… hat’s off Joost

  2. Adrian EdenBy Adrian Eden on 19 January, 2009

    Very powerful indeed, nice post, its good to see what people are looking at and where they came from.

  3. SteveBy Steve on 19 January, 2009

    Pretty straight forward campaign tracking for GA – I like the automated solution however.

    I guess the flaw is when people link to your campaign tracking URL or bookmark it. The source is then no longer accuate. This could be solved in the case of people posting links using advanced segmentation etc. but do you have any ideas how to solve the bookmark situation?

    Steve
    @Danger_Mouse

  4. review plugin wordpressBy review plugin wordpress on 19 January, 2009

    great site. thanks for the info.

  5. Joe SpencerBy Joe Spencer on 19 January, 2009

    Great solution for tracking tweet’d links, I´ll pass it on.

  6. Joe DolsonBy Joe Dolson on 20 January, 2009

    You may want to make a minor revision to this code – you’ll need to check whether the URL already has parameters.

    One simple option:

    if ( strpos( $url,"?" ) === FALSE) {
        $url .= "?";
    } else {
        $url .= "&";
    }
    $url .= "utm_campaign=twitter&utm_medium=twitter&utm_source=twitter";
    [/code]
    • Joost de ValkBy Joost de Valk on 20 January, 2009

      Thx a lot Joe, adapted it!

  7. PaulBy Paul on 20 January, 2009

    Great idea! Twitter traffic can (and should) be measured properly with the right approach.

  8. Aaron PetersBy Aaron Peters on 20 January, 2009

    Very nice, txs Joost!

  9. Ricky BuchananBy Ricky Buchanan on 20 January, 2009

    Do these parameter additions not mess somehow with the tweetbacks code? I’m already having trouble with it – don’t want to court more trouble!

    Also, how do you get your RSS tracking into the RSS feed? Both seems to be very useful techniques.

  10. AlexBy Alex on 20 January, 2009

    Very interesting insight, will try that out! Thank you very much!

  11. BradBy Brad on 20 January, 2009

    For an interesting look at follower counts I set up a website that I planned to promote solely through Twitter, http://staires.org, a daily music thing. Admittedly there are a few things popular twitter users do that I don’t: I’m not big on conversation (though I respond and try my best I don’t strike up convos) and my content is very much “you can look once and determine if you care to click”… But I’m up to 630 followers now and I get about 20-30 actual visits a day. I have very little (almost 0) search engine traffic even after unblocking them in my robots.txt. Since this a post about analytics and if Twitter generates real traffic I figured I’d share my “high follower count” story.

    Followers != Clicks.

  12. Gif DumpBy Gif Dump on 21 January, 2009

    Easier way is to just send out your link with the tag ?twitter – so google.com/page.php?twitter

    Same process but lessens the code soup you’re adding at the end – easily will be recognizable in your analytics as traffic from twitter. But both ways have bad SEO written all over them.

  13. KarriBy Karri on 21 January, 2009

    The websites I manage use OneStat, is there a way to track Twitter usage on that platform?

  14. JoSeBy JoSe on 23 January, 2009

    Sorry for sucha a noob question, but where do I place the bookmarklet ?

  15. Brian St. PierreBy Brian St. Pierre on 23 January, 2009

    Joost, thanks for a great solution to twitter referrer stats!

    As implemented, a visitor may end up bookmarking (delicious, digg, etc) the URL with the campaign stuff in it. This would mess up your stats. To avoid this, include this script below the Google Analytics script. It modifies the browser history. The reason the RegExp is complicated is becase, as Joe points out above, there may be other parameters in the URL that you want to preserve. Disclaimer: I haven’t widely tested this but it does work in FF2 (linux), FF3 (win32), IE7 with a handful of URL variations. Also, my javascript is weak so there may be a better way to implement this.


    // Show a clean URL if this came from a tweet/cli.gs URL.
    var campaignRe = new RegExp(/([?&])utm_campaign=twitter&utm_medium=twitter&utm_source=twitter(&?)/);
    var loc = new String(window.location);
    var match = campaignRe.exec(loc);
    if(match != null) {
    // Remove the crufty URL from browser history.
    if(match[1] == "?" && match[2] == "&") {
    // Change & to ?.
    var cleanLoc = loc.replace(campaignRe, "?");
    } else if(match[1] == "&" && match[2] == "&") {
    // Preserve &.
    var cleanLoc = loc.replace(campaignRe, "&");
    } else {
    // Just drop the params.
    var cleanLoc = loc.replace(campaignRe, "");
    }
    window.location.replace(cleanLoc);
    }

    @Gif Dump: does this solution change your opinion about “bad SEO written all over it”, or is there still some problem I’m not seeing? Can you elaborate about what you mean? The crufty URL is cloaked by cli.gs so I don’t see the issue.

  16. phpBy php on 26 January, 2009

    funny that you gave the code to the google dudes. hope they use it. :-) heeheee

  17. oneighturboBy oneighturbo on 28 January, 2009

    just came across this site, thanks joost. great stuff and this will be a great addition to our twitter unknowns!

  18. jon perryBy jon perry on 11 March, 2009

    It’s a basic question and I hope I didn’t overlook it, but to be clear, I am saving the text file as glig.php in the webroot directory. Where am I putting the javacode? In the theme index page?

    Thanks!

    Jon

  19. GaryBy Gary on 13 March, 2009

    Note, if your using the latest google analytics you don’t need to set those variables at all. Instead create your own, for example ?track_id=5 and maintain a database to lookup and set the tracking info yourself following the conventions here http://blog.venture-skills.co.uk/2007/12/22/social-media-tracking-ga/

    You can even go ahead and set a cookie to track browsers you have already run the code on and only run it once per browser.

  20. Jon HenshawBy Jon Henshaw on 19 March, 2009

    Joost, this is now supported in the URL link shortener http://kl.am

  21. NikolaiBy Nikolai on 8 April, 2009

    Joost, this sounds like a cool hack. I just have one question:

    If people tweet a direct link to your site, without using the bookmarklet underneath the post, Google Analytics will still display that as direct traffic, right?

    If so, is there a way to fix that as well?

    Thanks!

  22. AndrewBy Andrew on 13 April, 2009

    Here is how to do it with a simple bookmarklet: http://cli.gs/spp71M

  23. David WhitehouseBy David Whitehouse on 28 April, 2009

    I would say you would be better off specifying:
    utm_medium = referral
    utm_source = twitter.com
    utm_campaign = Tweets

    That way you can lump all the referrals together appropriately, lump all the twitter.com referrals together and just analyse it based on “Tweets”

  24. Hi, the script looks good as the shortening URL I use says hundreds of hits to my site, but the site is telling me it is only finding b/w 10 15 a day. As a beginner, where do I place the script to make this all work?
    Cheers.

  25. CraigBy Craig on 5 May, 2009

    FWIW: I wrote a plugin for Mint that helps you track just these kinds of campaigns in realtime: http://craigmod.com/interactive/link_spice/

  26. Tad ReevesBy Tad Reeves on 13 May, 2009

    Now that’s a pretty slick idea.

  27. Carazoo.com IndiaBy Carazoo.com India on 12 June, 2009

    Nice bit of info. :-)

  28. J. K. Taylor (OneTouch Massage)By J. K. Taylor (OneTouch Massage) on 25 August, 2009

    Thanks, Joost! I was baffled as to why I didn’t have more Twitter referrals showing up in Google Analytics. Even my cligs analytics showed more than Google did. You always have the answer for those little things that bug me.

  29. Cricket ManiacBy Cricket Maniac on 8 September, 2009

    I thought there would be some tracking for those visitors who are visiting my twitter profile

  30. Paul Patrick DaleBy Paul Patrick Dale on 20 October, 2009

    Thank you Joost! I only just arrived at a point where I can use something like this.
    You’re generous to share such great tips and tricks.
    Paul

  31. AshokaBy Ashoka on 21 November, 2009

    Great information as alway, I am going to try this on my site because it’s almost impossible to track twitter traffic as you have so correctly pointed out.
    Thanks again.

  32. ShrinageshBy Shrinagesh on 27 November, 2009

    I’ve been looking for a solution to properly track twitter traffic and stumbled on this post from google. Though I am a frequent reader here, I somehow missed this post. I will check it out to see how this works for us. Thanks Joost

Trackbacks

  1. [...] Sorry that this post has been a bit of a collection of interesting things found elsewhere rather than any new insight. I hope you’ve found it useful – my understanding and use of Google Analytics has improved in leaps and bounds recently so I wanted to share some of the tips with you. I’ll leave you with one more – from Joost again – a fantastic tip on tracking traffic you get from Twitter. [...]

  2. [...] Sorry that this post has been a bit of a collection of interesting things found elsewhere rather than any new insight. I hope you’ve found it useful – my understanding and use of Google Analytics has improved in leaps and bounds recently so I wanted to share some of the tips with you. I’ll leave you with one more – from Joost again – a fantastic tip on tracking traffic you get from Twitter. [...]

  3. [...] Sorry that this post has been a bit of a collection of interesting things found elsewhere rather than any new insight. I hope you’ve found it useful – my understanding and use of Google Analytics has improved in leaps and bounds recently so I wanted to share some of the tips with you. I’ll leave you with one more – from Joost again – a fantastic tip on tracking traffic you get from Twitter. [...]

  4. [...] Sorry that this post has been a bit of a collection of interesting things found elsewhere rather than any new insight. I hope you’ve found it useful – my understanding and use of Google Analytics has improved in leaps and bounds recently, so I wanted to share some of the tips with you. I’ll leave you with one more – from Joost again – a fantastic tip on tracking traffic you get from Twitter. [...]