≡ Menu

Guide to Installing Google Analytics Universal for NetSuite Websites

Install Google’s Newest Analytics for Your SuiteCommerce Advanced or Site Builder Website

Why Install Universal Analytics?

  • Better user identification across multiple devices – get closer to tracking users, not just visits.
  • For the first time, you can now track off-line conversions with the measurement protocol – trackable lifetime value in your web analytics!
  • All future analytics innovations will rollout to universal analytics.
  • Custom variables become custom dimensions, and are easier to implement and more powerful.
  • Set your own campaign and session timeout values
  • It can run alongside your existing analytics – it can be very helpful to have six months or more to compare between systems, as no two systems will ever match exactly in their reporting.

Prerequisites for This Guide

Please see my note about issues with the auto linker in NetSuite.
This guide is written for NetSuite SuiteCommerce Advanced and Site Builder websites. It assumes that you use the NetSuite checkout domain (checkout.netsuite.com or similar) as well as the default checkout process. If you have a custom checkout domain or use the reference cart/checkout or SSP checkout, you will need a different solution.

Set up a New Analytics Property

The new user interface has a three level hierarchy to your Google analytics account – Account, Property, and View. Multiple views can be configured for a single property, which allows you to interpret the same data in multiple ways. For example, I recommend having an additional view set up that strips all query string parameters, to make certain reports and exporting easier. A property corresponds to a single implementation of the Google analytics code – if you have an existing Google analytics account, you will need a new property for the universal analytics. Multiple properties can be set up within a single account, to make it easier to manage.

To create a new property, login to your Google analytics account and click on the admin button in the top right corner. In the property drop-down, choose ‘create new property’. It will start a wizard that will configure your account, and the first question is which version of analytics to install. It defaults to the Google analytics universal, so leave it that way.

Beware of Copy & Paste!
If you are copying and pasting any of the code examples below, be aware that your browser might replace the single quote (‘) character with an angled single quote – (’) – if so, this will break the JavaScript. Make sure that all of your single quote characters are actually single quotes, and not the angled version.

Page tracking code and cross domain support

Once you have entered some basic information about your website, Google will give you your default page tracking code. It will look something like this :

<script>
(function(i,s,o,g,r,a,m){i[‘GoogleAnalyticsObject’]=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,’script’,’//www.google-analytics.com/analytics.js’,’ga’);

ga(‘create’, ‘UA-XX‘, ‘fourthwc.com‘);
ga(‘send’, ‘pageview’);
</script>

Please note – wherever you see ‘UA-XX’ in the code examples, please replace it with your account number. It is a string of characters that begins with ‘UA’, which you can find in your tracking code. Also, replace fourthwc.com with your top level domain name (without the www).

Adding Cross Domain Tracking
Since the checkout and main website domains don’t match, we need to modify the default analytics code. Google analytics uses first party cookies, so a special link has to be created when changing domains, so that referrer data is preserved. This modified code will add that linking functionality:


<!– begin Google Analytics Universal header –>
<script>
(function(i,s,o,g,r,a,m){i[‘GoogleAnalyticsObject’]=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,’script’,’//www.google-analytics.com/analytics.js’,’ga’);

ga(‘create’, ‘UA-XX’, ‘auto’, {
‘allowLinker’: true
});

// Load the plugin.
ga(‘require’, ‘linker’);
// Define which domains to autoLink.
ga(‘linker:autoLink’, [‘fourthwc.com’, ‘netsuite.com’], false, true);

ga(‘send’, ‘pageview’);
</script>
<!– end Google Analytics Universal header –>

Make sure to use a text editor and not a word processor to modify your code, as Word can often replace the single quotes character (‘) with a slightly different one that can cause problems. Paste your new code into Setup > Site Builder > Set up Web Site, in the ‘Addition to <head>’ field under the Analytics tab. if you are not using the older version of Google analytics as well, make sure the ‘analytics click attributes’ and ‘analytics submit attributes’ fields are empty, and uncheck the box for ‘enable Google analytics integration’. If you are installing alongside the ga.js version of Google analytics, it is okay to leave these fields as they were.

Auto linker issues with NetSuite

(Updated June 10th, 2014)
While the auto linker code above works well for links like register or login that point to your checkout domain, there is a problem with the shopping cart page. When a user clicks on the ‘proceed to checkout’ button, it submits a form. Normally the auto linker would decorate the form, but the form actually submits to the local domain, not to the checkout domain. It is further complicated by a series of redirects that NetSuite uses to begin the checkout process. We have developed a custom solution that fixes this issue by using the redirect functionality. We can install it quickly and cheaply for you – please contact us if you are interested.

Conversion/Transaction Tracking

Make sure to enable e-commerce tracking under the admin link in the top right corner, under view settings if your site is e-commerce. In your NetSuite account, go to Lists > Web Site > Tabs, and edit the Checkout tab. Copy and paste the following code into the ‘Order Confirmation Message’ field (Make sure you are in view source mode, and not using the rich text editor):

<script type="text/javascript">
/* script developed by Fourth Wave Consulting [email protected]
purpose: to submit transaction data for a web order to Google analytics universal (analytics.js)*/

ga(‘require’, ‘ecommerce’, ‘ecommerce.js’);

ga(‘ecommerce:addTransaction’, {
‘id’: ‘<%=getCurrentAttribute(‘confirmation’,’ordernumber’)%>’, // Transaction ID. Required.
‘affiliation’: ‘<%=getCurrentAttribute(‘site’,’name’)%>’, // Affiliation or store name.
‘revenue’: ‘<%=getCurrentAttribute(‘confirmation’,’subtotal’)%>’, // Grand Total.
‘shipping’: ‘<%=getCurrentAttribute(‘confirmation’,’shipping’)%>’, // Shipping.
‘tax’: ‘<%=getCurrentAttribute(‘confirmation’,’tax’)%>’ // Tax.
});

var itemsInOrder = "<%=getCurrentAttribute(‘confirmation’,’orderitems’)%>";

var lineItem = itemsInOrder.split("||");

for(var inum = 0; inum < lineItem.length; inum++)
{
var itemAttributes = lineItem[inum].split("|");

ga(‘ecommerce:addItem’, {
‘id’: ‘<%=getCurrentAttribute(‘confirmation’,’ordernumber’)%>’, // Transaction ID. Required.
‘name’: itemAttributes[1], // Product name. Required.
‘sku’: itemAttributes[0], // SKU/code.
‘category’: itemAttributes[2], // Category or variation.
‘price’: itemAttributes[3], // Unit price.
‘quantity’: itemAttributes[4] // Quantity.
});
}

ga(‘ecommerce:send’);

</script>

Check Your Work

Over the last 10 years, a web developer’s job has gotten much less painful. Internet Explorer is taking a dirt nap, replaced by much faster, better, more secure browsers. Once you have installed the analytics code, it’s important to check to make sure everything is working correctly. My favorite way to do this is with the Google analytics Debugger, a chrome browser extension. Simply visit the link ( using chrome) and add the extension to your browser. It creates a button in the top right of the browser that looks like an envelope.

  1. Click the icon to toggle it on, and the graphic changes.
  2. Hit f12 in Chrome to bring up the developer tools console.
  3. Now visit your web site, and write down the clientID. Also check to make sure that it loads the linker plug-in, and sends the page view.
  4. Now click register or login, to take you to your checkout domain. If the client ID matches, the cross domain linking is working properly. Without this, referral data would not transfer properly to your conversion tracking.

Take your analytics Further – a Checklist

Basic page tracking and conversion tracking are really the first step in extracting useful web analytics from your website traffic. Fourth Wave Consulting can help you with these next steps and guide you through the process of using ever more advanced analytics. Simply having analytics won’t make you any more money – it’s power comes from its ability to inform decisions, allow for cheap and quick experimentation, and to surprise us with insights we never would have found any other way. Here are some recommended next steps:

  1. Enable site search tracking (in Admin section, view settings) – By default, Site Builder sites use ‘search’ as the query parameter.
  2. Link your analytics account to your Adwords and Google webmaster tools account.
  3. Configure query string handling – some query string parameters don’t change the content of the page, and analytics needs to know to ignore them.
  4. Set up a filter to exclude your IP address so analytics will ignore your visits.
  5. A/B content testing

The following two tabs change content below.
I have been working with computers and web sites for 20+ years, and have enjoyed mastering many areas of technology. I have been building websites for about 15 years, and working with NetSuite for more than 10. I have worked with dozens of small and medium-sized companies in that time, helping them to understand and leverage the latest tools to grow their business. My business is all about helping you to maximize your business, and I prefer to establish long-term relationships with clients who are dedicated to embracing smart ways to optimize and expand their business.
7 comments… add one
  • John N May 24, 2014, 2:55 am

    Hi David,

    Thanks very much for posting this guide. This is saving us a lot of time.

    One question re: your modified line of code where you have this —
    ga(‘linker:autoLink’, [‘fourthwc.com’, ‘netsuite.com’], false, true);

    Our Site Builder site uses webstorecheckout.com in the checkout flow. Would we replace netsuite.com with webstorecheckout.com in that line?

    Thanks!

    John

    • David Norris May 24, 2014, 9:07 am

      John,

      Thanks for the question. You are correct – the first domain should be your web domain (without the www) and the second domain should be your checkout domain. Since posting my original article, I have since found a problem with the way the auto linker works. it works fine if you are clicking a link like register or login from the web domain, but it doesn’t automatically decorate the proceed to checkout button, as the form action is on the same domain. NetSuite uses 2 different redirects to go from the shopping cart page to the checkout domain, so the form redirect has to be updated with a linker parameter for the cross domain tracking to work properly.

      It took a lot of reverse engineering, but I have found a workable solution. I have implemented it A number of times now and it works perfectly in the NetSuite web stores. Every analytics project requires a unique combination of troubleshooting, customization, and adjustments for the needs of the individual website, so please contact me for more details.

  • Daniel October 17, 2014, 10:31 am

    Hi David,

    Is it possible to use just a name instead of the URL of the webpage like
    ‘linker:autoLink’, [‘store’]

    Or would there be a way to avoid mentioning the URL.

    Thanks,
    Daniel.

  • Daniel October 17, 2014, 1:05 pm

    Hi David,

    Thanks for the answer, I believe it has to go that way.

    I was trying to avoid such mention since my informational page (domain1.com) is not directly associated with the store, and by adding the store URL on each one of my pages it will look as it is.

    Thanks again for clearing things out.

  • TimVB October 19, 2016, 1:23 am

    Thanks for the guide. Good stuff.
    Do you know where to place conversion tracking pixels in a Site Builder site using Mont Blanc? Been scratching my head over this all night long.

    • David Norris November 2, 2016, 6:24 pm

      Hello Tim,

      If you mean the new SuiteCommerce Advanced Mont Blanc, the analytics in it work very differently. There’s a separate application for tracking that can do pageviews, events, etc. You configure it in the configurationManfiest.json file.

Leave a Comment