How to Set User IDs in Amplitude via with Google Tag Manager (GTM)

For product teams who manage their tracking via Google Tag Manager (GTM), the process of setting the Amplitude User ID is a matter of sequencing three key components: a Variable, a dedicated Tag, and a precise Trigger.

Here is a step-by-step guide on how to configure GTM to pass the correct User ID to Amplitude.

Prerequisite: Installing the Amplitude Browser SDK

Before you start, ensure the Amplitude SDK is integrated into your GTM container:

  1. Open your GTM container (assuming your GTM code is already connected to your site).
  2. Navigate to the Template Gallery and search for the Amplitude Browser SDK or the relevant Amplitude tag template.
  1. Add the template to your workspace

Step-by-Step GTM Configuration

Step 1: Create the User ID Variable

The User ID needs to be pushed from your product’s backend to the browser’s Data Layer upon a login or account creation event.(Mainly when its available). GTM then needs a variable to access this value.

  1. In GTM, go to Variables and create a New >User-Defined Variable.
  2. Select the Data Layer Variable type.
  3. Enter the name of the Data Layer key that contains the User ID (e.g., user_id). This variable will dynamically return the user’s unique ID when it’s available.

Step 2: Create the “Set User ID” Tag

You need a specific tag dedicated to telling Amplitude who the user is, separate from any event tracking tags.

  1. Go to Tags and create a New Tag.
  2. Select the Amplitude tag template you installed.
  3. Select the Tag Type as Set User ID.
  1. In the User ID field, put the user id variable that we created earlier. 

Step 3: Define the Trigger

The trigger controls when the tag fires. It’s important that this tag only fires when a valid, non-null User ID is available.

  1. Go to Triggers and create a New Trigger.
  2. The best practice is to use a Custom Event that is pushed to the Data Layer precisely when the user has logged in or created an account (e.g., when the event account_created or user_logged_in is pushed).
  1. Assign this trigger to the Set User ID tag created in Step 2.

Now save the tag and publish!