featured post

Netsuite Google Analytics – Integrating Google Analytics with Netsuite

Netsuite Google Analytics Integration - Step 2

If you have struggled integrating Google Analytics with Netsuite, you are not alone.  It can be a bit tricky to get all the gears lined up.  But, we have successfully done this twice – once pre-netsuite official method and now a modified version of the official way.

If you have not read through the Official Netsuite Google Analytics document on analytics integrations, here is the pdf.  See page 356.  Most of the information is correct – but I had come conversion issues with the code and it’s placement.  Here is what I did to solve the issues with Netsuite’s Google Analytics integration problems.

Step 1:

Backup your current google analytics settings.

We have used tags for this in the past – so I backed up that tag and the confirmation page we were currently using. I just stick them in a text file and label the different sections so they could be accessed again later.  I also try to use a date in the file name so I can have an archive.

Step 2:

Login to Netsuite and go to Setup -> Web Site -> Set Up Web Site and then click the Analytics tab.

Here is the code from above:

  <script type="text/javascript">
    var _gaq = _gaq || [];
    _gaq.push(
      ['_setAccount', 'UA-XXXXXX-X'],
      ['_setDomainName', 'none'],
      ['_setAllowLinker', true],
      ['_trackPageview'],
      ['_trackPageLoadTime']
    );

    (function() {
      var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
      ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
      var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
    })();
  </script>

You’ll need to replace the UA code with yours…also, not the Analytics Click and Submit Attributes – these need to be:

  onclick="_gaq.push(['_link', this.href]); return false;"
  onsubmit="_gaq.push(['_linkByPost', this]); return true;"

Step 3:

Now we need to add the confirmation code.  You will find it in the “Order Tracking Script HTML” box on the same tab.

Here is the code needed in section above:

  <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
  <script type="text/javascript">
    $(document).ready(function () {
      var skulist = '';
      var pricelist = '';
      var quantitylist = '';

      var orderNum = "<%=getCurrentAttribute('confirmation','ordernumber')%>";
        _gaq.push(['_addTrans',
        orderNum,                                                    // ordered
        '{sitename}',                                                // affiliation
        '<%=getCurrentAttribute('confirmation','subtotal')%>', // total/subtotal
        '<%=getCurrentAttribute('confirmation','tax')%>',      // tax
        '<%=getCurrentAttribute('confirmation','shipping')%>', // shipping
        '', // city
        '', // state
        '' // country
      ]);

      var rows = document.getElementById("ordersummary_total").parentNode.rows;

      for (var i = 0; i < rows.length; i++) {
        try {
          var skuName   = rows[i].cells[X].innerHTML;
          var qty       = rows[i].cells[X].innerHTML;
          var prodName  = rows[i].cells[X].innerHTML;
          var price     = rows[i].cells[X].innerHTML;

          price = price.replace(",","");

          if (price.indexOf("$") != -1) {
            price = price.replace("$", "");
            _gaq.push(['_addItem', orderNum, skuName, prodName, '{sitename}', price, qty]);
          }
        } catch(e) {}
      }
      _gaq.push(['_trackTrans']);
    });
  </script>

You will need to change the “{sitename}” to any identifier you wish.  It will show up in Google Analytics.

Also – please note the “X“, this varies from site to site based on cart setup.  An easy way to figure it out is look at your shopping cart page – it uses a zero based index to identify each element.  So we use the Item Name/Code as SKU – so in the skuName variable above, we would use 0, the qty field here would be 1, prodname would be 2 and then price would be 3.  4 would not be used in this Netsuite integration.

Here is a picture to help explain:

Step 4:

Clearing out old Googel Analytics code.  If you have previously had GA installed – then it will be necessary to clear out all the old code.  As mentioned above, the Tag method may have been used in the past.  If this is the case – you can make a backup copy of the Google Analytics tag and then clear the tag data.

Also – check the Checkout Tab.  Tabs can be found under Lists -> Tabs in the main menu and many times have code in them.  This is the code/text which is executed at the confirmation of the sale.

Conclusion

The issue I found was the order in which the elements ended up on the confirmation page.  This is why I ended up using jquery and the document.ready – this way I know the page is fully loaded before trying to send the information about the purchase onto Google.

Good Luck

Integrating Google Analytics into Netsuite can be a bit intimidating, but with the Netsuite guide and this blog post – you should be on your way to clean tracking in Netsuite.

Please email if you have issues and I will help if I can.

Discussion

35 Responses to “Netsuite Google Analytics – Integrating Google Analytics with Netsuite”

  1. Thanks for posting this. We’re so happy to finally have this working on our site!

    Posted by Gary Kanning | January 13, 2012, 9:34 am
  2. No problem Gary – glad it worked for you.

    Have you taken a look at your analytics since? Can you see more detailed data than before?

    Posted by tom | January 13, 2012, 9:50 am
  3. This is a great post, thanks for taking the time to lay it out so clearly.

    I do have one question:

    On page 357 of the NetSuite WebSite.pdf https://system.netsuite.com/help/helpcenter/en_US/PDF/WebSite.pdf

    Point #3 says:

    “Important: If you have a hosted site, paste your Google Analytics tracking snippet in
    your hosted HTML pages. Then, enter custom analytics tracking code in the Analytics
    Click Attributes, Analytics Submit Attributes, and Order Tracking Script HTML fields.
    When you do this, Web site tags you use to create links to forms and checkout pages
    will collect tracking data across domains.”

    I have a hosted site, so I am wondering if I should keep my google analytics snippet in a tag on every page, or just keep it in the “Addition to ” like you specify in step #2?

    Thanks

    Posted by Aaron Hirshberg | February 7, 2012, 12:44 pm
  4. What Netsuite is speaking of here is if you have a site hosted elsewhere, AND an ecommerce store. Is that what you have Aaron?

    What are the URL’s of your sites?

    Posted by tom | February 7, 2012, 12:52 pm
  5. Any ideas on how to get the City, State, and Country to populate?

    Posted by Aaron Hirshberg | February 7, 2012, 1:18 pm
  6. Take a look at my previous post and it shows how to do just that Aaron:

    Netsuite Google Analytics

    Posted by tom | February 7, 2012, 1:29 pm
  7. Great post, I am curious about the .ready function.

    The jquery documentation states .ready() is generally incompatible with which NetSuite uses extensively.

    http://api.jquery.com/ready/

    Any thoughts on the jquery statement? What could be the impact?

    Posted by Bill Quinn | April 19, 2012, 7:03 am
  8. .ready is very important to getting the code to work properly.

    It allows the code to “wait” until the page loads to execute the javascript – allowing the NetSuite variables to populate before we start the code we want.

    You need it and it is super helpful.

    Posted by tom | April 19, 2012, 7:42 am
  9. Awesome post. Thank you so much. I was wondering if you had any idea if it was possible to get item prices and info from the server instead of parsing the html though. The issue I have is customers can checkout in other currencies so if it was possible to ask the server for the price in USD then I could get valid data back to Google.

    Posted by Mike Nestor | April 30, 2012, 4:58 pm
  10. As of now – there is not a way to get it directly from the server…we are basically grabbing the screen information from the screen. The company I work for does have an open ticket with Netsuite to try and get better data – but so far…no luck.

    Keep looking here – I keep it as up to date as I can.

    Thanks for reading,
    tom

    Posted by tom | April 30, 2012, 5:20 pm
  11. Oh well, that’s fine for now. Wish Google would do currency conversion though. Damn them!

    Posted by Mike Nestor | April 30, 2012, 5:52 pm
  12. I know – I wonder if it is in the source code on that page which currency? If it is – you may be able to convert it on the fly w/javascript.

    Good luck.

    Posted by tom | April 30, 2012, 8:09 pm
  13. Hi Tom

    Can you explain how to do cross-domain tracking with the tags? The help guide (it looks like it has been updated since you posted the link) doesn’t go into details on how to actually do it.

    Posted by Eric | September 12, 2012, 2:53 pm
  14. I can Eric – I’m just not exactly sure what you mean…tell me more of what you want?

    Posted by tom | September 12, 2012, 3:05 pm
  15. Well, I need to figure out how to do cross-domain tracking. The Netsuite guide only says

    “Important: If you have a hosted site, paste your Google Analytics tracking snippet in
    your hosted HTML pages. Then, enter custom analytics tracking code in the Analytics
    Click Attributes, Analytics Submit Attributes, and Order Tracking Script HTML fields.
    When you do this, Web site tags you use to create links to forms and checkout pages
    will collect tracking data across domains.”

    I just found your older post, is the information in your older post still relevant on how to do this correctly?

    So basically I just need to combine your old post and your new post together to achieve cross-domain tracking?

    Does the code in Step 3 of your OLD post have to be on both domains? Also, why is the [‘_setDomainName’, ‘none’], parameter set to none? Wouldn’t it need to specify the URL of the site you are pushing the data from?

    Posted by Eric | September 12, 2012, 3:31 pm
  16. This post is the most current code (http://tomaltman.com/netsuite-google-analytics-integrating-google-analytics-with-netsuite/).

    Eric – this is a good point and you can use this code “as is” if you are only tracking one domain.

    I have an update coming soon which will talk about multi-sub-domain tracking with Netsuite.

    Posted by tom | September 12, 2012, 3:50 pm
  17. Tom,

    So the link you just gave me will support cross-domain tracking? The reason I want to make sure is your old post had the Citricle code on it which was acting as a “proxy” to store cookies and I don’t see anything like that in your new post.

    Posted by Eric | September 12, 2012, 4:03 pm
  18. Yes Eric – all the code will track across domains. The “new” code is Netsuite’s new way (which still didn’t work correctly) – but is the better code.

    I’m combining the two in the next week or so to be cross-domain and cross-sub-domain.

    Let me know how it works…its been great for us so far. We just bit the bullet and are going to try the custom domain name – but it comes at a price, unfortunately for an item I feel should be part of the deal. But – thems the breaks. :)

    Posted by tom | September 12, 2012, 6:17 pm
  19. Oh yeah.. don’t even get me started on features Netsuite charges for that should be standard. Their e-Commerce portion of the software is so un-evolved it’s amazing!

    Posted by Eric | September 13, 2012, 7:32 am
  20. So no code needs to be on my main level domain? I set up all the new code in Netsuite but I’m not sure what to keep on my main level domain?

    Posted by Eric | September 13, 2012, 7:40 am
  21. If you follow the code on this post – you’ll be fine.

    Let me know if you need some help.

    Posted by tom | September 13, 2012, 7:51 am
  22. Hey Tom,

    Well, I followed everything in this post and no transaction information seems to be coming over anymore. It should only take a few hours to kick in, right? I changed everything early yesterday.

    Posted by Eric | September 14, 2012, 9:51 am
  23. It should be within 10-15 minutes.

    Email your domain, code, and code location and I’ll see if I can help. (tom@tomaltman.com)

    Posted by tom | September 14, 2012, 10:25 am
  24. Hi,
    Thanks for the great post. E-commerce tracking is working, but a question for you. If you want to set up a goal with a funnel to see drop offs throughout the process, do you have a list of URLs to use to create the funnel and goal.

    Thank you,
    Mike

    Posted by Mike | October 17, 2012, 6:27 pm
  25. Oh – I think I know what you mean. I had that written down someplace at one point. Let me see what I can dig up.

    Posted by tom | October 17, 2012, 7:20 pm
  26. Did you ever figure out the cross-domain issue, when the cart is using checkout.netsuite.com? I am trying to make it work but it is not. :-(

    Posted by Nikole Gipps | January 8, 2013, 12:02 pm
  27. Thank you for the post. I was looking for help to integrate GA and NetSuite, and sure enough you have laid it out perfectly. Wonderful instructions. I offer NetSuite development and integration, but I’ve always thought Google Analytics would be a great way to track inside of NetSuite. Again, thanks.

    Posted by NewGen | February 8, 2013, 1:58 pm
  28. Hey just wanted to give you a quick heads up. The text in
    your content seem to be running off the screen in Firefox.
    I’m not sure if this is a format issue or something to do with internet browser compatibility but I figured I’d post to let you know.
    The design look great though! Hope you get the problem fixed soon.

    Cheers

    Posted by Ronnie | March 7, 2013, 10:36 pm
  29. What version of Firefox – I’m seeing it fine here…

    Posted by tom | March 7, 2013, 11:17 pm
  30. Layout works fine here as well. Not seeing any “text runneth over”

    Also wondering if you got the cross-domain issues sorted out.

    Posted by Tim | March 19, 2013, 6:18 pm
  31. Cross domains working well now – are you having trouble?

    Posted by tom | March 19, 2013, 10:45 pm
  32. Does this work on Sales Order pages for our Customer Centers? I have a setup where end users buy using the shopping cart, but Dealers buy using the Enter New Sales Order from a customer center. Do I need to add analytics somehow so that it is reflected on those centers or will it work the same as if being purchased from the cart?

    Posted by Aaron JW | March 26, 2013, 1:56 pm
  33. You would need to add the google push code to those pages…iterate through the list of purchases and push them to the analytic api.

    Make sense?

    Posted by tom | March 26, 2013, 3:41 pm
  34. Right now its not working I think I need to add this onto our cart js files too? Its not custom scripted cart but I think it uses custom tabs. I followed your setup completely on two desperate occasions but no data.

    Posted by aaron jw | April 4, 2013, 2:50 am
  35. Are you getting any javascript errors in the checkout process?

    Posted by tom | April 4, 2013, 8:10 am

Post a comment