This guide is for our in-app message JavaScript library used when creating in-app messages with our HTML Editor. If you are looking for SDK methods for triggers, in-app click handler, lifecycle methods and others, please see our Mobile SDK reference.

Required

  1. data-onesignal-unique-label – must be included on the elements that trigger actions, with a unique label, to be handled correctly, and be tracked as a click. For example:

<button id="tag-user-button" data-onesignal-unique-label="my-tag-user-button">Tag User</button>

  1. getElementById – call actions based on when a user has clicked or engaged with your in-app message:

document.getElementById("tag-user-button").addEventListener("click", function(e) { OneSignalIamApi.tagUser(e, { fiz: "baz" }); });

<button id="tag-user-button" data-onesignal-unique-label="my-tag-user-button">Tag User</button>
<script>
document.getElementById("tag-user-button").addEventListener("click", function(e) {
  OneSignalIamApi.tagUser(e, { fiz: "baz" });
});
</script>

Available functions

Example

FAQ

Does Tag Substitution work for HTML IAMs?

Tag substitution will work for most HTML elements but will not work within script tags. Regular liquid syntax, like this will work: <div>Hi there {{ name | default: 'you' }}!</div> Here, the name OneSignal tag will be replaced with the device’s value for that tag, with ‘you’ being the default value if that tag isn’t set.

Tag substitution will work for:

  • text displayed to the end user (text within a div, p, li, etc)

  • in <style> tags i.e. body { background-color: "{{ favorite_color | default: '#fff' }}"; }

  • HTML element attributes which take a url:

    • elements with an href attribute
    • elements with a src attribute
    • action attribute on <form>
    • data attribute on <object>

Tag substitution will NOT work within <script> tags

Tag substitution does not work when using the “Send Test Message” button. You will need to test with a test user segment.