Perhaps you saw the articles a couple of weeks ago, indicating that Google had officially announced that its Google Analytics product was now able to track social media interaction. As the linked article mentioned, this is a welcome addition to the built-in capability of the Google +1 button to track clicks. However, this bit of news was soon overshadowed by all the buzz surrounding the (as yet, despite being enormous, and frequently discussed) beta of Google+ – the new Google social platform.
We had seen the articles and sort of filed them away for future reference. A friend got in touch last week, however, asking how to implement this, and indicating that the information wasn’t very clear. After reading the official documentation, we certainly had to agree. However, after a bit of testing, we were able to get it to work, and provide the results here, in case you’d like to use Google Analytics to track various social interaction on your website, blog, or whatever.
What we’re trying to accomplish
For the rest of us, there are three pieces of code to insert (We haven’t attempted to use anything but Facebook and Twitter – though the same principle would work with any; also Google +1 forwards data to GA automatically, so there is no need to do anything special for it), and of course a couple of prerequisites.
- You will need to be able to add files to your web server, and edit the page(s) you want the tracking to work on.
- You must have Google Analytics tracking code on the site (I’m not sure if you have to use async code, but I suspect you do)
- You must be using the “New” GA – so it will show Social under the Visitors area.
- Grab the ga_social_tracking.js file from Google and put it in the same location as the page to be tracked (or change the path to the js file in the first script tag under Code step 1).
Code needed to make this work:
- In the section of the page (I would suggest after the GA code, but don’t know if that is mandatory), add:
- Where you want the buttons to appear, put
a. for Twitter
<a href="http://www.twitter.com/share" data-url="http://www.YOURSITE.com" data-via="YOURTWITTERID" class="twitter-share-button">Tweet</a>
You can leave off the data-via line if you don’t want tweets to show up in your twitter feed. Obviously change YOURSITE and YOURTWITTERID to the appropriate values. The Twitter documentation allows for other ways to create a Twitter button. This is just one example. Feel free to play with others, but you may have to make other changes if it doesn’t work the same way as this example.
b. for Facebook
This is the simple version for creating a “simple” Facebook “Like” button. For other types, you can see the Facebook developer documentation. Here is one other example:
Put this in place of the
<fb:like href="http://www.YOURDOMAIN.com/PAGETOTRACK" send="true" show_faces="false" layout="button_count"></fb:like>
Then change YOURDOMAIN.com to your domain, and PAGETOTRACK to the path and page you want to have the button track. Do not omit the div with the fb-root id.
- Just before the closing body tag on the page, put
Done and done.
Social activities seem to show up in the new Google Analytics within an hour or so.