Overview
You can integrate the Web SDK for any of the supported frameworks (CDN, NPM, GTM, SPA, AMP, Flutter, and Shopify) using one of the following two methods:- Script-based Initialization (Recommended): Use the form-based interface to generate a validated code snippet or access module-specific configurations. For more information, refer to Script-based Initialization (Recommended).
- Manual Integration: Manually configure the SDK parameters and initialization code. For more information, refer to Option 2: Manual Integration.
You must have your Workspace ID (App ID) and Data Center. You can retrieve these details by navigating to
Settings > App > General on the Dashboard.Option 1: Script-based Initialization (Recommended)
To ensure a reliable and streamlined setup, we recommend using the Script-based initialization method. This method generates a validated JavaScript snippet, eliminating potential syntax errors and automatically including required flags based on the application type.- Workspace Details: Ensure you have your Workspace ID (App ID) and Data Center (found in
Settings > App > Generalon the Dashboard). - Service Worker (For Web Push): If enabling Web Push, create a file named
serviceworker.jsin your root directory. - Whitelisting (CSP): If your site uses a Content Security Policy, whitelist the necessary MoEngage URLs. For more information, refer here.
- Navigate to the Web SDK Initialization Website.
- Configure the values based on your application requirements. Refer to the Configuration Parameters table below for detailed descriptions of each field.
- Click Generate Code at the bottom of the form to create your validated JavaScript snippet.
- Implement the Generated Code: Copy the code snippets displayed by the tool and paste them into your project as follows:
- Update Service Worker (If Web Push Enabled): Add the generated
importScripts(...)line to the top of yourserviceworker.jsfile. - HTML File Changes (If Web Personalization Enabled): Add the generated
<link>tags and the Personalization<script>tag to the top of the<head>section of your root HTML file. - Initialize the SDK:
- For CDN: Paste the initialization script directly into the
<head>tag. - For NPM: Paste the
importstatement and theMoengage.initialize({...})block into your main JavaScript file.
- For CDN: Paste the initialization script directly into the
- Update Service Worker (If Web Push Enabled): Add the generated
Post-requisiteAfter integrating, verify the setup by opening your browser’s Developer Tools (Network tab). Reload the page and confirm that requests are successfully reaching MoEngage endpoints (e.g.,
cdn.moengage.com or sdk-0X.moengage.com).Configuration Parameters
The initialization method requires specific inputs to generate the correct code. The following table details the available fields in the configuration.Configuration Parameters
Configuration Parameters
| Section | Field Name | Description |
|---|---|---|
| Integration Method | How will you install the SDK? | Determines the installation method:
|
| Core Configuration | MoEngage Workspace ID | Identifies the application within the MoEngage dashboard using a unique App ID. |
| MoEngage Data Center | Specifies the data center associated with the dashboard URL. Refer here for more details. | |
| MoEngage Environment | Sets the data reporting environment. Use 'TEST' to send data to your test environment or 'LIVE' for production data. | |
| Log Level | Controls the verbosity of SDK logs in the browser console:
| |
| MoEngage Project ID | Identifies the specific project if the Portfolio feature is enabled. | |
| Use Latest SDK Version | Targets the most recent version of the Web SDK automatically when enabled. | |
| SDK Version | Specifies the SDK version you want to target. This field is not visible if Use Latest SDK Version checkbox is selected. | |
| Application Profile | My website is a Single Page Application (SPA) | Indicates whether your website operates as a Single Page Application (SPA). |
| This is for a browser extension | Indicates whether your application is a browser extension. Note: Prevents the SDK from storing cookies and disables cross-subdomain user sharing if selected. | |
| Feature Configuration | Enable Web Push Notifications | Includes the module required for collecting push tokens and displaying browser notifications. |
| Enable On-Site Messaging | Enables the module required to display on-site campaigns, such as pop-ups and interstitials, on the website. | |
| Enable Cards Notification Inbox | Enables the Notification Inbox for Cards module and unlocks the UI Customization section. | |
| Enable Web Personalization | Enables the web personalization module. | |
| Disable SDK at Initialization | Initializes the SDK in a disabled state. Note: Requires an explicit call to the Moengage.enableSdk() method to enable tracking if selected. | |
| Web Push Details (Visible when Enable Web Push Notifications is enabled) | Service Worker Path | Defines the path to your service worker file from the site root. The default path is, /serviceworker.js. |
| Service Worker Scope | Defines which pages the service worker can be active on. The default is / (the entire site). To limit it, enter a specific path, for example, /app/. | |
| Cards Configuration & UI Customization (Visible when Enable Cards Notification Inbox is enabled) | CSS Selector for Inbox Icon | Identifies the HTML element that opens the inbox when clicked using its unique CSS ID or Class (e.g., #bell-icon). |
| Floating Bell Icon (Desktop) | Configures the settings for the desktop floating bell icon:
| |
| Floating Bell Icon (Mobile) | Configures the settings for the mobile floating bell icon:
| |
| General & Icons | Configures the global styling and icons for the inbox container:
| |
| Card Dismissal | Controls the ability for users to dismiss cards.
| |
| Navigation Bar | Configures the settings for the top header of the inbox.
| |
| Tabs | Configures the category tabs (e.g., “All”, “Unread”).
| |
| Card Content | Configures the typography and separation style of the cards.
| |
| Empty State | Configures the visual elements displayed when there are no messages.
| |
| Cards Inbox z-index | z-index Value: Sets the z-axis stack order of the inbox container. |
Common Configuration Scenarios
You can configure environment selection and log verbosity independently to suit your development and debugging needs:Environment (env) | Log Level (logLevel) | Data Destination | Console Output |
|---|---|---|---|
'TEST' | 0 | Test Dashboard | Clean console (no SDK logs). |
'TEST' | 1 | Test Dashboard | Critical logs and errors (Recommended for testing). |
'LIVE' | 0 | Production Dashboard | Production settings. No logs shown. |
'LIVE' | 1 | Production Dashboard | Enables SDK error logs in production for troubleshooting. |
Option 2: Manual Integration
You can manually integrate the SDK by configuring the initialization parameters directly in your codebase. Select your platform or framework from the list below to view the specific manual integration guide:- CDN
- NPM
- Google Tag Manager(GTM)
- Single Page App (SPA) Support
- Configure and Integrate AMP Web Push
- Flutter SDK
- Shopify App
- Specify the MoEngage Data Center for Web SDK data collection.
- Enable Whitelisting.
This is a required step for all web modules.
Method 1: MoEngage CDN
TEST Integration
Data Center
Following details of the different data centers you need to set based on the dashboard hosts| Dashboard host | Data Center |
|---|---|
| dashboard-01.moengage.com | dc_1 |
| dashboard-02.moengage.com | dc_2 |
| dashboard-03.moengage.com | dc_3 |
| dashboard-04.moengage.com | dc_4 |
| dashboard-06.moengage.com | dc_6 |
- Insert the following code in the
<head>tag of every page that requires tracking. - Replace “APP ID” available in the settings page of MoEngage Dashboard.
Navigate toDashboard --> Settings --> App --> Generaland copy the APP ID. - Replace the value of sdkVersion with the version of Web SDK you intend to use. It is recommended to use the format x (major)
- Replace “DC” with the data center form the above table.
- if you have Portfolio enabled for your workspace, you need to pass the
project_idkey and the project ID of your project as value.
PRODUCTION or LIVE Integration
To integrate into the production or live environment:- Insert the following code in the
<head>tag of every page that requires tracking. - Replace “APP ID” available in the settings page of MoEngage Dashboard.
Navigate toDashboard --> Settings --> App --> Generaland copy the APP ID. - Replace the value of sdkVersion with the version of Web SDK you intend to use. It is recommended to use the format x (major)
- Replace “DC” with the data center form the above table
- If you have Portfolio enabled for your workspace, you need to pass the
project_idkey and the projectID of you project as value.
Upgrading the SDK
When you reference the MoEngage Web SDK from our content delivery network, for example,https://cdn.moengage.com/release/{DC}/versions/{sdkVersion}/moe_webSdk.min.latest.js where sdkVersion = x (using sdkVersion = x, i.e. fixing version only till major release is our default integration recommendation), your users will receive new features and bug fixes automatically when they refresh your site.
However, when we release major changes, we require you to upgrade the MoEngage Web SDK manually to ensure that nothing in your integration will be impacted by breaking changes.
You can keep up-to-date with our latest release following our changelog for a full accounting of our Web SDK release history. To upgrade the MoEngage Web SDK:
- Update the MoEngage library version by changing value of
sdkVersionin the integration script. - If you have web push integrated, update version in the serviceworker cdn url in the service worker file on your site - by default, this is located at
/serviceworker.jsat your site’s root directory, but the location may be customized in some integrations.importScripts("https://cdn.moengage.com/release/{DC}/versions/[old-version-number]/serviceworker_cdn.min.latest.js"); - If you have web personalisation integrated, update the version in the web personalisation script-
https://cdn.moengage.com/release/{DC}/versions/[old-version-number]/moe_webSdk_webp.min.latest.js?app_id={workspace-id}
Method 2: Using NPM
If your site uses NPM or Yarn package managers, you can add the Moengage NPM package as a dependency.import or require the library in the typical fashion:
- if you have Portfolio enabled for your workspace, you need to pass the
project_idkey. - if you want to change the integration settings for specialized projects, then pass it as shown in the following snippet:
If you wish to always use the latest version of the Web SDK (instead of the version of @moengage/web-sdk mentioned in your package manager), pass the property
useLatest with value set to true in the configuration:moengage.initialize({app_id: 'XXXXXXXXXXXXXXXX', useLatest: true});Use the version of Web SDK that you intend by altering the version of @moengage/web-sdk dependency in your package manager. More information on how to use specific version or range of versions can be found here.
Whitelisting URLs
Optional step for all web modules
Ensure that you whitelist the following endpoints for smooth integration. script-src: image-src:
- https://moe-email-campaigns.s3.amazonaws.com/
- https://image.moengage.com/
- https://image-eu.moengage.com/
- https://image-ap1.moengage.com/
- https://image-04.moengage.com/
- https://image-06.moengage.com/
- https://image.moengage.com/all-campaign-images-moe-dc-100/
- https://sdk-01.moengage.com/
- https://sdk-02.moengage.com/
- https://sdk-03.moengage.com/
- https://sdk-04.moengage.com/
- https://sdk-06.moengage.com/
Refused to connect to https://\*\*\*.moengage.com/\*\*\*\* because it violates the following Content Security Policy directive. if you do not whitelist the URLs.
For more information, refer to Content Security Policy.
Troubleshooting
Not able to debug SDK in the environment.
Check that thelogLevel is set to 1 (or 2 for verbose) while initializing the MoEngage SDK.
How to see SDK logs in Live environment?
Configure thelogLevel to 1 while initializing the MoEngage SDK.
What is the difference between TEST & LIVE environment?
MoEngage provides a staging environment referred to as the TEST environment. The LIVE environment contains data about your actual users/customers from your production website. MoEngage Web SDK uses theenv parameter to route data correctly:
env: 'TEST': Routes data to your Test dashboard.env: 'LIVE': Routes data to your production dashboard.
logLevel parameter regardless of the environment selected.