Google analytics tracking between domains

Updated: There is often a need for Google Analytics tracking between domains. Between your website, and a third party secure server that you are able to add code to, or maybe another secure server in your group of websites.

There is new Google analytics code as at January 2008. Please see the tracking code for multiple domains on the Google website, and their full Google analytics documentation.

Some Extras to Add to the tracking javascript

The standard new tracking code is below. There are two lines that need to be added (in bold) to allow for tracking between domains.
<script type="text/javascript"> var gaJsHost = (("https:" == document.location.protocol) ? " https://ssl." : "http://www."); document.write("<script src='" + gaJsHost + "google-analytics.com/ga.js ' type='text/javascript'></script>" ); </script>

<script type="text/javascript">
var pageTracker = _gat._getTracker("UA-12345-1");
pageTracker._setDomainName("none");
pageTracker._setAllowLinker(true);

pageTracker._trackPageview();
</script>

On the thank-you page, you need to then add the following code:
Per Google - tracking Ecommerce transactions

Begin with a call to _addTrans() to establish a transaction. _addTrans() takes the following arguments: Order ID,Affiliation, Total, Tax, Shipping, City, State, Country. For each item that the visitor purchases, call _addItem(). _addItem() takes the following arguments: Order ID, SKU or Code, Product Name, Category, Price, Quantity.

Here is a complete example:
<script type="text/javascript"> var gaJsHost = (("https:" == document.location.protocol) ? " https://ssl." : "http://www."); document.write("<script src='" + gaJsHost + "google-analytics.com/ga.js ' type='text/javascript'></script>" ); </script>

<script type="text/javascript">
var pageTracker = _gat._getTracker("UA-12345-1");
pageTracker._setDomainName("none");
pageTracker._setAllowLinker(true);
pageTracker._initData();
pageTracker._trackPageview();

pageTracker._addTrans(
"1234", // Order ID
"Mountain View", // Affiliation
"11.99", // Total
"1.29", // Tax
"5", // Shipping
"San Jose", // City
"California", // State
"USA" // Country
);

pageTracker._addItem(
"1234", // Order ID
"DD44", // SKU
"T-Shirt", // Product Name
"Green Medium", // Category
"11.99", // Price
"1" // Quantity
);

pageTracker._trackTrans();
</script>


And now for the main domain

Rather than:
<a href="https://www.seconddomain.co.nz/register.php">register</a>


change to:
per Google -
http://www.google.com/support/googleanalytics/bin/answer.py?hl=en&answer=55532
<a href="https://www.securecart.com/?store=parameters" onclick="pageTracker._link(this.href); return false;">Purchase Now</a>

If you are using a form to post to, have the following details:
- works for post and get forms
<form action="http://newdomain.com/form.cgi" name="post_form" method="post" onsubmit="pageTracker._linkByPost(this)">

Get domain to show in Google Analytics reports

per Google - By default, the data in your reports will only include the Request URI and not the domain name. If you'd like to see the domain names in your reports, you can create an Advanced filter for your profile with the following settings:

Filter Type : Custom filter > Advanced
Field A : Hostname Extract A : (.*)
Field B : Request URI
Extract B : (.*)
Output To : Request URI
Constructor : $A1$B1

Secure Server Code

Add this code to the thank-you page on https://www.seconddomain.co.nz following payment
- I have used $70. Please change to the appropriate value.

You can also use it to track leads - set the google_conversion_label and label to "lead", or "signup" or "pageview". In fact, you can make up any label to assign the variable to. ie "newsletter".
<!-- Google Code (regarding Adwords) for purchase Conversion Page --> <script language="JavaScript" type="text/javascript">
<!--
var google_conversion_id = xxxxxxxx;
var google_conversion_language = "en_AU";
var google_conversion_format = "1";
var google_conversion_color = "666666";
if (70.0)
{
var google_conversion_value = 70.0;
}
var google_conversion_label = "purchase";
//-->
</script>
<script language="JavaScript" src="https://www.googleadservices.com/pagead/conversion.js">
</script>
<noscript>
<img height=1 width=1 border=0 src = "https://www.googleadservices.com/pagead/conversion/xxxxx/imp.gif?value=70.0&amp;label=purchase&amp;script=0">
</noscript>

Make sure you track every movement

Do you have ajax on your pages??? If so, are you tracking those "page requests" on your stats package? Google analytics has facility to track ajax requests

Track Flash Events

Adding Tracking onto links


<a href="http://www.example.com" onClick="javascript: pageTracker._trackPageview('/outgoing/example.com');">


Air New Zealand Tickets
Book Air New Zealand Tickets and save on tickets on CheapOair,book today using CheapOair's exclusive travel coupon.
Digg StumbleUpon del.icio.us technorati blinklist furl reddit sphinn

Tags: 

6 Comments

Haiming - Search Engine Expert - Sep 23, 2008

Hi Michael,

Thank you so much for this article! It gives me the idea how to put the Google Adword tracking code in to onlineshop site. It seems like I should read all articles first before I ask you any question :)


- May 19, 2009

Thanks for your info, It is working fine with normal links . But I am having problem with form posting , Can you help on this?

Thank you

- May 19, 2009

The article gives details about forms. Or look directly on the Google help for more information

- Oct 21, 2009

Thanks for sharing your knowledge.

- Mar 10, 2010

I'm having an issue with using "return false", this stops the link been processed, any ideas?

Michael Brandon - Mar 10, 2010

The onclick="pageTracker._link(this.href); takes the href in the link, and adds parameters to it then sends it to the href via javascript.

So the actual <a ref is not being processed, it is being processed via the javascript.

Then the javascript stops, since its now transferred processing to the target webpage.


Post Comment

*
*


Visual CAPTCHA

*
Code is not case-sensitive
*

We welcome comments on this article, provided they have something to contribute. Please note that all links will be created using the nofollow attribute. This is a spam free zone. HTML is stripped from comments, but BBCode is allowed.