Google Tag Manager uses trigger configurations to fire tags in response to events. This article explains how to use Tag Manager to set up Universal Analytics event tags that are triggered in response to clicks on links, clicks on other types of elements, at timed intervals and when forms are submitted.
Link clicks
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 link names 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 measure clicks
This method requires the creation of three triggers and three tags – one trigger/tag pair for each item in the table above:
- Add a Google Analytics pageview tag if one doesn't already exist. This tag must fire on all pages.
- Enable Tag Manager to capture clicked URL data:
- Click Variables.
- In the Built-In Variables section, click Configure.
- Enable the tick box for Click URL.
- Create triggers that listen for link clicks for buy.html, contact.html and about.html:
- Click Triggers New.
- Click Trigger configuration Click – Just links.
- Add these settings to the trigger configuration:
- Wait for tags: Enable
- Max waiting time: 2,000 (milliseconds)
- Check validation: Disable
- Enable this trigger when all of these conditions are true: Page URL contains
/
- This trigger fires on: Some link clicks Click URL contains buy.html
- Name the trigger ‘Trigger – Buy clicks’ and save the trigger.
- Repeat these steps for ‘contact.html’ and ‘about.html’
- Create three new Google Analytics tags to measure clicks for each page:
- Click Tags New.
- Click Tag configuration Google Analytics – Universal Analytics.
- Set Track type to Event.
- Enter 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.
- Click Triggering and select the trigger that you created in step 3, titled ‘Trigger – Buy clicks’.
- Give the tag a name and save the tag configuration.
- Repeat these steps to create tags for the Contact and About links. Remember to set the Label value according to the name of the page, e.g. ‘Buy’ for buy.html, ‘Contact’ for contact.html, and ‘About’ for about.html
- Publish the container.
Use a single tag to measure 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:
- Add a Google Analytics pageview tag if one doesn't already exist. This tag must fire on all pages.
- Enable Tag Manager to capture clicked URL values:
- Click Variables.
- In the Built-In Variables section, click Configure.
- Select the Click URL built-in variable.
- Create a single trigger to handle link clicks for each item in the table above:
- Click Triggers New.
- Click Trigger configuration Click – Just links
- Configure the trigger with these settings:
- Wait for tags: Enable
- Max waiting time: 2,000ms
- Check validation: Disable
- Enable this trigger when all of these conditions are true: Page URL contains
/
- This trigger fires on: Some clicks Click URL matches RegEx
contact\.html|buy\.html|about\.html
- Name the trigger ‘Trigger – Nav clicks’ and save.
- Create a single tag to handle all clicks:
- Click Tags New.
- Click Tag configuration Google Analytics – Universal Analytics.
- Set Track type to Event.
- Complete the Event tracking parameters:
- Category: Nav
- Action: Select
- Label: {{Click URL}}
- Click Triggering and select the trigger that you created in step 3, titled ‘Trigger – Nav clicks’.
- Save the tag.
- Publish the container.
Clicks on any element
Use this technique to measure 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, each image has a class
attribute value of gallery
and a unique ID attribute value for each image:
In this example, we use these attributes to configure a trigger that fires on image tags with class="gallery"
, and use that trigger to fire a tag that sends the respective ID values (e.g. Golden_Gate_Bridge
, Taj_Mahal
) to Google Analytics:
- Add a Google Analytics pageview tag if one doesn't already exist. This tag must fire on all pages.
- Enable Tag Manager to capture clicked class and ID values:
- Click Variables.
- In the Built-In Variables section, click Configure.
- Select the Click classes and Click ID built-in variables.
- Create a new trigger that fires when a link has a class attribute value of
gallery
:- Click Triggers New.
- Click Trigger configuration Click – All elements.
- Enable this trigger when all of these conditions are true: Page URL contains
/
- This trigger fires on: Some clicks Click classes contains
gallery
. - Save the trigger and name it ‘Trigger – Gallery image click’ when prompted.
- Create a tag to capture the ID attribute values for a clicked image:
- Click Tags New.
- Click Tag configuration Universal Analytics.
- Set Track type to Event.
- Complete the Event tracking parameters:
- Category: Image gallery
- Action: Click
- Label: {{Click ID}}
Note: The curly brackets are used in text fields and custom code to replace a valid Tag Manager variable name with the relevant value retrieved from the event. - Non-interaction hit: False
- Google Analytics settings: Select an existing Google Analytics settings variable, or create a new one if necessary.
- Click Triggering and select the trigger that you created in step 3, titled ‘Trigger – Gallery image click’.
- Save the tag as ‘GA – Event tag – Gallery image click’.
- Publish the container.
Timed intervals
Measure 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 time out 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 measures timed intervals:
- Add a basic Google Analytics pageview tag if one doesn't already exist. This tag must fire on all pages.
- Create a Timer Trigger:
- Click Triggers New.
- Click Trigger configuration Timer.
- Add these settings to the trigger configuration:
- Event name: gtm.timer
- Interval: 1,500,000 (calculated in milliseconds)
- Limit: 5
- Enable this trigger when all of these conditions are true: Page URL contains video.html
- This trigger fires on: All timers
- Save the trigger as ‘Trigger – Session timer’
- Create a session timer tag:
- Click Tags New.
- Click Tag configuration 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.
- Click Triggering and select the trigger that you created in step 2, titled ‘Trigger – Session timer’.
- Publish the container.
Form submits
This technique will cause a tag to fire every time a form on a web page is submitted. This example assumes that the <form>
HTML tag contains an ID attribute with a value of ‘contact_us
’:
We can use this ID to create a trigger that will listen for when this form is submitted:
- Add a basic Google Analytics pageview tag if one doesn't already exist. This tag must fire on all pages.
- Enable Tag Manager to capture form IDs:
- Click Variables.
- Click Configure in the Built-in variables section.
- Select the Form ID built-in variable.
- Create a form submit trigger:
- Click Triggers New.
- Click Trigger configuration Form submission.
- Add these settings to the trigger configuration:
- Wait for tags: Disable
- Check validation: Enable
- Enable this trigger when all of these conditions are true: Page URL contains
/
- This trigger fires on: Some forms Form ID contains
contact_us
- Save the trigger as ‘Trigger – My form submits’.
- Create the tag to measure form submits:
- Click Tags New.
- Click Tag configuration Universal Analytics.
- Set Track type to Event.
- Fill in the Event tracking parameters:
- Category: Forms
- Action: Submit
- Label: Lead gen – {{Form ID}}
Note: The curly brackets are used in text fields and custom code to replace a valid Tag Manager variable name with the relevant value retrieved from the event.
- Non-interaction hit: False
- Google Analytics settings: Select an existing Google Analytics settings variable, or create a new one.
- Click Triggering and select the trigger that you created in step 3, titled ‘Trigger – My form submits’.
- Save the tag as ‘GA – Event tag – Form submits’.
- Publish the container.