Tracking Chef
  • Guides
    • Google Ads
    • Google Analytics
    • Google Tag Manager
    • Google Data Studio
    • Facebook
    • LinkedIn Ads
    • Hubspot
    • Segment
    • Quora Ads
    • Reddit Ads
  • Blog
  • GTM Playground
  • Swag
  • Contact
  • Guides
    • Google Ads
    • Google Analytics
    • Google Tag Manager
    • Google Data Studio
    • Facebook
    • LinkedIn Ads
    • Hubspot
    • Segment
    • Quora Ads
    • Reddit Ads
  • Blog
  • GTM Playground
  • Swag
  • Contact
Tracking Chef
  • Guides
    • Google Ads
    • Google Analytics
    • Google Tag Manager
    • Google Data Studio
    • Facebook
    • LinkedIn Ads
    • Hubspot
    • Segment
    • Quora Ads
    • Reddit Ads
  • Blog
  • GTM Playground
  • Swag
  • Contact
  • Guides
    • Google Ads
    • Google Analytics
    • Google Tag Manager
    • Google Data Studio
    • Facebook
    • LinkedIn Ads
    • Hubspot
    • Segment
    • Quora Ads
    • Reddit Ads
  • Blog
  • GTM Playground
  • Swag
  • Contact
Generic event tracking in Google Tag Manager
Home » Google Analytics
May 21, 2020 Elad Levy

When working with a client to implement a measurement plan in Google Tag Manager (GTM), I often need to set up multiple events to capture different user interactions.

These can range from ecommerce (e.g. Add to Cart) or user engagement (e.g. Form Submissions).

To simplify the setup, I usually create a generic set of a Custom Event and Data Layer Variables that can be reused across any event I want to track. This also enables me to add additional events down the line without altering the current GTM setup.

Let’s break it down

Custom event

The first step is creating a Custom Event that will be used as a Trigger. I like to name this event ‘ga_event’ as I mostly use it for Google Analytics events, but it can be named anything you like. The important thing is to be consistent in its naming across whichever events you trigger.

To create the trigger, navigate to the Triggers page in GTM and click “New.

Select the trigger type is ‘Custom Event’ and set the Event name to ‘ga_event’. The trigger should fire on all custom events.

Setting up the Custom Event

Data Layer Variables

To hold the data of the event, I like to use GA’s event data hierarchy:

  1. Event Category
  2. Event Action
  3. Event Label

To pass the data I create three Data Layer Variables (DLV). To create the DLVs, navigate to the Variables page in GTM and under the User-Defined Variables click New.

Select the variable type is ‘Data Layer Variable’ and set the Data Layer Variable name to ‘eventCategory’. Save the variable and repeat for eventAction and eventLabel.

The reason for writing ‘eventCategory’ instead of ‘event category’ is simply because of standard JS naming conventions. It will work just as well written in either form.

Setting up the Data Layer Variable

Creating a generic Google Analytics event

Now that we have the Custom Event and DLVs ready, we can create our generic Google Analytics event.

Navigate to the Tags page in GTM and click New. Select the Tag Type ‘Google Analytics: Universal Analytics’ and set the Track Type to ‘Event’.

You can now add the DLVs you created in their relevant slots, eventCategory to Event Category and so forth.

Make sure you add Google Analytics Settings to the tag.

Adding the DLVs to the Google Analytics event

Now that the tag is set up, you can select a trigger that will fire it. Click on the Triggering section and select the Custom Event you created.

Adding the Custom Event trigger to the Google Analytics event

And that’s it, your event is ready to fire.

Triggering the generic event

To trigger the event, you need to run the following script on the user interaction you want to capture.

The value of ‘event’ should always be ‘ga_event’ (as this is the name of the Custom Event). The value of the DLVs can change according to the data you want to pass.

     dataLayer.push({
       'event' : 'ga_event',
       'eventCategory' : eventCategory,
       'eventAction' : eventAction,
       'eventLabel' : eventLabel
     });	

Form submission tracking

In this example, I want to send form submission data, so the event’s category is form submission and the event action will carry the form’s name.

     dataLayer.push({
       'event' : 'ga_event',
       'eventCategory' : 'form submission',
       'eventAction' : 'contact us',
       'eventLabel' : ''
     });	

About the Author

Elad Levy View all posts by Elad Levy

Experienced Web Analyst, working for almost a decade now with various web analytics tools.
Also a husband, father of three rascals, and the co-founder of Fixel.

« Previous
Next »
3 Responses
  1. Yishai
    Reply
    August 23, 2020 at 9:59 pm

    Hola, is there an option that the GTM is blind to the GA events.

    • Elad Levy
      Reply
      August 24, 2020 at 2:50 pm

      Hi Yishai
      GTM can indeed “miss out” on GA events that are hardcoded into the site, if that’s what you mean.
      This generally considered a bad practice, to split the events between GTM/hardcoded.

  2. seoravindra
    Reply
    May 13, 2021 at 5:57 pm

    Hi Elad Levy,

    I having facing issues with tracking with HubSpot from in GTM. I Google it I found this site I implemented like this but I have tracked a few & a few are not tracked.

    So I contacted Elad Leavy through some SM channels he immediately replies to me about what is wrong I did & correct my mistake(s).

    Now I am able tracking perfectly

    Thank you Very Much Elad Leavy, Great Support & help

    Regards,
    Ravindra

Leave a Reply

Click here to cancel reply.

Contents hide
Let’s break it down
Creating a generic Google Analytics event
Triggering the generic event
Made with ❤️ by Elad Levy
Disclaimer: Some of the links shared on this site are affiliate links, so if you choose to make a purchase, I’ll earn a small commission. Please note, I only recommend tools I’ve used and have found useful, the commission is not a driving factor