How to Integrate NetSuite with Google Analytics
Thursday, October 8th, 2009We recently announced that we found a workaround to integrate Google Analytics with NetSuite and it’s available as one of our services. We decided to share this information with everyone and tell you how it’s done.
If you have no scripting skills we can do this for you, just contact us.
Although this is a pretty small script, it achieves something pretty important, so we decided to release it under the LGPL license which means you can use it or adapt it to your needs, improve it and distribute it freely across the web as long as you don’t remove the copyright notice.
Basically Google Analytics is not able to track all the data (keyword, referrer and everything else) because it changes the domain name. Although it’s a pretty simple approach, it does a lot.
Our aproach to this is pretty unique in two ways:
- It uses a hidden iframe and pageTracker._getLinkerURL() while Google recommends using a regular link and a pageTracker._link() to make the eCommerce tracking work. This is pretty important because it makes the code so much smaller than having to parse all the links and forms on the site.
- Instead of linking to the checkout page like Google suggests in their documentation, in the case of NetSuite, the checkout page does an unnecessary refresh we decided it’s better to just have a blank html page that you can send the cookies to.
In our example we are on the domain www.roomitup.com and we have some cookies stored by Google Analytics, but visible only within that domain.
We need to find a way to transfer all those cookies into checkout.netsuite.com
In your page, after the Google Analytics code, write the following lines:
//***********************************************************************************
// Copyright 2009 Citricle. All rights reserved.
// This script is released under the LGPL license which means you can use it or adapt it
// to your needs, improve it and distribute it freely across the web as long as you don’t remove
// this copyright notice. For technical support go to www.citricle.com.
//***********************************************************************************
var domain = “roomitup.com”; //replace this with your own domain name
try {
if(document.URL.indexOf(domain) != -1) {
if((document.referrer.indexOf(domain) == -1) && (document.referrer != “”)) {
var iframeElement = document.createElement(”iframe”);
var proxyAddress = “https://checkout.netsuite.com/c.664770/citricle-ga.html”; //replace 664770 with your own NetSuite Account ID
iframeElement.setAttribute(”src”, pageTracker._getLinkerUrl(proxyAddress));
document.getElementById(”div__header”).appendChild(iframeElement);
iframeElement.style.display = “none”;
}
}
}
catch(e) {};
This will create a hidden iframe inside your website’s header (id is div__header) that will load the ga-tracker.html page, and it will pass the cookies using a query string generated by pageTracker._getLinkerURL(). That query string will contain those cookies that Google Analytics needs to track the keyword, referrer and everything else. Simple but useful huh?
The next step is to create what we call a proxy. It’s a blank html page that contains nothing more but your regular Google Analytics Code. Call it citricle-ga.html and upload it into your “Live Hosting Files” folder. The trick is that this file is hosted on the checkout.netsuite.com domain, which will allow Google Analytics to parse the cookies from the query string.
Why don’t we use the <NLCHECKOUTURL> ? Pretty simple. After going to the checkout page, NetSuite does a page refresh and reloads without the query string generated by Google Analytics. The first time it loads it (with the query string) it sends out the Location headers before Google’s Analytics script load and that was the main reason why this was so hard to achieve before.
Here’s the code for the citricle-ga.html:
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″ />
<title>Citricle Google Analytics NetSuite Proxy</title>
</head>
<body>
<script type=”text/javascript”>
var gaJsHost = ((”https:” == document.location.protocol) ? “https://ssl.” : “http://www.”);
document.write(unescape(”%3Cscript src=’” + gaJsHost + “google-analytics.com/ga.js’ type=’text/javascript’%3E%3C/script%3E”));
</script>
<script type=”text/javascript”>
var pageTracker = _gat._getTracker(”UA-1579697-1″); //replace UA-1579697-1 with your own account #
pageTracker._setDomainName(”none”);
pageTracker._setAllowLinker(true);
pageTracker._initData();
pageTracker._trackPageview();
</script>
<p>This solution was developed by <a href=”http://www.citricle.com”>Citricle</a>.</p>
</body>
</html>
This is pretty much our unique way of crossing the two domains. After that it’s only a matter of tracking the order on the checkout page. It’s nothing complicated, it was done before and there’s nothing unique about it. It’s just about following Google’s Documentation here.
If you still have any questions, contact us.





