Skip to content

Create in-apps with JavaScript

In-app messages are displayed directly within the app interface while a user is already interacting with an app. As a result, users perceive in-apps as less intrusive than push notifications, emails or SMS.

In-app messages always contain images or videos called Rich Media. In-apps can also include formatted text, links, buttons with CTAs, and other data, allowing you to communicate with your app users in engaging forms.

In-Apps are HTML-based and support JavaScript. Pushwoosh SDK injects pushwooshvariable that provides the following API:

You can use postEvent method to send a new event directly from In-App JavaScript code.

pushwoosh.postEvent(
'eventName',
{
TestAttributeString: 'testString',
TestAttributeInt: 42,
TestAttributeList: [123, 456, 'someString'],
TestAttributeBool: true,
TestAttributeNull: null,
TestAttributeDaysAgo: 7,
TestAttributeDate: new Date()
},
function() {
console.log('Post event success')
},
function(error) {
console.log('Post event failed: ', error)
}
)

You can also use sendTags method to set tags for the device from an in-app:

pushwoosh.sendTags({
IntTag: 42,
BoolTag: true,
StringTag: 'testString',
ListTag: ['string1', 'string2']
})

To get device tags, use the getTags method as follows:

pushwoosh.getTags(
function(tags) {
console.log('tags: ' + JSON.stringify(tags))
},
function(error) {
console.log('failded to get tags: ' + error)
}
)

If you want to close an in-app from the JavaScript code call closeInApp() method:

pushwoosh.closeInApp();

Or simply use custom scheme URL for the button/link <a href="pushwoosh://close">

When sending a push notification with Rich Media, you can get custom data of that push with the following code: pushwoosh.getCustomData()

Custom JavaScript interface

In-App Messages JavaScript functionality can be unlimitedly extended by exposing native Java/Objective-C/Swift methods to JavaScript. This can be achieved with addJavaScriptInterface methods of Pushwoosh SDK for iOS and Android.