Jump to content

How to set up Google Analytics event tracking on a form submission button

Recommended Posts

Hi there!

I'd like to set up Google Analytics event tracking on a form submission button and other buttons that are not related to e-commerce.

What is the best way to do that with code injection?

I've been using Google Tag Manager with my previous site, and I know how to create G.A. event tracking there. 

Installing GTM was my first option, but Google's documentation says that the second part of the code should go immediately after the <body> opening tag, and the squarespace code injection only gives me the option to add it to the footer (I believe it means just before closing the </body> tag). So I'm not sure it's going to work fine.

Has anyone here done it?

Link to comment
  • Replies 5
  • Views 3.2k
  • Created
  • Last Reply

Top Posters In This Topic

17 hours ago, IsabelFurtado said:

Can anyone help with this? 🙄😊

 the squarespace code injection only gives me the option to add it to the footer (I believe it means just before closing the </body> tag)

Yes. Code in Footer will be in <body> and </body>

 

Email me if you have need any help (free, of course.). Answer within 24 hours. 
Or send to forum message

Contact Customer Care - Learn CSS - Buy me a coffee (thank you!)

Link to comment
  • 10 months later...
  • 2 years later...

Setting up event tracking with Google Analytics on Squarespace is doable using code injection. Even if Squarespace primarily offers footer injection, you can still make it work.

U can add your Google Tag Manager container code through the Squarespace code injection in the footer. Then, for event tracking on specific buttons, you can use JavaScript and fire the events based on button clicks.

Use JavaScript to trigger events for your buttons, and push those events to GTM

document.getElementById('your-button-id').addEventListener('click', function() {
  dataLayer.push({
    'event': 'your-event-name'
  });
});

Replace your-button-id with the actual ID of ur button, and 'your-event-name' with a relevant event name

yeah, it's a bit manual compared to GTM, but it'll work 😅

Be nice, and don't forget to like or upvote my replies if they were helpful 🌸

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

×
×
  • Create New...

Squarespace Webinars

Free online sessions where you’ll learn the basics and refine your Squarespace skills.

Hire a Designer

Stand out online with the help of an experienced designer or developer.