moengage.
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.
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.
- shouldAttachMetaData: 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. A method for this case would be like - moengage.trackEvent("Response_Submitted", {"response1":"[email protected]","response2":"approved"})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 dismiss event will be tracked without widgetID. If not passed, the event will get tracked without <widgetId>
Track Dismiss(Deprecated - Use Above API with widget ID instead)
To track the in-app dismissal usemoengage.trackDismiss() API.
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: