Muschamp Rd

Tracking social media button clicks in Google Analytics

October 2nd, 2013
Social Media Icons

The best way to track social media button clicks is to use a plugin in your CMS, I used Professional Share on this blog for a long time. It has most every feature I want except support for Twitter Cards. I’m hoping the author will add Twitter Card Support as he already supports Facebook Open Graph meta data. Sometimes you don’t have the luxury of a plugin or content management system, I took one of my oldest webpages, a webpage I’ve been maintaing for over a dozen years and I added structured meta data and social media buttons which track in Google Analytics.

Social Media Keeps Changing

I’ve done a lot of work on the problem of tracking social media sharing buttons and although what I documented below works, Facebook and the other social networks have the nasty habit of changing the way things work and introducing new ‘features’. So be sure and look at the source of the linked to webpages to see the latest techniques I’m using and experimenting with.

Google+ is No More

Google+ is of course the easiest social network to track with Google Analytics as Google does it automatically. There is official documentation on tracking Facebook Likes and Tweets in Google Analytics but I found in the real world, you want a bit better instructions. I tried numerous tutorials and none of them seem to have the big 3 social networks along with the proper structured meta data so your content looks the best when it is shared, so I took my HTML and put it into Pastebin.

A Working Example

This isn’t really a tutorial, but it is a webpage which has working social media buttons that track in Google Analytics along with the correct structured meta data so you can copy, paste, and modify. You’ll have to include your Google Analytics tracking code, your Facebook App ID, and your Twitter account and of course your URL when you modify the code below.

Like, Tweet, and +1 tracked in Google Analytics

This is how my Tweets look with Twitter Card support

But What of Pinterest?

I didn’t do Pinterest, probably because I never thought of it, but also because I was using a plugin to dynamically put the Pin button on top of every image for this blog. Pinterest also has a “Pin It” bookmarklet I use, but what most people are probably using is the regular old JavaScript Pinterest button, unfortunantly they are not that easy to track with Google Analytics from what I’ve read.

StackOverflow Has Answers

Here is a screen shot of Google Analytics showing social events for four different social networks on the same page. The actual code can be seen by viewing source on this webpage. I also came across an even more elaborate technique if the one I use doesn’t cut it.

Social Events for Google+, Facebook, Twitter, and Pinterest

Twitter and Pinterest work best of all the social networks IMHO

Tracking Social Media Remains Hard

I finally tried to use code like this in my day job, it didn’t go perfectly. I don’t understand why structure meta data and social sharing buttons don’t work perfectly every time. It is enough to almost make me switch to one of the sleazy share bars.

More Links

If you have any advice on tracking social media shares you can leave them below. I’ve switched to Yoast’s plugin for my structured metadata but I’ve also removed social sharing buttons to increase page load speed especially inside the Great Firewall of China.

3 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Posts on Muskblog © Andrew "Muskie" McKay.
CFA Institute does not endorse, promote or warrant the accuracy or quality of Muskblog. CFA® and Chartered Financial Analyst® are registered trademarks owned by CFA Institute.