There are three ways to send events to Amplitude via Google Tag Manager:
- By using the Google Tag Manager template created by Amplitude, available for download here. This is the preferred method.
- The app sends events to the data layer, which are then logged to Google Analytics by GTM.
- Instrumenting Amplitude events on elements in the UI to events directly in GTM.
This article will give you a brief explanation of each method.
Use Amplitude's GTM template
To send events to GTM using Amplitude's GTM template, follow these steps:
- Download the
template.tpl
file from this Github repo. - Browse to the Google Tag Manager web container where you want to test the template.
- In the container, click Templates in the left-hand side navigation.
- In the Tag Templates panel, click New.
- In the template editor, select Import from the overflow menu (the three-dot menu in the top right corner).
- Select the
template.tpl
file and click to proceed. - Wait for the template to finish importing. Once it has, click Save and close the editor.
Send events to a data layer
The requirements for sending events to a data layer are different for web, Android, and iOS applications. For more information on each, follow the links below:
Instrument events on UI elements directly in GTM
To log your first event in this way, follow these steps:
-
In your web application, add the Amplitude JS load snippet and initialize with your API key (see the Amplitude Javascript SDK documentation for more information). Do this on every page before you load the Google Tag Manager script.
-
In Google Tag Manager, create a custom HTML tag and a trigger. In this example, we are logging an event any time a user accesses a URL that contains “customers” in it.
Configure the trigger like this:
Then, inside the custom HTML tag, enter the event you’d like to log:
Verify your events were sent successfully
NOTE: The free Chrome extension Instrumentation Explorer will display events that trigger into Amplitude as you click through your app, and can be used to verify events are reaching Amplitude.
-
In your web application, trigger the event (i.e., visit one of your pages that contains “customers," as in the example above).
-
In Amplitude, click New > User look-up.
- Check if the events you triggered are showing for your user.
Learn more about data validation in How to validate your event data in Amplitude.