{{ searchResult.published_at | date:'d MMMM yyyy' }}

Loading ...
Loading ...

Enter a search term such as “mobile analytics” or browse our content using the filters above.

No_results

That’s not only a poor Scrabble score but we also couldn’t find any results matching “”.
Check your spelling or try broadening your search.

Logo_distressed

Sorry about this, there is a problem with our search at the moment.
Please try again later.

Chris Lake's earlier post How Econsultancy measures Twitter via Google Analytics gave some great insight into how Econsultancy was already tracking Twitter, and what trends it was observing.

However, inward traffic is only part of the picture, and with some additional tweaks it's possible to get a shedload of additional data on Twitter usage which could be used to further improve social media performance.

While it's possible to track inward links to your site from Twitter without the need to undertake any site alterations, if you want to measure how many people click the 'Follow' or 'Tweet' buttons on your site you're going to need the assistance of a web developer.

That said, the code required is really straightforward, quick and inexpensive to implement, and there are some code examples below that you can show your developers to help get them started. All of this can be done in less than an hour.

Create your tweet button

Twitter provides some really good buttons for adding to your site and it's fairly simple to add tracking to these so the data appear within your Google Analytics account.

Unfortunately, as Josh Cunningham kindly pointed out, the widgets use JavaScript to write an iframe, so although it may appear simple to track, the tracking isn't passed back to Google Analytics. Instead, you'll either need to use a static button image or use the Topsy JavaScript widget instead.

You can manually create the button code using the tool on the Twitter site. and then use a server-side language, such as PHP, to write in the necessary content to make it work dynamically across every page on your site.

The code you need to add will look something like this:

The url field contains the URL of the page you're allowing the user to Retweet, while the title holds the title. To add your Twitter username you'll need to add an extra line of code. You can also change the style of the button.

Including the tweet button in a prominent position on your page will make it easy for your visitors to tetweet your content and share it with their followers, increasing your brand exposure on Twitter and bringing additional traffic.

However, although you'll be able to view any incoming traffic in your Google Analytics profile, things would be neater if the incoming visits were assigned to a specific area of your account, making analysis and monitoring far easier. To do this, a few tweaks are needed.

Track incoming visits from Twitter

The first thing to do is to add Google Analytics campaign tracking to the URL. Add a question mark to the end of the URL and then append your tracking parameters to the end using an ampersand to separate each name=value pair. (If there's already a question mark in your URL, you'll need to use an ampersand to append the first of the tracking parameters).

You will need to define the utm_medium (I've called this Social), the utm_source (I've called this Twitter), the utm_campaign (I've called this TweetButton) and the utm_term (I've used a URL-friendly version of the article title).

These are case sensitive, so you'll need to make sure you use either twitter or Twitter, not both.

You'll then need to get your developer to use a server-side language to write this data into your Tweet button HTML. It's very easy to do this using either raw PHP or a templating engine such as Smarty.

When a user clicks the Tweet button, the widget JavaScript will send the user to Twitter.com allowing the user to add some text and Tweet your post. The long URL will be shorted using the bit.ly URL shortening service and your campaign tracking code will be preserved and hidden.

Anyone who clicks the shortened URL will come back to the site via a link containing embedded tracking parameters which Google Analytics will detect and use to segment the visit using the parameters you provided.You'll be able to find the data under Traffic Sources > Campaigns, as well as in the Traffic Sources > Overview and other sections.

If you're using the Twitter API to auto-Tweet new content to your Twitter feed you really ought to be using the campaign tracking in there too. The auto-Tweets should be tagged in a similar way, but it makes sense to give them a different campaign name so you can track the original source.

Track on-site follows and tweets

Now we've got campaign tracking parameters added to our URLs we can move on to the really good bit: tracking the people who are sharing your content via the Tweet button or clicking the Follow button on your site.

While the debate on how to measure the value of Tweets and Follows is ongoing, it's clear that they've got some value, so it makes sense to measure them and do what you can to try and optimise your site to get people to click them.

In order to track an outward click in Google Analytics you need to use an HTML onclick handler to trigger a JavaScript event.

Clicking a Tweet or Follow button which contains a custom onclick handler will send a bit of information back to the Google Analytics tracking code before the user gets transferred to the destination URL, allowing the click to be categorised and tracked in your GA account.

The flexibility of Google Analytics means that there are two different ways to track events like these: event tracking and virtual pageviews. The method you choose is entirely up to you, but there are pros and cons to each one that you'll want to consider before taking the plunge.

In a nutshell, virtual pageviews will only track the item being shared and add it to your page views data. However, they can be used as a goal in all versions of Google Analytics and in Google Website Optimizer.

Event tracking allows you to send more information to your GA account, but they can only be used as goals in the next version of GA, which most of us don't have yet. They also have the bonus of not artificially inflating your page views, as virtual pageviews can.

Event tracking

With event tracking you can pass up to four different values to Google Analytics. The first two - category and action - are essential, but the second two - label and value - are optional.

The data collected will appear under Content > Event Tracking > Categories in your GA account, and you'll be able to drill-down among the results to see further details on the event.

For the tweet button I'd suggest using the same category and action but a label which more accurately reflects the content being shared, perhaps something like "Tweet - How Econsultancy measures Twitter with Google Analytics", where that's the title of the post being shared.

This is sent to GA using _gaq.push(['_trackEvent','Social','Twitter','Tweet - How Econsultancy measures Twitter with Google Analytics']); inside an onclick handler for the button anchor code.

To track clicks on your Follow button I'd recommend using "Social" for the category, "Twitter" for the action and "Follow" for the label.You can do that by using the following code: _gaq.push(['_trackEvent','Social','Twitter','Follow']);

Virtual pageviews

Compared to event tracking virtual pageviews seem a bit crude, and given that the next version of GA allows you to use event tracking as goals, I can only assume that they'll eventually be deprecated.

The idea with virtual pageviews is that you provide a fake chunk of URL to Google Analytics, which it adds to your other data. You can then create advanced segments based around key chunks of the fake URL allowing you to pull out more information that just the URL alone.

To track a Tweet button using a virtual pageview we might pass a URL like this to GA: /social/twitter/tweet/how-econsultancy-measures-twitter-via-google-analytics.

We can then create advanced segments to pull in all of the data for /social/, /twitter/ or /tweet/ as well as being able to view individual posts to see how many times they've been tweeted from your site.

The bonus is, you can also set up goals allowing you to easily monitor how many Tweets or Follows you've had over any given period. Very handy. Though in a month or two when Google Analytics 5 comes out of beta you'll be able to do the same with event tracking.

Accessing the data in Google Analytics

You can view the data you've collected on incoming visitors, users clicking your Tweet button or users using the on-site Follow button through the regular Google Analytics interface, but the easiest way to access the data is to create a series of advanced segments. This sounds complicated but it's actually dead easy.

Create an advanced segment for users from Twitter

You can easily separate all of the users who've come to your site from Twitter via the URLs you tagged with campaign tracking variables. You just need to make an advanced segment to look for "twitter" in the Medium, as this pulls in the data you sent in utm_medium.

1. Click Advanced Segments > All visits > Create a new advanced segment.

2. Click Dimensions > Traffic Sources, then drag Medium to dimension or metric.

3. Set Condition to 'Matches exactly' then enter 'twitter' (or whatever medium you defined in your code above).

4. Give the segment a name > Create segment.

5. Or, click here to add this segment to your Google Analytics account.

Create an advanced segment for an event

If you went down the event tracking route, you can create an advanced segment for the users who clicked the Tweet button or clicked the Follow button by looking for the word "tweet" or "follow" in the event label. You'll need to create one advanced segment for the tweeters and one for the followers.

Twitter follows from event tracking

1. Click Advanced Segments > All visits > Create a new advanced segment.

2. Click Dimensions > Content, then drag Event Label to dimension or metric.

3. Set Condition to 'Matches exactly' then enter 'follow'.

4. Give the segment a name > Create segment.

5. Or, click here to add this segment to your Google Analytics account.

Twitter tweets from event tracking

1. Click Advanced Segments > All visits > Create a new advanced segment.

2. Click Dimensions > Content, then drag Event Label to dimension or metric.

3. Set Condition to 'Matches exactly' then enter 'tweet'.

4. Give the segment a name > Create segment.

5. Or, click here to add this segment to your Google Analytics account.

Creating an advanced segment for a virtual pageview

Setting up advanced segments for data you're capturing via virtual pageviews is much the same, you just need to pull in the data from the Page dimension under Content.

Twitter Tweets from virtual pageviews

1. Click Advanced Segments > All visits > Create a new advanced segment.

2. Click Dimensions > Content, then drag Page to dimension or metric.

3. Change Condition to 'Contains' then enter '/twitter/tweet/'.

4. Give the segment a name > Create segment.

5. Or, click here to add this segment to your Google Analytics account.

Twitter Follows from virtual pageviews

1. Click Advanced Segments > All visits > Create a new advanced segment.

2. Click Dimensions > Content, then drag Page to dimension or metric.

3. Change Condition to 'Contains' then enter '/twitter/follow/'.

4. Give the segment a name > Create segment.

5. Or, click here to add this segment to your Google Analytics account.

Take-home tips

  1. Create a solid URL tagging strategy for all of your inward links and make sure everyone uses it.
  2. Track all outgoing URLs from auto-Tweets, Tweet buttons and widgets.
  3. Track clicks to the Follow and Tweet button using either virtual pageviews or event tracking. 
  4. Create advanced segments to allow easier access to data in GA.
  5. Create a separate profile in your GA account and apply a filter to pull in all of your Twitter data.
  6. Don't forget to pull in untagged data from twitter.com or mobile.twitter.com.
  7. Create additional segments to see what proportion of your users are using mobile devices.
  8. Create goals based around Twitter Follows and Tweets and assign values to them.
  9. Use Google Website Optimiser to test the best place and button type to promote Tweets and Follows.
Matt Clarke

Published 22 March, 2011 by Matt Clarke

Matt Clarke is E-commerce Manager at Swell Uk and a contributor to Econsultancy. Follow him on Twitter , Google + or connect via LinkedIn

5 more posts from this author

Comments (11)

Comment
No-profile-pic
Save or Cancel
Avatar-blank-50x50

Nick Stamoulis

This is a great breakdown of how to use Google Analytics to track Twitter activity. Analytics are still something many website owners are comfortable with and don't really know how to use to their full advantage. Hopefully this breakdown will give them a clearer picture of what they can do with Analytics and how much information it can provide.

over 5 years ago

Avatar-blank-50x50

Lucy Temple

Hi
Thanks for this- really useful. I'm used to using GA to track campaigns and incoming clicks with source, medium and campaign parameters, but haven't used the on-site tracking before.

Just one question though- wouldn't it be a lot easier to use a third party share widget like Add This which tracks shares and clickbacks to your site? Is the extra data you get in Analytics worth it do you think?

over 5 years ago

Avatar-blank-50x50

Josh Cunningham

This would be great if it actually worked :) The problem is that the Tweet button JS replaces that seemingly easy-to-track anchor element with an iframe that will not register onclick events (like all iframes).

We were trying for a while to get this to work and had to switch to a different button, the Topsy one. Not as pretty but we really wanted to see the click tracking.

over 5 years ago

Paul Shearing

Paul Shearing, Head Of Product Development at Search Laboratory

A great post giving a clear way to gain some insight from your twitter efforts.

Can I just point out the obvious that this only takes care of people that use the buttons you have control over that you place on your pages. If people use a toolbar, for example then any URL shortener would not add the tags.

There is not much you could do about this but I would recommend that people also include the traffic where 'referral = twitter' as well as the 'medium = twitter'.

over 5 years ago

Matt Clarke

Matt Clarke, Ecommerce Director at B2B

Thanks for the feedback.

@Lucy: I've not used Add This before, but I think it provides its own analytics dashboard. This looks quite good actually, and contains additional data, but it's not integrated into GA, as far as I can see. The benefit of having the data in GA is that you can compare it to other campaigns and segment it more easily.

@Josh: Thanks a lot for pointing that out! My apologies. I've updated the examples to use Topsy instead.

over 5 years ago

Avatar-blank-50x50

lee

So how do you use topsy for the follow code?

over 5 years ago

Avatar-blank-50x50

maps4pets

We will be definitely running this past our webmaster. Can you tell me what software the more advanced Social Media managers use to get ROI figures please? Ie: the big agencies etc

over 5 years ago

Matt Clarke

Matt Clarke, Ecommerce Director at B2B

@Lee: For the Follow buttons, I'd recommend using any Twitter button of your choice - there's a selection on the Twitter site - and then just attaching the required onclick to the image href link. This is the onclick part: _gaq.push(['_trackEvent','Social','Twitter','Follow']);

@maps4pets: Not sure what everyone else is using. Google Analytics will give you fairly decent data on traffic coming in and going out. If you want engagement metrics or any of the more advanced stuff, I'd recommend taking a look at Twitalyzer.

over 5 years ago

James Gurd

James Gurd, Owner at Digital JugglerSmall Business Multi-user

Hi Matt,

Superb post, great detail and insights. Sorry for the delay in commenting, still catching up with reading after my travels.

Have you ever come across/use Tynt? I found it through Avinash Kaushik's blog - it is complimentary to what you're recommending here.

It uses js to track people who copy and paste your content. We know from the data that most visitors don't retweet, leave comments, like etc - it's only a small % of the audience. The Tynt tool captures another type of engagement - those who just copy and paste from websites to share (often via email).

Avinash explains it far better than I can so here's the link: http://www.kaushik.net/avinash/viral-social-sentiment-mobile-data-web-analytics-tools/

thanks
james

almost 5 years ago

Avatar-blank-50x50

Boatwright

Hey there! I've been following your web site for a while now and finally got the courage to go ahead and give you a shout out from Houston Tx! Just wanted to say keep up the excellent work!

about 4 years ago

Avatar-blank-50x50

Ngo

Fantastic as usual, keep up the radical work!

almost 4 years ago

Comment
No-profile-pic
Save or Cancel
Daily_pulse_signup_wide

Enjoying this article?

Get more just like this, delivered to your inbox.

Keep up to date with the latest analysis, inspiration and learning from the Econsultancy blog with our free Daily Pulse newsletter. Each weekday, you ll receive a hand-picked digest of the latest and greatest articles, as well as snippets of new market data, best practice guides and trends research.