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:
PropertyValue
Workspace IDApp ID of your MoEngage account. You can find this by navigating to Settings -> General Settings
Debug Logs
  • True - if you want the logs to be shown on the console
  • False - if you want to hide the logs (make sure you select False for production website)
Critical - When Going Live
While pushing the code to live website please ensure debug_logs: 0 is initialized to send website data to LIVE MoEngage Dashboard (top toggle switch on Dashboard to right).
Data centerYour MoEngage Data Center region (DC_X).
  • DC_1
  • DC_2
  • DC_3
  • DC_4
Serviceworker custom pathThe path of your service worker file. Read more about setting up Push notifications support here.
Is Onsite-Messaging disabled?On-site Messaging Campaigns allow you to show personalized pop-ups and non-intrusive banners on your website.

Web SDK integration for On-site Messaging will automatically start working on all the pages where the web SDK is integrated.

If you want to disable Onsite-Messaging for this website, check this option. Read more about how to configure Onsite-Messaging here.
Is SPA enabled?If your website is a Single Page Application (SPA), select this option. Read more about how MoEngage handles SPAs here.
Keep SDK disabled?If selected, SDK is disabled during initialization. For more information, refer here.
Enable Web PersonalizationWeb Personalization is used to personalize the website experience for each user. Select this option if you want to leverage our Web Personalization capabilities. Read more about Web Personalization here.
Cards Config (in JSON)If you want to personalize cards, paste the JSON config in here. Read more about how to customise cards according to your needs here.
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”.
PropertyValue
Tag typeSelect “Track Custom Event”.
Event NameThe name of the event that you want to track. Note that standard events are automatically tracked by the SDK.
Event AttributesHere you can specify additional event attributes that you want to track along with this event. For each attribute, click on “Add Row” and then provide: 1. Attribute Name: The name of the custom attribute 2. Attribute Value: The value of the custom attribute. You can also use variables here.

Track Custom User Attributes

Gtm8
In order to track custom user attributes, select the Tag Type as “Track Custom User Attributes”.
PropertyValue
Tag typeSelect “Track Custom User Attributes”.
Attribute NameThe name of the custom attribute that you want to track.
Attribute ValueThe value of the custom attribute. You can also use variables here.

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
PropertyValue
Tag typeSelect “Identify User (Identity object as param)”.
User IdentitiesHere you can specify all the attributes you want to identify the user with. For each attribute, click on “Add Row” and then provide: 1. Attribute Name: The name of the attribute you want to set as indentity. 2. Attribute Value: The value of the attribute. You can also use variables here.
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.
User Attribute NameName to be used in “Attribute Name”
IDuid
Email (Standard)u_em
Genderu_gd
Birthdayu_bd
Nameu_n
First Nameu_fn
Last Nameu_ln
Mobile Number (Standard)u_mb
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
PropertyValue
Tag typeSelect “Identify User (uid as param)”.
Value of uidThe value of ID for the user. You can also use variables here.

Logout

Logout
In order to log the user out, select the Tag Type as “Logout”.
PropertyValue
Tag typeSelect “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
PropertyValue
Tag typeSelect “Track First Name/Last Name/Email/Mobile/Username/Gender/Date of Birth”.
ValueThe value of the standard attribute you selected.
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
PropertyValue
Tag typeEnable SDK

Disable SDK

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

Enable Data Tracking

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

Disable Data Tracking

You can use this track to disable data tracking. For more information, refer here.
Disable Data Tracking
PropertyValue
Tag typeDisable 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