"use strict";const smPushApplicationServerPublicKey="BK5jncLIvQ_hz86vqsvDrn-hSpKyh3TlcN-D-XTt3zVNbVIgfLVS0_J1WKw9ir32M9giVjDiNLaBqbY-4gykWdw=",smPushSiteId="l8em00vdkr",smClientId="z0gr1nodx9",serviceWorker="/service-worker.js",smPushDomain="push.trk-instructior.com",pushLogging=!0,version=823;let smPushSubscriptionId;const subscriptionDomain="subscription.trk-instructior.com",eventDomain="event.trk-instructior.com";let sessionId="";const utmObj={mt:"",utm_source:"",utm_medium:"",utm_campaign:"",source_one:"",source_two:"",source_three:"",source_four:"",source_five:"",first_name:"",last_name:"",email:"",email_md5:"",zip_code:"",gender:"",age:"",phone:""},taboolaUrl="https://api.taboola.com/2.0/json/smpush-general/user.sync?app.type=web&app.apikey=dd83e155339c3c4626a1a3e8465b50db3024b412",smWebViewUaPatterns=[/;\s*wv\)/,/\b(?:FBAN|FBAV|FB_IAB)\//,/\bInstagram\b/,/musical_ly|BytedanceWebview|TikTok/,/\bSnapchat\b/,/\bLine\/\d/,/\bLinkedInApp\b/,/MicroMessenger/,/KAKAOTALK/];function smIsInAppWebView(e){try{const t=void 0===e?navigator.userAgent:e;return"string"==typeof t&&""!==t&&smWebViewUaPatterns.some((e=>e.test(t)))}catch(e){return!1}}const smAllowHintMinChrome=155,smAllowHintEnabled=1===Number("0"),smAllowHintMs=Number("5000")||5e3,smAllowHintDefaultText="Tap “Allow” to confirm you’re a real person",smAllowHintText=smAllowHintDecode("Allow%20Notifications%20Now")||smAllowHintDefaultText,smAllowHintArrow=smAllowHintPick("",["up","down","none"],"up"),smAllowHintTopOffset=80,smAllowHintSide=smAllowHintPick("",["right","center","left"],"right"),smAllowHintId="sm-push-allow-hint";let smAllowHintTimer;function smAllowHintPick(e,t,o){return t.indexOf(e)>=0?e:o}const smAllowHintMaxText=120;let smAllowHintPage=null;function setAllowHint(e){null!==e&&"object"==typeof e?smAllowHintPage=e:!1===e&&(smAllowHintPage={enabled:!1})}function smAllowHintSettings(){const e=smAllowHintPage||("object"==typeof window.smAllowHint&&null!==window.smAllowHint?window.smAllowHint:null),t=e&&"string"==typeof e.text?e.text.trim().slice(0,120):"",o=e?Number(e.ms):NaN;return{enabled:e?!1!==e.enabled:smAllowHintEnabled,text:t||smAllowHintText,arrow:smAllowHintPick(e&&e.arrow,["up","down","none"],smAllowHintArrow),side:smAllowHintPick(e&&e.side,["right","center","left"],smAllowHintSide),ms:o>=1e3?Math.min(o,15e3):smAllowHintMs}}function smAllowHintDecode(e){try{return decodeURIComponent(e)}catch(e){return""}}function smNeedsAllowHint(e){try{if(!smAllowHintSettings().enabled)return!1;const t=void 0===e?navigator.userAgent:e;if("string"!=typeof t||!/Android/.test(t)||!/Mobile/.test(t))return!1;if(/EdgA|OPR\/|SamsungBrowser|Firefox|FxiOS/.test(t))return!1;const o=/Chrome\/(\d+)/.exec(t);return null!==o&&parseInt(o[1],10)>=155&&!smIsInAppWebView(t)}catch(e){return!1}}function smHideAllowHint(){try{clearTimeout(smAllowHintTimer);const e=document.getElementById(smAllowHintId);e&&e.parentNode&&e.parentNode.removeChild(e)}catch(e){}}function smShowAllowHint(){try{if(!smNeedsAllowHint()||"default"!==Notification.permission||!document.body||document.getElementById(smAllowHintId))return;const e=smAllowHintSettings(),t="down"!==e.arrow,o="none"!==e.arrow,n=document.createElement("div");n.id=smAllowHintId,n.setAttribute("aria-hidden","true"),n.style.cssText=`position:fixed;left:0;right:0;top:0;bottom:0;z-index:2147483647;pointer-events:none;background:rgba(0,0,0,.55);display:flex;flex-direction:${t?"column":"column-reverse"};align-items:${{right:"flex-end",left:"flex-start",center:"center"}[e.side]};justify-content:flex-start;`+(t?"padding:80px 28px 16px;":"padding:16px 28px;")+"box-sizing:border-box;font-family:-apple-system,Roboto,Arial,sans-serif;color:#fff;text-align:"+e.side+";";const s=document.createElement("div");s.textContent=t?"↑":"↓",s.style.cssText="font-size:64px;line-height:1;font-weight:700;";const r=document.createElement("div");r.textContent=e.text,r.style.cssText="font-size:20px;font-weight:600;margin:8px 0;max-width:280px;",o&&n.appendChild(s),n.appendChild(r),document.body.appendChild(n),smAllowHintTimer=setTimeout(smHideAllowHint,e.ms)}catch(e){}}function urlBase64ToUint8Array(e){const t=(e+"=".repeat((4-e.length%4)%4)).replace(/\-/g,"+").replace(/_/g,"/"),o=window.atob(t),n=new Uint8Array(o.length);for(let e=0;e<o.length;++e)n[e]=o.charCodeAt(e);return n}function pullUrlParams(e){const t=getUrlVars();e.timezone=(new Intl.DateTimeFormat).resolvedOptions().timeZone,e.mediaId=setIfNull(utmObj.mt,t.mt),e.utmSource=setIfNull(utmObj.utm_source,t.utm_source),e.utmMedium=setIfNull(utmObj.utm_medium,t.utm_medium),e.utmMedium=setIfNull(e.utmMedium,t.source_one),e.utmCampaign=setIfNull(utmObj.utm_campaign,t.utm_campaign),e.sourceOne=setIfNull(utmObj.source_one,t.source_one),e.sourceTwo=setIfNull(utmObj.source_two,t.source_two),e.sourceThree=setIfNull(utmObj.source_three,t.source_three),e.sourceFour=setIfNull(utmObj.source_four,t.source_four),e.sourceFive=setIfNull(utmObj.source_five,t.source_five),e.sourceOne=setIfNull(e.sourceOne,t.s1),e.sourceTwo=setIfNull(e.sourceTwo,t.s2),e.sourceThree=setIfNull(e.sourceThree,t.s3),e.sourceFour=setIfNull(e.sourceFour,t.s4),e.sourceFour=setIfNull(e.sourceFour,t.keywords),e.sourceFour=setIfNull(e.sourceFour,t.keyword),e.sourceFour=setIfNull(e.sourceFour,t.ky),e.sourceFive=setIfNull(e.sourceFive,t.s5),e.email=setIfNull(utmObj.email,t.email),e.firstName=setIfNull(utmObj.first_name,t.first_name),e.firstName=setIfNull(e.firstName,t.fname),e.lastName=setIfNull(utmObj.last_name,t.last_name),e.lastName=setIfNull(e.lastName,t.lname),e.gender=setIfNull(utmObj.gender,t.gender),e.age=setIfNull(utmObj.age,t.age),e.zip=setIfNull(utmObj.zip_code,t.zip_code),e.offerId=t.offer_id,e.sessionId=setIfNull(setIfNull(getSessionId(),t.session_id),""),e.version=823,e.psid=t.psid,e.oai=t.oai,e.fullUrl=encodeURI(window.location.href),e.phone=setIfNull(utmObj.phone,t.phone),e.phone=setIfNull(e.phone,t.phone_number)}function push_subscribe(){smIsInAppWebView()||navigator.serviceWorker.ready.then((function(e){return e.pushManager.getSubscription().then((async function(t){if(!t&&"denied"!==Notification.permission){const t=urlBase64ToUint8Array(smPushApplicationServerPublicKey);return logPushEvent("subscribe_prompt","subscribe_prompt",823),smShowAllowHint(),e.pushManager.subscribe({userVisibleOnly:!0,applicationServerKey:t}).finally(smHideAllowHint)}"denied"===Notification.permission&&logPushEvent("denied_impression","denied_impression",823)})).catch((function(e){console.error("Service Worker Error",e),"Registration failed - permission denied"===e.message?"default"===Notification.permission?logPushEvent("closed_prompt",e.toString(),823):logPushEvent("blocked",e.toString(),823):logPushEvent("other_error",e.toString(),823)}))})).then((function(e){if(e){const t=e.toJSON(),o=`https://${subscriptionDomain}/register/push/${smPushSiteId}`;pullUrlParams(t);const n={name:"pushUtm"};n.value={utmSource:t.utmSource,utmMedium:t.utmMedium,utmCampaign:t.utmCampaign,email:t.email,firstName:t.firstName,lastName:t.lastName,zip:t.zipCode,age:t.age,gender:t.gender},fetch(o,{method:"post",headers:{"Content-type":"application/json"},body:JSON.stringify(t)}).then((function(e){if(e.ok){return e.json()}})).then((function(e){console.log("subscribed!"),smPushSubscriptionId=e.id,getStore((function(e){const t={name:"pushSubscriptionId"};t.value=smPushSubscriptionId,smPushSubscriptionId&&e.put(t),n&&e.put(n),fetch(taboolaUrl).then((e=>e.json())).then((e=>{e.user&&e.user.id?getStore((t=>t.put({name:"userId",value:{taboola:e.user.id}}))):logPushEvent("taboola_request_error","No user id",823)})).catch((e=>{console.log("taboolaUrl fetch error",e),logPushEvent("taboola_request_error",e,823)}))}))})).catch((function(e){console.error("Service Worker Error",e),logPushEvent("error_subscribing",e,823)}))}}))}function push_subscribe_promise(){return smIsInAppWebView()?Promise.resolve():navigator.serviceWorker.ready.then((function(e){return e.pushManager.getSubscription().then((function(t){if(!t){const t=urlBase64ToUint8Array(smPushApplicationServerPublicKey);return smShowAllowHint(),e.pushManager.subscribe({userVisibleOnly:!0,applicationServerKey:t}).finally(smHideAllowHint)}})).catch((function(e){console.error("Service Worker Error",e),"Registration failed - permission denied"===e.message?logPushEvent("blocked",e.toString(),823):logPushEvent("other_error",e.toString(),823)}))})).then((function(e){if(e){const t=e.toJSON();return pullUrlParams(t),t}})).then((e=>fetch(`https://${subscriptionDomain}/register/push/${smPushSiteId}`,{method:"post",headers:{"Content-type":"application/json"},body:JSON.stringify(e)}))).then((function(e){if(e.ok)return e.json()})).then((function(e){console.log("subscribed!"),smPushSubscriptionId=e.id;const t={name:"pushUtm"};t.value={utmSource:e.utmSource,utmMedium:e.utmMedium,utmCampaign:e.utmCampaign},getStore((function(e){const o={name:"pushSubscriptionId"};o.value=smPushSubscriptionId,smPushSubscriptionId&&e.put(o),t&&e.put(t)}))})).catch((function(e){console.error("Service Worker Error",e),logPushEvent("error_subscribing",e,823)}))}function setIfNull(e,t){return null==e||""===e?t:e}function logPushEvent(e,t,o){const n=JSON.stringify(t);"{}"!==n&&(t=n);const s={};pullUrlParams(s),s.message=t,s.version=o,s.event=`p_${e}`;fetch(`https://${eventDomain}/register/event_log/${smPushSiteId}`,{method:"post",headers:{"Content-type":"application/json"},body:JSON.stringify(s)}).catch((function(e){console.error("Log Error, error ",e)}))}function push_unsubscribe(){navigator.serviceWorker.ready.then((function(e){return e.pushManager.getSubscription()})).then((function(e){console.log("Unsubscribed",e.endpoint);return fetch(`https://${subscriptionDomain}/register/unsubscribe/${smPushSiteId}`,{method:"post",headers:{"Content-type":"application/json"},body:JSON.stringify(e)})}))}function push_init(){smIsInAppWebView()?console.log("In-app webview detected, skipping service worker registration"):"serviceWorker"in navigator&&"PushManager"in window?(console.log("Service Worker and Push is supported"),navigator.serviceWorker.register(serviceWorker).then((function(e){console.log("Service Worker is registered",e)})).catch((function(e){console.error("Service Worker Error",e),"https:"===location.protocol&&logPushEvent("sw_register_error",`${location.href} error:${e}`,823)}))):(console.warn("Push messaging is not supported"),logPushEvent("not_supported","not_supported",823))}function setSessionId(e){"serviceWorker"in navigator&&"PushManager"in window&&(sessionId=e)}function setUtm(e){"serviceWorker"in navigator&&"PushManager"in window&&null!=e&&Object.assign(utmObj,e)}function getSessionId(){return sessionId}function getUrlVars(){const e={};window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi,(function(t,o,n){e[o]=n}));return e}function getDomainName(e){return e.substring(e.lastIndexOf(".",e.lastIndexOf(".")-1)+1)}function getStore(e){if(self.indexedDB){const t=self.indexedDB.open("pushPlatFormDb",2);t.onerror=function(o){console.log(`error db${t.error}`),e(null)},t.onsuccess=function(o){const n=t.result.transaction(["store"],"readwrite").objectStore("store");e(n)},t.onupgradeneeded=function(e){console.log(`upgrading db from version ${e.oldVersion} to 2`);const o=t.result;if(e.oldVersion<2){o.createObjectStore("store",{keyPath:"name"})}}}else e(null)}function setAttributes(e){"serviceWorker"in navigator&&"PushManager"in window&&"object"==typeof e&&null!==e&&getStore((function(t){let o=null;null!=t&&(t.get("pushSubscriptionId").onsuccess=function(t){if(t.target.result)try{o=t.target.result.value,e.push_subscription_id=o;const n=`https://${subscriptionDomain}/ads-api/attributes`;fetch(n,{method:"POST",body:JSON.stringify({data:e}),headers:{"Content-type":"application/json"}})}catch(t){}})}))}
