There are effectively two ways to send events to Amplitude via GTM:
- The app sends events to the data layer, which are then logged to GA by GTM (recommended option as it allows more flexibility in sending events)
- Instrumenting Amplitude events on elements in the UI to events directly in GTM.
Sending events to a data layer
This demo app is a proof of concept, with just the 3 most important functionalities implemented (logging events, setting user Id, and setting user properties).
Instrumenting events on UI elements directly in GTM
This is a step-by-step tutorial to log your first event:
In Google Tag Manager, create a Custom HTML Tag and a Trigger. For this example, we are logging an event any time a user accesses a URL that contains “customers” in it.
2. Example Tag
Inside the Custom HTML tag, enter the event you’d like to log.
Verify if the events are successfully sent to Amplitude
Note: We recommend getting the Instrumentation Explorer, a free Chrome extension that will display events that fire into Amplitude as you click around your website.
In your web application, perform the event (visit one of your pages that contains “customers”, as in the example above).
In Amplitude, click on New > User look-up
- Check if the events you performed are showing for your user
You can get more information about data validation in How to validate your event data in Amplitude.
One of our customers put together some more information on how to setup a Google Tag Manager implementation. You can find it here.