Empower User Privacy with MoEngage Web SDK
The MoEngage Web SDK empowers you to offer your users explicit control over their data tracking. This is crucial for complying with privacy regulations such as GDPR and CCPA, ensuring that you collect data only from users who have given their explicit consent. With this feature, you can dynamically disable and enable the SDK, providing a flexible approach to managing user privacy preferences.
Understand SDK Opt-Out Functionality
When the MoEngage Web SDK is opted out of (either during initialisation or by a subsequent API call), its data tracking and communication capabilities are paused. This means the SDK will cease to collect or transmit user data and will not perform most of its usual functions.
When the Web SDK is disabled:
- No Data Transmission: The SDK will not track or send any user attributes, event data, or device information to MoEngage servers.
- Queue Clearance: Any data pending in the SDK's batch queue will be cleared and will not be sent.
- Feature Impact: Most SDK features that depend on active data tracking (like analytics, personalization, and triggered campaigns) will become unavailable.
- Web Push: Users will no longer receive push notifications.
You can re-enable the SDK at any time using the appropriate API method, at which point data tracking and SDK functionalities will resume.
How to Disable SDK?
Disable SDK at Initialisation (Preventing Initial Tracking)
To prevent any data tracking from the moment your website loads, you can initialise the SDK in a disabled state. This is achieved by passing the disableSdk: true
parameter in the SDK's initialisation configuration.
Moengage = moe({
app_id: "YOUR_APP_ID", // Replace with your actual App ID
debug_logs: 0, // Standard setting: 1 for development/testing, 0 for production
disableSdk: true // This line disables SDK functionality from the start
});
When the SDK is initialised with disableSdk: true
:
- It will not make any initial network calls for device registration (for example, device/add) or to fetch configurations (for example, websdksettings, sdkconfig).
- No default events that are typically tracked on page load will be recorded or sent.
- The SDK will remain dormant until it is explicitly enabled via an API call.
info |
Note If you initialise the SDK with |
Disable SDK Dynamically (After Initialisation)
If the SDK is already initialised and operational, you can dynamically disable all its data tracking and other functions by calling the disableSdk()
method. This is particularly useful for scenarios where a user revokes their consent for data tracking after initially granting it.
Moengage.disableSdk();
Upon calling disableSdk()
:
- All data currently in the batch queue is discarded and not sent to MoEngage.
- Any subsequent attempts by your application or by the SDK internally to track events or user attributes will be ignored.
- The current user's session data and locally cached attributes are cleared.
- Core identifiers are retained (though inactive) to ensure a smoother experience if the SDK is re-enabled and to avoid unnecessary re-registrations.
- If cross-domain data sharing is enabled, data tracking will also cease on any linked subdomains.
Enable Data Tracking
To resume data tracking and all other SDK functionalities after the SDK has been disabled, call the enableSdk()
method.
Moengage.enableSdk();
When enableSdk()
is invoked:
- If the SDK was initially disabled via the
disableSdk: true
configuration, calling this method will trigger the complete SDK initialisation sequence (including device registration, fetching remote configurations, etc.). - If it was disabled dynamically, it resumes operations from its previous state. Event and attribute tracking will function again.
- Push notifications will be available to be shown to the users.
Check the SDK's Current Status
To determine whether the Web SDK is currently enabled or disabled, you can use the isSdkEnabled()
method.
Moengage.isSdkEnabled();
This method returns a boolean value:
-
true
: The SDK is enabled and operational. -
false
: The SDK is disabled.
warning |
Information Cross-Subdomain Data Sharing Important considerations for managing the SDK in a cross-subdomain environment:
Effect of Clearing Browser Storage If the Web SDK is in a disabled state and the user subsequently clears their browser's storage (including cookies, localStorage, and IndexedDB) or site-specific data, the SDK's persisted opt-out state will be lost. On the next page load, the SDK will initialise as if it's a fresh start (enabled by default, unless Service Worker Update Delays Even after the SDK is disabled, the MoEngage service worker (which handles web push notifications) might continue to track web push interaction events (like impressions or clicks) and render push notifications for a brief period. This occurs because service workers operate and update independently of the main website code, a process managed by the browser that cannot be controlled by the SDK. Shopify Integration For websites using MoEngage's Shopify integration, calling Campaign Display and Opt-out Impact
|