Google Analytics events

In this article:

Google Tag Manager only fires tags in response to events. This article explains how to use auto-event tracking to generate Google Analytics...

If auto-event tracking does not meet the needs of your scenario, you can manually trigger events from your code.

For the purposes of this discussion, imagine that every page on your site has a navigation menu that allows you to go to the "Buy" page, the "About" page, or the "Contact" page, depending upon which navigation item is selected. The "Buy" selection links to "http://example.com/buy.html". "About" links to "http://example.com/about.html". "Contact" links to "http://example.com/contact.html". You want to generate a Google Analytics event each time someone clicks one of these navigation items.

  1. Add a basic page tracking tag (i.e. Tag Type of Google Analytics or Universal Analytics; Track Type of Page View) if you don't already have one. This tag must fire on all pages.
  2. Create a new Trigger:
    • Type: Click
      NOTE: Creating a ‘Click’ trigger will automatically enable GTM Auto-Event Listening for the container upon publishing. Learn more about event triggers.
    1. Enable When: URL contains buy.html
    2. Trigger Name: Buy Clicks
    3. Trigger Type: Just Links
    4. Wait for tags: Check
    5. Max wait time: [enter appropriate time here, e.g. 2000ms]
  3. For each link, add a Google Analytics event tracking tag and set the firing condition to the ‘Buy Clicks’ trigger configured above. For example:
    1. Tag: Google Analytics
    2. Triggers: Click
      1. Name: Buy Clicks
    3. Tag Name: UA - Event - Buy Link
    4. Tag type: Universal Analytics
    5. Track Type: Event
      1. Category: Nav
      2. Action: Select
      3. Label: Buy
  4. Save and publish container

All clicks

Imagine that your webpage contains elements that users might click which are not traditional links. You want to generate a Google Analytics event each time someone clicks HTML elements with a certain Element ID, for example, clicks on an image with the ID ‘Gallery_Image’.

  1. Add a basic page tracking tag (i.e. Tag Type of Google Analytics or Universal Analytics; Track Type of Page View) if you don't already have one. This tag must fire on all pages.
  2. Create a new Trigger:
    • Type: Click
    • Enable When: Element ID contains Gallery_Image
    • Trigger Name: Gallery Image Clicks
    • Trigger Type: All elements
      NOTE: Creating a ‘Click’ trigger will automatically enable GTM Auto-Event Listening for the container upon publishing. Learn more about event triggers.
  3. Add an Analytics event tracking tag (i.e. Tag Type of Google Analytics or Universal Analytics; Track Type of Event). Add the trigger you created in the previous step (for example, "Gallery Image Clicks"). Enter a Category, Action, and and Label for the event. For example, you might use the following:
    • Category "All"
    • Action "Click"
    • Label "All".
  4. Save a version of the container and publish it.

Timed intervals

Imagine that you have a page where users might spend a significant amount of time without triggering any events, for example a page where a video is viewed. Given that Google Analytics sessions timeout after 30 minutes by default, you may wish to implement a ‘keepalive event’ to ensure that activity is sent every 25 minutes. For this purpose, you may use a GTM Timer:

  1. Add a basic page tracking tag (i.e. Tag Type of Google Analytics or Universal Analytics; Track Type of Page View) if you don't already have one. This tag must fire on all pages.
  2. Create a new Trigger:
    • Trigger Name: Session Timer
    • Type: Timer
    • NOTE: Creating a Timer trigger will automatically enable GTM Auto-Event Listening for the container upon publishing. Learn more about event triggers.
    • Enable When: URL matches RegEx .*
    • Event Name: gtm.timer
    • Interval: 1500000
    • Limit: 5
  3. Add an Analytics event tracking tag (i.e. Tag Type of Google Analytics or Universal Analytics; Track Type of Event). Add the trigger you created in the previous step (for example, "Session Timer"). Enter a Category, Action, and and Label for the event.
  4. Save a version of the container and publish it.

Form submits

Imagine that you want to record all submissions of a form on your site with the Element ID ‘My_Form’:

  1. Add a basic page tracking tag (i.e. Tag Type of Google Analytics or Universal Analytics; Track Type of Page View) if you don't already have one. This tag must fire on all pages.
  2. Create a new Trigger:
    • Trigger Name: My Form Submits
    • Submit Type: Form Submission
      NOTE: Creating a Form trigger will automatically enable GTM Auto-Event Listening for the container upon publishing. Learn more about event triggers.
    • Wait for Tags: unchecked
    • Check Validation: unchecked
    • Fire On: Some Forms
      • Form ID contains My_Form
        NOTE: The Form ID built-in variable must be enabled before it will show up as a Fire On option.
  3. Add an Analytics event tracking tag (i.e. Tag Type of Google Analytics or Universal Analytics; Track Type of Event). Add the trigger you created in the previous step (for example, "My Form Submit"). Enter a Category, Action, and and Label for the event. For example, you might use the following:
    • Category "Forms"
    • Action "Submit"
    • Label "Lead Gen".
  4. Save a version of the container and publish it.
Was this article helpful?