Netsuite Google Analytics – Integrating Google Analytics with Netsuite

tomfeatured post35 Comments

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.

tomNetsuite Google Analytics – Integrating Google Analytics with Netsuite

35 Comments on “Netsuite Google Analytics – Integrating Google Analytics with Netsuite”

  1. tom

    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?

  2. Aaron Hirshberg

    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

  3. tom

    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?

  4. Bill Quinn

    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?

  5. tom

    .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.

  6. Mike Nestor

    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.

  7. tom

    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

  8. tom

    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.

  9. Eric

    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.

  10. Eric

    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?

  11. Eric

    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.

  12. tom

    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. :)

  13. Eric

    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!

  14. Eric

    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?

  15. Eric

    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.

  16. tom

    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)

  17. Mike

    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

  18. tom

    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.

  19. Nikole Gipps

    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. :-(

  20. NewGen

    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.

  21. Ronnie

    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

  22. Tim

    Layout works fine here as well. Not seeing any “text runneth over”

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

  23. Aaron JW

    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?

  24. tom

    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?

  25. aaron jw

    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.

Leave a Reply

Your email address will not be published. Required fields are marked *