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 pushwoosh variable 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('failed 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">

In the built-in in-app editor, a button can close the in-app without code: set its Action Type to Close In-App.

To request the push permission from inside an in-app (for example, a pre-permission in-app shown before the system prompt), call registerForPushNotifications():

pushwoosh.registerForPushNotifications();

The method takes no arguments and triggers the platform’s native permission prompt. On iOS, the SDK also closes the in-app automatically once you call it, so a further closeInApp() call is optional and harmless. On Android, the in-app stays open until you call closeInApp() yourself.

To send users who already declined push to the system settings for your app, call openAppSettings(). On Android, it opens the app’s notification settings. On iOS, it opens the app’s page in Settings. Like registerForPushNotifications(), it closes the in-app automatically on iOS but not on Android:

pushwoosh.openAppSettings();
pushwoosh.closeInApp();

In the built-in in-app editor, a button can make either call without code: set its Action Type to Request push permission or Open notification settings. Both actions close the in-app after the tap on every platform.

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

Anchor link to

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.