Web SDK Opt-out

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.

JavaScript
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 disableSdk: true and later enable it using Moengage.enableSdk(), remember to remove the disableSdk: true parameter from your SDK initialisation code for subsequent page loads. Otherwise, the SDK will revert to a disabled state on the user's next visit.

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.

JavaScript
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.

JavaScript
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.

JavaScript
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:

    • If you utilize cross-subdomain data sharing and disable the SDK at initialisation (disableSdk: true) on one subdomain, ensure you apply the same configuration to all other subdomains involved in data sharing for consistent behavior.
    • When disableSdk() is called on one subdomain, SDK operations will generally cease on all linked subdomains immediately. However, web push notifications on other subdomains might continue until a page load occurs on those specific subdomains.
    • After re-enabling the SDK with Moengage.enableSdk() on one subdomain, a page reload or redirection is necessary on the other sharing subdomains for the SDK to become fully operational there. For Single Page Applications (SPAs), this implies a full browser page refresh, not merely a client-side route change.

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 disableSdk: true is in the init config), potentially creating a new user profile and session.

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 Moengage.disableSdk() will only disable the client-side Web SDK tracking on your storefront. Any server-to-server webhook events configured for your Shopify store will continue to be received and processed by MoEngage, irrespective of the Web SDK's client-side status.

Campaign Display and Opt-out Impact

    • When disableSdk() is called, the SDK will attempt to dismiss any currently rendered On-Site Messages (OSM), and Card campaigns. If tracking impression and dismiss events for these campaigns is critical, ensure this is done *before* invoking disableSdk().
    • For Web Personalization, if content has already been rendered on the page when disableSdk() is called, the SDK may not be able to remove it from the current view. However, no new personalized content will be applied on subsequent page loads or navigations while the SDK remains disabled.
    • If you are using a custom UI element (for example, a bell icon) for a Card inbox, the SDK will try to remove its click listener when disabled. You are responsible for managing the UI state of such custom elements (for example, hiding or disabling them as appropriate).

Previous

Next

Was this article helpful?
0 out of 0 found this helpful

How can we improve this article?