Connect your IDE to the MoEngage docs MCP server for accurate, context-aware SDK guidance inside your development environment. Your assistant searches this documentation directly, helping you move through the integration with confidence.
Prefetch the MoE domain
Add the following code snippet at the top of the<head> to prefetch the moengage.com domain:
Method 1: Initiate Web P Module
The following table contains the details of the different data centers mapped to the dashboard hosts and is required for integration.Production or LIVE Environment
Add this script to initiate the web personalization module:- Replace the ‘workspace_id’ in the URL above with the Workspace ID in the MoEngage Dashboard settings. Navigate to Dashboard -> Settings -> App -> General and copy the Workspace ID.
- Replace ‘DC’ in the URL above with the data center your instance is hosted on. MoEngage hosts each customer in a different data center. Tracked data is stored in the default data center of MoEngage. To find your data center mapping, refer to Data Center Mapping. The possible value is dc_X where ‘X’ is your data center number.
- Replace ‘sdkVersion’ in the URL above with the version of Web SDK that you are using. In case you are using NPM, use the version number of @moengage/web-sdk dependency that is in your package.json file.
Test Environment
For data to be tracked in the test environment, includedebug_logs in the src of the above script as follows:
Method 2: If you have passed the useLatest: true flag in NPM initialisation config
In this case, Add this script to initiate the web personalization module:- Replace the ‘workspace_id’ in the URL above with the Workspace ID in the MoEngage Dashboard settings. Navigate to Dashboard -> Settings -> App -> General and copy the Workspace ID.
- Replace ‘DC’ in the URL above with the data center your instance is hosted on. MoEngage hosts each customer in a different data center. Tracked data is stored in the default data center of MoEngage. To find your data center mapping, refer to Data Center Mapping. The possible value is dc_X where ‘X’ is your data center number.
Cache Data Refresh
Web Personalization data will be fetched and stored in the browser cache. The data will be synced again on the Next Page Load only if it meets any of the below conditions:- 15 minutes have passed since the last data fetch
- Login or Logout is executed
Web Personalization Anti-Flicker Code
The Anti-Flicker snippet is a small piece of code that helps to maintain the user experience on your website when running a web personalisation experience. Know more about Flicker Page flickering is a problem that only occurs with experiments on a web page in areas that are visible when the page initially loads. There are certain cases where page flickering may not be an issue, such as experiments occurring below the visible area or experiments that occur after a visitor performs a specific action, such as triggering a Recently Viewed or Added to Cart product grids. In such scenarios, generally, the anti-flicker code need not be added to the website.Steps To Install Anti-flicker Code
To prevent page-flickering, there are 2 options- Masking the content of the entire page until the personalization is complete OR
- Masking individual elements that have been personalized using the WYSIWYG editor
Option 1: Masking content of the entire webpage
-
Add the below code as high on the page as possible, in the
<head>of your website code. -
In the script below, MAX_RENDER_TIME refers to the wait time (in milliseconds) before the visitor is shown the original website in case the personalized experience fails to load. You can update this value based on your website performance needs.
Option 2: Masking individual elements on the webpage
This method will only mask specific elements on the webpage that have been personalized. In the script below,- Add HTML selector of each personalized element on the webpage to the array personalizedSelectors. How to find HTML selectors for personalized elements?
- maxRenderTime refers to the wait time (in milliseconds) before the visitor is shown the original website in case the personalized experience fails to load. You can update this value based on your website performance needs.
-
Add the below code as high on the page as possible, in the
<head>section of your website code.
Option 1: Use the element’s HTML ID
- Right-click on the element.
- Select Inspect or Inspect Element in the context menu.
-
In the highlighted HTML, find the HTML ID for that element. This is how the input would look like for the element highlighted in the image.

Below is the input to be given to the anti-flicker snippet for the HTML element in consideration.
Option 2: Use the element’s HTML selector path
- Right-click on the element.
- Select Inspect Elementin the context menu.
- In the highlighted HTML, right click and choose Copy Selector in the context menu.

Below is the input to be given to the anti-flicker snippet for the HTML element in consideration