<script src="https://cdn.onesignal.com/sdks/OneSignalSDK.js" async=""></script>
<script>
OneSignal = window.OneSignal || [];
if (typeof OneSignal !== 'undefined') {
OneSignal.push(function() {
let oldPlayerId = localStorage.getItem('roviniete.old.player_id');
OneSignal.init({
appId: '{{ one_signal_app_id }}',
});
OneSignal.on('subscriptionChange', function (isSubscribed) {
if(isSubscribed) {
syncOnesignal();
}
});
if (typeof OneSignal.getUserId === "function") {
OneSignal.getUserId().then(function(userId) {
if(userId && userId != oldPlayerId) {
syncOnesignal();
localStorage.setItem('roviniete.old.player_id', userId);
}
});
}
});
}
window.syncOnesignal = function syncOnesignal() {
let OneSignal = window.OneSignal || [];
if (typeof OneSignal !== 'undefined' && typeof OneSignal.getUserId !== "undefined"
&& typeof OneSignal.getUserId === "function") {
let customerEmail = $("#customerEmail");
OneSignal.getUserId().then(function (userId) {
let url = Routing.generate('app_shop_onesignal_sync');
$.ajax({
url: url,
data: {data: JSON.stringify({
"playerId": userId,
"email": customerEmail.length ? customerEmail.val() : '',
})},
type: 'GET',
dataType: 'json',
async: false,
success: function(data) {
}
});
localStorage.setItem('roviniete.old.player_id', userId);
});
}
}
</script>