Free Javascripts for Google Analytics

 
 
 
 

Want to implement cross domain tracking across several domains i.e. main domain to sub-domain and/or third party domains. You can implement using this Javascript code (requires jquery) which would automatically update anchor links with _link function to pass cookie information and all the forms with _linkbypost function of GA which points to sub domains or 3rd party domains.

Note: This code requires jquery.

 $(document).ready(function(){

	// Creating custom :external selector

	$.expr[':'].external = function(obj){
		return !obj.href.match(/^mailto\:/) && !obj.href.match(/^javascript\:/) && (obj.hostname != location.hostname);
	};

}


This JavaScript, that you can use in Google Analytics or Google Tag Manager, will provide insight as to how much proportion of page is viewed by user. This JavaScript will populate scroll % data in Events report in Google Analytics. Event reports will provide information of how much % scroll occurs on a given page. Using scroll tracking you can identify if users are using scroll to consume content on in-below-the-fold pages. With the insights from scroll analysis, you can restructure the content of different webpages for optimal consumption.

Note: This code requires jquery.

 $(document).ready(function() {

  $(window).bind('scroll ready',function(event){updateResult();});

  $(document).bind('scroll ready',function(event){updateResult();});

});


This JavaScript, that you can use with Google Analytics or Google Tag Manager, will provide insight as to how many visitors are clicking on links that are external to the website or mailto links or document download links. The data with this JavaScript will be available in Event tracking reports in Google Analytics.

Note: This code requires jquery.

// Creating custom :external selector
$.expr[':'].external = function(obj){
	return !obj.href.match(/^javascript/) && (obj.hostname != location.hostname);
};


There are many websites which have many Query Parameters as part of the URL. Sometimes these query params provide key insights of user's actions on website. This script when used with Google Analytics or Google Tag Manager, can take specific value of parameters and push it into event tracking or in custom variable. The data will be available in Google Analytics events report or Custom Variable reports.

Note: Needs your modification depending on your URL query parameters.

 //parse url parameters and convert it into array object
var urlParams = {};
(function () {
    var e,
        a = /\+/g,  // Regex for replacing addition symbol with a space
        r = /([^&=]+)=?([^&]*)/g,
        d = function (s) { return decodeURIComponent(s.replace(a, " ")); },
        q = window.location.search.substring(1);
	console.log(q);

    while (e = r.exec(q))
       urlParams[d(e[1])] = d(e[2]);
})();


Visitor ID script helps you tag your each visitor with randomly generated number and assigns it to custom variable on visitor level so you can analyze visitors information anonymously for your website and get more insights.

 var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXXXX-1']); //set UA id
_gaq.push(['_setDomainName','none']); //set domain name
// set visitor id to the custom variable slot 1 and visitor 
// level this code can be called before 1st page view or 
// you'll need to call another trackevent or trackpageview call


This script, when used with Google Analytics or Google Tag Manager, can help you identify how your users are navigating through various pages. This script stores dynamically generated visitor id and sets a cookie value for each page viewed. On each page view or refresh counter is incremented by one. Which is sent to GA using trackEvent or trackPageview call. For further customization you can contact us or comment on the blog

Note: This code requires jquery.

{
  tat_nc = tat_nc + 1;
  setCookie('tat_nc1', tat_nc);
}

var n = window.location.pathname.substr(1);

_gaq.push(['_trackPageview', '/vp/pgc/' + n + "|" + tat_nc]);


 
 
 
 
Sep 09
Upcoming Webinar
 
How Online Retailers Can Benefit from Enhanced Ecommerce? Know more
 
 
 
From the Blog

Anonymous Tracking of visitor using visitor id

When a user visits your website and performs any activity involved with your website. i.e. viewing videos, purchas...... Read more

Web Page Sequencing Analysis Using Google Analytics

Recently on a project, we were trying to implement the network path diagram and carry out an analysis with website...... Read more

 
Webinar

What is Universal Analytics & How it Can Help Your Business Grow

 
Who should attend

CMO, Digital Marketing Managers, eCommerce Store Owners