Skip to main content
HTML in-app messages for Android support a bridge interface for web apps to interact with the MoEngage SDK. The bridge contains a set of APIs that can be accessed using a global variable 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 use moengage.dismissMessage() API.
Do not use other API when the moengage.dismissMessage()API is in use.

Navigation Actions

You can open a screen using moengage.navigateToScreen(<screen-name>, <optional-data-json>).
To open a deeplink URL use moengage.openDeepLink(<deeplink-url>, <optional-data-json>).

Open Richlanding Screen

To open a Richlanding screen use moengage.openRichLanding(<richlanding-url>, <data-json>).

Open Web URL

To open a URL in a web browser use moengage.openWebURL(<web-url>, <optional-data-json>).

Copy Text to Clipboard

To copy text to clipboard use moengage.copyText(<text-to-copy>, <message>) API.

Call

To perform call action use moengage.call(<mobile-number> API.

SMS

To send an SMS use moengage.sms(<mobile-number>, <message>) API.

Share

To share a string content use moengage.share(<share-text>) API.

Custom Action

To perform custom action set the data using moengage.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 use moengage.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 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 use moengage.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, use moengage.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 use moengage.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: