Squarespace, AJAX & Google Analytics
Squarespace is great, AJAX is great, Google Analytics is great. But they don’t always play nice together on Squarespace websites. If you don’t know, AJAX makes your website feel much faster and snappier. When a user clicks on a new page, instead of re-loading the whole page again, Squarespace only loads the content that has changed on the page.
But this presents a problem, header and footer elements are never re-loaded because they never change. This means that your Google Analytics code won’t update and page views won’t be logged. But don’t worry there is a way around this by utilising Google Tag Manager.
This isn’t necessary if you’re on version 7.1 of Squarespace, you can use the built-in Google Analytics integration.
Step-By-Step Guide
1. Log into Google Tag Manager.
2. Install Google Tag Manager on your Squarespace website. Navigate to Admin > Install Google Tag Manager.
3. Copy and paste the first section of code into your sites Global Code Injection Header. Then copy and paste the second section of code in your sites Global Code Injection Footer.
4. Navigate back to Workspace, click on Triggers & finally click New.
5. Click ‘Choose a trigger type to begin set-up…’.
6. Scroll down to the bottom of the list and select History Change.
7. Click Save and then Save again.
8. Now navigate to Tags and then click on New.
9. Click on ‘Choose a tag type to begin set-up…’.
10. Now click on ‘Google Analytics: Universal Analytics’.
11. Make sure that ‘Track Type’ is set to ‘Pageview’ and that ‘Google Analytics settings’ is set to ‘{{Google Analytics Settings}}’. Finally, click on ‘Choose a trigger to make this tag fire…’ in the section below.
12. Click on ‘Change History’.
13. Now click on the ‘+’ button.
14. Click on ‘All Pages’.
15. Now click ‘Save’.
16. Click ‘Save’ again.
17. Click ‘Submit’ or ‘Publish’.
18. Click ‘Publish’.
19. Give it a name and click ‘Continue’.
That’s it, Google Analytics is now set-up to work on your AJAX enabled Squarespace website.