Google Analytics events

Google Tag Manager only fires tags in response to events. This article explains how to set up Google Analytics tags that are triggered...

This article describes how to configure Tag Manager to create triggers that listen for certain types of events that are expected to occur on a web page. For more control of your trigger functionality, set up your code to push trigger events to the data layer.

There are two common methods shown here for how to send click event information to Google Analytics:

  • Use a separate trigger and tag for each type of link.
  • Use a single tag with a regular expression to handle all click data.

For these examples, we will assume that a web page contains a navigation menu with these items and URLs:

 

Buy

https://example.com/buy.html

About

https://example.com/about.html

Contact

https://example.com/contact.html

Use separate triggers and tags to track clicks

This example is the most basic implementation for how to track separate clicks. This requires the creation of three triggers and three tags - one trigger/tag pair for each item in the table above:

  1. Add a Google Analytics pageview tag if one does not already exist. This tag must fire on all pages.
  2. Enable Tag Manager to capture clicked URL values:
    1. Click Variables.
    2. Click Configure in the Built-In Variables section.
    3. Select the Click URL built-in variable.
  3. Create triggers to track link clicks for buy.html, contact.html, and about.html:
    1. Click Triggers and then New and create a new trigger with these settings:
      • Trigger type: Click - Just Links
      • Wait for tags: Check
      • Max wait time: (use the default value of 2000ms)
      • Check Validation: Uncheck
      • Enable this trigger when all of these conditions are true: Click URL and then contains and then buy.html
      • Fire On: All Clicks
      • Name the trigger “Trigger - Buy Clicks” and save the trigger.
    2. Repeat these steps for “contact.html” and “about.html
  4. Create three new Google Analytics tags to track clicks for each page:
    1. Click Tags and then New.
    2. Click Tag Configuration and then Universal Analytics.
    3. Set Track Type to Event.
    4. Complete the Event Tracking Parameters:
      • Category: Nav
      • Action: Select
      • Label: Buy
        NOTE: The Label value should correspond to the particular link being clicked (e.g. "Buy" for buy.html, "Contact" for contact.html, and "About" for about.html).
      • Tag Name: UA - Event - Buy Link
      • Non-Interaction Hit: False
      • Google Analytics Settings: Select an existing Google Analytics Settings variable, or create a new one.
    5. Click Triggering and select the trigger that you created in step 3, titled "Trigger - Buy Clicks"
    6. Save the tag.
  5. Repeat these steps to create tags for the Contact and About links.
  6. Publish

Use a single tag to track clicks

You can simplify your container with a single trigger that uses a regular expression to fire on the correct pages, and a single tag that uses a Tag Manager variable for the Label field:

  1. Add a Google Analytics pageview tag if one does not already exist. This tag must fire on all pages.
  2. Enable Tag Manager to capture clicked URL values:
    1. Click Variables.
    2. Click Configure in the Built-In Variables section
    3. Select the Click URL built-in variable.
  3. Create a single trigger to handle link clicks for each item in the table above:
    1. Click Triggers and then New and create a new trigger with these settings:
      • Trigger type: Click - Just Links
      • Wait for tags: Check
      • Max wait time: (use the default value of 2000ms)
      • Check Validation: Uncheck
      •  Enable this trigger when all of these conditions are true: Click URL and then matches RegEx and then contact\.html|buy\.html|about\.html
      • Fire On: All Clicks
    2. Name the trigger “Trigger - Nav Clicks” and save.
  4. Create a single Tag to handle all clicks:
    1. Click Tags and then New.
    2. Click Tag Configuration and then Universal Analytics.
    3. Set Track Type to Event.
    4. Complete the Event Tracking Parameters:
      • Category: Nav
      • Action: Select
      • Label: {{Click URL}}
    5. Click Triggering and select the trigger that you created in step 3, titled “Trigger - Nav Clicks”.
    6. Save the tag.
  5. Publish.
Tag Manager variables are called in text fields when wrapped in double brackets: {{Example}}.

Clicks on any element

Use this technique to track clicks on elements other than links. This includes clicks on images, <div> elements, or any other item on the page accessible by the DOM. For this example, assume that each image has a class attribute value of Gallery_Image and a unique id attribute value for each image (e.g. id="Golden_Gate_Bridge", id="Taj_Mahal", etc.):

  1. Add a Google Analytics pageview tag if one does not already exist. This tag must fire on all pages.
  2. Enable Tag Manager to capture clicked class and ID values:
    1. Click Variables.
    2. Click Configure in the Built-In Variables section.
    3. Select the Click Classes and Click ID built-in variables.
  3. Create a new trigger that fires when a link has a class attribute value of Gallery_Image:
    1. Click Triggers and then New and create a new trigger with these settings:
      • Trigger type: Click - All Elements
      • Fire On: Some Clicks
      • Fire this trigger when an Event occurs and all of these conditions are true: Click Class and then contains and then Gallery_Image.
    2. Save the trigger and name it "Trigger - Gallery Image Click" when prompted.
  4. Create a tag to capture the ID attribute values for a clicked image:
    1. Click Tags and then New.
    2. Click Tag Configuration and then Universal Analytics.
    3. Set Track Type to Event.
    4. Complete the Event Tracking Parameters:
      • Category: Image Gallery
      • Action: Click
      • Label: {{Click ID}}
      • Non-Interaction Hit: False
      • Google Analytics Settings: Select an existing Google Analytics Settings variable, or create a new one.
    5. Click Triggering and select the trigger that you created in step 3, titled "Trigger - Gallery Image Click".
    6. Save the tag as "GA - Event Tag - Gallery Image Click".
  5. Publish.

Timed intervals

Implementation of timed interval tags may influence bounce rate reports to appear lower than expected.

Track timed intervals when you need to  understand time on page when no events are triggered. This might include users who read text or play video on the page. Additionally, given that Google Analytics sessions timeout after 30 minutes by default, you may wish to implement a ‘keepalive event’ to ensure that an activity is sent every 25 minutes.

To configure a tag that tracks timed intervals:

  1. Add a basic Google Analytics pageview tag if one does not already exist. This tag must fire on all pages.
  2. Create a Timer Trigger:
    1. Click Triggers and then New and add these settings to the trigger configuration:
      • Trigger type: Timer
      • Event Name: gtm.timer
      • Interval: 1500000 (calculated in milliseconds)
      • Limit: 5
      • Enable this trigger when all of these conditions are true: Page URL and then contains and then video.html
    2. Save the Trigger as “Trigger - Session Timer"
  3. Create a session timer tag:
    1. Click Tags and then New.
    2. Click Tag Configuration and then Universal Analytics and add these settings to the tag configuration:
      • Track type: Timing
      • User Timing Tracking Parameters: Leave blank or add values as desired for your reports.
    3. Click Triggering and select the trigger that you created in step 2, titled “Trigger - Session Timer”.
  4. Publish.

Form submits

This technique will cause a tag to fire every time a form is submitted. For this example, we want to record all submissions of a form with the element ID attribute value of "My_Form":

  1. Add a basic Google Analytics pageview tag if one does not already exist. This tag must fire on all pages.
  2. Enable Tag Manager to capture form IDs:
    • Click Variables.
    • Click Configure in the Built-In Variables section.
    • Select the Form ID built-in variable.
  3. Create a form submit trigger:
    • Click Triggers and then New and create a new trigger with these settings:
      • Type: Form Submission
      • Wait for Tags: unchecked
      • Check Validation: unchecked
      • Fire On: Some Forms
      • Fire this trigger when an Event occurs and all of these conditions are true: Form ID and then contains and then My_Form
    • Save the trigger as “Trigger - My Form Submits”.
  4. Create the tag to track form submits:
    1. Click Tags and then New.
    2. Click Tag Configuration and then Universal Analytics.
    3. Set Track Type to Event.
    4. Fill in the Event Tracking Parameters:
      • Category: Forms
      • Action: Submit
      • Label: Lead Gen - {{Form ID}}
    5. Non-Interaction Hit: False
    6. Google Analytics Settings: Select an existing Google Analytics Settings variable, or create a new one.
    7. Click Triggering and select the trigger that you created in step 3, titled “Trigger - My Form Submits”.
    8. Save the tag as "GA - Event Tag - Form Submits".
  5. Publish.
Was this article helpful?
How can we improve it?