Google Analytics for Search and Social Media Data

Gary Viray

August 20, 2011

The convergence of search, social and content marketing is pretty getting too fast especially that even the search giant, Google never backed up on their quest to get a hand on the social media arena until finally, they seem to have seen the light in Google Plus (+).

So can we say now that the real battle between Facebook and Google is on? I think yes.

On content marketing, Google implemented the famous Panda Update primarily to prioritize real good contents and penalize those ‘thin contents’. After all, the ‘content is king’ mantra never fades away especially now that the said convergence is happening right before our spectacles. Content will remain as king.

Admittedly, I am a search fan and not more of the social one however; having been in the industry for quite sometime, the convergence of search, social and content marketing is becoming the way to go and I need to get the data of these traffic highways consolidated and be part of it else, I will be extinct in no time. You see, not only marketers but even hardcore developers feel the rush to integrate these components to whatever ‘a-ha moments”  that strike them inside their bathrooms, command centers and hubs.

Okay, so much for that. The real reason why I am writing this post is all-about getting your hands dirty on how you can integrate social media data to your search data via the powerful Google Analytics.

Lately, Google Analytics came out with the new interface in order to give traction to their Google plus (they have to admit that!) and that Google plus data are automatically detected once you have in place the G + Button on your website. However; the rest of the social media buttons like Facebook, LinkedIn and Twitter remains to be integrated first before you get to see the data you need.

So how to? Here you go:

To See Your New Google Analytics Interface

1. Login to your Google Analytics Account.

2. Look for the New Version link beside your account. Click it. See Figure below.

go analytics

3. You will be brought the the new Google Analytics interface. Then click the gear below.

google analytics gear

4. Click the Tracking code tab and copy paste your Google Analytics before the </head> tag of your website. This is used to be placed before the </body> tag but not anymore.

google analytics tracking code

Just change the code, UA-xxxxxxxx-x with your unique code generated.

<script type=”text/javascript”>
var _gaq = _gaq || [];
_gaq.push([‘_setAccount’, ‘UA-xxxxxxxx-x’]);
_gaq.push([‘_trackPageview’]);
(function() {
var ga = document.createElement(‘script’); ga.type = ‘text/javascript’; ga.async = true;
ga.src = (‘https:’ == document.location.protocol ? ‘https://ssl’ : ‘http://www’) + ‘.google-analytics.com/ga.js’;
var s = document.getElementsByTagName(‘script’)[0]; s.parentNode.insertBefore(ga, s);
})();
</script>

 Now, here is the next important trick you need to include after putting your Google Analytics code before the </head> tag.

 <script type=”text/javascript” src=”//propelrr.com/ga_social_tracking.js”></script>

Simply copy the script right after the Google Analytics code as is. The end result should look like this one.

<script type=”text/javascript”>
var _gaq = _gaq || [];
_gaq.push([‘_setAccount’, ‘UA-xxxxxxxx-x’]);
_gaq.push([‘_trackPageview’]);
(function() {
var ga = document.createElement(‘script’); ga.type = ‘text/javascript’; ga.async = true;
ga.src = (‘https:’ == document.location.protocol ? ‘https://ssl’ : ‘http://www’) + ‘.google-analytics.com/ga.js’;
var s = document.getElementsByTagName(‘script’)[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
<script type=”text/javascript” src=”//propelrr.com/ga_social_tracking.js”></script>
</head>

Take note of the </head> just below the script, to guide you that you are on the right track.

So you are now ready to install the Facebook Like/Send Button on your website.

1. Login to your Facebook account then simply click on this link -> Social Plugin Like/Share Button Code Generator.

2. Try to customize the Facebook Like/Share button that will suit your website. Then generate the code. You will be given this type of code,

<div id="fb-root"></div><script src="http://connect.facebook.net/en_US/all.js#appId=231657916876765&xfbml=1"></script><fb:like href="//propelrr.com" send="true" width="450" show_faces="false" font=""></fb:like>

Just simply change the appId which is unique for every like/share button generated and the URL with your own website.

3. Another important tracker must be inserted to the generated like/share facebook code is below,

<script type="text/javascript">_ga.trackFacebook();</script>

Inserting it to the Facebook generated script will look like the code below:

<div id=”fb-root”></div><script src=”http://connect.facebook.net/en_US/all.js#appId=231657916876765xfbml=1″></script></script><script type="text/javascript">_ga.trackFacebook();</script><fb:like href=”//propelrr.com” send=”true” width=”450″ show_faces=”true” action=”like” font=””></fb:like>

4. Start integrating the Facebook Like/Share Code + Google Analytics script above to your website wherever you want to place it. But my personal advice is to put the button where is it easier for your visitors to see and click. “Above the Fold” placement should be a good strategy to put in mind.

Now, Let us integrate the Twitter button:

1. Visit this link –> Twitter Button Code generator

2. Enter the URL of your website, customize the look of the twitter button according to your liking and copy the code. It should look like the one below,

<a href=”http://twitter.com/share” data-url=”//propelrr.com” data-count=”horizontal”>Tweet</a><script type=”text/javascript” src=”http://platform.twitter.com/widgets.js”></script>

3. Place the Twitter button code above on your website. I normally place it beside the Facebook button.

4.  Try to place the code below  the Google Analytics tracker code we generated previously,

<!-- Load Twitter JS-API asynchronously -->
<script>
(function(){
var twitterWidgets = document.createElement('script');
twitterWidgets.type = 'text/javascript';
twitterWidgets.async = true;
twitterWidgets.src = 'http://platform.twitter.com/widgets.js';
// Setup a callback to track once the script loads.
twitterWidgets.onload = _ga.trackTwitter;
document.getElementsByTagName('head')[0].appendChild(twitterWidgets);
})();
</script>

5.  In short, your tracking code just before the </head> tag should look like the one below,

<script type=”text/javascript”>
var _gaq = _gaq || [];
_gaq.push([‘_setAccount’, ‘UA-xxxxxxxx-x’]);
_gaq.push([‘_trackPageview’]);
(function() {
var ga = document.createElement(‘script’); ga.type = ‘text/javascript’; ga.async = true;
ga.src = (‘https:’ == document.location.protocol ? ‘https://ssl’ : ‘http://www’) + ‘.google-analytics.com/ga.js’;
var s = document.getElementsByTagName(‘script’)[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
<script type=”text/javascript” src=”//propelrr.com/ga_social_tracking.js”></script>
<!-- Load Twitter JS-API asynchronously -->
<script>
(function(){
var twitterWidgets = document.createElement('script');
twitterWidgets.type = 'text/javascript';
twitterWidgets.async = true;
twitterWidgets.src = 'http://platform.twitter.com/widgets.js';
// Setup a callback to track once the script loads.
twitterWidgets.onload = _ga.trackTwitter;
document.getElementsByTagName('head')[0].appendChild(twitterWidgets);
})();
</script>

</head>

 Let us integrate the Google Plus Button.

1. Insert the code below just before the </head> tag.

<script type=”text/javascript” src=”https://apis.google.com/js/plusone.js”></script>

2. Install the Google Plus Button to your website by copying the code below. You can customize the Google Plus button as usual. You can also visit the Google Plus Code website to get the code .

<g:plusone size=”medium” count=”false”></g:plusone>

 

Important: You should have a Google Plus Profile Account, else this will not work.

Ultimately, the entire Tracking Code just before the </head> tag is now,

<script type=”text/javascript”>
var _gaq = _gaq || [];
_gaq.push([‘_setAccount’, ‘UA-xxxxxxxx-x’]);
_gaq.push([‘_trackPageview’]);
(function() {
var ga = document.createElement(‘script’); ga.type = ‘text/javascript’; ga.async = true;
ga.src = (‘https:’ == document.location.protocol ? ‘https://ssl’ : ‘http://www’) + ‘.google-analytics.com/ga.js’;
var s = document.getElementsByTagName(‘script’)[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
<script type=”text/javascript” src=”//propelrr.com/ga_social_tracking.js”></script>
<!-- Load Twitter JS-API asynchronously -->
<script>
(function(){
var twitterWidgets = document.createElement('script');
twitterWidgets.type = 'text/javascript';
twitterWidgets.async = true;
twitterWidgets.src = 'http://platform.twitter.com/widgets.js';
// Setup a callback to track once the script loads.
twitterWidgets.onload = _ga.trackTwitter;
document.getElementsByTagName('head')[0].appendChild(twitterWidgets);
})();
</script>

<script type=”text/javascript” src=”https://apis.google.com/js/plusone.js”></script>
</head>

Wait for a few hours or at most within 24 hours, and your social media data will start appearing in your Google Analytics.  See screenshots below.