jquerygoogle-analyticsevent-trackingsquarespace

Google Analytics Event Tracking Issues


I'd like to add event tracking to my website using Google Analytics but I can't seem to get any data. I'm trying to capture button click events. Here is my jQuery code:

<script> 
$(document).ready(function () {
   $("input[type='submit'][value='Sign Up']").on('click', function () {
      alert("Test.");
      ga('send', 'event', 'amazon', 'item', 'topreviewbutton');
   });
}); 
</script>

For some reason I'm not pulling in any data (but my alert is going off so I know the code is running). Does anybody have any tips for troubleshooting/setting up event tracking? Also, I get an error that says:

Uncaught ReferenceError: ga is not defined

when I click the button. Is adding the UA - XXXX - ID in the correct section in SquareSpace not sufficient for event tracking? Should I copy and paste their universal analytics javascript code instead? Am I missing a library?


Solution

  • SquareSpace does not currently support Universal Analytics into their default integration: http://help.squarespace.com/guides/using-google-analytics-with-squarespace#toc-universal-analytics

    Google is currently rolling out an update to Google Analytics called Universal Analytics. We don't offer Universal Analytics with our official Google Analytics integration. However, you can add Universal Analytics to your Squarespace site by adding some tracking code to Code Injection.

    You must then copy and paste the Google Analytics tracking snippet into your template to load the JavaScript library which will load the ga() function.

    The SquareSpace documentation linked above has references to the steps required to include that snippet into your pages.