Google Tag Manager Setup

Integrate the Leanplum JavaScript SDK through Google Tag Manager

The Leanplum JavaScript SDK can be used through a Google Tag Manager (GTM) tag. The tag loads the complete SDK and provides a user interface for triggering common tracking scenarios, as well as to enable the Rich In-App messaging channel in your website.

When firing, the tag can be configured to trigger the following functionality:

  • Track user sessions
  • Track events
  • Track purchases
  • Set user attributes
  • Load the Leanplum JavaScript SDK and use Custom Scripts to trigger functionality

To install the tag, search the Google Tag Manager gallery for 'leanplum' and add the tag to your workspace.

Using the Leanplum SDK Tag

To use the tag, copy your App ID and Production client key from the app settings screen in your Leanplum dashboard.

For more information about in-app messaging on your website, refer to the multi-platform delivery help topic.

Once configured, you can start tracking with Leanplum.

Using custom code when loading through GTM

The Leanplum Tag will queue any calls made to it while the script loads. Once the SDK loads, the calls will be resolved sequentially. To call methods after the tag loads, trigger a Custom HTML Tag after the Leanplum SDK Tag loads.

Previewing in-app messages and running in development mode

If your site has a development (staging/QA) environment, you can set up the Leanplum GTM tag to get the client secret from the data layer. This allows you to preview in-app messages campaigns on your development site, while using the production keys on your public website.


Use only production keys on public websites

Using keys with more privileges (e.g. a development key) on a public website allows users to query and change data that they should not. Never expose such keys to a public site.

In case a non-production key has been exposed, you can revoke it and create a new one in the App settings screen.

Example use-cases

These examples show how to configure the GTM tag for common scenarios.

Track user sessions

To track user sessions, configure the tag trigger and set the Firing options of the Leanplum tag to "Load SDK and start session".


The Google Tag Manager configuration for tracking user sessions. The Application Key and Client Secret fields are set, and the Firing options are set to "Load and start session".

Update user attributes and track behaviors

You can use the "Set user attributes" firing options to update the user profile.

For example, set the email attribute of the user to allow targeting by email campaigns in Leanplum. You can use a GTM Variable that gets the email value from the site data and pass it to the firing options.


A screenshot of the Google Tag Manager configuration for updating the user attributes.

When tracking events, you can set their parameters, so that you can use these for segmentation by event parameters.

For example, by tracking an "Add to cart" event and setting the product parameter to the {{ Product Name }} variable (defined in Google Tag Manager and fetched from the page), you will be able to send Leanplum campaigns to users who added specific product (e.g. Bananas) to their shopping cart.


A screenshot of the Google Tag Manager configuration for tracking an "Add to cart" event.