Back in February, Tom Anthony wrote a couple of great posts on how to detect if visitors were logged into a social network and then how to use Google Analytics to track this information.
After the post, there was some discussion about how there are only 5 CustomVar slots in the standard version of Google Analytics, and how it would be nice to consolidate all the Social Media logged in statuses into a single Custom Var.
Well here is the code and steps to track them all in a single Custom Var slot
1. Read Tom Anthony’s Original Posts
Found here: http://www.tomanthony.co.uk/blog/detect-visitor-social-networks/
and here: http://www.seomoz.org/blog/visitor-social-network-login-status-google-analytics
2. Install The New JavaScript Code
Put this in your <HEAD>
Download the above code here
Then add the following to the bottom of the page, before the closing </BODY> tag:
Download the above code here
NOTE 1: Remember to replace Your-App-Id with your Facebook App Id and http://www.yourdomain.com/pixel.png with a url to an image on your website. (This last line can probably be implemented with just an in-line JavaScript call, but I’m posting this code as-is because it “Works on My Site”)
NOTE 2: The code above is configured to log your Social Traffic login status in Custom Variable Slot 5. Change this number if you want a different slot.
3. Setup Custom Segments
If you setup the code above properly, you should see data similar to this in your Analytics Account under the appropriate CustomVar (#5 in our case):
What you want to do is setup Custom Segments so you can isolate individual networks when the user is logged into multiple networks at the same time. This is very similar to how it was done in the original post, but here are the screen shots for the 4 networks tracked:
Google Plus
Gmail/Google Login
4. View Data in Analytics
Choose your custom segments:
View your beautiful data!
(Note: We had a bug with our Facebook tracking when we initially set this up – hence the strange zero-to-hero traffic spike with Facebook towards the end of the graph)
WordPress Plugins
There are already 2 (that I know of) WordPress plugins that implement Tom Anthony’s initial code:
- Adapt Partners Social Media User Detection WordPress Plugin
- Springest’s Social Analytics WordPress Plugin
And because I can’t take all the credit…











How about checking if the user is logged into LinkedIn as well? That’s all this is missing!
Definitely something that’s missing. I will look into it when I get a chance. Basically, you just need to find an image on Linkedin that is only accessible when a user is logged in — so then you just try to load that image. If it loads, you are logged in. If it doesn’t, then you are not logged in…
Just need to track down an image…
Is it further possible via Facebook to find out who the users are, where they are from, age, etc… so that in addition to getting a total number of visitors from FB, you can also learn a bit about who they are?
Yes indeed. For a little bit more insight on this, check out my post on SEOmoz.org about tracking Age and Gender demographics in Google Analytics:
http://www.seomoz.org/ugc/enhance-your-analytics-with-age-and-gender-demographics