templates/ShopCustom/one_signal.html.twig line 1

Open in your IDE?
  1. <script src="https://cdn.onesignal.com/sdks/OneSignalSDK.js" async=""></script>
  2. <script>
  3.     OneSignal = window.OneSignal || [];
  4.     if (typeof OneSignal !== 'undefined') {
  5.         OneSignal.push(function() {
  6.             let oldPlayerId = localStorage.getItem('roviniete.old.player_id');
  7.             OneSignal.init({
  8.                 appId: '{{ one_signal_app_id }}',
  9.             });
  10.             OneSignal.on('subscriptionChange', function (isSubscribed) {
  11.                 if(isSubscribed) {
  12.                     syncOnesignal();
  13.                 }
  14.             });
  15.             if (typeof OneSignal.getUserId === "function") {
  16.                 OneSignal.getUserId().then(function(userId) {
  17.                     if(userId && userId != oldPlayerId) {
  18.                         syncOnesignal();
  19.                         localStorage.setItem('roviniete.old.player_id', userId);
  20.                     }
  21.                 });
  22.             }
  23.         });
  24.     }
  25.     window.syncOnesignal = function syncOnesignal() {
  26.         let OneSignal = window.OneSignal || [];
  27.         if (typeof OneSignal !== 'undefined' && typeof OneSignal.getUserId !== "undefined"
  28.             && typeof OneSignal.getUserId === "function") {
  29.             let customerEmail = $("#customerEmail");
  30.             OneSignal.getUserId().then(function (userId) {
  31.                 let url = Routing.generate('app_shop_onesignal_sync');
  32.                 $.ajax({
  33.                     url: url,
  34.                     data: {data: JSON.stringify({
  35.                             "playerId": userId,
  36.                             "email": customerEmail.length ? customerEmail.val() : '',
  37.                         })},
  38.                     type: 'GET',
  39.                     dataType: 'json',
  40.                     async: false,
  41.                     success: function(data) {
  42.                     }
  43.                 });
  44.                 localStorage.setItem('roviniete.old.player_id', userId);
  45.             });
  46.         }
  47.     }
  48. </script>