This guide covers the JavaScript API for HTML in-app messages created with the OneSignal HTML Editor. If you are looking for SDK methods to set triggers, handle in-app click events, or manage the in-app lifecycle, see the Mobile SDK Reference.Documentation Index
Fetch the complete documentation index at: https://documentation.onesignal.com/llms.txt
Use this file to discover all available pages before exploring further.
Requirements
Use the data-onesignal-unique-label attribute for click tracking
All clickable elements must have a data-onesignal-unique-label attribute with a unique value. This enables OneSignal to:
- Track click analytics
- Correctly trigger associated actions
HTML
Attach event listeners
You must explicitly attach JavaScript event listeners to trigger OneSignal in-app actions.JavaScript
HTML
Handling click tracking in sandboxed HTML in-app messages
Because HTML in-app messages run in a sandboxed WebView, click tracking and navigation must occur inside the same frame. Standard anchors (<a href="...">) and window.open() calls are not tracked and can trigger console warnings such as:
Correct: use a button and OneSignal APIs
HTML
Incorrect: using <a> or window.open()
HTML
- Each clickable element must have a unique
data-onesignal-unique-label. - Always call
OneSignalIamApi.trackClick(e)beforeopenUrl()or any other OneSignal API method. - Bind event listeners after
DOMContentLoadedto ensure that the elements exist. - OneSignal automatically tracks clicks only for methods listed in this reference; any custom navigation must call
trackClick()manually.
Common issues
- Clicks not recorded:
trackClick()was not called or the element is missing adata-onesignal-unique-label.- Call
trackClick(e)and ensure each element has a unique label.
- Call
- Console shows “Attempting to perform subframe navigation”:
The code useswindow.open()or an<a>link instead ofOneSignalIamApi.openUrl().- Use
OneSignalIamApi.openUrl(e, "https://example.com/")inside the same click handler.
- Use
- Wrong label appears in analytics:
Multiple elements share the samedata-onesignal-unique-label.- Give each clickable element a unique label.
Available functions
All click actions from the Block Editor are also available for HTML in-app messages.Push permission prompt
Shows the native push notification permission prompt. Click events are automatically tracked. See Prompt for push permissions.HTML
Location permission prompt
Shows the native location permission prompt. Click events are automatically tracked. See Location permission prompts.HTML
Close in-app message
Dismisses the current in-app message. Click events are automatically tracked.html
Tag user
Sets a Tag. Click events are automatically tracked.HTML
Open URL
Opens a URL in the device’s browser and closes the in-app message. Click events are automatically tracked. Supports Deep Linking.HTML
Click name
Assigns a click name that can be read in the in-app message click listener. Click events are automatically tracked. Supports Deep Linking.HTML
Track click
Tracks a click event when you’re not using other clickable API methods.HTML
Send Outcome
Tracks an unattributed Custom Outcome and sets a Tag on the user in formatoutcome name : true. Click events are automatically tracked.
html
Personalizing HTML in-app messages
You can use tag substitution in HTML in-app messages just like in the Block Editor. Tag substitution works for:-
Inline text (
<h1>,<p>,<li>, etc.) -
<style>rules:CSS -
Attributes with URLs:
hrefsrc<form action><object data>
Using tags in openUrl() and addClickName()
Since <script> tags don’t support substitution, use one of these methods:
1. Access all tags with liquidPlayerTags
This global object becomes available after DOMContentLoaded.
HTML
href attribute
HTML
Next steps
- Learn more about using liquid syntax for tag substitution
- Explore Deep Linking for URL handling
- Design in-app messages with HTML