Skip to main content

Introduction

Google Tag Manager is a free tool that enables marketers to install, store, and manage marketing tags without modifying website code, and instantly deploy tags on your website or mobile app from an easy-to-use web-based interface. 

MoEngage and Google Tag Manager Integration

With the MoEngage and Google Tag Manager integration, you can deploy the MoEngage Web SDK and leverage all its capabilities without writing any code on your website.

Integration via Web SDK

Ensure you have a Google Tag Manager account with permission to import templates and add new tags.
There are two Google Tag Manager templates built by MoEngage, the Initialization Tag and the Actions Tag. Both tags can be added to your workspace by importing them from the Templates section.

Import the templates into your GTM Workspace

Step 1: Download and import the two tags:
GTM1
  1. Download the Initialization Tag and the Actions Tag (right-click and Save).
  2. To import the tag into your GTM workspace, go to the Templates screen from the left side menu.
    Gtm2
  3. Under Tag Templates, click the “New” button >> Actions menu (top-right) >> Import. Select the Initialization tag file you just downloaded.
  4. Click save when you see the MoEngage logo on the left.
  5. Do the same for the Actions tag as well.

Initialization tag

The Initialization tag is used to add the MoEngage Web SDK to your website. This will enable you to take full advantage of the MoEngage native setup. Step 1: Select and configure the Initialisation Tag
Gtm3
  1. On your GTM dashboard, click Tags >> New.
  2. Click Tag Configuration, and under “Custom” look for the MoEngage initialization tag.
  3. Setup the tag according to your needs:
Step 2 (Optional): Enabling Web Push notification Optionally, if you want to be able to send push through the Google Tag Manager, first follow the push integration guidelines and place serviceworker file at the root directory of your project. Step 3: Triggering After configuring the tag, trigger it at every page view of your site:
Gtm4
This will ensure the MoEngage Web SDK is initialized on every page of your website.

Actions tag

The MoEngage Actions Tag template lets you trigger custom events, update custom as well as standard user attributes, and add or update user IDs. Step 1: Select and configure the Actions Tag:
Gtm6
  1. On your GTM dashboard, click Tags >> New.
  2. Click Tag Configuration, and under “Custom” look for the MoEngage Actions Tag.
  3. Setup the tag according to your needs.
The MoEngage Actions tag can be used to perform any of the following actions using the MoEngage Web SDK:

Track Custom Event

Gtm7
In order to track custom events, select the Tag Type as “Track Custom Event”.

Track Custom User Attributes

Gtm8
In order to track custom user attributes, select the Tag Type as “Track Custom User Attributes”.

Login

Please download and use the latest initialisation and action templates. If you are using “Login” tag type to login users, please switch to the below tag type.
In order to log the user in, select the Tag Type as “Identify User (Identity object as param)“
Logingtm
Use the below names as the “Attribute Name” if you want to track the standard user attributes. Custom user attribute names can be used as is. For example, if Email (Standard), Mobile Number (Standard) and ID are configured as User Indentities for your account, then you can login the user with these three attributes like it is done below. You can use variables to dynamically set the attribute values for the user; we have given static values just for the example.
Example
If you want to login users with just an ID, you can choose the “Identify User (uid as param)” tag type instead.
Identify User

Logout

Logout
In order to log the user out, select the Tag Type as “Logout”.

Update User Identities

Please download and use the latest initialisation and action templates. If you are using “Update User ID” tag type to update user ID, please switch to the below tag type.
You can use Idenitfy User tag types to update the identities of the user. For example, if you wish to update the current user’s identities- Email and ID then it can be done like this (variables can be used)-
Update User Identities
Read more about how updating the User ID of a user works in MoEngage.

Track Standard Attribute

Track Standard Attribute
In order to track a standard attribute, select the Tag Type as one of the following:
  1. Track First Name
  2. Track Last Name
  3. Track Email
  4. Track Mobile
  5. Track Username
  6. Track Gender
  7. Track Date of Birth
Read more about updating the standard attributes of a user in MoEngage.

Enable SDK

You can use this tag to enable the SDK. For more information, refer here.
Enablesdk

Disable SDK

You can use this tag to disable the SDK. For more information, refer here.
Disable SDK

Enable Data Tracking

You can use this track to enable data tracking. For more information, refer here.
Enable Data Tracking

Disable Data Tracking

You can use this track to disable data tracking. For more information, refer here.
Disable Data Tracking
Step 2: Triggering After configuring the tag, trigger it at the appropriate point on your website. This will depend on whether you want to track a custom event, or login/logout a user.

Tags sequencing

Please ensure that the Initialisation Tag has been executed before any Action Tag is executed. If you have Actions that need to be executed on page load or immediately after the Initialisation tag, the Action tag may execute before the SDK is even initialised. To prevent this undesired behavior, add Tag Sequencing and only fire the Action tag after the Initialisation Tag.
  1. Go to your Action Tag -> Advanced Settings -> Tag Sequencing -> Fire a tag before Moengage Actions Tag fires
    Tagssequencing
  2. Select the Initialisation Tag.

Integration via GTM Server Side

You can also forward the events captured on your GTM server to MoEngage without writing any code on your website. Read more about how to set up the integration with GTM Server and MoEngage on our help docs.

Handle Ad Blockers (Custom Proxy Domain)

To ensure ad blockers do not interrupt MoEngage SDK traffic, you can route requests through a custom proxy domain. For more information, refer to Handle Ad Blockers. Follow these steps to update your GTM configuration. 1. Update Template Permissions: You must authorize the MoEngage SDK to load scripts from your custom domain by updating the script injection permissions in the GTM template. Follow these steps:
  1. In the MoEngage initialization tag template, select the Permissions tab and expand the Inject scripts section.
  2. Add your custom domain to the allowed URL match patterns. Use the format https://cdn.yoursubdomain.yourdomain.com, replacing the placeholder with your actual customProxyDomain.
Update Template Permissions
2. Configure the Custom Proxy Domain Field: Specify your subdomain hostname in the tag configuration to ensure all network requests use your proxy.
  • In the Custom Proxy Domain field, enter your configured subdomain hostname, for example, yoursubdomain.yourdomain.com.
Configurethe Custom Proxy Domain Field