Lee Willis

Tracking Twitter Traffic

| 2 Comments

Twitter is a revolution

So, Twitter is a revolution (Apparently). The important thing about Twitter isn’t that you can find out what Stephen Fry had for lunch, or when Oprah is having her makeup done. No, the important thing, for people trying to use Twitter as a a weapon in their digital marketing arsenal, is that Twitter traffic is 10x higher through their API, than through their website.

What is Twitter doing for you?

So what does that mean for Average Joe Ltd. trying to engage with his customers in a brave new digital world?

Simple – links that you post are likely to get read on a mobile phone, or in any one of hundreds of different desktop clients . There’s every chance that if someone clicks through to your site you will have no idea that they came from a Twitter link (Desktop clients particularly tend not to send the all-important HTTP-Referrer information).

So – what’s to be done?

For SnugBaby, as well as twittering as a normal user, we use the excellent WordPress “Twitter Tools” plugin to tweet when we update our blog. So – how to track how much traffic we were generating from these links? Fortunately there’s a fairly straightforward solution to the problem. We analyse our traffic using Google Analytics, which provides the ability to “tag” links with extra information. This is commonly used to track inbound links relating to specific marketing, or email campaigns – but we use it to track Twitter as a campaign all of it’s own. This is nothing new.

However – our blog-related links are tweeted automatically – so we needed to make some changes to the Twitter Tools plugin to add on the tracking codes.

The Solution

For those that are interested I’ll step through the changes below – but if you want a quick twitter tracking fix, then you can download a patch (Against version 1.6 of twitter tools), or a complete copy of the twitter-tools.php file.

Step 1. Flexibility is king

We want to make our solution a little bit flexible, so we set up the tagging as a setting which can be controlled through the WordPress admin pages. We called it extra_query_args:

Line 120-146:
	$this->options = array(
			'twitter_username'
			, 'twitter_password'
			, 'create_blog_posts'
			, 'create_digest'
			, 'create_digest_weekly'
			, 'digest_daily_time'
			, 'digest_weekly_time'
			, 'digest_weekly_day'
			, 'digest_title'
			, 'digest_title_weekly'
			, 'blog_post_author'
			, 'blog_post_category'
			, 'blog_post_tags'
			, 'notify_twitter'
			, 'sidebar_tweet_count'
			, 'tweet_from_sidebar'
			, 'give_tt_credit'
			, 'exclude_reply_tweets'
			, 'last_tweet_download'
			, 'doing_tweet_download'
			, 'doing_digest_post'
			, 'install_date'
			, 'js_lib'
			, 'digest_tweet_order'
			, 'notify_twitter_default'
			, 'extra_query_args'
		);

We also provide a sensible default for people installing the first time:

Line 178:
$this->extra_query_args = '?utm_source=twitter&
utm_medium=twitter&utm_campaign=twitter';

The final step is to build the form that will let users change the value of the new parameter:

Line 1580:

<div class="option">
  <label for="aktt_extra_query_args">'.__('Text to tag on
the end of URLs in generated tweets', 'twitter-tools').
'</label>
  <input type="text" size="30" name="aktt_extra_query_args"
id="aktt_extra_query_args" value="'.$aktt->extra_query_args
.'" />
  <span>'.__('Include the leading ? before query args',
'twitter-tools').'</span>
</div>

Step 2. The magic bit

The final change simply adds the contents of your parameter onto the end of the post URL before passing it off to the URL shortener.

Line 466:

$url = $url . $this->extra_query_args;

Job Done

And that’s that. Twitter tools will now post URLs that include tracking information – all you have to do know is keep an eye out for them in Google Analytics!

2 Comments

  1. This can be done as a separate supplemental plugin to Twitter Tools, using the hook to the URL that is provided (read the README).

  2. Pingback: 10 Essential Wordpress Plugins | leewillis.co.uk

Leave a Reply

Required fields are marked *.