Site icon Shaharia's Blog

Click Tracking – How to track click with Google Analytics

Since long days I was looking for a perfect system to track clicked link in my company website and at last I made the solution. Basically it’s easy to track click with the help of Google Analytics, jQuery or simple javascript. My solution has given below-

<!–Google Analytics Code–>
<script type=”text/javascript”>
var _gaq = _gaq || [];
_gaq.push([‘_setAccount’, ‘UA-17736742-1’]);
_gaq.push([‘_setDomainName’, ‘previewict.com’]);
_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>
<!–End analytics–>
<script type=”text/javascript”>
//This is the extra code to track click
$(document).ready(function(){
$(“a[href^=’http://’]”).click(function(){
//pageTracker._trackEvent(“links”, “TestPurpose”, $(this).attr(“href”), 0);
//_gaq.push(“links”, “TestPurpose”, $(this).attr(“href”), “Preview ICT”);
url = $(this).attr(‘href’).replace(/^#/, ”);
_gaq.push([‘_trackEvent’, ‘WEBService’, ‘click’, $(this).attr(‘href’)]);
});
});
</script>

The last portion of the above code is the solution to track all <a> tag’s href value which will be clicked. it’s the mechanism of Google Analytics Event tracking feature. I have tested it and successfully I can track link now.

Before placing the code inside you <head> tag you must add Jquery script above all this code. You can use https://www.previewict.com/web/js/jquery-1.6.2.min.js this link or you can use your latest jQuery framework to run the above code precisely.
After placing the code inside <head> tag you can be able to see the clicked event tracking report from your Google Analytics ‘Custom Reporting’->Content->Event->Overview like the below image-

That’s all.

To know more details about Google Analytics you can follow me on the following social site-

Don’t forget to add me in your Google+ circle and don’t forget to bookmark this webpage coz I will write lots of writes up here regarding many interesting feature of Google Analytics.

Exit mobile version