moengage. Most APIs work on both Android and iOS. The Platform column in the table below lists the platforms each API is implemented on. Check this column before you use an API in a template that serves both platforms.
The below table lists all the JS Bridge methods and in the subsequent sections, each API is explained in detail.
The subsequent sections provide more details on how to use each API. The provided JS Methods are classified into two categories - JS Methods for Actions and JS Methods for Data Tracking
Actions
The following sections will provide more details on the JS Methods for actions.JS Methods for ActionsIntegrate the JS Methods for Actions with your HTML Template to execute on-click actions like message close, navigation actions like re-direction to screens or webpages, or any other actions as supported with in-app campaigns.
Dismiss In-App Message
To dismiss in-app messages usemoengage.dismissMessage() API.
Do not use other API when the
moengage.dismissMessage()API is in use.Navigation Actions
Navigate to Screen
You can open a screen usingmoengage.navigateToScreen(<screen-name>, <optional-data-json>).
Open Deeplink URL
To open a deeplink URL usemoengage.openDeepLink(<deeplink-url>, <optional-data-json>).
Open Richlanding Screen
To open a Richlanding screen usemoengage.openRichLanding(<richlanding-url>, <data-json>).
Open Web URL
To open a URL in a web browser usemoengage.openWebURL(<web-url>, <optional-data-json>).
Copy Text to Clipboard
To copy text to clipboard usemoengage.copyText(<text-to-copy>, <message>) API.
Call
To perform call action usemoengage.call(<mobile-number> API.
SMS
To send an SMS usemoengage.sms(<mobile-number>, <message>) API.
Share
To share a string content usemoengage.share(<share-text>) API.
Custom Action
To perform custom action set the data usingmoengage.customAction(<data-json>) API.
Push Notification Permission
Use these methods to prompt users to enable push notifications, or to send them to the notification settings screen when they have already disabled notifications.Request the Notification Permission
To request the notification permission, use themoengage.requestNotificationPermission() API. This method works on both Android and iOS, so you can use it in a single template that serves both platforms.
Navigate to Notification Settings
To take the user directly to the app’s notification settings screen without first requesting the permission, use themoengage.navigateToNotificationSettings() API. This method works on both Android and iOS.
Use this when push is already disabled for your app and a permission prompt would not be shown — for example, an in-app message that tells users notifications are off and gives them a CTA to turn them back on.
To handle notification permission from your app code instead of an in-app message, see Notification Runtime Permissions.
Show the Push Opt-In Prompt
To prompt for the notification permission on iOS, use themoengage.showPushOptIn() API. Based on the current notification status, the SDK either shows the notification permission prompt or takes the user to the settings screen where the notification status can be updated.
Navigate to Device Settings
To open the device settings screen, use themoengage.navigateToSettings() API.
Data Tracking
The following sections will provide more details on the JS Methods for data tracking.JS Methods for Data TrackingYou would need to integrate the JS Methods for Data Tracking in your template for the following use-cases:
- Tracking stats (clicks, close)
- Tracking events (for surveys, rating, lead gen)
- Tracking user attributes (for lead gen, signup etc.)
Track Event
To track an event usemoengage.trackEvent(eventName, generalAttrJson, locationAttrJson, dateAttrJson, isNonInteractive, shouldAttachCampaignMeta) API.
The trackEvent() takes in up to six parameters.
- eventName : String
- generalAttrJson : JSON Object for general attributes. Accepted data types are string, float, boolean, int, JSON objects.
- locationAttrJson : JSON Object for location attributes. Accepts attribute name and latitude and longitude
- dateAttrJson : JSON Object for date-time attributes. Accepts only ISO-8601 format dates
- isNonInteractive: true if you want the event to be non-interactive, else false.
- shouldAttachCampaignMeta: true if you want to attach campaign metadata to the event, else false.
Apart from the
It is important to maintain the order in which parameters are passed, i.e. if you want to pass only the location attributes general attribute should be passed
eventName parameter, other parameters are non-mandatory you can pass {}.It is important to maintain the order in which parameters are passed, i.e. if you want to pass only the location attributes general attribute should be passed
{}.For general cases, you would just be passing the event-name and event-attributes JSON and in this case you can skip the other params.{} for the attribute types you skip.
Track Click Event
To track widget click events usemoengage.trackClick(widgetId) API. The <widgetId> can be int or string, otherwise, the click event will not be tracked.
Track Dismiss
To track in-app dismissal events, usemoengage.trackDismiss(widgetId) API. The <widgetId> can be int or string. If not passed, the event is tracked without a <widgetId>.
Deprecated: trackDismiss() Without a Widget ID
Deprecated: trackDismiss() Without a Widget ID
Calling
moengage.trackDismiss() with no argument is deprecated. The dismissal is still tracked, but without a <widgetId> the click distribution table is not populated. Pass a <widgetId> as shown above instead.Identify User
To identify the user against a unique identifier configured in your workspace, use themoengage.identifyUser(<value>) API. Use this from lead generation, sign-up, or login templates to attribute the session to a known user.
Configure your identifiers in MoEngage before you call this method. For details on how identifiers are resolved into a single user profile, see Unified Identity and Identity Resolution.
Track Default User Attributes
The following JavaScript methods are available for tracking default user attributes.
Example:
Track Custom User Attributes
The following JavaScript methods are available for tracking custom user attributes.
Example: