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.
OneSignalSDKWorker.js
The OneSignal Service Worker code within the OneSignalSDKWorker.js
file needs to be updated from:
Player Model code:
importScripts('https://cdn.onesignal.com/sdks/OneSignalSDKWorker.js');
To User Model code:
importScripts("https://cdn.onesignal.com/sdks/web/v16/OneSignalSDK.sw.js");
The location and path of the file should stay the same. Just update this one line.
See OneSignal Service Worker for details.
Initialization
init()
init()
Player Model doc
<script src="https://cdn.onesignal.com/sdks/OneSignalSDK.js" async></script>
<script>
window.OneSignal = window.OneSignal || [];
OneSignal.push(function() {
OneSignal.init({
appId: "YOUR_APP_ID"
});
});
</script>
User Model doc
<script src="https://cdn.onesignal.com/sdks/web/v16/OneSignalSDK.page.js" defer></script>
<script>
window.OneSignalDeferred = window.OneSignalDeferred || [];
OneSignalDeferred.push(async function(OneSignal) {
await OneSignal.init({
appId: "YOUR_APP_ID",
});
});
</script>
provideUserConsent()
provideUserConsent()
Player Model doc
OneSignal.provideUserConsent(true)
User Model doc
OneSignal.setConsentGiven(true)
Registering Push
showNativePrompt()
showNativePrompt()
Player Model doc
OneSignal.showNativePrompt()
User Model doc
OneSignal.Notifications.requestPermission()
registerForPushNotifications()
[dropped]
registerForPushNotifications()
[dropped]Player Model doc
OneSignal.registerForPushNotifications()
#permissionPromptDisplay
#permissionPromptDisplay
Player Model doc
OneSignal.on('permissionPromptDisplay', () => ... })
User Model doc
OneSignal.Notifications.addEventListener('permissionPromptDisplay', event => { ... })
showSlidedownPrompt()
showSlidedownPrompt()
Player Model
doc
OneSignal.showSlidedownPrompt()
User Model doc
OneSignal.Slidedown.promptPush()
showHttpPrompt()
[dropped]
showHttpPrompt()
[dropped]Player Model
doc
OneSignal.showHttpPrompt()
showCategorySlidedown()
showCategorySlidedown()
Player Model doc
OneSignal.showCategorySlidedown()
User Model doc
OneSignal.Slidedown.promptPushCategories()
#getNotificationPermission
#getNotificationPermission
Player Model doc
OneSignal.on('getNotificationPermission', (permission) => ... })
User Model doc
OneSignal.User.PushSubscription.addEventListener('change', ({ optedIn }) => { ... })
isPushNotificationsSupported()
isPushNotificationsSupported()
Player Model doc
OneSignal.isPushNotificationsSupported()
User Model doc
OneSignal.Notifications.isPushSupported()
isPushNotificationsEnabled()
isPushNotificationsEnabled()
Player Model doc
await OneSignal.isPushNotificationsEnabled()
User Model doc
OneSignal.User.PushSubscription.optedIn
#subscriptionChange
#subscriptionChange
Player Model doc
OneSignal.on('subscriptionChange', (subscribed) => ... })
User Model doc
OneSignal.User.PushSubscription.addEventListener('change', ({ token }) => { ... })
Analytics
#notificationPermissionChange
#notificationPermissionChange
Player Model doc
OneSignal.on('notificationPermissionChange', ({ to }) => ... })
User Model doc
OneSignal.Notifications.addEventListener('permissionChange', permission => { ... })
#popoverShown
#popoverShown
Player Model doc
OneSignal.on('popoverShown', () => ... })
User Model doc
OneSignal.Slidedown.addEventListener('slidedownShown', presented => { ...})
#customPromptClick
#customPromptClick
Player Model doc
OneSignal.on('customPromptClick', ({ result }) => ... })
User Model doc
OneSignal.Notifications.addEventListener('click', ({notification, result}) => { ... })
User IDs
getUserId
getUserId
Player Model doc
OneSignal.getUserId()
User Model doc
OneSignal.User.PushSubscription.id;
setExternalUserId()
setExternalUserId()
Player Model doc
OneSignal.setExternalUserId("external id")
User Model doc
OneSignal.login("external id")
removeExternalUserId()
removeExternalUserId()
Player Model doc
OneSignal.removeExternalUserId()
User Model doc
OneSignal.logout()
getExternalUserId()
getExternalUserId()
Player Model
doc
await OneSignal.getExternalUserId()
User Model doc
OneSignal.User.externalId
Tags
sendTag()
sendTag()
Player Model doc
OneSignal.sendTag("key", "value")
User Model doc
OneSignal.User.addTag("key", "value")
sendTags()
sendTags()
Player Model doc
OneSignal.sendTags({ key1: 'value1', key2: 'value2' })
User Model doc
OneSignal.User.addTags({ key1: 'value1', key2: 'value2' })
getTags()
getTags()
Player Model doc
await OneSignal.getTags()
User Model doc
OneSignal.User.getTags()
deleteTag()
deleteTag()
Player Model doc
OneSignal.deleteTag("key")
User Model doc
OneSignal.User.removeTag("key")
deleteTags()
deleteTags()
Player Model doc
OneSignal.deleteTags(["key1", "key2"])
User Model doc
OneSignal.User.removeTags(["key1", "key2"])
Push Notifications
sendSelfNotification()
[dropped]
sendSelfNotification()
[dropped]Player Model doc
OneSignal.sendSelfNotification('title', 'message', 'url')
setSubscription()
setSubscription()
Player Model doc
OneSignal.setSubscription(false)
User Model
OneSignal.Notifications.permission = false
Receiving Notifications
#notificationDisplay
#notificationDisplay
Player Model doc
OneSignal.on('notificationDisplay', (event) => { ... })
User Model doc
OneSignal.Notifications.addEventListener('foregroundWillDisplay', ({ notification ) => { ... })
#notificationDismiss
#notificationDismiss
Player Model doc
OneSignal.on('notificationDismiss', (event) => { ... })
User Model doc
OneSignal.Notifications.addEventListener('dismiss', ({ notification }) => { ... })
#addListenerForNotificationOpened
#addListenerForNotificationOpened
Player Model doc
OneSignal.on('addListenerForNotificationOpened', (event) => { ... })
User Model doc
// TODO
Email
setEmail()
setEmail()
Player Model doc
OneSignal.setEmail('[email protected]')
User Model doc
OneSignal.User.addEmail('[email protected]')
logoutEmail()
logoutEmail()
Player Model doc
OneSignal.logoutEmail()
User Model doc
OneSignal.User.removeEmail('[email protected]')
getEmailId()
[dropped]
getEmailId()
[dropped]Player Model doc
await OneSignal.getEmailId()
SMS
setSMSNumber()
setSMSNumber()
Player Model doc
OneSignal.setSMSNumber('+11234567890')
User Model doc
OneSignal.User.addSms('+11234567890')
logoutSMSNumber()
logoutSMSNumber()
Player Model doc
OneSignal.logoutSMS()
User Model doc
OneSignal.User.removeSms('+11234567890')
Updated 16 days ago