Web SDK Mapping

Maps method from our older Player Model SDK to User Model

The structure of this document is similar to the one in the original Player Model Web SDK Reference doc. The headers indicate the method(), property, and #event names from the Player Model, and the code snippet shows the differences between the two models. All snippets are presented in the Typescript programming language and may not represent complete working code. Please refer to the docs linked for each method/property to see examples in other languages and to learn more about it.

Initialization

init()

Player Model doc

OneSignal.init({
  appId: 'YOUR_APP_ID' 
})

User Model doc

OneSignal.init({
  appId: 'YOUR_APP_ID'
})

provideUserConsent()

Player Model doc

OneSignal.provideUserConsent(true)

User Model doc

OneSignal.setConsentGiven(true)

Registering Push

showNativePrompt()

Player Model doc

OneSignal.showNativePrompt()

User Model doc

OneSignal.Notifications.requestPermission()

registerForPushNotifications() [dropped]

Player Model doc

OneSignal.registerForPushNotifications()

#permissionPromptDisplay

Player Model doc

OneSignal.on('permissionPromptDisplay', () => ... })

User Model doc

OneSignal.Notifications.addEventListener('permissionPromptDisplay', event => { ... })

showSlidedownPrompt()

Player Model
doc

OneSignal.showSlidedownPrompt()

User Model doc

OneSignal.Slidedown.promptPush()

showHttpPrompt() [dropped]

Player Model
doc

OneSignal.showHttpPrompt()

showCategorySlidedown()

Player Model doc

OneSignal.showCategorySlidedown()

User Model doc

OneSignal.Slidedown.promptPushCategories()

#getNotificationPermission

Player Model doc

OneSignal.on('getNotificationPermission', (permission) => ... })

User Model doc

OneSignal.User.PushSubscription.addEventListener('change', ({ optedIn }) => { ... })

isPushNotificationsSupported()

Player Model doc

OneSignal.isPushNotificationsSupported()

User Model doc

OneSignal.Notifications.isPushSupported()

isPushNotificationsEnabled()

Player Model doc

await OneSignal.isPushNotificationsEnabled()

User Model doc

OneSignal.User.PushSubscription.optedIn

#subscriptionChange

Player Model doc

OneSignal.on('subscriptionChange', (subscribed) => ... })

User Model doc

OneSignal.User.PushSubscription.addEventListener('change', ({ token }) => { ... })

Analytics

#notificationPermissionChange

Player Model doc

OneSignal.on('notificationPermissionChange', ({ to }) => ... })

User Model doc

OneSignal.Notifications.addEventListener('permissionChange', permission => { ... })

#popoverShown

Player Model doc

OneSignal.on('popoverShown', () => ... })

User Model doc

OneSignal.Slidedown.addEventListener('slidedownShown', presented => { ...})

#customPromptClick

Player Model doc

OneSignal.on('customPromptClick', ({ result }) => ... })

User Model doc

 OneSignal.Notifications.addEventListener('click', ({notification, result}) => { ... })

User IDs

getUserId [dropped]

Player Model doc

await OneSignal.getUserId()

setExternalUserId() [dropped]

Player Model doc

OneSignal.setExternalUserId("external id")

removeExternalUserId()

Player Model doc

OneSignal.removeExternalUserId()

User Model doc

// TODO

getExternalUserId()

Player Model
doc

await OneSignal.getExternalUserId()

User Model doc

await OneSignal.logout()

Tags

sendTag()

Player Model doc

OneSignal.sendTag("key", "value")

User Model doc

OneSignal.User.addTag("key", "value")

sendTags()

Player Model doc

OneSignal.sendTags({ key1: 'value1', key2: 'value2' })

User Model doc

OneSignal.User.addTags({ key1: 'value1', key2: 'value2' })

getTags()

Player Model doc

await OneSignal.getTags()

User Model doc

OneSignal.User.getTags()

deleteTag()

Player Model doc

OneSignal.deleteTag("key")

User Model doc

OneSignal.User.removeTag("key")

deleteTags()

Player Model doc

OneSignal.deleteTags(["key1", "key2"])

User Model doc

OneSignal.User.removeTags(["key1", "key2"])

Push Notifications

sendSelfNotification() [dropped]

Player Model doc

OneSignal.sendSelfNotification('title', 'message', 'url') 

setSubscription()

Player Model doc

OneSignal.setSubscription(false)

User Model

OneSignal.Notifications.permission = false

Receiving Notifications

#notificationDisplay

Player Model doc

OneSignal.on('notificationDisplay', (event) => { ... })

User Model doc

OneSignal.Notifications.addEventListener('foregroundWillDisplay', ({ notification ) => { ... })

#notificationDismiss

Player Model doc

OneSignal.on('notificationDismiss', (event) => { ... })

User Model doc

OneSignal.Notifications.addEventListener('dismiss', ({ notification }) => { ... })

#addListenerForNotificationOpened

Player Model doc

OneSignal.on('addListenerForNotificationOpened', (event) => { ... })

User Model doc

// TODO

Emal

setEmail()

Player Model doc

OneSignal.setEmail('[email protected]')

User Model doc

OneSignal.User.addEmail('[email protected]')

logoutEmail()

Player Model doc

OneSignal.logoutEmail()

User Model doc

OneSignal.User.removeEmail('[email protected]')

getEmailId() [dropped]

Player Model doc

await OneSignal.getEmailId()

SMS

setSMSNumber()

Player Model doc

OneSignal.setSMSNumber('+11234567890')

User Model doc

OneSignal.User.addSms('+11234567890')

logoutSMSNumber()

Player Model doc

OneSignal.logoutSMS()

User Model doc

OneSignal.User.removeSms('+11234567890')