Learn business growth with Google Analytics 4 Forums Google Analytics 4 . Configuring G4 Events as HTML Attributes

  • . Configuring G4 Events as HTML Attributes

    Posted by George on 4 November 2022 at 6:10 pm

    Hey there! I’m setting up an event in Google Analytics and hope someone could give me a hand. I’ve added the event as shown in this image.

    Now, I’ve added this to my HTML code:

    `


    `

    My goal is to track when people click on two different email buttons on our site, and figure out whether they’re clicking on the main one or the secondary one.

    Am I on the right track? Is there something else I should be doing? Thanks in advance for your help!

    Peyton replied 1 year, 4 months ago 2 Members · 1 Reply
  • 1 Reply
  • Peyton

    Member
    5 June 2023 at 6:02 pm

    Sure, here’s a more laid-back explanation:

    So, you’re on the right idea with tracking the button clicks. But, here’s the thing – Google Analytics isn’t that great at creating new events. It kinda just works with the data it already has, it doesn’t let you change the way data is gathered.

    What you gotta do instead is set up your own tracking system for the clicks you want to monitor. This is typically done with Google Tag Manager (GTM for short). Another way is to whip up some event listeners for the clicks in your code and dispatch custom events using the gtag.js library.

    Also, heads up about adding random attributes to your HTML elements like what you did with GA-TRACKER. If you need custom attributes, check out data-attributes. It’s a better way to go about it and you can learn more about it online. Happy coding!

Log in to reply.