In our previous post,[Asynchronous Tracking Code Migration from ga.js.] we discussed why Asynchronous tracking code is important and what are the methods to execute the migration process We are going to discuss some more of such methods in this post. Recently Google has announced that it will consider the site speed as a factor for the SERP in their official Analytics blog [ http://analytics.blogspot.com/2010/04/making-web-faster.html ], so how about considering Asynchronous tracking code to increase the site speed?

Cross Domain Tracking
In this post we will discuss deeply on cross domain tracking migration for the following conditions:

  • How to track a single sub directory
  • How to track two subdirectories on a same domain
  • How to track a domain and subdirectory of another domain
  • How to track a domain and sub domains


How to track a single sub directory

If you create a blog for your website as a folder like http://www.yourwebsite.com/blog Now you want to see the stats of this folder alone on analytics then you need to use _setCookiePath() method. Here is the migration guide for this

Traditional ga.js Medhod
var pageTracker = _gat._getTracker(“UA-12345-1″);
pageTracker._setCookiePath(“/blog/”);
pageTracker._trackPageview();

Asynchronous Method:
_gaq.push(['_setAccount', 'UA-12345-1']);
_gaq.push(['_setCookiePath', '/blog/']);
_gaq.push(['_trackPageview']);

While you use the _setCookiePath() then you need to consider the following points.

  • Your visitor statistics like new vs returning, time on site and number of visits might be incorrect because of your cookie might reflect in other parts of your website
  • Your reports might reflect campaign details from another store

How to track two subdirectories on a same domain:
If you want to track two subdirectories in your site then you need to use one more method for the second subdirectory viz _cookiePathCopy(). For example, if you want to track your blog and event subdirecories then you need to place _setCookiePath() and _cookiePathCopy().

Traditional ga.js Method:
var pageTracker = _gat._getTracker(“UA-12345-1″);
pageTracker._setCookiePath(“/blog/”);
pageTracker._cookiePathCopy(“/event/”);
pageTracker._trackPageview();

Asynchronous Tracking Method:
_gaq.push(['_setAccount', 'UA-12345-1']);
_gaq.push(['_setCookiePath', '/blog/']);
_gaq.push(['_cookiePathCopy', '/event/']);
_gaq.push(['_trackPageview']);

How to track a domain and subdirectory of another domain
One more criteria is tracking a full domain and a subdirectory of another domain. This will happen when you have an online store but you can use a 3rd-party website for your shopping cart, where you have limited access to a sub-directory of that site. You need to place two codes for your online store and the subdirectory of the 3rd-party website. For example, if your primary site is http://www.example.com and the subdirectory of another domain is http://www.example-site.com/shopping-cart then, you need to place the below code:

Primary: http://www.example.com/
Traditional ga.js Tracking:

var pageTracker = _gat._getTracker(“UA-12345-1″);
pageTracker._setAllowLinker(true);
pageTracker._setAllowHash(false)

Asynchronous Tracking Method:
_gaq.push(['_setAccount', 'UA-12345-1']);
_gaq.push(['_setAllowLinker', true]);
_gaq.push(['_setAllowHash', false]);

Subdirectory of another domain: http://www.example-site.com/shopping-cart
Traditional ga.js Tracking:
var pageTracker = _gat._getTracker(“UA-12345-1″);
pageTracker._setDomainName(‘none’);
pageTracker._setAllowLinker(true);
pageTracker._setAllowHash(false);

Asynchronous Tracking Method:
_gaq.push(['_setAccount', 'UA-12345-1']);
_gaq.push(['_setDomainName', 'none']);
_gaq.push(['_setAllowLinker', true]);
_gaq.push(['_setAllowHash', false]);

Whereas we need to pass the cookie values from the primary domain to the subdirectory of another domain using the following methods _linkByPost() and _link(). Using onsubmit() event we can pass our datas to the 3rd-party subdirectory shopping cart.

Traditional ga.js Tracking:
<form name=”f” method=”post” onsubmit=”pageTracker._linkByPost(this);”>

Asynchronous Tracking:
<form name=”f” method=”post” onsubmit=”_gaq.push(['_linkByPost', this]);”>

How to track a domain and sub domains:
If we want to track the subdomains of a website then we have useed the method called _setDomainName() to separate the vistitor data.
Suppose we take the following as our example

  • http://www.example.com
  • http://www.blog.example.com
  • http://www.event.example.com

Traditional ga.js Tracking:
var pageTracker = _gat._getTracker(“UA-12345-1″); pageTracker._setDomainName(“.example.com”);
pageTracker._trackPageview();

Asynchronous Tracking:
_gaq.push(['_setAccount', 'UA-12345-1']);
_gaq.push(['_setDomainName', '.example.com']);
_gaq.push(['_trackPageview']);

Use the migration guide and change your traditional tracking code into Asynchronous tracking code to increase the site speed and get better tracking data.

Popularity: 10%

Leave a Reply:

5 Responses to “Asynchronous Tracking Migration Part- II”

commenter

This is a wonderful post! But you got the onsubmit functions round the wrong way on:

Traditional ga.js Tracking:
<form name=”f” method=”post” onsubmit=”_gaq.push(['_linkByPost', this]);”>

Asynchronous Tracking:
<form name=”f” method=”post” onsubmit=”pageTracker._linkByPost(this);”>

commenter

Thanks for your kind information, we have modified the necessary changes in the blog post.

commenter

Send me which are the search engine your would like to receive the report

commenter

Hi.. Thanks for sharing this ..

Can anyone help me out how to add analytics code for the domain and the subdirectory of that same domain???
ex:- http://www.example.com and http://www.example.com/site

DCIBlog_Live | May 12th, 2011 at 1:40 pm
commenter

Normally, your subdirectories are normally tracked by Google Analytics if you track your website. If you want to separate the traffic from your subdirectory alone then you can create a separate profile with the subdirectory filter.

Leave a Reply:

Name (required):
Email Address (required, not published) :
Website :
Comment (required):

Contact Us :

Dot Com Infoway, a CMMI Level 3 multinational information technology company, is a pioneer in delivering software development, mobile application and Internet marketing solutions and technologies to businesses. With offices in India, the United States and Netherlands, DCI is positioned to become a leader in delivering advanced IT services for your business.

For more information, email ask@dotcominfoway.com or visit our Contact Page.

Follow Us :

Dot Com Infoway

Tailored to meet international standards and client expectations, our methodology ensures proper risk management, seamless work flow and deadline-oriented development. It has built-in processes to monitor stringent adherence to quality, consistency in performance and accomplishment of project milestones. Our well-defined and flexible business model is a result of our deep industry intelligence and vast experience. Adhering to industry standards, our business model facilitates enterprises to get the best-of-breed solutions at affordable prices and top-notch quality.

Our privacy policy explains how we use and protect any information that you provide when you use our website. With high standards of security, we ensure that your valuable data is protected from misuse, loss or any external amendment.