OneSignal Push Notification

You'll need to import the javascript file in your website before starting from this .

getPlayerId: It returns playerId from OneSignal - that can be used to send custom notification from OneSignalApis.

const { getPlayerId } = WTN.OneSignal;

getPlayerId().then(function(playerId){
  if(playerId){
    // handle for playerId
    console.log(playerId)
  }
});

setExternalUserId: To set unique user Id to OneSignal.

const { setExternalUserId } = WTN.OneSignal;

setExternalUserId("#$%jfnkjf");

removeExternalUserId: To remove externalUserId

const { removeExternalUserId } = WTN.OneSignal;

removeExternalUserId();

setTags: To add custom data attributes to your OneSignal Users

const { setTags } = WTN.OneSignal;

setTags({
  tags:{
    type:'PREMIUM'
  }
});

Triggers: https://documentation.onesignal.com/docs/iam-triggers

addTrigger

const { addTrigger } = WTN.OneSignal;

addTrigger({
    key: "Trigger Key",
    value: "Trigger Value"
});

addTriggers

const { addTriggers } = WTN.OneSignal;

addTriggers({
    triggers: [
        {
            key: "Trigger Key 1",
            value: "Trigger Value 1"
        },
        {
            key: "Trigger Key 2",
            value: "Trigger Value 2"
        }
    ]
});

removeTrigger

const { removeTrigger } = WTN.OneSignal;

removeTrigger({
    key: "Trigger Key"
});

removeTriggers

const { removeTriggers } = WTN.OneSignal;

removeTriggers({
    keys: [ "Trigger Key 1" , "Trigger Key 2" ]
});

getTriggerValue - depricated

const { getTriggerValue } = WTN.OneSignal;

getTriggerValue({
    key: "Trigger Key",
    callback: function(data){
        if(data.isSuccess){
            //data.value contains trigger value for corresponding key
        }
    }
});

getTriggers - depricated

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"
                }
            /*
        }
    }
});

Setting Email and SMS Numbers

Feature released on 12/06/2023

Available only on Android

Setting and Logging Out Email

const { setEmail, logoutEmail } = WTN.OneSignal;

setEmail({
    emailId:"abc@xyz.com"
});

logoutEmail({
    emailId:"abc@xyz.com"
});

Setting and Logging Out SMS Number

const { setEmail, logoutEmail } = WTN.OneSignal;

setSMSNumber({
    smsNumber:"+911234567890"
});
//Pass Mobile Number with ISD Code

logoutSMSNumber({
    smsNumber:"+911234567890"
}); 
  • Changes done on 26th June, 2024 for Android targetSdk 34. Now for logout the email and number is mandatory for the required functions.

OptIn and OptOut Functions

Feature added on 06/12/2024

This can be used to manually optin and optout users from OnrSignal.

const { optInUser, optOutUser } = WTN.OneSignal;

optInUser();

optOutUser();

Last updated