OneSignal Push Notification
Copy You'll need to import the javascript file in your website before starting from this link .
getPlayerId : It returns playerId from OneSignal - that can be used to send custom notification from OneSignalApis.
Plain Javascript ES5+
Copy const { getPlayerId } = WTN.OneSignal;
getPlayerId().then(function(playerId){
if(playerId){
// handle for playerId
console.log(playerId)
}
});
Copy import { getPlayerId } from "webtonative/OneSignal";
getPlayerId().then(function(playerId){
if(playerId){
// handle for playerId
console.log(playerId)
}
});
setExternalUserId : To set unique user Id to OneSignal.
Plain Javascript ES5+
Copy const { setExternalUserId } = WTN.OneSignal;
setExternalUserId("#$%jfnkjf");
Copy import { setExternalUserId } from "webtonative/OneSignal";
setExternalUserId("#$%jfnkjf");
removeExternalUserId : To remove externalUserId
Plain Javascript ES5+
Copy const { removeExternalUserId } = WTN.OneSignal;
removeExternalUserId();
Copy import { removeExternalUserId } from "webtonative/OneSignal";
removeExternalUserId();
setTags : To add custom data attributes to your OneSignal Users
Plain Javascript ES5+
Copy const { setTags } = WTN.OneSignal;
setTags({
tags:{
type:'PREMIUM'
}
});
Copy import { setTags } from "webtonative/OneSignal";
setTags({
tags:{
type:'PREMIUM'
}
});
Triggers: https://documentation.onesignal.com/docs/iam-triggers
addTrigger
Plain Javascript ES5+
Copy const { addTrigger } = WTN.OneSignal;
addTrigger({
key: "Trigger Key",
value: "Trigger Value"
});
Copy import { addTrigger } from "webtonative/OneSignal";
addTrigger({
key: "Trigger Key",
value: "Trigger Value"
});
addTriggers
Plain Javascript ES5+
Copy const { addTriggers } = WTN.OneSignal;
addTriggers({
triggers: [
{
key: "Trigger Key 1",
value: "Trigger Value 1"
},
{
key: "Trigger Key 2",
value: "Trigger Value 2"
}
]
});
Copy import { addTriggers } from "webtonative/OneSignal";
addTriggers({
triggers: [
{
key: "Trigger Key 1",
value: "Trigger Value 1"
},
{
key: "Trigger Key 2",
value: "Trigger Value 2"
}
]
});
removeTrigger
Plain Javascript ES5+
Copy const { removeTrigger } = WTN.OneSignal;
removeTrigger({
key: "Trigger Key"
});
Copy import { removeTrigger } from "webtonative/OneSignal";
removeTrigger({
key: "Trigger Key"
});
removeTriggers
Plain Javascript ES5+
Copy const { removeTriggers } = WTN.OneSignal;
removeTriggers({
keys: [ "Trigger Key 1" , "Trigger Key 2" ]
});
Copy import { removeTriggers } from "webtonative/OneSignal";
removeTriggers({
keys: [ "Trigger Key 1" , "Trigger Key 2" ]
});
getTriggerValue
Plain Javascript ES5+
Copy const { getTriggerValue } = WTN.OneSignal;
getTriggerValue({
key: "Trigger Key",
callback: function(data){
if(data.isSuccess){
//data.value contains trigger value for corresponding key
}
}
});
Copy import { getTriggerValue } from "webtonative/OneSignal";
getTriggerValue({
key: "Trigger Key",
callback: function(data){
if(data.isSuccess){
//data.value contains trigger value for corresponding key
}
}
});
getTriggers
Plain Javascript ES5+
Copy const { getTriggers } = WTN.OneSignal;
getTriggers({
callback:function(data){
if(data.isSuccess){
//data.triggers contains list of active trigger
/*
e.g.
{
key: "Trigger Key 1",
value: "Trigger Value 1"
},
{
key: "Trigger Key 2",
value: "Trigger Value 2"
}
/*
}
}
});
Copy import { getTriggers } from "webtonative/OneSignal";
getTriggers({
callback:function(data){
if(data.isSuccess){
//data.triggers contains list of active trigger
/*
e.g.
{
key: "Trigger Key 1",
value: "Trigger Value 1"
},
{
key: "Trigger Key 2",
value: "Trigger Value 2"
}
/*
}
}
});
Setting Email and SMS Numbers
Feature released on 12/06/2023
Available only on Android
Setting and Logging Out Email
Plain Javascript ES5+
Copy const { setEmail, logoutEmail } = WTN.OneSignal;
setEmail({
emailId:"abc@xyz.com"
});
logoutEmail({
emailId:"abc@xyz.com"
});
Copy import { setEmail, logoutEmail } from "webtonative/OneSignal";
setEmail({
emailId:"abc@xyz.com"
});
logoutEmail();
Setting and Logging Out SMS Number
Plain Javascript ES5+
Copy const { setEmail, logoutEmail } = WTN.OneSignal;
setSMSNumber({
smsNumber:"+911234567890"
});
//Pass Mobile Number with ISD Code
logoutSMSNumber({
smsNumber:"+911234567890"
});
Copy import { setSMSNumber, logoutSMSNumber } from "webtonative/OneSignal";
setSMSNumber({
smsNumber:"+911234567890"
});
//Pass Mobile Number with ISD Code
logoutSMSNumber();
Changes done on 26th June, 2024 for Android targetSdk 34. Now for logout the email and number is mandatory for the required functions.
Last updated 2 months ago