Our website uses cookies to improve your user experience. If you continue browsing, we assume that you consent to our use of cookies. More information can be found in our Cookies Policy and Privacy Policy.

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.

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.

If a new startup called Color has its way, photo sharing will never be the same. The company is creating a completely smart phone-based ‘social network‘ of sorts for photos, but instead of focusing on people, it’s focusing on location, a concept some have likened to Twitter-for-pics.

Companies are pouring billions of dollars a year into social media and influencer marketing campaigns, many of which target consumers on Facebook-owned Instagram, in an effort to parlay social engagement into sales.