In the world of freelancers one does come up against massive walls of code that are really not made to work with one another. In setting up Google Analytics tracking on any site that is made in wordpress, Wix or Squarespace, one encounters all sorts of peculiarities.
I am going to talk of capturing events in Google Analytics from within the Squarespace environment.
First of all, the normal way to integrate Google Analytics in Squarespace is easy enough. Just do the following:
However, please note that this will conform to Google Analytics tracking that is several generations old.
Also, this is just page view tracking though. You won’t be tracking any events this way.
How does one add event tracking where a new page is not going to be called?
I am going to describe how you do this for a newsletter capture lightbox in Squarespace.
It turns out that there are three ways to do this although only one works for me. I am listing all three in case my environment is weird and the other ways might work for you.
Essentially, what you want is to pass the event code to Google Analytics only when the submit button on the lightbox is clicked. For that you set up a listener to call a function which fires the event tracking code when called. This is very well described by Rocketeer SEO Hero and also by Silvabokis.
This did not work for me. Even though I tried several combinations but the variable value that should get assigned to 1, never happened.
2. Try and force Google Tag Manager(GTM) to do this for you:
GTM is not supported directly in Squarespace. You have to take your GTM header code below:
Now go to Google Tag Manager and build an event only tag that collects data when a trigger is fired upon a particular form class is seen. Please see this wonderful description ( read carefully for this process is convoluted) by Atomic Marketing.
3. Try to play within Squarespace:
This is a simple technique and did work for me. Go to the newsletter form and click on edit.
Click on Advanced and then scroll down to ” Post-Submit HTML”.
Now, this is a place where you put in the event call as follows:
Effectively, you are stating the Event Category [newsletter], Event Action [click] and Event Label [submit]. There are single quotes in the code above. When you copy and paste from here, they sometimes don’t get picked up that way so make sure to error-check that.
Go into the Google Analytics interface and add these values as a desirable goal and you are done. This method is quite simple but please be aware that this may not work like this if Google stops supporting this or Squarespace updates their codebase.
In any event, I hope this article is of some use. Do let me know if you have any further questions.