@mparticle/web-rokt-kit 3.7.0 → 3.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Rokt-Kit.common.js +1 -1
- package/dist/Rokt-Kit.esm.js +37 -23
- package/dist/Rokt-Kit.iife.js +1 -1
- package/package.json +1 -1
package/dist/Rokt-Kit.common.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const Ne=["active_time_on_site_ms","billingaddress1","billingaddress2","billingcity","billingstate","billingzipcode","cartitems","ccbin","confirmationref","conversiontype","country","couponcode","currency","language","paymentserviceprovider","paymentserviceproviderattribute","paymenttype","shippingaddress1","shippingcity","shippingcountry","shippingmethod","shippingstate","shippingzipcode","totalprice"],Ue=new Set(Ne);function me(i){return Ue.has(i.toLowerCase())}function y(i){const e={},t=i||{},n=Object.keys(t);for(let r=0;r<n.length;r++){const s=n[r];me(s)||(e[s]=t[s])}return e}function m(i){return typeof i=="object"&&i!==null&&!Array.isArray(i)}function g(i){return typeof i=="string"}function U(i){return typeof i=="function"}function S(i){return i==null?!0:typeof i=="string"?i.length===0:typeof i=="object"?Object.keys(i).length===0:!1}function z(i){try{const e=new URL(i);return e.search="",e.toString()}catch{return i}}function Ee(i){let e=5381;for(let t=0;t<i.length;t++)e=(e<<5)+e+i.charCodeAt(t),e=e&e;return e}const h="mp-rokt-kit",ee="__rokt_ls_probe__";function H(){try{return window.localStorage.setItem(ee,"1"),window.localStorage.removeItem(ee),!0}catch{return!1}}const R=()=>window.localStorage;function $(i,e=R){try{const t=e().getItem(i);return t===null?null:JSON.parse(t)}catch{return null}}function _e(i,e,t=R){try{return t().setItem(i,JSON.stringify(e)),!0}catch{return!1}}function Ke(i,e=R){try{e().removeItem(i)}catch{}}function O(i,e,t=R){const n=$(i,t);return m(n)?n[e]:void 0}function x(i,e,t,n=R){const r=$(i,n),s=m(r)?{...r}:{};return s[e]=t,_e(i,s,n)}function Y(i,e,t=R){const n=$(i,t);if(!m(n)||!(e in n))return;const r={...n};delete r[e],Object.keys(r).length===0?Ke(i,t):_e(i,r,t)}const q="pageViews",D="utmParams",Ie=25,Ce=["utm_source","utm_medium","utm_campaign","utm_term","utm_content"];function ye(i){return i.slice(-Ie)}function te(){const i=O(h,q);return Array.isArray(i)?i:[]}function De(i){const e=ye(i);for(let t=0;t<e.length;t++){const n=e.slice(t);if(x(h,q,n))return n.length}return 0}function ie(){Y(h,q)}function Me(i){const e=ye(i);return e.map((t,n)=>{const r=t.activeTimeOnSite,s=r!==void 0&&Number.isFinite(r),c=e[n+1]?.activeTimeOnSite,u=c!==void 0&&Number.isFinite(c),l=s&&u?c-r:void 0;return{pageUrl:t.pageUrl,sourceMessageId:t.sourceMessageId,timestamp:t.timestamp,...t.pageTitle!==void 0?{pageTitle:t.pageTitle}:{},...t.canonicalUrl!==void 0?{canonicalUrl:t.canonicalUrl}:{},...s?{activeTimeOnSite:r}:{},...l!==void 0&&l>=0?{activeTimeOnPage:l}:{}}})}function Fe(i){if(O(h,D)!==void 0)return;const e=new URLSearchParams(window.location.search),t={};for(const r of Ce){const s=e.get(r);s&&(t[r]=s)}if(Object.keys(t).length===0)return;const n=Object.keys(t).join(", ");if(!x(h,D,t)){const r=H()?"quota":"ls_unavailable";i?.log({message:`Rokt Kit: Failed to persist UTM params [reason: ${r}]`,code:"UTM_CAPTURE_FAILED"});return}i?.log({message:`Rokt Kit: Captured UTM params [${n}]`,code:"UTM_CAPTURE_SUCCESS"})}function xe(){const i=O(h,D);return m(i)?i:null}function ne(){Y(h,D)}function Ye(){const e=document.querySelector('link[rel="canonical"]')?.href;if(e)return z(e)}const J=[{accountId:"2919171670744024290",pathname:"/checkout",targetPageIdentifier:"prod.rokt.conf",attributeKeys:["email","customertype","eventvenue","firstname","lastname","member_status","billingzipcode","currency"],optionalAttributeKeys:["firstname","lastname"]},{accountId:"2550745407543340151",pathname:"/checkout",targetPageIdentifier:"RoktExperience",attributeKeys:["email","firstname","lastname","customertype","loyaltytier","paymenttype","ccbin"],optionalAttributeKeys:["loyaltytier","paymenttype","ccbin"]},{accountId:"3236704179315511296",pathname:"/check-out/pay",targetPageIdentifier:"confirmation_page",attributeKeys:["email","firstname","lastname","loyaltytier"],optionalAttributeKeys:["firstname","lastname","loyaltytier"]},{accountId:"2192288523645376337",pathname:"/checkout/*/review",targetPageIdentifier:"ppx-ad-view-prod",attributeKeys:["email","firstname","lastname"],optionalAttributeKeys:["email"]}],Ge=6e4;function je(i){return m(i)&&typeof i.expiresAt=="number"&&m(i.attributes)}function He(i,e){return`activePreselect:${i}:${e}`}function Ve(i){const e=O(h,i);return je(e)?e:null}function We(i,e){x(h,i,{expiresAt:Date.now()+Ge,attributes:e})}const ze=5*6e4;function M(){return window.sessionStorage}function $e(i){return m(i)&&typeof i.expiresAt=="number"&&g(i.pathname)&&g(i.identifier)&&m(i.attributes)&&g(i.mpid)}function B(i){return`pendingPreselect:${i}`}function qe(i){const e=B(i),t=O(h,e,M);return $e(t)?t.expiresAt<=Date.now()?(Y(h,e,M),null):t:null}function Je(i,e,t,n,r){return x(h,B(i),{expiresAt:Date.now()+ze,pathname:e,identifier:t,attributes:n,mpid:r},M)}function L(i){Y(h,B(i),M)}function A(i,e){const t={fired:"PRESELECT_FIRED",missed:"PRESELECT_MISSED",queued:"PRESELECT_QUEUED",skipped:"PRESELECT_SKIPPED"};return{message:`Rokt Kit: preselect ${i} [reason=${e}]`,code:t[i]}}function Be(i,e){if(!i.includes("*"))return i===e;const t=i.split("/"),n=e.split("/");return t.length!==n.length?!1:t.every((r,s)=>r==="*"?n[s]!=="":r===n[s])}function Se(i,e){if(i)return J.find(t=>t.accountId===i&&Be(t.pathname,e))}function Qe(i,e){if(!(!i||!g(e)))return J.find(t=>t.accountId===i&&t.targetPageIdentifier===e)}function Xe(i,e){return i?J.some(t=>t.accountId===i&&t.attributeKeys.includes(e)):!1}function Ze(){return{pending:[]}}function j(i,e){const t=i.pending.findIndex(n=>n.pathname===e.pathname);if(t>=0){i.pending[t]=e;return}i.pending.push(e)}function V(i){if(!i?.getUserIdentities)return!1;const e=i.getUserIdentities().userIdentities;return e?Object.keys(e).some(t=>{const n=e[t];return g(n)&&n.length>0}):!1}function Ae(i){const e=i?.getMPID?.();return e==null?null:String(e)}function Pe(i,e){const t=new Set((i.optionalAttributeKeys??[]).map(n=>n.toLowerCase()));return i.attributeKeys.filter(n=>!t.has(n.toLowerCase())&&S(e[n]))}function re(i,e,t){const n=i.filteredUser?.getAllUserAttributes?.()||{},r={};for(const s of t.attributeKeys){const o=i.getEventAttributeValue(e,s),c=S(o)?i.userAttributes[s]??n[s]:o;S(c)||(r[s]=c)}return{collected:r,missingKeys:Pe(t,r)}}function et(i,e){Promise.resolve(i.selectPlacements(e)).catch(t=>{const n=t instanceof Error?t.message:String(t);i.log({message:`Rokt Kit: Preselect selectPlacements call failed: ${n}`,code:"PRESELECT_DISPATCH_FAILED"})})}function be(i,e,t,n,r,s){const o=He(e,t),c=Ve(o),u=!!c&&JSON.stringify(c.attributes)===JSON.stringify(r);if(c&&c.expiresAt>Date.now()&&u){i.logPlacementDiagnostic(A("skipped","active_preselection"));return}We(o,r),i.logPlacementDiagnostic(A("fired",s)),et(i,{attributes:r,preselect:!0,identifier:n,omitUrl:!0})}function tt(i,e){if(!e.accountId||!e.isKitReady())return;const t=qe(e.accountId);if(!t)return;if(i.pending.some(o=>o.pathname===t.pathname)){L(e.accountId);return}if(!e.isPreselectionEnabled()){L(e.accountId);return}if(!V(e.filteredUser)||(L(e.accountId),Ae(e.filteredUser)!==t.mpid))return;const n=Se(e.accountId,t.pathname);if(!n||n.targetPageIdentifier!==t.identifier)return;const r=y(t.attributes),s=Pe(n,r);if(s.length>0){for(const o of s)e.logPlacementDiagnostic(A("missed",`missing_persisted_attribute:${o}`));return}be(e,e.accountId,t.identifier,t.identifier,r,"recovered")}function Re(i,e,t,n=window.location.pathname){const r=Se(e.accountId,n);if(!r)return;if(!e.isKitReady()){const c=[],u=Ae(e.filteredUser);if(e.accountId&&u&&V(e.filteredUser)){const{collected:l,missingKeys:f}=re(e,t,r);if(f.length===0){const k=y(l);Je(e.accountId,n,r.targetPageIdentifier,k,u)||c.push(A("queued","persist_failed"))}}j(i,{event:t,pathname:n,storedDiagnostics:c});return}if(!e.isPreselectionEnabled())return;if(!V(e.filteredUser)){e.logPlacementDiagnostic(A("missed","no_valid_identity")),j(i,{event:t,pathname:n});return}const{collected:s,missingKeys:o}=re(e,t,r);if(o.length>0){for(const c of o)e.logPlacementDiagnostic(A("missed",`missing_attribute:${c}`));j(i,{event:t,pathname:n});return}be(e,e.accountId||"",n,r.targetPageIdentifier,s,"fired")}function it(i,e,t=window.location.pathname){if(tt(i,e),i.pending.length===0)return;const n=i.pending;i.pending=[],n.forEach(({event:r,pathname:s,storedDiagnostics:o})=>{s===t&&(e.isKitReady()&&e.isPreselectionEnabled()&&o?.forEach(c=>e.logPlacementDiagnostic(c)),Re(i,e,r,s))})}function nt(){return{context:null,lifecycle:"idle",recreateInFlight:null}}function rt(i,e){i.context={accountId:e.accountId,launcherOptions:{...e.launcherOptions},legacyRoktExtensions:[...e.legacyRoktExtensions]}}function st(i){i.lifecycle="attached"}function ot(i){i.lifecycle!=="idle"&&(i.lifecycle="terminated")}function ct(i){i.lifecycle="terminated"}function at(i){i.context=null,i.lifecycle="idle",i.recreateInFlight=null}function lt(i,e,t){if(i.recreateInFlight)return i.recreateInFlight;if(i.lifecycle!=="terminated"||!i.context||!e)return;i.lifecycle="recreating";const n=i.context;return i.recreateInFlight=t(n).finally(()=>{i.recreateInFlight=null}),i.recreateInFlight}const d="Rokt",K=181,ut="selectPlacements",dt="apps.roktecommerce.com",ht=.1,gt="ThankYouPageJourney",ft="rokt-launcher",pt="rokt-thank-you-element",mt="userIdentifiedInWorkspace",Et=3,_t=2,It="page_events",yt="page_view_attributes",St="mparticle_session_id",At="mparticle_device_id",se=500,Q={UNKNOWN_ERROR:"UNKNOWN_ERROR",UNHANDLED_EXCEPTION:"UNHANDLED_EXCEPTION",IDENTITY_REQUEST:"IDENTITY_REQUEST",LOG_DELIVERY_FAILURE:"LOG_DELIVERY_FAILURE"},P={ERROR:"ERROR",INFO:"INFO",WARNING:"WARNING"},Pt="apps.rokt-api.com",bt="/v1/log",Rt="/v1/errors",kt=10;function a(){return window.mParticle}function oe(i,e){const n=[G(i),"/wsdk/integrations/launcher.js"].join("");return!e||e.length===0?n:n+"?extensions="+e.join(",")}function ce(i){return[G(i),"/rokt-elements/rokt-element-thank-you.js"].join("")}function G(i){const e=i!==void 0?i:Pt;return e.includes("://")?e.replace(/\/+$/,""):["https://",e].join("")}function ke(i,e,t){if(i)return i.startsWith("http://")||i.startsWith("https://")?i:"https://"+i;const r=e?.includes("://")&&!/^https?:\/\//i.test(e)?void 0:e;return G(r)+t}function ae(i,e,t){if(document.getElementById(i))return;const n=document.head||document.body,r=document.createElement("script");r.id=i,r.type="text/javascript",r.src=e,r.async=!0,r.crossOrigin="anonymous",r.fetchPriority="high",t?.onLoad&&(r.onload=t.onLoad),t?.onError&&(r.onerror=t.onError),n.appendChild(r)}function C(i){if(!i)return[];try{return JSON.parse(i.replace(/"/g,'"'))}catch{console.error("Settings string contains invalid JSON")}return[]}function le(i){const e=i?C(i):[],t=[],n=[];let r=!1;for(let s=0;s<e.length;s++){const o=e[s].value;o==="thank-you-journey"?(r=!0,n.push(gt)):t.push(o)}return{roktExtensionsQueryParams:t,legacyRoktExtensions:n,loadThankYouElement:r}}async function vt(i,e){const t=[];if(e)for(const n of i)t.push(e.use(n));return Promise.all(t)}function ue(i){if(!i)return{};const e={};for(let t=0;t<i.length;t++){const n=i[t];e[n.jsmap]=n.value}return e}function de(i){const e={};if(!Array.isArray(i))return e;for(let t=0;t<i.length;t++){const n=i[t];if(!n||!g(n.value)||!g(n.map))continue;const r=n.value,s=n.map;e[r]||(e[r]=[]),e[r].push({eventAttributeKey:s,conditions:Array.isArray(n.conditions)?n.conditions:[]})}return e}function he(i,e,t){return a().generateHash([i,e,t].join(""))}function wt(i){let n="mParticle_wsdkv_"+a().getVersion()+"_kitv_"+"3.7.0";return i&&(n+="_"+i),n}function W(i){const e=document.createElement("iframe");e.style.display="none",e.setAttribute("sandbox","allow-scripts allow-same-origin"),e.src=i,e.onload=function(){e.onload=null,e.parentNode&&e.parentNode.removeChild(e)};const t=document.body||document.head;t&&t.appendChild(e)}function ge(i,e){const t=Ee(window.location.origin);if(b._allowedOriginHashes.indexOf(t)===-1||Math.random()>=ht)return;const r=window.__rokt_li_guid__;if(!r||i&&i.includes("://")&&!/^https:\/\//i.test(i))return;const s=window.location.href.split("?")[0].split("#")[0],o="version="+encodeURIComponent(e??"")+"&launcherInstanceGuid="+encodeURIComponent(r)+"&pageUrl="+encodeURIComponent(s),c=i?G(i):"https://apps.rokt.com";W(c+"/v1/wsdk-init/index.html?"+o),W("https://"+dt+"/v1/wsdk-init/index.html?"+o+"&isControl=true")}function Tt(){return typeof window<"u"&&!!window.location?.search?.toLowerCase().includes("mp_enable_logging=true")}function Lt(){return typeof window<"u"?window.location?.href:void 0}function Ot(){return typeof window<"u"?window.navigator?.userAgent:void 0}class ve{constructor(){this._logCount={}}incrementAndCheck(e){const n=(this._logCount[e]||0)+1;return this._logCount[e]=n,n>kt}}class F{constructor(e,t,n,r,s){this._reporter="mp-wsdk";const o=e.isLoggingEnabled;this._integrationName=t||"",this._launcherInstanceGuid=n,this._accountId=r||null,this._rateLimiter=s||new ve,this._isEnabled=Tt()||o}send(e,t,n,r,s,o){if(!(!this._isEnabled||this._rateLimiter.incrementAndCheck(t)))try{const c={additionalInformation:{message:n,version:this._integrationName},severity:t,code:r||Q.UNKNOWN_ERROR,url:Lt(),deviceInfo:Ot(),stackTrace:s,reporter:this._reporter,integration:this._integrationName},u={Accept:"text/plain;charset=UTF-8","Content-Type":"application/json","rokt-launcher-version":this._integrationName,"rokt-wsdk-version":"joint"};this._launcherInstanceGuid&&(u["rokt-launcher-instance-guid"]=this._launcherInstanceGuid),this._accountId&&(u["rokt-account-id"]=this._accountId),fetch(e,{method:"POST",headers:u,body:JSON.stringify(c)}).then(l=>{if(!l.ok){const f=new Error("HTTP "+l.status+" from log endpoint");throw f.statusCode=l.status,f}}).catch(l=>{console.error("ReportingTransport: Failed to send log",l),o&&o(l)})}catch(c){console.error("ReportingTransport: Failed to send log",c),o&&o(c)}}}class fe{constructor(e,t,n,r,s){this._transport=new F(e,t,n,r,s),this._errorUrl=ke(e?.errorUrl,e?.integrationDomain,Rt)}report(e){if(!e)return;const t=e.severity||P.ERROR;this._transport.send(this._errorUrl,t,e.message,e.code,e.stackTrace)}}class pe{constructor(e,t,n,r,s,o){this._transport=new F(e,n,r,s,o),this._placementDiagnosticTransport=new F(e,n,r,s),this._loggingUrl=ke(e?.loggingUrl,e?.integrationDomain,bt),this._errorReportingService=t}log(e){e&&this._send(this._transport,e)}logPlacementDiagnostic(e){e&&this._send(this._placementDiagnosticTransport,e)}_send(e,t){e.send(this._loggingUrl,P.INFO,t.message,t.code,void 0,n=>{if(this._errorReportingService){const r=typeof n.statusCode=="number";this._errorReportingService.report({message:"LoggingService: Failed to send log: "+n.message,code:Q.LOG_DELIVERY_FAILURE,severity:r?P.ERROR:P.WARNING})}})}}function Nt(i){const e=z(window.location.href),t=i.EventAttributes?.title||document.title,n=Ye(),r=i.ActiveTimeOnSite;return{pageUrl:e,sourceMessageId:i.SourceMessageId,timestamp:i.Timestamp,...t?{pageTitle:t}:{},...n!==void 0?{canonicalUrl:n}:{},...Number.isFinite(r)?{activeTimeOnSite:r}:{}}}const _=class _{constructor(){this.name=d,this.id=K,this.moduleId=K,this.isInitialized=!1,this.launcher=null,this.filters={},this.userAttributes={},this.userIdentifiedInWorkspace=!1,this.testHelpers=null,this.placementEventMappingLookup={},this.placementEventAttributeMappingLookup={},this.integrationName=null,this.errorReportingService=null,this.loggingService=null,this._thankYouElementOnLoadCallback=null,this._isThankYouElementLoaded=!1,this._workspaceSearchInFlightPromise=null,this._launcherAttachState=nt(),this.accountId=null,this._preselectState=Ze()}getEventAttributeValue(e,t){const n=e&&e.EventAttributes;return!n||n[t]===void 0?null:n[t]}doesEventAttributeConditionMatch(e,t){if(!e||!g(e.operator))return!1;const n=e.operator.toLowerCase(),r=e.attributeValue;return n==="exists"?t!==null:t==null?!1:n==="equals"?String(t)===String(r):n==="contains"?String(t).indexOf(String(r))!==-1:!1}doesEventMatchRule(e,t){if(!t||!g(t.eventAttributeKey))return!1;const n=t.conditions;if(!Array.isArray(n))return!1;const r=this.getEventAttributeValue(e,t.eventAttributeKey);if(n.length===0)return r!==null;for(let s=0;s<n.length;s++)if(!this.doesEventAttributeConditionMatch(n[s],r))return!1;return!0}applyPlacementEventAttributeMapping(e){const t=Object.keys(this.placementEventAttributeMappingLookup);for(let n=0;n<t.length;n++){const r=t[n],s=this.placementEventAttributeMappingLookup[r];if(S(s))continue;let o=!0;for(let c=0;c<s.length;c++)if(!this.doesEventMatchRule(e,s[c])){o=!1;break}o&&a().Rokt.setLocalSessionAttribute?.(r,!0)}}capturePageView(e){let t;try{t=z(window.location.href);const n=te(),r=Nt(e);n.push(r);const s=Math.min(n.length,Ie),o=De(n);if(o===0){const c=H()?"quota":"ls_unavailable";this.loggingService?.log({message:`Rokt Kit: Failed to persist page view for ${t} [reason: ${c}]`,code:"PAGE_VIEW_CAPTURE_FAILED"})}else o<s&&this.loggingService?.log({message:`Rokt Kit: Page view storage reduced from ${s} to ${o} record(s) under quota pressure [reason: quota_eviction]`,code:"PAGE_VIEW_QUOTA_EVICTION"})}catch(n){const r=H()?"exception":"ls_unavailable",s=n instanceof Error?n.message:String(n);this.loggingService?.log({message:`Rokt Kit: Failed to capture page view for ${t}: ${s} [reason: ${r}]`,code:"PAGE_VIEW_CAPTURE_FAILED"})}}isPreselectionEnabled(){return this.launcher?.enablePreselection===!0}buildCacheMatchKeys(e){if(!this.isPreselectionEnabled())return;const t=Qe(this.accountId,e);if(t)return t.attributeKeys}buildPreselectHost(){return{accountId:this.accountId,filteredUser:this.filters.filteredUser,userAttributes:this.userAttributes,isKitReady:()=>this.isKitReady(),isPreselectionEnabled:()=>this.isPreselectionEnabled(),getEventAttributeValue:(e,t)=>this.getEventAttributeValue(e,t),logPlacementDiagnostic:e=>this.loggingService?.logPlacementDiagnostic(e),log:e=>this.loggingService?.log(e),selectPlacements:e=>this.selectPlacements(e)}}flushPendingPreselectDispatches(){it(this._preselectState,this.buildPreselectHost())}isLauncherReadyToAttach(){return!!window.Rokt&&U(window.Rokt.createLauncher)}returnUserIdentities(e){if(!e||!e.getUserIdentities)return{};const t=e.getUserIdentities().userIdentities;return this.replaceOtherIdentityWithEmailsha256(t)}returnLocalSessionAttributes(){return!a().Rokt||typeof a().Rokt.getLocalSessionAttributes!="function"?{}:a().Rokt.getLocalSessionAttributes()}replaceOtherIdentityWithEmailsha256(e){const t={...e||{}},n=this._mappedEmailSha256Key;return n&&e[n]&&(t[_.EMAIL_SHA256_KEY]=e[n]),n&&delete t[n],t}logSelectPlacementsEvent(e){if(!window.mParticle||typeof a().logEvent!="function"||!m(e))return;const t=a().EventType.Other;a().logEvent(ut,t,e)}setRoktSessionId(e){if(!(!e||typeof e!="string"))try{const t=a().getInstance();t&&U(t.setIntegrationAttribute)&&t.setIntegrationAttribute(K,{roktSessionId:e})}catch{}}readMpSessionId(){const e=a()?.sessionManager,t=e?.getSessionId??e?.getSession;if(U(t))return t.call(e)||void 0}readMpDeviceId(){return a()?.getDeviceId?.()||void 0}attachLauncher(e,t,n=[]){rt(this._launcherAttachState,{accountId:e,launcherOptions:t||{},legacyRoktExtensions:n});const r={accountId:e,...t||{}};let s;return this.isPartnerInLocalLauncherTestGroup()?s=Promise.resolve(window.Rokt.createLocalLauncher(r)):s=window.Rokt.createLauncher(r),s.then(async o=>{await vt([...n],o),this.initRoktLauncher(o)}).catch(o=>{const c=this._launcherAttachState.lifecycle==="attached";if(ct(this._launcherAttachState),!c){const u=o instanceof Error?o.message:String(o);this.loggingService?.log({message:`Rokt Kit: Failed to attach Rokt launcher: ${u}`,code:"LAUNCHER_ATTACH_FAILED"})}console.error("Error creating Rokt launcher:",o)})}recreateLauncherIfTerminated(){return lt(this._launcherAttachState,this.isLauncherReadyToAttach(),e=>this.attachLauncher(e.accountId,e.launcherOptions,e.legacyRoktExtensions))}initRoktLauncher(e){window.Rokt&&(window.Rokt.currentLauncher=e),this.launcher=e,st(this._launcherAttachState);const t=a().Rokt?.filters;t?(this.filters=t,t.filteredUser?this._workspaceSearchInFlightPromise=this.search(t.filteredUser):console.warn("Rokt Kit: No filtered user has been set.")):console.warn("Rokt Kit: No filters have been set."),this.isInitialized=!0,ge(this.domain,this.integrationName),a().Rokt.attachKit(this),this.flushPendingPreselectDispatches()}fetchOptimizely(){const e=a()._getActiveForwarders().filter(t=>t.name==="Optimizely");try{if(e.length>0&&window.optimizely){const t=window.optimizely.get("state");return!t||!t.getActiveExperimentIds?{}:t.getActiveExperimentIds().reduce((s,o)=>(s["rokt.custom.optimizely.experiment."+o+".variationId"]=t.getVariationMap()[o].id,s),{})}}catch(t){console.error("Error fetching Optimizely attributes:",t)}return{}}isKitReady(){return!!(this.isInitialized&&this.launcher)}isTargetingDisabled(){return a().Rokt?.launcherOptions?.noTargeting===!0}isPartnerInLocalLauncherTestGroup(){return!!(a().config&&a().config.isLocalLauncherEnabled&&this.isAssignedToSampleGroup())}isAssignedToSampleGroup(){return Math.random()>.5}captureTiming(e){window&&a()&&a().captureTiming&&e&&a().captureTiming(e)}init(e,t,n,r,s){const o=e,c=o.accountId;this.accountId=c||null,this.userAttributes=y(s),this._onboardingExpProvider=o.onboardingExpProvider;const u=C(o.placementEventMapping);this.placementEventMappingLookup=ue(u);const l=C(o.placementEventAttributeMapping);this.placementEventAttributeMappingLookup=de(l),o.hashedEmailUserIdentityType&&(this._mappedEmailSha256Key=o.hashedEmailUserIdentityType.toLowerCase()),this._workspaceIdSyncApiKey=g(o.workspaceIdSyncApiKey)?o.workspaceIdSyncApiKey:void 0;const f=a().Rokt?.domain,{roktExtensionsQueryParams:k,legacyRoktExtensions:v,loadThankYouElement:N}=le(o.roktExtensions),E={...a().Rokt?.launcherOptions||{}};this.integrationName=wt(E.integrationName),E.integrationName=this.integrationName,this.domain=f;const w={loggingUrl:o.loggingUrl,errorUrl:o.errorUrl,integrationDomain:f,isLoggingEnabled:a().config?.isLoggingEnabled===!0},I=new fe(w,this.integrationName,window.__rokt_li_guid__,o.accountId),T=new pe(w,I,this.integrationName,window.__rokt_li_guid__,o.accountId);if(this.errorReportingService=I,this.loggingService=T,this.isTargetingDisabled())try{ie(),ne()}catch(p){this.errorReportingService?.report({message:"Rokt Kit: Failed to clear page views when targeting is disabled",code:"PAGE_VIEW_CAPTURE_FAILED",severity:P.INFO,stackTrace:p instanceof Error?p.stack:void 0})}return a()._registerErrorReportingService&&a()._registerErrorReportingService(I),a()._registerLoggingService&&a()._registerLoggingService(T),n?(this.testHelpers={generateLauncherScript:oe,generateThankYouElementScript:ce,extractRoktExtensionConfig:le,hashEventMessage:he,parseSettingsString:C,generateMappedEventLookup:ue,generateMappedEventAttributeLookup:de,sendAdBlockMeasurementSignals:ge,createAutoRemovedIframe:W,djb2:Ee,setAllowedOriginHashes:p=>{_._allowedOriginHashes=p},ReportingTransport:F,ErrorReportingService:fe,LoggingService:pe,RateLimiter:ve,ErrorCodes:Q,WSDKErrorSeverity:P,resetLauncherAttachState:()=>at(this._launcherAttachState)},this.attachLauncher(c,E),"Successfully initialized: "+d):(N&&(a().Rokt.flushOnShoppableAdsReadyMessageQueue?.(this),ae(pt,ce(f),{onLoad:()=>{this._isThankYouElementLoaded=!0,this._thankYouElementOnLoadCallback&&this._thankYouElementOnLoadCallback()},onError:p=>{console.error("Error loading Rokt Thank You Element script:",p)}})),this.isLauncherReadyToAttach()?this.attachLauncher(c,E,v):(ae(ft,oe(f,k),{onLoad:()=>{this.isLauncherReadyToAttach()?this.attachLauncher(c,E,v):console.error("Rokt object is not available after script load.")},onError:p=>{console.error("Error loading Rokt launcher script:",p)}}),this.captureTiming(_.PERFORMANCE_MARKS.RoktScriptAppended)),"Successfully initialized: "+d)}process(e){if(this.isTargetingDisabled()||(e.EventDataType===Et&&(Fe(this.loggingService),this.capturePageView(e),Re(this._preselectState,this.buildPreselectHost(),e)),e.EventDataType===_t&&(ie(),ne(),this.accountId&&L(this.accountId))),!this.isKitReady())return"Kit not ready for forwarder: "+d;if(U(a().Rokt?.setLocalSessionAttribute)&&(S(this.placementEventAttributeMappingLookup)||this.applyPlacementEventAttributeMapping(e),!S(this.placementEventMappingLookup))){const t=he(e.EventDataType,e.EventCategory,e.EventName??"");this.placementEventMappingLookup[String(t)]&&a().Rokt.setLocalSessionAttribute?.(this.placementEventMappingLookup[String(t)],!0)}return"Successfully sent to forwarder: "+d}setExtensionData(e){if(!this.isKitReady()){console.error("Rokt Kit: Not initialized");return}window.Rokt.setExtensionData(e)}setUserAttribute(e,t){return me(e)||(this.userAttributes[e]=t),Xe(this.accountId,e)&&this.flushPendingPreselectDispatches(),"Successfully set user attribute for forwarder: "+d}removeUserAttribute(e){return delete this.userAttributes[e],"Successfully removed user attribute for forwarder: "+d}handleIdentityComplete(e,t){return this.userAttributes=y(e.getAllUserAttributes()),"Successfully called "+t+" for forwarder: "+d}onUserIdentified(e){const t=e;this.filters.filteredUser=t,this._workspaceSearchInFlightPromise=this.search(t);const n=this.handleIdentityComplete(e,"onUserIdentified");return this.flushPendingPreselectDispatches(),n}search(e){const t=this._workspaceIdSyncApiKey;if(!t)return this.userIdentifiedInWorkspace=!1,this._workspaceLastSearchedIdentitiesKey=void 0,Promise.resolve();const n=a().Identity?.search;if(typeof n!="function")return this.userIdentifiedInWorkspace=!1,this._workspaceLastSearchedIdentitiesKey=void 0,Promise.resolve();const r=e.getUserIdentities?e.getUserIdentities().userIdentities:null,s={};if(r)for(const u of Object.keys(r)){const l=r[u];g(l)&&l.length>0&&(s[u]=l)}const o=Object.keys(s);if(o.length===0)return this.userIdentifiedInWorkspace=!1,this._workspaceLastSearchedIdentitiesKey=void 0,Promise.resolve();const c=o.sort().map(u=>`${u}=${s[u]}`).join("&");return c===this._workspaceLastSearchedIdentitiesKey?this._workspaceSearchInFlightPromise||Promise.resolve():(this.userIdentifiedInWorkspace=!1,this._workspaceLastSearchedIdentitiesKey=c,new Promise(u=>{try{n(t,s,l=>{l?.httpCode===200&&(this.userIdentifiedInWorkspace=!0),u()})}catch(l){console.error("Rokt Kit: Workspace IDSync search failed",l),this._workspaceLastSearchedIdentitiesKey=void 0,u()}}))}onLoginComplete(e,t){return this.handleIdentityComplete(e,"onLoginComplete")}onLogoutComplete(e,t){return this.userIdentifiedInWorkspace=!1,this._workspaceSearchInFlightPromise=null,this._workspaceLastSearchedIdentitiesKey=void 0,this.accountId&&L(this.accountId),this.handleIdentityComplete(e,"onLogoutComplete")}onModifyComplete(e,t){return this.handleIdentityComplete(e,"onModifyComplete")}selectPlacements(e){const t=this.recreateLauncherIfTerminated();if(t){const n=this._workspaceSearchInFlightPromise,r=n?Promise.race([n,new Promise(s=>setTimeout(s,se))]):Promise.resolve();return Promise.all([t,r]).then(()=>this._dispatchPlacements(e))}if(this._workspaceSearchInFlightPromise){const n=this._workspaceSearchInFlightPromise;return Promise.race([n,new Promise(r=>setTimeout(r,se))]).then(()=>this._dispatchPlacements(e))}return this._dispatchPlacements(e)}_dispatchPlacements(e){const t=e&&e.attributes||{},r={...y(this.userAttributes),...t},s=this.filters||{},o=s.userAttributeFilters||[],c=s.filteredUser||null,u=c?c.getMPID():null;let l;s?s.filterUserAttributes?l=s.filterUserAttributes(r,o):l=r:(console.warn("Rokt Kit: No filters available, using user attributes"),l=r),this.userAttributes=y(l);const f=this._onboardingExpProvider==="Optimizely"?this.fetchOptimizely():{},k=this.returnUserIdentities(c),v=this.returnLocalSessionAttributes(),N=Me(te()),E=xe(),w=this.readMpSessionId(),I=this.readMpDeviceId(),T={...k,...l,...f,...v,...N.length?{[It]:JSON.stringify(N)}:{},...E?{[yt]:E}:{},...this.userIdentifiedInWorkspace?{[mt]:!0}:{},...w?{[St]:w}:{},...I?{[At]:I}:{},mpid:u},p=this.buildCacheMatchKeys(typeof e.identifier=="string"?e.identifier:void 0),we={...e,attributes:T,...p!==void 0?{cacheMatchKeys:p}:{}},X=this.launcher.selectPlacements(we),Z=e.preselect===!0,Te=()=>{Z||this.logSelectPlacementsEvent(T)};return Promise.resolve(X).then(Le=>{if(!Z)return Le?.context?.sessionId?.then(Oe=>this.setRoktSessionId(Oe))}).catch(()=>{}).finally(Te),X}hashAttributes(e){return this.isKitReady()?this.launcher.hashAttributes(e):(console.error("Rokt Kit: Not initialized"),null)}use(e){return this.isKitReady()?!e||!g(e)?Promise.reject(new Error("Rokt Kit: Invalid extension name")):this.launcher.use(e):(console.error("Rokt Kit: Not initialized"),Promise.reject(new Error("Rokt Kit: Not initialized")))}terminate(){return this.isKitReady()?(ot(this._launcherAttachState),this.launcher.terminate()):(console.error("Rokt Kit: Not initialized"),Promise.resolve())}onShoppableAdsReady(e){this._isThankYouElementLoaded?e():this._thankYouElementOnLoadCallback=e}};_._allowedOriginHashes=[-553112570,549508659],_.PERFORMANCE_MARKS={RoktScriptAppended:"mp:RoktScriptAppended"},_.EMAIL_SHA256_KEY="emailsha256";let b=_;function Ut(){return K}function Kt(i){if(!i){window.console.log("You must pass a config object to register the kit "+d);return}if(!m(i)){window.console.log("'config' must be an object. You passed in a "+typeof i);return}m(i.kits)?i.kits[d]={constructor:b}:(i.kits={},i.kits[d]={constructor:b}),window.console.log("Successfully registered "+d+" to your mParticle configuration")}typeof window<"u"&&window.mParticle&&a().addForwarder&&a().addForwarder({name:d,constructor:b,getId:Ut});exports.register=Kt;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const Ne=["active_time_on_site_ms","billingaddress1","billingaddress2","billingcity","billingstate","billingzipcode","cartitems","ccbin","confirmationref","conversiontype","country","couponcode","currency","language","paymentserviceprovider","paymentserviceproviderattribute","paymenttype","shippingaddress1","shippingcity","shippingcountry","shippingmethod","shippingstate","shippingzipcode","totalprice"],Ue=new Set(Ne);function me(i){return Ue.has(i.toLowerCase())}function y(i){const e={},t=i||{},n=Object.keys(t);for(let r=0;r<n.length;r++){const s=n[r];me(s)||(e[s]=t[s])}return e}function m(i){return typeof i=="object"&&i!==null&&!Array.isArray(i)}function g(i){return typeof i=="string"}function U(i){return typeof i=="function"}function S(i){return i==null?!0:typeof i=="string"?i.length===0:typeof i=="object"?Object.keys(i).length===0:!1}function z(i){try{const e=new URL(i);return e.search="",e.toString()}catch{return i}}function Ee(i){let e=5381;for(let t=0;t<i.length;t++)e=(e<<5)+e+i.charCodeAt(t),e=e&e;return e}const h="mp-rokt-kit",ee="__rokt_ls_probe__";function H(){try{return window.localStorage.setItem(ee,"1"),window.localStorage.removeItem(ee),!0}catch{return!1}}const R=()=>window.localStorage;function $(i,e=R){try{const t=e().getItem(i);return t===null?null:JSON.parse(t)}catch{return null}}function _e(i,e,t=R){try{return t().setItem(i,JSON.stringify(e)),!0}catch{return!1}}function Ke(i,e=R){try{e().removeItem(i)}catch{}}function O(i,e,t=R){const n=$(i,t);return m(n)?n[e]:void 0}function x(i,e,t,n=R){const r=$(i,n),s=m(r)?{...r}:{};return s[e]=t,_e(i,s,n)}function Y(i,e,t=R){const n=$(i,t);if(!m(n)||!(e in n))return;const r={...n};delete r[e],Object.keys(r).length===0?Ke(i,t):_e(i,r,t)}const q="pageViews",D="utmParams",Ie=25,Ce=["utm_source","utm_medium","utm_campaign","utm_term","utm_content"];function ye(i){return i.slice(-Ie)}function te(){const i=O(h,q);return Array.isArray(i)?i:[]}function De(i){const e=ye(i);for(let t=0;t<e.length;t++){const n=e.slice(t);if(x(h,q,n))return n.length}return 0}function ie(){Y(h,q)}function Me(i){const e=ye(i);return e.map((t,n)=>{const r=t.activeTimeOnSite,s=r!==void 0&&Number.isFinite(r),c=e[n+1]?.activeTimeOnSite,u=c!==void 0&&Number.isFinite(c),l=s&&u?c-r:void 0;return{pageUrl:t.pageUrl,sourceMessageId:t.sourceMessageId,timestamp:t.timestamp,...t.pageTitle!==void 0?{pageTitle:t.pageTitle}:{},...t.canonicalUrl!==void 0?{canonicalUrl:t.canonicalUrl}:{},...s?{activeTimeOnSite:r}:{},...l!==void 0&&l>=0?{activeTimeOnPage:l}:{}}})}function Fe(i){if(O(h,D)!==void 0)return;const e=new URLSearchParams(window.location.search),t={};for(const r of Ce){const s=e.get(r);s&&(t[r]=s)}if(Object.keys(t).length===0)return;const n=Object.keys(t).join(", ");if(!x(h,D,t)){const r=H()?"quota":"ls_unavailable";i?.log({message:`Rokt Kit: Failed to persist UTM params [reason: ${r}]`,code:"UTM_CAPTURE_FAILED"});return}i?.log({message:`Rokt Kit: Captured UTM params [${n}]`,code:"UTM_CAPTURE_SUCCESS"})}function xe(){const i=O(h,D);return m(i)?i:null}function ne(){Y(h,D)}function Ye(){const e=document.querySelector('link[rel="canonical"]')?.href;if(e)return z(e)}const J=[{accountId:"2919171670744024290",pathname:"/checkout",targetPageIdentifier:"prod.rokt.conf",attributeKeys:["email","customertype","eventvenue","firstname","lastname","member_status","billingzipcode","currency"],optionalAttributeKeys:["firstname","lastname"]},{accountId:"2550745407543340151",pathname:"/checkout",targetPageIdentifier:"RoktExperience",attributeKeys:["email","firstname","lastname","customertype","loyaltytier","paymenttype","ccbin"],optionalAttributeKeys:["loyaltytier","paymenttype","ccbin"]},{accountId:"3236704179315511296",pathname:"/check-out/pay",targetPageIdentifier:"confirmation_page",attributeKeys:["email","firstname","lastname","loyaltytier"],optionalAttributeKeys:["firstname","lastname","loyaltytier"]},{accountId:"2192288523645376337",pathname:"/checkout/*/review",targetPageIdentifier:"ppx-ad-view-prod",attributeKeys:["email","firstname","lastname"],optionalAttributeKeys:["email"]},{accountId:"2074245483568304147",pathname:"/checkout/cart",targetPageIdentifier:"new_confirmation",attributeKeys:["email","firstname","lastname"],optionalAttributeKeys:["firstname","lastname"]}],Ge=6e4;function je(i){return m(i)&&typeof i.expiresAt=="number"&&m(i.attributes)}function He(i,e){return`activePreselect:${i}:${e}`}function Ve(i){const e=O(h,i);return je(e)?e:null}function We(i,e){x(h,i,{expiresAt:Date.now()+Ge,attributes:e})}const ze=5*6e4;function M(){return window.sessionStorage}function $e(i){return m(i)&&typeof i.expiresAt=="number"&&g(i.pathname)&&g(i.identifier)&&m(i.attributes)&&g(i.mpid)}function B(i){return`pendingPreselect:${i}`}function qe(i){const e=B(i),t=O(h,e,M);return $e(t)?t.expiresAt<=Date.now()?(Y(h,e,M),null):t:null}function Je(i,e,t,n,r){return x(h,B(i),{expiresAt:Date.now()+ze,pathname:e,identifier:t,attributes:n,mpid:r},M)}function L(i){Y(h,B(i),M)}function A(i,e){const t={fired:"PRESELECT_FIRED",missed:"PRESELECT_MISSED",queued:"PRESELECT_QUEUED",skipped:"PRESELECT_SKIPPED"};return{message:`Rokt Kit: preselect ${i} [reason=${e}]`,code:t[i]}}function Be(i,e){if(!i.includes("*"))return i===e;const t=i.split("/"),n=e.split("/");return t.length!==n.length?!1:t.every((r,s)=>r==="*"?n[s]!=="":r===n[s])}function Se(i,e){if(i)return J.find(t=>t.accountId===i&&Be(t.pathname,e))}function Qe(i,e){if(!(!i||!g(e)))return J.find(t=>t.accountId===i&&t.targetPageIdentifier===e)}function Xe(i,e){return i?J.some(t=>t.accountId===i&&t.attributeKeys.includes(e)):!1}function Ze(){return{pending:[]}}function j(i,e){const t=i.pending.findIndex(n=>n.pathname===e.pathname);if(t>=0){i.pending[t]=e;return}i.pending.push(e)}function V(i){if(!i?.getUserIdentities)return!1;const e=i.getUserIdentities().userIdentities;return e?Object.keys(e).some(t=>{const n=e[t];return g(n)&&n.length>0}):!1}function Ae(i){const e=i?.getMPID?.();return e==null?null:String(e)}function Pe(i,e){const t=new Set((i.optionalAttributeKeys??[]).map(n=>n.toLowerCase()));return i.attributeKeys.filter(n=>!t.has(n.toLowerCase())&&S(e[n]))}function re(i,e,t){const n=i.filteredUser?.getAllUserAttributes?.()||{},r={};for(const s of t.attributeKeys){const o=i.getEventAttributeValue(e,s),c=S(o)?i.userAttributes[s]??n[s]:o;S(c)||(r[s]=c)}return{collected:r,missingKeys:Pe(t,r)}}function et(i,e){Promise.resolve(i.selectPlacements(e)).catch(t=>{const n=t instanceof Error?t.message:String(t);i.log({message:`Rokt Kit: Preselect selectPlacements call failed: ${n}`,code:"PRESELECT_DISPATCH_FAILED"})})}function be(i,e,t,n,r,s){const o=He(e,t),c=Ve(o),u=!!c&&JSON.stringify(c.attributes)===JSON.stringify(r);if(c&&c.expiresAt>Date.now()&&u){i.logPlacementDiagnostic(A("skipped","active_preselection"));return}We(o,r),i.logPlacementDiagnostic(A("fired",s)),et(i,{attributes:r,preselect:!0,identifier:n,omitUrl:!0})}function tt(i,e){if(!e.accountId||!e.isKitReady())return;const t=qe(e.accountId);if(!t)return;if(i.pending.some(o=>o.pathname===t.pathname)){L(e.accountId);return}if(!e.isPreselectionEnabled()){L(e.accountId);return}if(!V(e.filteredUser)||(L(e.accountId),Ae(e.filteredUser)!==t.mpid))return;const n=Se(e.accountId,t.pathname);if(!n||n.targetPageIdentifier!==t.identifier)return;const r=y(t.attributes),s=Pe(n,r);if(s.length>0){for(const o of s)e.logPlacementDiagnostic(A("missed",`missing_persisted_attribute:${o}`));return}be(e,e.accountId,t.identifier,t.identifier,r,"recovered")}function Re(i,e,t,n=window.location.pathname){const r=Se(e.accountId,n);if(!r)return;if(!e.isKitReady()){const c=[],u=Ae(e.filteredUser);if(e.accountId&&u&&V(e.filteredUser)){const{collected:l,missingKeys:f}=re(e,t,r);if(f.length===0){const k=y(l);Je(e.accountId,n,r.targetPageIdentifier,k,u)||c.push(A("queued","persist_failed"))}}j(i,{event:t,pathname:n,storedDiagnostics:c});return}if(!e.isPreselectionEnabled())return;if(!V(e.filteredUser)){e.logPlacementDiagnostic(A("missed","no_valid_identity")),j(i,{event:t,pathname:n});return}const{collected:s,missingKeys:o}=re(e,t,r);if(o.length>0){for(const c of o)e.logPlacementDiagnostic(A("missed",`missing_attribute:${c}`));j(i,{event:t,pathname:n});return}be(e,e.accountId||"",n,r.targetPageIdentifier,s,"fired")}function it(i,e,t=window.location.pathname){if(tt(i,e),i.pending.length===0)return;const n=i.pending;i.pending=[],n.forEach(({event:r,pathname:s,storedDiagnostics:o})=>{s===t&&(e.isKitReady()&&e.isPreselectionEnabled()&&o?.forEach(c=>e.logPlacementDiagnostic(c)),Re(i,e,r,s))})}function nt(){return{context:null,lifecycle:"idle",recreateInFlight:null}}function rt(i,e){i.context={accountId:e.accountId,launcherOptions:{...e.launcherOptions},legacyRoktExtensions:[...e.legacyRoktExtensions]}}function st(i){i.lifecycle="attached"}function ot(i){i.lifecycle!=="idle"&&(i.lifecycle="terminated")}function ct(i){i.lifecycle="terminated"}function at(i){i.context=null,i.lifecycle="idle",i.recreateInFlight=null}function lt(i,e,t){if(i.recreateInFlight)return i.recreateInFlight;if(i.lifecycle!=="terminated"||!i.context||!e)return;i.lifecycle="recreating";const n=i.context;return i.recreateInFlight=t(n).finally(()=>{i.recreateInFlight=null}),i.recreateInFlight}const d="Rokt",K=181,ut="selectPlacements",dt="apps.roktecommerce.com",ht=.1,gt="ThankYouPageJourney",ft="rokt-launcher",pt="rokt-thank-you-element",mt="userIdentifiedInWorkspace",Et=3,_t=2,It="page_events",yt="page_view_attributes",St="mparticle_session_id",At="mparticle_device_id",se=500,Q={UNKNOWN_ERROR:"UNKNOWN_ERROR",UNHANDLED_EXCEPTION:"UNHANDLED_EXCEPTION",IDENTITY_REQUEST:"IDENTITY_REQUEST",LOG_DELIVERY_FAILURE:"LOG_DELIVERY_FAILURE"},P={ERROR:"ERROR",INFO:"INFO",WARNING:"WARNING"},Pt="apps.rokt-api.com",bt="/v1/log",Rt="/v1/errors",kt=10;function a(){return window.mParticle}function oe(i,e){const n=[G(i),"/wsdk/integrations/launcher.js"].join("");return!e||e.length===0?n:n+"?extensions="+e.join(",")}function ce(i){return[G(i),"/rokt-elements/rokt-element-thank-you.js"].join("")}function G(i){const e=i!==void 0?i:Pt;return e.includes("://")?e.replace(/\/+$/,""):["https://",e].join("")}function ke(i,e,t){if(i)return i.startsWith("http://")||i.startsWith("https://")?i:"https://"+i;const r=e?.includes("://")&&!/^https?:\/\//i.test(e)?void 0:e;return G(r)+t}function ae(i,e,t){if(document.getElementById(i))return;const n=document.head||document.body,r=document.createElement("script");r.id=i,r.type="text/javascript",r.src=e,r.async=!0,r.crossOrigin="anonymous",r.fetchPriority="high",t?.onLoad&&(r.onload=t.onLoad),t?.onError&&(r.onerror=t.onError),n.appendChild(r)}function C(i){if(!i)return[];try{return JSON.parse(i.replace(/"/g,'"'))}catch{console.error("Settings string contains invalid JSON")}return[]}function le(i){const e=i?C(i):[],t=[],n=[];let r=!1;for(let s=0;s<e.length;s++){const o=e[s].value;o==="thank-you-journey"?(r=!0,n.push(gt)):t.push(o)}return{roktExtensionsQueryParams:t,legacyRoktExtensions:n,loadThankYouElement:r}}async function vt(i,e){const t=[];if(e)for(const n of i)t.push(e.use(n));return Promise.all(t)}function ue(i){if(!i)return{};const e={};for(let t=0;t<i.length;t++){const n=i[t];e[n.jsmap]=n.value}return e}function de(i){const e={};if(!Array.isArray(i))return e;for(let t=0;t<i.length;t++){const n=i[t];if(!n||!g(n.value)||!g(n.map))continue;const r=n.value,s=n.map;e[r]||(e[r]=[]),e[r].push({eventAttributeKey:s,conditions:Array.isArray(n.conditions)?n.conditions:[]})}return e}function he(i,e,t){return a().generateHash([i,e,t].join(""))}function wt(i){let n="mParticle_wsdkv_"+a().getVersion()+"_kitv_"+"3.8.0";return i&&(n+="_"+i),n}function W(i){const e=document.createElement("iframe");e.style.display="none",e.setAttribute("sandbox","allow-scripts allow-same-origin"),e.src=i,e.onload=function(){e.onload=null,e.parentNode&&e.parentNode.removeChild(e)};const t=document.body||document.head;t&&t.appendChild(e)}function ge(i,e){const t=Ee(window.location.origin);if(b._allowedOriginHashes.indexOf(t)===-1||Math.random()>=ht)return;const r=window.__rokt_li_guid__;if(!r||i&&i.includes("://")&&!/^https:\/\//i.test(i))return;const s=window.location.href.split("?")[0].split("#")[0],o="version="+encodeURIComponent(e??"")+"&launcherInstanceGuid="+encodeURIComponent(r)+"&pageUrl="+encodeURIComponent(s),c=i?G(i):"https://apps.rokt.com";W(c+"/v1/wsdk-init/index.html?"+o),W("https://"+dt+"/v1/wsdk-init/index.html?"+o+"&isControl=true")}function Tt(){return typeof window<"u"&&!!window.location?.search?.toLowerCase().includes("mp_enable_logging=true")}function Lt(){return typeof window<"u"?window.location?.href:void 0}function Ot(){return typeof window<"u"?window.navigator?.userAgent:void 0}class ve{constructor(){this._logCount={}}incrementAndCheck(e){const n=(this._logCount[e]||0)+1;return this._logCount[e]=n,n>kt}}class F{constructor(e,t,n,r,s){this._reporter="mp-wsdk";const o=e.isLoggingEnabled;this._integrationName=t||"",this._launcherInstanceGuid=n,this._accountId=r||null,this._rateLimiter=s||new ve,this._isEnabled=Tt()||o}send(e,t,n,r,s,o){if(!(!this._isEnabled||this._rateLimiter.incrementAndCheck(t)))try{const c={additionalInformation:{message:n,version:this._integrationName},severity:t,code:r||Q.UNKNOWN_ERROR,url:Lt(),deviceInfo:Ot(),stackTrace:s,reporter:this._reporter,integration:this._integrationName},u={Accept:"text/plain;charset=UTF-8","Content-Type":"application/json","rokt-launcher-version":this._integrationName,"rokt-wsdk-version":"joint"};this._launcherInstanceGuid&&(u["rokt-launcher-instance-guid"]=this._launcherInstanceGuid),this._accountId&&(u["rokt-account-id"]=this._accountId),fetch(e,{method:"POST",headers:u,body:JSON.stringify(c)}).then(l=>{if(!l.ok){const f=new Error("HTTP "+l.status+" from log endpoint");throw f.statusCode=l.status,f}}).catch(l=>{console.error("ReportingTransport: Failed to send log",l),o&&o(l)})}catch(c){console.error("ReportingTransport: Failed to send log",c),o&&o(c)}}}class fe{constructor(e,t,n,r,s){this._transport=new F(e,t,n,r,s),this._errorUrl=ke(e?.errorUrl,e?.integrationDomain,Rt)}report(e){if(!e)return;const t=e.severity||P.ERROR;this._transport.send(this._errorUrl,t,e.message,e.code,e.stackTrace)}}class pe{constructor(e,t,n,r,s,o){this._transport=new F(e,n,r,s,o),this._placementDiagnosticTransport=new F(e,n,r,s),this._loggingUrl=ke(e?.loggingUrl,e?.integrationDomain,bt),this._errorReportingService=t}log(e){e&&this._send(this._transport,e)}logPlacementDiagnostic(e){e&&this._send(this._placementDiagnosticTransport,e)}_send(e,t){e.send(this._loggingUrl,P.INFO,t.message,t.code,void 0,n=>{if(this._errorReportingService){const r=typeof n.statusCode=="number";this._errorReportingService.report({message:"LoggingService: Failed to send log: "+n.message,code:Q.LOG_DELIVERY_FAILURE,severity:r?P.ERROR:P.WARNING})}})}}function Nt(i){const e=z(window.location.href),t=i.EventAttributes?.title||document.title,n=Ye(),r=i.ActiveTimeOnSite;return{pageUrl:e,sourceMessageId:i.SourceMessageId,timestamp:i.Timestamp,...t?{pageTitle:t}:{},...n!==void 0?{canonicalUrl:n}:{},...Number.isFinite(r)?{activeTimeOnSite:r}:{}}}const _=class _{constructor(){this.name=d,this.id=K,this.moduleId=K,this.isInitialized=!1,this.launcher=null,this.filters={},this.userAttributes={},this.userIdentifiedInWorkspace=!1,this.testHelpers=null,this.placementEventMappingLookup={},this.placementEventAttributeMappingLookup={},this.integrationName=null,this.errorReportingService=null,this.loggingService=null,this._thankYouElementOnLoadCallback=null,this._isThankYouElementLoaded=!1,this._workspaceSearchInFlightPromise=null,this._launcherAttachState=nt(),this.accountId=null,this._preselectState=Ze()}getEventAttributeValue(e,t){const n=e&&e.EventAttributes;return!n||n[t]===void 0?null:n[t]}doesEventAttributeConditionMatch(e,t){if(!e||!g(e.operator))return!1;const n=e.operator.toLowerCase(),r=e.attributeValue;return n==="exists"?t!==null:t==null?!1:n==="equals"?String(t)===String(r):n==="contains"?String(t).indexOf(String(r))!==-1:!1}doesEventMatchRule(e,t){if(!t||!g(t.eventAttributeKey))return!1;const n=t.conditions;if(!Array.isArray(n))return!1;const r=this.getEventAttributeValue(e,t.eventAttributeKey);if(n.length===0)return r!==null;for(let s=0;s<n.length;s++)if(!this.doesEventAttributeConditionMatch(n[s],r))return!1;return!0}applyPlacementEventAttributeMapping(e){const t=Object.keys(this.placementEventAttributeMappingLookup);for(let n=0;n<t.length;n++){const r=t[n],s=this.placementEventAttributeMappingLookup[r];if(S(s))continue;let o=!0;for(let c=0;c<s.length;c++)if(!this.doesEventMatchRule(e,s[c])){o=!1;break}o&&a().Rokt.setLocalSessionAttribute?.(r,!0)}}capturePageView(e){let t;try{t=z(window.location.href);const n=te(),r=Nt(e);n.push(r);const s=Math.min(n.length,Ie),o=De(n);if(o===0){const c=H()?"quota":"ls_unavailable";this.loggingService?.log({message:`Rokt Kit: Failed to persist page view for ${t} [reason: ${c}]`,code:"PAGE_VIEW_CAPTURE_FAILED"})}else o<s&&this.loggingService?.log({message:`Rokt Kit: Page view storage reduced from ${s} to ${o} record(s) under quota pressure [reason: quota_eviction]`,code:"PAGE_VIEW_QUOTA_EVICTION"})}catch(n){const r=H()?"exception":"ls_unavailable",s=n instanceof Error?n.message:String(n);this.loggingService?.log({message:`Rokt Kit: Failed to capture page view for ${t}: ${s} [reason: ${r}]`,code:"PAGE_VIEW_CAPTURE_FAILED"})}}isPreselectionEnabled(){return this.launcher?.enablePreselection===!0}buildCacheMatchKeys(e){if(!this.isPreselectionEnabled())return;const t=Qe(this.accountId,e);if(t)return t.attributeKeys}buildPreselectHost(){return{accountId:this.accountId,filteredUser:this.filters.filteredUser,userAttributes:this.userAttributes,isKitReady:()=>this.isKitReady(),isPreselectionEnabled:()=>this.isPreselectionEnabled(),getEventAttributeValue:(e,t)=>this.getEventAttributeValue(e,t),logPlacementDiagnostic:e=>this.loggingService?.logPlacementDiagnostic(e),log:e=>this.loggingService?.log(e),selectPlacements:e=>this.selectPlacements(e)}}flushPendingPreselectDispatches(){it(this._preselectState,this.buildPreselectHost())}isLauncherReadyToAttach(){return!!window.Rokt&&U(window.Rokt.createLauncher)}returnUserIdentities(e){if(!e||!e.getUserIdentities)return{};const t=e.getUserIdentities().userIdentities;return this.replaceOtherIdentityWithEmailsha256(t)}returnLocalSessionAttributes(){return!a().Rokt||typeof a().Rokt.getLocalSessionAttributes!="function"?{}:a().Rokt.getLocalSessionAttributes()}replaceOtherIdentityWithEmailsha256(e){const t={...e||{}},n=this._mappedEmailSha256Key;return n&&e[n]&&(t[_.EMAIL_SHA256_KEY]=e[n]),n&&delete t[n],t}logSelectPlacementsEvent(e){if(!window.mParticle||typeof a().logEvent!="function"||!m(e))return;const t=a().EventType.Other;a().logEvent(ut,t,e)}setRoktSessionId(e){if(!(!e||typeof e!="string"))try{const t=a().getInstance();t&&U(t.setIntegrationAttribute)&&t.setIntegrationAttribute(K,{roktSessionId:e})}catch{}}readMpSessionId(){const e=a()?.sessionManager,t=e?.getSessionId??e?.getSession;if(U(t))return t.call(e)||void 0}readMpDeviceId(){return a()?.getDeviceId?.()||void 0}attachLauncher(e,t,n=[]){rt(this._launcherAttachState,{accountId:e,launcherOptions:t||{},legacyRoktExtensions:n});const r={accountId:e,...t||{}};let s;return this.isPartnerInLocalLauncherTestGroup()?s=Promise.resolve(window.Rokt.createLocalLauncher(r)):s=window.Rokt.createLauncher(r),s.then(async o=>{await vt([...n],o),this.initRoktLauncher(o)}).catch(o=>{const c=this._launcherAttachState.lifecycle==="attached";if(ct(this._launcherAttachState),!c){const u=o instanceof Error?o.message:String(o);this.loggingService?.log({message:`Rokt Kit: Failed to attach Rokt launcher: ${u}`,code:"LAUNCHER_ATTACH_FAILED"})}console.error("Error creating Rokt launcher:",o)})}recreateLauncherIfTerminated(){return lt(this._launcherAttachState,this.isLauncherReadyToAttach(),e=>this.attachLauncher(e.accountId,e.launcherOptions,e.legacyRoktExtensions))}initRoktLauncher(e){window.Rokt&&(window.Rokt.currentLauncher=e),this.launcher=e,st(this._launcherAttachState);const t=a().Rokt?.filters;t?(this.filters=t,t.filteredUser?this._workspaceSearchInFlightPromise=this.search(t.filteredUser):console.warn("Rokt Kit: No filtered user has been set.")):console.warn("Rokt Kit: No filters have been set."),this.isInitialized=!0,ge(this.domain,this.integrationName),a().Rokt.attachKit(this),this.flushPendingPreselectDispatches()}fetchOptimizely(){const e=a()._getActiveForwarders().filter(t=>t.name==="Optimizely");try{if(e.length>0&&window.optimizely){const t=window.optimizely.get("state");return!t||!t.getActiveExperimentIds?{}:t.getActiveExperimentIds().reduce((s,o)=>(s["rokt.custom.optimizely.experiment."+o+".variationId"]=t.getVariationMap()[o].id,s),{})}}catch(t){console.error("Error fetching Optimizely attributes:",t)}return{}}isKitReady(){return!!(this.isInitialized&&this.launcher)}isTargetingDisabled(){return a().Rokt?.launcherOptions?.noTargeting===!0}isPartnerInLocalLauncherTestGroup(){return!!(a().config&&a().config.isLocalLauncherEnabled&&this.isAssignedToSampleGroup())}isAssignedToSampleGroup(){return Math.random()>.5}captureTiming(e){window&&a()&&a().captureTiming&&e&&a().captureTiming(e)}init(e,t,n,r,s){const o=e,c=o.accountId;this.accountId=c||null,this.userAttributes=y(s),this._onboardingExpProvider=o.onboardingExpProvider;const u=C(o.placementEventMapping);this.placementEventMappingLookup=ue(u);const l=C(o.placementEventAttributeMapping);this.placementEventAttributeMappingLookup=de(l),o.hashedEmailUserIdentityType&&(this._mappedEmailSha256Key=o.hashedEmailUserIdentityType.toLowerCase()),this._workspaceIdSyncApiKey=g(o.workspaceIdSyncApiKey)?o.workspaceIdSyncApiKey:void 0;const f=a().Rokt?.domain,{roktExtensionsQueryParams:k,legacyRoktExtensions:v,loadThankYouElement:N}=le(o.roktExtensions),E={...a().Rokt?.launcherOptions||{}};this.integrationName=wt(E.integrationName),E.integrationName=this.integrationName,this.domain=f;const w={loggingUrl:o.loggingUrl,errorUrl:o.errorUrl,integrationDomain:f,isLoggingEnabled:a().config?.isLoggingEnabled===!0},I=new fe(w,this.integrationName,window.__rokt_li_guid__,o.accountId),T=new pe(w,I,this.integrationName,window.__rokt_li_guid__,o.accountId);if(this.errorReportingService=I,this.loggingService=T,this.isTargetingDisabled())try{ie(),ne()}catch(p){this.errorReportingService?.report({message:"Rokt Kit: Failed to clear page views when targeting is disabled",code:"PAGE_VIEW_CAPTURE_FAILED",severity:P.INFO,stackTrace:p instanceof Error?p.stack:void 0})}return a()._registerErrorReportingService&&a()._registerErrorReportingService(I),a()._registerLoggingService&&a()._registerLoggingService(T),n?(this.testHelpers={generateLauncherScript:oe,generateThankYouElementScript:ce,extractRoktExtensionConfig:le,hashEventMessage:he,parseSettingsString:C,generateMappedEventLookup:ue,generateMappedEventAttributeLookup:de,sendAdBlockMeasurementSignals:ge,createAutoRemovedIframe:W,djb2:Ee,setAllowedOriginHashes:p=>{_._allowedOriginHashes=p},ReportingTransport:F,ErrorReportingService:fe,LoggingService:pe,RateLimiter:ve,ErrorCodes:Q,WSDKErrorSeverity:P,resetLauncherAttachState:()=>at(this._launcherAttachState)},this.attachLauncher(c,E),"Successfully initialized: "+d):(N&&(a().Rokt.flushOnShoppableAdsReadyMessageQueue?.(this),ae(pt,ce(f),{onLoad:()=>{this._isThankYouElementLoaded=!0,this._thankYouElementOnLoadCallback&&this._thankYouElementOnLoadCallback()},onError:p=>{console.error("Error loading Rokt Thank You Element script:",p)}})),this.isLauncherReadyToAttach()?this.attachLauncher(c,E,v):(ae(ft,oe(f,k),{onLoad:()=>{this.isLauncherReadyToAttach()?this.attachLauncher(c,E,v):console.error("Rokt object is not available after script load.")},onError:p=>{console.error("Error loading Rokt launcher script:",p)}}),this.captureTiming(_.PERFORMANCE_MARKS.RoktScriptAppended)),"Successfully initialized: "+d)}process(e){if(this.isTargetingDisabled()||(e.EventDataType===Et&&(Fe(this.loggingService),this.capturePageView(e),Re(this._preselectState,this.buildPreselectHost(),e)),e.EventDataType===_t&&(ie(),ne(),this.accountId&&L(this.accountId))),!this.isKitReady())return"Kit not ready for forwarder: "+d;if(U(a().Rokt?.setLocalSessionAttribute)&&(S(this.placementEventAttributeMappingLookup)||this.applyPlacementEventAttributeMapping(e),!S(this.placementEventMappingLookup))){const t=he(e.EventDataType,e.EventCategory,e.EventName??"");this.placementEventMappingLookup[String(t)]&&a().Rokt.setLocalSessionAttribute?.(this.placementEventMappingLookup[String(t)],!0)}return"Successfully sent to forwarder: "+d}setExtensionData(e){if(!this.isKitReady()){console.error("Rokt Kit: Not initialized");return}window.Rokt.setExtensionData(e)}setUserAttribute(e,t){return me(e)||(this.userAttributes[e]=t),Xe(this.accountId,e)&&this.flushPendingPreselectDispatches(),"Successfully set user attribute for forwarder: "+d}removeUserAttribute(e){return delete this.userAttributes[e],"Successfully removed user attribute for forwarder: "+d}handleIdentityComplete(e,t){return this.userAttributes=y(e.getAllUserAttributes()),"Successfully called "+t+" for forwarder: "+d}onUserIdentified(e){const t=e;this.filters.filteredUser=t,this._workspaceSearchInFlightPromise=this.search(t);const n=this.handleIdentityComplete(e,"onUserIdentified");return this.flushPendingPreselectDispatches(),n}search(e){const t=this._workspaceIdSyncApiKey;if(!t)return this.userIdentifiedInWorkspace=!1,this._workspaceLastSearchedIdentitiesKey=void 0,Promise.resolve();const n=a().Identity?.search;if(typeof n!="function")return this.userIdentifiedInWorkspace=!1,this._workspaceLastSearchedIdentitiesKey=void 0,Promise.resolve();const r=e.getUserIdentities?e.getUserIdentities().userIdentities:null,s={};if(r)for(const u of Object.keys(r)){const l=r[u];g(l)&&l.length>0&&(s[u]=l)}const o=Object.keys(s);if(o.length===0)return this.userIdentifiedInWorkspace=!1,this._workspaceLastSearchedIdentitiesKey=void 0,Promise.resolve();const c=o.sort().map(u=>`${u}=${s[u]}`).join("&");return c===this._workspaceLastSearchedIdentitiesKey?this._workspaceSearchInFlightPromise||Promise.resolve():(this.userIdentifiedInWorkspace=!1,this._workspaceLastSearchedIdentitiesKey=c,new Promise(u=>{try{n(t,s,l=>{l?.httpCode===200&&(this.userIdentifiedInWorkspace=!0),u()})}catch(l){console.error("Rokt Kit: Workspace IDSync search failed",l),this._workspaceLastSearchedIdentitiesKey=void 0,u()}}))}onLoginComplete(e,t){return this.handleIdentityComplete(e,"onLoginComplete")}onLogoutComplete(e,t){return this.userIdentifiedInWorkspace=!1,this._workspaceSearchInFlightPromise=null,this._workspaceLastSearchedIdentitiesKey=void 0,this.accountId&&L(this.accountId),this.handleIdentityComplete(e,"onLogoutComplete")}onModifyComplete(e,t){return this.handleIdentityComplete(e,"onModifyComplete")}selectPlacements(e){const t=this.recreateLauncherIfTerminated();if(t){const n=this._workspaceSearchInFlightPromise,r=n?Promise.race([n,new Promise(s=>setTimeout(s,se))]):Promise.resolve();return Promise.all([t,r]).then(()=>this._dispatchPlacements(e))}if(this._workspaceSearchInFlightPromise){const n=this._workspaceSearchInFlightPromise;return Promise.race([n,new Promise(r=>setTimeout(r,se))]).then(()=>this._dispatchPlacements(e))}return this._dispatchPlacements(e)}_dispatchPlacements(e){const t=e&&e.attributes||{},r={...y(this.userAttributes),...t},s=this.filters||{},o=s.userAttributeFilters||[],c=s.filteredUser||null,u=c?c.getMPID():null;let l;s?s.filterUserAttributes?l=s.filterUserAttributes(r,o):l=r:(console.warn("Rokt Kit: No filters available, using user attributes"),l=r),this.userAttributes=y(l);const f=this._onboardingExpProvider==="Optimizely"?this.fetchOptimizely():{},k=this.returnUserIdentities(c),v=this.returnLocalSessionAttributes(),N=Me(te()),E=xe(),w=this.readMpSessionId(),I=this.readMpDeviceId(),T={...k,...l,...f,...v,...N.length?{[It]:JSON.stringify(N)}:{},...E?{[yt]:E}:{},...this.userIdentifiedInWorkspace?{[mt]:!0}:{},...w?{[St]:w}:{},...I?{[At]:I}:{},mpid:u},p=this.buildCacheMatchKeys(typeof e.identifier=="string"?e.identifier:void 0),we={...e,attributes:T,...p!==void 0?{cacheMatchKeys:p}:{}},X=this.launcher.selectPlacements(we),Z=e.preselect===!0,Te=()=>{Z||this.logSelectPlacementsEvent(T)};return Promise.resolve(X).then(Le=>{if(!Z)return Le?.context?.sessionId?.then(Oe=>this.setRoktSessionId(Oe))}).catch(()=>{}).finally(Te),X}hashAttributes(e){return this.isKitReady()?this.launcher.hashAttributes(e):(console.error("Rokt Kit: Not initialized"),null)}use(e){return this.isKitReady()?!e||!g(e)?Promise.reject(new Error("Rokt Kit: Invalid extension name")):this.launcher.use(e):(console.error("Rokt Kit: Not initialized"),Promise.reject(new Error("Rokt Kit: Not initialized")))}terminate(){return this.isKitReady()?(ot(this._launcherAttachState),this.launcher.terminate()):(console.error("Rokt Kit: Not initialized"),Promise.resolve())}onShoppableAdsReady(e){this._isThankYouElementLoaded?e():this._thankYouElementOnLoadCallback=e}};_._allowedOriginHashes=[-553112570,549508659],_.PERFORMANCE_MARKS={RoktScriptAppended:"mp:RoktScriptAppended"},_.EMAIL_SHA256_KEY="emailsha256";let b=_;function Ut(){return K}function Kt(i){if(!i){window.console.log("You must pass a config object to register the kit "+d);return}if(!m(i)){window.console.log("'config' must be an object. You passed in a "+typeof i);return}m(i.kits)?i.kits[d]={constructor:b}:(i.kits={},i.kits[d]={constructor:b}),window.console.log("Successfully registered "+d+" to your mParticle configuration")}typeof window<"u"&&window.mParticle&&a().addForwarder&&a().addForwarder({name:d,constructor:b,getId:Ut});exports.register=Kt;
|
|
2
2
|
//# sourceMappingURL=Rokt-Kit.common.js.map
|
package/dist/Rokt-Kit.esm.js
CHANGED
|
@@ -44,7 +44,7 @@ function g(i) {
|
|
|
44
44
|
function U(i) {
|
|
45
45
|
return typeof i == "function";
|
|
46
46
|
}
|
|
47
|
-
function
|
|
47
|
+
function A(i) {
|
|
48
48
|
return i == null ? !0 : typeof i == "string" ? i.length === 0 : typeof i == "object" ? Object.keys(i).length === 0 : !1;
|
|
49
49
|
}
|
|
50
50
|
function z(i) {
|
|
@@ -237,6 +237,20 @@ const J = [
|
|
|
237
237
|
optionalAttributeKeys: [
|
|
238
238
|
"email"
|
|
239
239
|
]
|
|
240
|
+
},
|
|
241
|
+
{
|
|
242
|
+
accountId: "2074245483568304147",
|
|
243
|
+
pathname: "/checkout/cart",
|
|
244
|
+
targetPageIdentifier: "new_confirmation",
|
|
245
|
+
attributeKeys: [
|
|
246
|
+
"email",
|
|
247
|
+
"firstname",
|
|
248
|
+
"lastname"
|
|
249
|
+
],
|
|
250
|
+
optionalAttributeKeys: [
|
|
251
|
+
"firstname",
|
|
252
|
+
"lastname"
|
|
253
|
+
]
|
|
240
254
|
}
|
|
241
255
|
], Ge = 6e4;
|
|
242
256
|
function je(i) {
|
|
@@ -286,7 +300,7 @@ function Je(i, e, t, n, r) {
|
|
|
286
300
|
function L(i) {
|
|
287
301
|
Y(h, B(i), M);
|
|
288
302
|
}
|
|
289
|
-
function
|
|
303
|
+
function S(i, e) {
|
|
290
304
|
const t = {
|
|
291
305
|
fired: "PRESELECT_FIRED",
|
|
292
306
|
missed: "PRESELECT_MISSED",
|
|
@@ -306,7 +320,7 @@ function Be(i, e) {
|
|
|
306
320
|
(r, s) => r === "*" ? n[s] !== "" : r === n[s]
|
|
307
321
|
);
|
|
308
322
|
}
|
|
309
|
-
function
|
|
323
|
+
function Ae(i, e) {
|
|
310
324
|
if (i)
|
|
311
325
|
return J.find(
|
|
312
326
|
(t) => t.accountId === i && Be(t.pathname, e)
|
|
@@ -339,19 +353,19 @@ function V(i) {
|
|
|
339
353
|
return g(n) && n.length > 0;
|
|
340
354
|
}) : !1;
|
|
341
355
|
}
|
|
342
|
-
function
|
|
356
|
+
function Se(i) {
|
|
343
357
|
const e = i?.getMPID?.();
|
|
344
358
|
return e == null ? null : String(e);
|
|
345
359
|
}
|
|
346
360
|
function Pe(i, e) {
|
|
347
361
|
const t = new Set((i.optionalAttributeKeys ?? []).map((n) => n.toLowerCase()));
|
|
348
|
-
return i.attributeKeys.filter((n) => !t.has(n.toLowerCase()) &&
|
|
362
|
+
return i.attributeKeys.filter((n) => !t.has(n.toLowerCase()) && A(e[n]));
|
|
349
363
|
}
|
|
350
364
|
function re(i, e, t) {
|
|
351
365
|
const n = i.filteredUser?.getAllUserAttributes?.() || {}, r = {};
|
|
352
366
|
for (const s of t.attributeKeys) {
|
|
353
|
-
const o = i.getEventAttributeValue(e, s), c =
|
|
354
|
-
|
|
367
|
+
const o = i.getEventAttributeValue(e, s), c = A(o) ? i.userAttributes[s] ?? n[s] : o;
|
|
368
|
+
A(c) || (r[s] = c);
|
|
355
369
|
}
|
|
356
370
|
return {
|
|
357
371
|
collected: r,
|
|
@@ -370,10 +384,10 @@ function et(i, e) {
|
|
|
370
384
|
function be(i, e, t, n, r, s) {
|
|
371
385
|
const o = He(e, t), c = Ve(o), u = !!c && JSON.stringify(c.attributes) === JSON.stringify(r);
|
|
372
386
|
if (c && c.expiresAt > Date.now() && u) {
|
|
373
|
-
i.logPlacementDiagnostic(
|
|
387
|
+
i.logPlacementDiagnostic(S("skipped", "active_preselection"));
|
|
374
388
|
return;
|
|
375
389
|
}
|
|
376
|
-
We(o, r), i.logPlacementDiagnostic(
|
|
390
|
+
We(o, r), i.logPlacementDiagnostic(S("fired", s)), et(i, { attributes: r, preselect: !0, identifier: n, omitUrl: !0 });
|
|
377
391
|
}
|
|
378
392
|
function tt(i, e) {
|
|
379
393
|
if (!e.accountId || !e.isKitReady())
|
|
@@ -389,25 +403,25 @@ function tt(i, e) {
|
|
|
389
403
|
L(e.accountId);
|
|
390
404
|
return;
|
|
391
405
|
}
|
|
392
|
-
if (!V(e.filteredUser) || (L(e.accountId),
|
|
406
|
+
if (!V(e.filteredUser) || (L(e.accountId), Se(e.filteredUser) !== t.mpid))
|
|
393
407
|
return;
|
|
394
|
-
const n =
|
|
408
|
+
const n = Ae(e.accountId, t.pathname);
|
|
395
409
|
if (!n || n.targetPageIdentifier !== t.identifier)
|
|
396
410
|
return;
|
|
397
411
|
const r = y(t.attributes), s = Pe(n, r);
|
|
398
412
|
if (s.length > 0) {
|
|
399
413
|
for (const o of s)
|
|
400
|
-
e.logPlacementDiagnostic(
|
|
414
|
+
e.logPlacementDiagnostic(S("missed", `missing_persisted_attribute:${o}`));
|
|
401
415
|
return;
|
|
402
416
|
}
|
|
403
417
|
be(e, e.accountId, t.identifier, t.identifier, r, "recovered");
|
|
404
418
|
}
|
|
405
419
|
function Re(i, e, t, n = window.location.pathname) {
|
|
406
|
-
const r =
|
|
420
|
+
const r = Ae(e.accountId, n);
|
|
407
421
|
if (!r)
|
|
408
422
|
return;
|
|
409
423
|
if (!e.isKitReady()) {
|
|
410
|
-
const c = [], u =
|
|
424
|
+
const c = [], u = Se(e.filteredUser);
|
|
411
425
|
if (e.accountId && u && V(e.filteredUser)) {
|
|
412
426
|
const { collected: l, missingKeys: f } = re(e, t, r);
|
|
413
427
|
if (f.length === 0) {
|
|
@@ -418,7 +432,7 @@ function Re(i, e, t, n = window.location.pathname) {
|
|
|
418
432
|
r.targetPageIdentifier,
|
|
419
433
|
k,
|
|
420
434
|
u
|
|
421
|
-
) || c.push(
|
|
435
|
+
) || c.push(S("queued", "persist_failed"));
|
|
422
436
|
}
|
|
423
437
|
}
|
|
424
438
|
j(i, { event: t, pathname: n, storedDiagnostics: c });
|
|
@@ -427,13 +441,13 @@ function Re(i, e, t, n = window.location.pathname) {
|
|
|
427
441
|
if (!e.isPreselectionEnabled())
|
|
428
442
|
return;
|
|
429
443
|
if (!V(e.filteredUser)) {
|
|
430
|
-
e.logPlacementDiagnostic(
|
|
444
|
+
e.logPlacementDiagnostic(S("missed", "no_valid_identity")), j(i, { event: t, pathname: n });
|
|
431
445
|
return;
|
|
432
446
|
}
|
|
433
447
|
const { collected: s, missingKeys: o } = re(e, t, r);
|
|
434
448
|
if (o.length > 0) {
|
|
435
449
|
for (const c of o)
|
|
436
|
-
e.logPlacementDiagnostic(
|
|
450
|
+
e.logPlacementDiagnostic(S("missed", `missing_attribute:${c}`));
|
|
437
451
|
j(i, { event: t, pathname: n });
|
|
438
452
|
return;
|
|
439
453
|
}
|
|
@@ -484,7 +498,7 @@ function lt(i, e, t) {
|
|
|
484
498
|
i.recreateInFlight = null;
|
|
485
499
|
}), i.recreateInFlight;
|
|
486
500
|
}
|
|
487
|
-
const d = "Rokt", K = 181, ut = "selectPlacements", dt = "apps.roktecommerce.com", ht = 0.1, gt = "ThankYouPageJourney", ft = "rokt-launcher", pt = "rokt-thank-you-element", mt = "userIdentifiedInWorkspace", Et = 3, _t = 2, It = "page_events", yt = "page_view_attributes",
|
|
501
|
+
const d = "Rokt", K = 181, ut = "selectPlacements", dt = "apps.roktecommerce.com", ht = 0.1, gt = "ThankYouPageJourney", ft = "rokt-launcher", pt = "rokt-thank-you-element", mt = "userIdentifiedInWorkspace", Et = 3, _t = 2, It = "page_events", yt = "page_view_attributes", At = "mparticle_session_id", St = "mparticle_device_id", se = 500, Q = {
|
|
488
502
|
UNKNOWN_ERROR: "UNKNOWN_ERROR",
|
|
489
503
|
UNHANDLED_EXCEPTION: "UNHANDLED_EXCEPTION",
|
|
490
504
|
IDENTITY_REQUEST: "IDENTITY_REQUEST",
|
|
@@ -579,7 +593,7 @@ function he(i, e, t) {
|
|
|
579
593
|
return a().generateHash([i, e, t].join(""));
|
|
580
594
|
}
|
|
581
595
|
function wt(i) {
|
|
582
|
-
let n = "mParticle_wsdkv_" + a().getVersion() + "_kitv_" + "3.
|
|
596
|
+
let n = "mParticle_wsdkv_" + a().getVersion() + "_kitv_" + "3.8.0";
|
|
583
597
|
return i && (n += "_" + i), n;
|
|
584
598
|
}
|
|
585
599
|
function W(i) {
|
|
@@ -753,7 +767,7 @@ const _ = class _ {
|
|
|
753
767
|
const t = Object.keys(this.placementEventAttributeMappingLookup);
|
|
754
768
|
for (let n = 0; n < t.length; n++) {
|
|
755
769
|
const r = t[n], s = this.placementEventAttributeMappingLookup[r];
|
|
756
|
-
if (
|
|
770
|
+
if (A(s))
|
|
757
771
|
continue;
|
|
758
772
|
let o = !0;
|
|
759
773
|
for (let c = 0; c < s.length; c++)
|
|
@@ -1011,7 +1025,7 @@ const _ = class _ {
|
|
|
1011
1025
|
process(e) {
|
|
1012
1026
|
if (this.isTargetingDisabled() || (e.EventDataType === Et && (Fe(this.loggingService), this.capturePageView(e), Re(this._preselectState, this.buildPreselectHost(), e)), e.EventDataType === _t && (ie(), ne(), this.accountId && L(this.accountId))), !this.isKitReady())
|
|
1013
1027
|
return "Kit not ready for forwarder: " + d;
|
|
1014
|
-
if (U(a().Rokt?.setLocalSessionAttribute) && (
|
|
1028
|
+
if (U(a().Rokt?.setLocalSessionAttribute) && (A(this.placementEventAttributeMappingLookup) || this.applyPlacementEventAttributeMapping(e), !A(this.placementEventMappingLookup))) {
|
|
1015
1029
|
const t = he(e.EventDataType, e.EventCategory, e.EventName ?? "");
|
|
1016
1030
|
this.placementEventMappingLookup[String(t)] && a().Rokt.setLocalSessionAttribute?.(this.placementEventMappingLookup[String(t)], !0);
|
|
1017
1031
|
}
|
|
@@ -1131,8 +1145,8 @@ const _ = class _ {
|
|
|
1131
1145
|
...N.length ? { [It]: JSON.stringify(N) } : {},
|
|
1132
1146
|
...E ? { [yt]: E } : {},
|
|
1133
1147
|
...this.userIdentifiedInWorkspace ? { [mt]: !0 } : {},
|
|
1134
|
-
...w ? { [
|
|
1135
|
-
...I ? { [
|
|
1148
|
+
...w ? { [At]: w } : {},
|
|
1149
|
+
...I ? { [St]: I } : {},
|
|
1136
1150
|
mpid: u
|
|
1137
1151
|
}, p = this.buildCacheMatchKeys(typeof e.identifier == "string" ? e.identifier : void 0), we = {
|
|
1138
1152
|
...e,
|
package/dist/Rokt-Kit.iife.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var RoktKit=(function(j){"use strict";const Te=["active_time_on_site_ms","billingaddress1","billingaddress2","billingcity","billingstate","billingzipcode","cartitems","ccbin","confirmationref","conversiontype","country","couponcode","currency","language","paymentserviceprovider","paymentserviceproviderattribute","paymenttype","shippingaddress1","shippingcity","shippingcountry","shippingmethod","shippingstate","shippingzipcode","totalprice"],Le=new Set(Te);function Z(i){return Le.has(i.toLowerCase())}function I(i){const e={},t=i||{},n=Object.keys(t);for(let r=0;r<n.length;r++){const s=n[r];Z(s)||(e[s]=t[s])}return e}function f(i){return typeof i=="object"&&i!==null&&!Array.isArray(i)}function g(i){return typeof i=="string"}function N(i){return typeof i=="function"}function y(i){return i==null?!0:typeof i=="string"?i.length===0:typeof i=="object"?Object.keys(i).length===0:!1}function H(i){try{const e=new URL(i);return e.search="",e.toString()}catch{return i}}function ee(i){let e=5381;for(let t=0;t<i.length;t++)e=(e<<5)+e+i.charCodeAt(t),e=e&e;return e}const d="mp-rokt-kit",te="__rokt_ls_probe__";function V(){try{return window.localStorage.setItem(te,"1"),window.localStorage.removeItem(te),!0}catch{return!1}}const S=()=>window.localStorage;function W(i,e=S){try{const t=e().getItem(i);return t===null?null:JSON.parse(t)}catch{return null}}function ie(i,e,t=S){try{return t().setItem(i,JSON.stringify(e)),!0}catch{return!1}}function Oe(i,e=S){try{e().removeItem(i)}catch{}}function k(i,e,t=S){const n=W(i,t);return f(n)?n[e]:void 0}function U(i,e,t,n=S){const r=W(i,n),s=f(r)?{...r}:{};return s[e]=t,ie(i,s,n)}function K(i,e,t=S){const n=W(i,t);if(!f(n)||!(e in n))return;const r={...n};delete r[e],Object.keys(r).length===0?Oe(i,t):ie(i,r,t)}const z="pageViews",C="utmParams",ne=25,Ne=["utm_source","utm_medium","utm_campaign","utm_term","utm_content"];function re(i){return i.slice(-ne)}function se(){const i=k(d,z);return Array.isArray(i)?i:[]}function Ue(i){const e=re(i);for(let t=0;t<e.length;t++){const n=e.slice(t);if(U(d,z,n))return n.length}return 0}function oe(){K(d,z)}function Ke(i){const e=re(i);return e.map((t,n)=>{const r=t.activeTimeOnSite,s=r!==void 0&&Number.isFinite(r),c=e[n+1]?.activeTimeOnSite,u=c!==void 0&&Number.isFinite(c),l=s&&u?c-r:void 0;return{pageUrl:t.pageUrl,sourceMessageId:t.sourceMessageId,timestamp:t.timestamp,...t.pageTitle!==void 0?{pageTitle:t.pageTitle}:{},...t.canonicalUrl!==void 0?{canonicalUrl:t.canonicalUrl}:{},...s?{activeTimeOnSite:r}:{},...l!==void 0&&l>=0?{activeTimeOnPage:l}:{}}})}function Ce(i){if(k(d,C)!==void 0)return;const e=new URLSearchParams(window.location.search),t={};for(const r of Ne){const s=e.get(r);s&&(t[r]=s)}if(Object.keys(t).length===0)return;const n=Object.keys(t).join(", ");if(!U(d,C,t)){const r=V()?"quota":"ls_unavailable";i?.log({message:`Rokt Kit: Failed to persist UTM params [reason: ${r}]`,code:"UTM_CAPTURE_FAILED"});return}i?.log({message:`Rokt Kit: Captured UTM params [${n}]`,code:"UTM_CAPTURE_SUCCESS"})}function De(){const i=k(d,C);return f(i)?i:null}function ce(){K(d,C)}function Me(){const e=document.querySelector('link[rel="canonical"]')?.href;if(e)return H(e)}const $=[{accountId:"2919171670744024290",pathname:"/checkout",targetPageIdentifier:"prod.rokt.conf",attributeKeys:["email","customertype","eventvenue","firstname","lastname","member_status","billingzipcode","currency"],optionalAttributeKeys:["firstname","lastname"]},{accountId:"2550745407543340151",pathname:"/checkout",targetPageIdentifier:"RoktExperience",attributeKeys:["email","firstname","lastname","customertype","loyaltytier","paymenttype","ccbin"],optionalAttributeKeys:["loyaltytier","paymenttype","ccbin"]},{accountId:"3236704179315511296",pathname:"/check-out/pay",targetPageIdentifier:"confirmation_page",attributeKeys:["email","firstname","lastname","loyaltytier"],optionalAttributeKeys:["firstname","lastname","loyaltytier"]},{accountId:"2192288523645376337",pathname:"/checkout/*/review",targetPageIdentifier:"ppx-ad-view-prod",attributeKeys:["email","firstname","lastname"],optionalAttributeKeys:["email"]}],Fe=6e4;function xe(i){return f(i)&&typeof i.expiresAt=="number"&&f(i.attributes)}function Ye(i,e){return`activePreselect:${i}:${e}`}function Ge(i){const e=k(d,i);return xe(e)?e:null}function je(i,e){U(d,i,{expiresAt:Date.now()+Fe,attributes:e})}const He=5*6e4;function D(){return window.sessionStorage}function Ve(i){return f(i)&&typeof i.expiresAt=="number"&&g(i.pathname)&&g(i.identifier)&&f(i.attributes)&&g(i.mpid)}function q(i){return`pendingPreselect:${i}`}function We(i){const e=q(i),t=k(d,e,D);return Ve(t)?t.expiresAt<=Date.now()?(K(d,e,D),null):t:null}function ze(i,e,t,n,r){return U(d,q(i),{expiresAt:Date.now()+He,pathname:e,identifier:t,attributes:n,mpid:r},D)}function v(i){K(d,q(i),D)}function A(i,e){const t={fired:"PRESELECT_FIRED",missed:"PRESELECT_MISSED",queued:"PRESELECT_QUEUED",skipped:"PRESELECT_SKIPPED"};return{message:`Rokt Kit: preselect ${i} [reason=${e}]`,code:t[i]}}function $e(i,e){if(!i.includes("*"))return i===e;const t=i.split("/"),n=e.split("/");return t.length!==n.length?!1:t.every((r,s)=>r==="*"?n[s]!=="":r===n[s])}function ae(i,e){if(i)return $.find(t=>t.accountId===i&&$e(t.pathname,e))}function qe(i,e){if(!(!i||!g(e)))return $.find(t=>t.accountId===i&&t.targetPageIdentifier===e)}function Je(i,e){return i?$.some(t=>t.accountId===i&&t.attributeKeys.includes(e)):!1}function Be(){return{pending:[]}}function J(i,e){const t=i.pending.findIndex(n=>n.pathname===e.pathname);if(t>=0){i.pending[t]=e;return}i.pending.push(e)}function B(i){if(!i?.getUserIdentities)return!1;const e=i.getUserIdentities().userIdentities;return e?Object.keys(e).some(t=>{const n=e[t];return g(n)&&n.length>0}):!1}function le(i){const e=i?.getMPID?.();return e==null?null:String(e)}function ue(i,e){const t=new Set((i.optionalAttributeKeys??[]).map(n=>n.toLowerCase()));return i.attributeKeys.filter(n=>!t.has(n.toLowerCase())&&y(e[n]))}function de(i,e,t){const n=i.filteredUser?.getAllUserAttributes?.()||{},r={};for(const s of t.attributeKeys){const o=i.getEventAttributeValue(e,s),c=y(o)?i.userAttributes[s]??n[s]:o;y(c)||(r[s]=c)}return{collected:r,missingKeys:ue(t,r)}}function Qe(i,e){Promise.resolve(i.selectPlacements(e)).catch(t=>{const n=t instanceof Error?t.message:String(t);i.log({message:`Rokt Kit: Preselect selectPlacements call failed: ${n}`,code:"PRESELECT_DISPATCH_FAILED"})})}function he(i,e,t,n,r,s){const o=Ye(e,t),c=Ge(o),u=!!c&&JSON.stringify(c.attributes)===JSON.stringify(r);if(c&&c.expiresAt>Date.now()&&u){i.logPlacementDiagnostic(A("skipped","active_preselection"));return}je(o,r),i.logPlacementDiagnostic(A("fired",s)),Qe(i,{attributes:r,preselect:!0,identifier:n,omitUrl:!0})}function Xe(i,e){if(!e.accountId||!e.isKitReady())return;const t=We(e.accountId);if(!t)return;if(i.pending.some(o=>o.pathname===t.pathname)){v(e.accountId);return}if(!e.isPreselectionEnabled()){v(e.accountId);return}if(!B(e.filteredUser)||(v(e.accountId),le(e.filteredUser)!==t.mpid))return;const n=ae(e.accountId,t.pathname);if(!n||n.targetPageIdentifier!==t.identifier)return;const r=I(t.attributes),s=ue(n,r);if(s.length>0){for(const o of s)e.logPlacementDiagnostic(A("missed",`missing_persisted_attribute:${o}`));return}he(e,e.accountId,t.identifier,t.identifier,r,"recovered")}function ge(i,e,t,n=window.location.pathname){const r=ae(e.accountId,n);if(!r)return;if(!e.isKitReady()){const c=[],u=le(e.filteredUser);if(e.accountId&&u&&B(e.filteredUser)){const{collected:l,missingKeys:p}=de(e,t,r);if(p.length===0){const w=I(l);ze(e.accountId,n,r.targetPageIdentifier,w,u)||c.push(A("queued","persist_failed"))}}J(i,{event:t,pathname:n,storedDiagnostics:c});return}if(!e.isPreselectionEnabled())return;if(!B(e.filteredUser)){e.logPlacementDiagnostic(A("missed","no_valid_identity")),J(i,{event:t,pathname:n});return}const{collected:s,missingKeys:o}=de(e,t,r);if(o.length>0){for(const c of o)e.logPlacementDiagnostic(A("missed",`missing_attribute:${c}`));J(i,{event:t,pathname:n});return}he(e,e.accountId||"",n,r.targetPageIdentifier,s,"fired")}function Ze(i,e,t=window.location.pathname){if(Xe(i,e),i.pending.length===0)return;const n=i.pending;i.pending=[],n.forEach(({event:r,pathname:s,storedDiagnostics:o})=>{s===t&&(e.isKitReady()&&e.isPreselectionEnabled()&&o?.forEach(c=>e.logPlacementDiagnostic(c)),ge(i,e,r,s))})}function et(){return{context:null,lifecycle:"idle",recreateInFlight:null}}function tt(i,e){i.context={accountId:e.accountId,launcherOptions:{...e.launcherOptions},legacyRoktExtensions:[...e.legacyRoktExtensions]}}function it(i){i.lifecycle="attached"}function nt(i){i.lifecycle!=="idle"&&(i.lifecycle="terminated")}function rt(i){i.lifecycle="terminated"}function st(i){i.context=null,i.lifecycle="idle",i.recreateInFlight=null}function ot(i,e,t){if(i.recreateInFlight)return i.recreateInFlight;if(i.lifecycle!=="terminated"||!i.context||!e)return;i.lifecycle="recreating";const n=i.context;return i.recreateInFlight=t(n).finally(()=>{i.recreateInFlight=null}),i.recreateInFlight}const h="Rokt",M=181,ct="selectPlacements",at="apps.roktecommerce.com",lt=.1,ut="ThankYouPageJourney",dt="rokt-launcher",ht="rokt-thank-you-element",gt="userIdentifiedInWorkspace",ft=3,pt=2,mt="page_events",Et="page_view_attributes",_t="mparticle_session_id",It="mparticle_device_id",fe=500,Q={UNKNOWN_ERROR:"UNKNOWN_ERROR",UNHANDLED_EXCEPTION:"UNHANDLED_EXCEPTION",IDENTITY_REQUEST:"IDENTITY_REQUEST",LOG_DELIVERY_FAILURE:"LOG_DELIVERY_FAILURE"},P={ERROR:"ERROR",INFO:"INFO",WARNING:"WARNING"},yt="apps.rokt-api.com",St="/v1/log",At="/v1/errors",Pt=10;function a(){return window.mParticle}function pe(i,e){const n=[F(i),"/wsdk/integrations/launcher.js"].join("");return!e||e.length===0?n:n+"?extensions="+e.join(",")}function me(i){return[F(i),"/rokt-elements/rokt-element-thank-you.js"].join("")}function F(i){const e=i!==void 0?i:yt;return e.includes("://")?e.replace(/\/+$/,""):["https://",e].join("")}function Ee(i,e,t){if(i)return i.startsWith("http://")||i.startsWith("https://")?i:"https://"+i;const r=e?.includes("://")&&!/^https?:\/\//i.test(e)?void 0:e;return F(r)+t}function _e(i,e,t){if(document.getElementById(i))return;const n=document.head||document.body,r=document.createElement("script");r.id=i,r.type="text/javascript",r.src=e,r.async=!0,r.crossOrigin="anonymous",r.fetchPriority="high",t?.onLoad&&(r.onload=t.onLoad),t?.onError&&(r.onerror=t.onError),n.appendChild(r)}function x(i){if(!i)return[];try{return JSON.parse(i.replace(/"/g,'"'))}catch{console.error("Settings string contains invalid JSON")}return[]}function Ie(i){const e=i?x(i):[],t=[],n=[];let r=!1;for(let s=0;s<e.length;s++){const o=e[s].value;o==="thank-you-journey"?(r=!0,n.push(ut)):t.push(o)}return{roktExtensionsQueryParams:t,legacyRoktExtensions:n,loadThankYouElement:r}}async function bt(i,e){const t=[];if(e)for(const n of i)t.push(e.use(n));return Promise.all(t)}function ye(i){if(!i)return{};const e={};for(let t=0;t<i.length;t++){const n=i[t];e[n.jsmap]=n.value}return e}function Se(i){const e={};if(!Array.isArray(i))return e;for(let t=0;t<i.length;t++){const n=i[t];if(!n||!g(n.value)||!g(n.map))continue;const r=n.value,s=n.map;e[r]||(e[r]=[]),e[r].push({eventAttributeKey:s,conditions:Array.isArray(n.conditions)?n.conditions:[]})}return e}function Ae(i,e,t){return a().generateHash([i,e,t].join(""))}function Rt(i){let n="mParticle_wsdkv_"+a().getVersion()+"_kitv_"+"3.7.0";return i&&(n+="_"+i),n}function X(i){const e=document.createElement("iframe");e.style.display="none",e.setAttribute("sandbox","allow-scripts allow-same-origin"),e.src=i,e.onload=function(){e.onload=null,e.parentNode&&e.parentNode.removeChild(e)};const t=document.body||document.head;t&&t.appendChild(e)}function Pe(i,e){const t=ee(window.location.origin);if(b._allowedOriginHashes.indexOf(t)===-1||Math.random()>=lt)return;const r=window.__rokt_li_guid__;if(!r||i&&i.includes("://")&&!/^https:\/\//i.test(i))return;const s=window.location.href.split("?")[0].split("#")[0],o="version="+encodeURIComponent(e??"")+"&launcherInstanceGuid="+encodeURIComponent(r)+"&pageUrl="+encodeURIComponent(s),c=i?F(i):"https://apps.rokt.com";X(c+"/v1/wsdk-init/index.html?"+o),X("https://"+at+"/v1/wsdk-init/index.html?"+o+"&isControl=true")}function kt(){return typeof window<"u"&&!!window.location?.search?.toLowerCase().includes("mp_enable_logging=true")}function vt(){return typeof window<"u"?window.location?.href:void 0}function wt(){return typeof window<"u"?window.navigator?.userAgent:void 0}class be{constructor(){this._logCount={}}incrementAndCheck(e){const n=(this._logCount[e]||0)+1;return this._logCount[e]=n,n>Pt}}class Y{constructor(e,t,n,r,s){this._reporter="mp-wsdk";const o=e.isLoggingEnabled;this._integrationName=t||"",this._launcherInstanceGuid=n,this._accountId=r||null,this._rateLimiter=s||new be,this._isEnabled=kt()||o}send(e,t,n,r,s,o){if(!(!this._isEnabled||this._rateLimiter.incrementAndCheck(t)))try{const c={additionalInformation:{message:n,version:this._integrationName},severity:t,code:r||Q.UNKNOWN_ERROR,url:vt(),deviceInfo:wt(),stackTrace:s,reporter:this._reporter,integration:this._integrationName},u={Accept:"text/plain;charset=UTF-8","Content-Type":"application/json","rokt-launcher-version":this._integrationName,"rokt-wsdk-version":"joint"};this._launcherInstanceGuid&&(u["rokt-launcher-instance-guid"]=this._launcherInstanceGuid),this._accountId&&(u["rokt-account-id"]=this._accountId),fetch(e,{method:"POST",headers:u,body:JSON.stringify(c)}).then(l=>{if(!l.ok){const p=new Error("HTTP "+l.status+" from log endpoint");throw p.statusCode=l.status,p}}).catch(l=>{console.error("ReportingTransport: Failed to send log",l),o&&o(l)})}catch(c){console.error("ReportingTransport: Failed to send log",c),o&&o(c)}}}class Re{constructor(e,t,n,r,s){this._transport=new Y(e,t,n,r,s),this._errorUrl=Ee(e?.errorUrl,e?.integrationDomain,At)}report(e){if(!e)return;const t=e.severity||P.ERROR;this._transport.send(this._errorUrl,t,e.message,e.code,e.stackTrace)}}class ke{constructor(e,t,n,r,s,o){this._transport=new Y(e,n,r,s,o),this._placementDiagnosticTransport=new Y(e,n,r,s),this._loggingUrl=Ee(e?.loggingUrl,e?.integrationDomain,St),this._errorReportingService=t}log(e){e&&this._send(this._transport,e)}logPlacementDiagnostic(e){e&&this._send(this._placementDiagnosticTransport,e)}_send(e,t){e.send(this._loggingUrl,P.INFO,t.message,t.code,void 0,n=>{if(this._errorReportingService){const r=typeof n.statusCode=="number";this._errorReportingService.report({message:"LoggingService: Failed to send log: "+n.message,code:Q.LOG_DELIVERY_FAILURE,severity:r?P.ERROR:P.WARNING})}})}}function Tt(i){const e=H(window.location.href),t=i.EventAttributes?.title||document.title,n=Me(),r=i.ActiveTimeOnSite;return{pageUrl:e,sourceMessageId:i.SourceMessageId,timestamp:i.Timestamp,...t?{pageTitle:t}:{},...n!==void 0?{canonicalUrl:n}:{},...Number.isFinite(r)?{activeTimeOnSite:r}:{}}}const E=class E{constructor(){this.name=h,this.id=M,this.moduleId=M,this.isInitialized=!1,this.launcher=null,this.filters={},this.userAttributes={},this.userIdentifiedInWorkspace=!1,this.testHelpers=null,this.placementEventMappingLookup={},this.placementEventAttributeMappingLookup={},this.integrationName=null,this.errorReportingService=null,this.loggingService=null,this._thankYouElementOnLoadCallback=null,this._isThankYouElementLoaded=!1,this._workspaceSearchInFlightPromise=null,this._launcherAttachState=et(),this.accountId=null,this._preselectState=Be()}getEventAttributeValue(e,t){const n=e&&e.EventAttributes;return!n||n[t]===void 0?null:n[t]}doesEventAttributeConditionMatch(e,t){if(!e||!g(e.operator))return!1;const n=e.operator.toLowerCase(),r=e.attributeValue;return n==="exists"?t!==null:t==null?!1:n==="equals"?String(t)===String(r):n==="contains"?String(t).indexOf(String(r))!==-1:!1}doesEventMatchRule(e,t){if(!t||!g(t.eventAttributeKey))return!1;const n=t.conditions;if(!Array.isArray(n))return!1;const r=this.getEventAttributeValue(e,t.eventAttributeKey);if(n.length===0)return r!==null;for(let s=0;s<n.length;s++)if(!this.doesEventAttributeConditionMatch(n[s],r))return!1;return!0}applyPlacementEventAttributeMapping(e){const t=Object.keys(this.placementEventAttributeMappingLookup);for(let n=0;n<t.length;n++){const r=t[n],s=this.placementEventAttributeMappingLookup[r];if(y(s))continue;let o=!0;for(let c=0;c<s.length;c++)if(!this.doesEventMatchRule(e,s[c])){o=!1;break}o&&a().Rokt.setLocalSessionAttribute?.(r,!0)}}capturePageView(e){let t;try{t=H(window.location.href);const n=se(),r=Tt(e);n.push(r);const s=Math.min(n.length,ne),o=Ue(n);if(o===0){const c=V()?"quota":"ls_unavailable";this.loggingService?.log({message:`Rokt Kit: Failed to persist page view for ${t} [reason: ${c}]`,code:"PAGE_VIEW_CAPTURE_FAILED"})}else o<s&&this.loggingService?.log({message:`Rokt Kit: Page view storage reduced from ${s} to ${o} record(s) under quota pressure [reason: quota_eviction]`,code:"PAGE_VIEW_QUOTA_EVICTION"})}catch(n){const r=V()?"exception":"ls_unavailable",s=n instanceof Error?n.message:String(n);this.loggingService?.log({message:`Rokt Kit: Failed to capture page view for ${t}: ${s} [reason: ${r}]`,code:"PAGE_VIEW_CAPTURE_FAILED"})}}isPreselectionEnabled(){return this.launcher?.enablePreselection===!0}buildCacheMatchKeys(e){if(!this.isPreselectionEnabled())return;const t=qe(this.accountId,e);if(t)return t.attributeKeys}buildPreselectHost(){return{accountId:this.accountId,filteredUser:this.filters.filteredUser,userAttributes:this.userAttributes,isKitReady:()=>this.isKitReady(),isPreselectionEnabled:()=>this.isPreselectionEnabled(),getEventAttributeValue:(e,t)=>this.getEventAttributeValue(e,t),logPlacementDiagnostic:e=>this.loggingService?.logPlacementDiagnostic(e),log:e=>this.loggingService?.log(e),selectPlacements:e=>this.selectPlacements(e)}}flushPendingPreselectDispatches(){Ze(this._preselectState,this.buildPreselectHost())}isLauncherReadyToAttach(){return!!window.Rokt&&N(window.Rokt.createLauncher)}returnUserIdentities(e){if(!e||!e.getUserIdentities)return{};const t=e.getUserIdentities().userIdentities;return this.replaceOtherIdentityWithEmailsha256(t)}returnLocalSessionAttributes(){return!a().Rokt||typeof a().Rokt.getLocalSessionAttributes!="function"?{}:a().Rokt.getLocalSessionAttributes()}replaceOtherIdentityWithEmailsha256(e){const t={...e||{}},n=this._mappedEmailSha256Key;return n&&e[n]&&(t[E.EMAIL_SHA256_KEY]=e[n]),n&&delete t[n],t}logSelectPlacementsEvent(e){if(!window.mParticle||typeof a().logEvent!="function"||!f(e))return;const t=a().EventType.Other;a().logEvent(ct,t,e)}setRoktSessionId(e){if(!(!e||typeof e!="string"))try{const t=a().getInstance();t&&N(t.setIntegrationAttribute)&&t.setIntegrationAttribute(M,{roktSessionId:e})}catch{}}readMpSessionId(){const e=a()?.sessionManager,t=e?.getSessionId??e?.getSession;if(N(t))return t.call(e)||void 0}readMpDeviceId(){return a()?.getDeviceId?.()||void 0}attachLauncher(e,t,n=[]){tt(this._launcherAttachState,{accountId:e,launcherOptions:t||{},legacyRoktExtensions:n});const r={accountId:e,...t||{}};let s;return this.isPartnerInLocalLauncherTestGroup()?s=Promise.resolve(window.Rokt.createLocalLauncher(r)):s=window.Rokt.createLauncher(r),s.then(async o=>{await bt([...n],o),this.initRoktLauncher(o)}).catch(o=>{const c=this._launcherAttachState.lifecycle==="attached";if(rt(this._launcherAttachState),!c){const u=o instanceof Error?o.message:String(o);this.loggingService?.log({message:`Rokt Kit: Failed to attach Rokt launcher: ${u}`,code:"LAUNCHER_ATTACH_FAILED"})}console.error("Error creating Rokt launcher:",o)})}recreateLauncherIfTerminated(){return ot(this._launcherAttachState,this.isLauncherReadyToAttach(),e=>this.attachLauncher(e.accountId,e.launcherOptions,e.legacyRoktExtensions))}initRoktLauncher(e){window.Rokt&&(window.Rokt.currentLauncher=e),this.launcher=e,it(this._launcherAttachState);const t=a().Rokt?.filters;t?(this.filters=t,t.filteredUser?this._workspaceSearchInFlightPromise=this.search(t.filteredUser):console.warn("Rokt Kit: No filtered user has been set.")):console.warn("Rokt Kit: No filters have been set."),this.isInitialized=!0,Pe(this.domain,this.integrationName),a().Rokt.attachKit(this),this.flushPendingPreselectDispatches()}fetchOptimizely(){const e=a()._getActiveForwarders().filter(t=>t.name==="Optimizely");try{if(e.length>0&&window.optimizely){const t=window.optimizely.get("state");return!t||!t.getActiveExperimentIds?{}:t.getActiveExperimentIds().reduce((s,o)=>(s["rokt.custom.optimizely.experiment."+o+".variationId"]=t.getVariationMap()[o].id,s),{})}}catch(t){console.error("Error fetching Optimizely attributes:",t)}return{}}isKitReady(){return!!(this.isInitialized&&this.launcher)}isTargetingDisabled(){return a().Rokt?.launcherOptions?.noTargeting===!0}isPartnerInLocalLauncherTestGroup(){return!!(a().config&&a().config.isLocalLauncherEnabled&&this.isAssignedToSampleGroup())}isAssignedToSampleGroup(){return Math.random()>.5}captureTiming(e){window&&a()&&a().captureTiming&&e&&a().captureTiming(e)}init(e,t,n,r,s){const o=e,c=o.accountId;this.accountId=c||null,this.userAttributes=I(s),this._onboardingExpProvider=o.onboardingExpProvider;const u=x(o.placementEventMapping);this.placementEventMappingLookup=ye(u);const l=x(o.placementEventAttributeMapping);this.placementEventAttributeMappingLookup=Se(l),o.hashedEmailUserIdentityType&&(this._mappedEmailSha256Key=o.hashedEmailUserIdentityType.toLowerCase()),this._workspaceIdSyncApiKey=g(o.workspaceIdSyncApiKey)?o.workspaceIdSyncApiKey:void 0;const p=a().Rokt?.domain,{roktExtensionsQueryParams:w,legacyRoktExtensions:T,loadThankYouElement:G}=Ie(o.roktExtensions),_={...a().Rokt?.launcherOptions||{}};this.integrationName=Rt(_.integrationName),_.integrationName=this.integrationName,this.domain=p;const L={loggingUrl:o.loggingUrl,errorUrl:o.errorUrl,integrationDomain:p,isLoggingEnabled:a().config?.isLoggingEnabled===!0},R=new Re(L,this.integrationName,window.__rokt_li_guid__,o.accountId),O=new ke(L,R,this.integrationName,window.__rokt_li_guid__,o.accountId);if(this.errorReportingService=R,this.loggingService=O,this.isTargetingDisabled())try{oe(),ce()}catch(m){this.errorReportingService?.report({message:"Rokt Kit: Failed to clear page views when targeting is disabled",code:"PAGE_VIEW_CAPTURE_FAILED",severity:P.INFO,stackTrace:m instanceof Error?m.stack:void 0})}return a()._registerErrorReportingService&&a()._registerErrorReportingService(R),a()._registerLoggingService&&a()._registerLoggingService(O),n?(this.testHelpers={generateLauncherScript:pe,generateThankYouElementScript:me,extractRoktExtensionConfig:Ie,hashEventMessage:Ae,parseSettingsString:x,generateMappedEventLookup:ye,generateMappedEventAttributeLookup:Se,sendAdBlockMeasurementSignals:Pe,createAutoRemovedIframe:X,djb2:ee,setAllowedOriginHashes:m=>{E._allowedOriginHashes=m},ReportingTransport:Y,ErrorReportingService:Re,LoggingService:ke,RateLimiter:be,ErrorCodes:Q,WSDKErrorSeverity:P,resetLauncherAttachState:()=>st(this._launcherAttachState)},this.attachLauncher(c,_),"Successfully initialized: "+h):(G&&(a().Rokt.flushOnShoppableAdsReadyMessageQueue?.(this),_e(ht,me(p),{onLoad:()=>{this._isThankYouElementLoaded=!0,this._thankYouElementOnLoadCallback&&this._thankYouElementOnLoadCallback()},onError:m=>{console.error("Error loading Rokt Thank You Element script:",m)}})),this.isLauncherReadyToAttach()?this.attachLauncher(c,_,T):(_e(dt,pe(p,w),{onLoad:()=>{this.isLauncherReadyToAttach()?this.attachLauncher(c,_,T):console.error("Rokt object is not available after script load.")},onError:m=>{console.error("Error loading Rokt launcher script:",m)}}),this.captureTiming(E.PERFORMANCE_MARKS.RoktScriptAppended)),"Successfully initialized: "+h)}process(e){if(this.isTargetingDisabled()||(e.EventDataType===ft&&(Ce(this.loggingService),this.capturePageView(e),ge(this._preselectState,this.buildPreselectHost(),e)),e.EventDataType===pt&&(oe(),ce(),this.accountId&&v(this.accountId))),!this.isKitReady())return"Kit not ready for forwarder: "+h;if(N(a().Rokt?.setLocalSessionAttribute)&&(y(this.placementEventAttributeMappingLookup)||this.applyPlacementEventAttributeMapping(e),!y(this.placementEventMappingLookup))){const t=Ae(e.EventDataType,e.EventCategory,e.EventName??"");this.placementEventMappingLookup[String(t)]&&a().Rokt.setLocalSessionAttribute?.(this.placementEventMappingLookup[String(t)],!0)}return"Successfully sent to forwarder: "+h}setExtensionData(e){if(!this.isKitReady()){console.error("Rokt Kit: Not initialized");return}window.Rokt.setExtensionData(e)}setUserAttribute(e,t){return Z(e)||(this.userAttributes[e]=t),Je(this.accountId,e)&&this.flushPendingPreselectDispatches(),"Successfully set user attribute for forwarder: "+h}removeUserAttribute(e){return delete this.userAttributes[e],"Successfully removed user attribute for forwarder: "+h}handleIdentityComplete(e,t){return this.userAttributes=I(e.getAllUserAttributes()),"Successfully called "+t+" for forwarder: "+h}onUserIdentified(e){const t=e;this.filters.filteredUser=t,this._workspaceSearchInFlightPromise=this.search(t);const n=this.handleIdentityComplete(e,"onUserIdentified");return this.flushPendingPreselectDispatches(),n}search(e){const t=this._workspaceIdSyncApiKey;if(!t)return this.userIdentifiedInWorkspace=!1,this._workspaceLastSearchedIdentitiesKey=void 0,Promise.resolve();const n=a().Identity?.search;if(typeof n!="function")return this.userIdentifiedInWorkspace=!1,this._workspaceLastSearchedIdentitiesKey=void 0,Promise.resolve();const r=e.getUserIdentities?e.getUserIdentities().userIdentities:null,s={};if(r)for(const u of Object.keys(r)){const l=r[u];g(l)&&l.length>0&&(s[u]=l)}const o=Object.keys(s);if(o.length===0)return this.userIdentifiedInWorkspace=!1,this._workspaceLastSearchedIdentitiesKey=void 0,Promise.resolve();const c=o.sort().map(u=>`${u}=${s[u]}`).join("&");return c===this._workspaceLastSearchedIdentitiesKey?this._workspaceSearchInFlightPromise||Promise.resolve():(this.userIdentifiedInWorkspace=!1,this._workspaceLastSearchedIdentitiesKey=c,new Promise(u=>{try{n(t,s,l=>{l?.httpCode===200&&(this.userIdentifiedInWorkspace=!0),u()})}catch(l){console.error("Rokt Kit: Workspace IDSync search failed",l),this._workspaceLastSearchedIdentitiesKey=void 0,u()}}))}onLoginComplete(e,t){return this.handleIdentityComplete(e,"onLoginComplete")}onLogoutComplete(e,t){return this.userIdentifiedInWorkspace=!1,this._workspaceSearchInFlightPromise=null,this._workspaceLastSearchedIdentitiesKey=void 0,this.accountId&&v(this.accountId),this.handleIdentityComplete(e,"onLogoutComplete")}onModifyComplete(e,t){return this.handleIdentityComplete(e,"onModifyComplete")}selectPlacements(e){const t=this.recreateLauncherIfTerminated();if(t){const n=this._workspaceSearchInFlightPromise,r=n?Promise.race([n,new Promise(s=>setTimeout(s,fe))]):Promise.resolve();return Promise.all([t,r]).then(()=>this._dispatchPlacements(e))}if(this._workspaceSearchInFlightPromise){const n=this._workspaceSearchInFlightPromise;return Promise.race([n,new Promise(r=>setTimeout(r,fe))]).then(()=>this._dispatchPlacements(e))}return this._dispatchPlacements(e)}_dispatchPlacements(e){const t=e&&e.attributes||{},r={...I(this.userAttributes),...t},s=this.filters||{},o=s.userAttributeFilters||[],c=s.filteredUser||null,u=c?c.getMPID():null;let l;s?s.filterUserAttributes?l=s.filterUserAttributes(r,o):l=r:(console.warn("Rokt Kit: No filters available, using user attributes"),l=r),this.userAttributes=I(l);const p=this._onboardingExpProvider==="Optimizely"?this.fetchOptimizely():{},w=this.returnUserIdentities(c),T=this.returnLocalSessionAttributes(),G=Ke(se()),_=De(),L=this.readMpSessionId(),R=this.readMpDeviceId(),O={...w,...l,...p,...T,...G.length?{[mt]:JSON.stringify(G)}:{},..._?{[Et]:_}:{},...this.userIdentifiedInWorkspace?{[gt]:!0}:{},...L?{[_t]:L}:{},...R?{[It]:R}:{},mpid:u},m=this.buildCacheMatchKeys(typeof e.identifier=="string"?e.identifier:void 0),Nt={...e,attributes:O,...m!==void 0?{cacheMatchKeys:m}:{}},ve=this.launcher.selectPlacements(Nt),we=e.preselect===!0,Ut=()=>{we||this.logSelectPlacementsEvent(O)};return Promise.resolve(ve).then(Kt=>{if(!we)return Kt?.context?.sessionId?.then(Ct=>this.setRoktSessionId(Ct))}).catch(()=>{}).finally(Ut),ve}hashAttributes(e){return this.isKitReady()?this.launcher.hashAttributes(e):(console.error("Rokt Kit: Not initialized"),null)}use(e){return this.isKitReady()?!e||!g(e)?Promise.reject(new Error("Rokt Kit: Invalid extension name")):this.launcher.use(e):(console.error("Rokt Kit: Not initialized"),Promise.reject(new Error("Rokt Kit: Not initialized")))}terminate(){return this.isKitReady()?(nt(this._launcherAttachState),this.launcher.terminate()):(console.error("Rokt Kit: Not initialized"),Promise.resolve())}onShoppableAdsReady(e){this._isThankYouElementLoaded?e():this._thankYouElementOnLoadCallback=e}};E._allowedOriginHashes=[-553112570,549508659],E.PERFORMANCE_MARKS={RoktScriptAppended:"mp:RoktScriptAppended"},E.EMAIL_SHA256_KEY="emailsha256";let b=E;function Lt(){return M}function Ot(i){if(!i){window.console.log("You must pass a config object to register the kit "+h);return}if(!f(i)){window.console.log("'config' must be an object. You passed in a "+typeof i);return}f(i.kits)?i.kits[h]={constructor:b}:(i.kits={},i.kits[h]={constructor:b}),window.console.log("Successfully registered "+h+" to your mParticle configuration")}return typeof window<"u"&&window.mParticle&&a().addForwarder&&a().addForwarder({name:h,constructor:b,getId:Lt}),j.register=Ot,Object.defineProperty(j,Symbol.toStringTag,{value:"Module"}),j})({});
|
|
1
|
+
var RoktKit=(function(j){"use strict";const Te=["active_time_on_site_ms","billingaddress1","billingaddress2","billingcity","billingstate","billingzipcode","cartitems","ccbin","confirmationref","conversiontype","country","couponcode","currency","language","paymentserviceprovider","paymentserviceproviderattribute","paymenttype","shippingaddress1","shippingcity","shippingcountry","shippingmethod","shippingstate","shippingzipcode","totalprice"],Le=new Set(Te);function Z(i){return Le.has(i.toLowerCase())}function I(i){const e={},t=i||{},n=Object.keys(t);for(let r=0;r<n.length;r++){const s=n[r];Z(s)||(e[s]=t[s])}return e}function f(i){return typeof i=="object"&&i!==null&&!Array.isArray(i)}function g(i){return typeof i=="string"}function N(i){return typeof i=="function"}function y(i){return i==null?!0:typeof i=="string"?i.length===0:typeof i=="object"?Object.keys(i).length===0:!1}function H(i){try{const e=new URL(i);return e.search="",e.toString()}catch{return i}}function ee(i){let e=5381;for(let t=0;t<i.length;t++)e=(e<<5)+e+i.charCodeAt(t),e=e&e;return e}const d="mp-rokt-kit",te="__rokt_ls_probe__";function V(){try{return window.localStorage.setItem(te,"1"),window.localStorage.removeItem(te),!0}catch{return!1}}const S=()=>window.localStorage;function W(i,e=S){try{const t=e().getItem(i);return t===null?null:JSON.parse(t)}catch{return null}}function ie(i,e,t=S){try{return t().setItem(i,JSON.stringify(e)),!0}catch{return!1}}function Oe(i,e=S){try{e().removeItem(i)}catch{}}function k(i,e,t=S){const n=W(i,t);return f(n)?n[e]:void 0}function U(i,e,t,n=S){const r=W(i,n),s=f(r)?{...r}:{};return s[e]=t,ie(i,s,n)}function K(i,e,t=S){const n=W(i,t);if(!f(n)||!(e in n))return;const r={...n};delete r[e],Object.keys(r).length===0?Oe(i,t):ie(i,r,t)}const z="pageViews",C="utmParams",ne=25,Ne=["utm_source","utm_medium","utm_campaign","utm_term","utm_content"];function re(i){return i.slice(-ne)}function se(){const i=k(d,z);return Array.isArray(i)?i:[]}function Ue(i){const e=re(i);for(let t=0;t<e.length;t++){const n=e.slice(t);if(U(d,z,n))return n.length}return 0}function oe(){K(d,z)}function Ke(i){const e=re(i);return e.map((t,n)=>{const r=t.activeTimeOnSite,s=r!==void 0&&Number.isFinite(r),c=e[n+1]?.activeTimeOnSite,u=c!==void 0&&Number.isFinite(c),l=s&&u?c-r:void 0;return{pageUrl:t.pageUrl,sourceMessageId:t.sourceMessageId,timestamp:t.timestamp,...t.pageTitle!==void 0?{pageTitle:t.pageTitle}:{},...t.canonicalUrl!==void 0?{canonicalUrl:t.canonicalUrl}:{},...s?{activeTimeOnSite:r}:{},...l!==void 0&&l>=0?{activeTimeOnPage:l}:{}}})}function Ce(i){if(k(d,C)!==void 0)return;const e=new URLSearchParams(window.location.search),t={};for(const r of Ne){const s=e.get(r);s&&(t[r]=s)}if(Object.keys(t).length===0)return;const n=Object.keys(t).join(", ");if(!U(d,C,t)){const r=V()?"quota":"ls_unavailable";i?.log({message:`Rokt Kit: Failed to persist UTM params [reason: ${r}]`,code:"UTM_CAPTURE_FAILED"});return}i?.log({message:`Rokt Kit: Captured UTM params [${n}]`,code:"UTM_CAPTURE_SUCCESS"})}function De(){const i=k(d,C);return f(i)?i:null}function ce(){K(d,C)}function Me(){const e=document.querySelector('link[rel="canonical"]')?.href;if(e)return H(e)}const $=[{accountId:"2919171670744024290",pathname:"/checkout",targetPageIdentifier:"prod.rokt.conf",attributeKeys:["email","customertype","eventvenue","firstname","lastname","member_status","billingzipcode","currency"],optionalAttributeKeys:["firstname","lastname"]},{accountId:"2550745407543340151",pathname:"/checkout",targetPageIdentifier:"RoktExperience",attributeKeys:["email","firstname","lastname","customertype","loyaltytier","paymenttype","ccbin"],optionalAttributeKeys:["loyaltytier","paymenttype","ccbin"]},{accountId:"3236704179315511296",pathname:"/check-out/pay",targetPageIdentifier:"confirmation_page",attributeKeys:["email","firstname","lastname","loyaltytier"],optionalAttributeKeys:["firstname","lastname","loyaltytier"]},{accountId:"2192288523645376337",pathname:"/checkout/*/review",targetPageIdentifier:"ppx-ad-view-prod",attributeKeys:["email","firstname","lastname"],optionalAttributeKeys:["email"]},{accountId:"2074245483568304147",pathname:"/checkout/cart",targetPageIdentifier:"new_confirmation",attributeKeys:["email","firstname","lastname"],optionalAttributeKeys:["firstname","lastname"]}],Fe=6e4;function xe(i){return f(i)&&typeof i.expiresAt=="number"&&f(i.attributes)}function Ye(i,e){return`activePreselect:${i}:${e}`}function Ge(i){const e=k(d,i);return xe(e)?e:null}function je(i,e){U(d,i,{expiresAt:Date.now()+Fe,attributes:e})}const He=5*6e4;function D(){return window.sessionStorage}function Ve(i){return f(i)&&typeof i.expiresAt=="number"&&g(i.pathname)&&g(i.identifier)&&f(i.attributes)&&g(i.mpid)}function q(i){return`pendingPreselect:${i}`}function We(i){const e=q(i),t=k(d,e,D);return Ve(t)?t.expiresAt<=Date.now()?(K(d,e,D),null):t:null}function ze(i,e,t,n,r){return U(d,q(i),{expiresAt:Date.now()+He,pathname:e,identifier:t,attributes:n,mpid:r},D)}function v(i){K(d,q(i),D)}function A(i,e){const t={fired:"PRESELECT_FIRED",missed:"PRESELECT_MISSED",queued:"PRESELECT_QUEUED",skipped:"PRESELECT_SKIPPED"};return{message:`Rokt Kit: preselect ${i} [reason=${e}]`,code:t[i]}}function $e(i,e){if(!i.includes("*"))return i===e;const t=i.split("/"),n=e.split("/");return t.length!==n.length?!1:t.every((r,s)=>r==="*"?n[s]!=="":r===n[s])}function ae(i,e){if(i)return $.find(t=>t.accountId===i&&$e(t.pathname,e))}function qe(i,e){if(!(!i||!g(e)))return $.find(t=>t.accountId===i&&t.targetPageIdentifier===e)}function Je(i,e){return i?$.some(t=>t.accountId===i&&t.attributeKeys.includes(e)):!1}function Be(){return{pending:[]}}function J(i,e){const t=i.pending.findIndex(n=>n.pathname===e.pathname);if(t>=0){i.pending[t]=e;return}i.pending.push(e)}function B(i){if(!i?.getUserIdentities)return!1;const e=i.getUserIdentities().userIdentities;return e?Object.keys(e).some(t=>{const n=e[t];return g(n)&&n.length>0}):!1}function le(i){const e=i?.getMPID?.();return e==null?null:String(e)}function ue(i,e){const t=new Set((i.optionalAttributeKeys??[]).map(n=>n.toLowerCase()));return i.attributeKeys.filter(n=>!t.has(n.toLowerCase())&&y(e[n]))}function de(i,e,t){const n=i.filteredUser?.getAllUserAttributes?.()||{},r={};for(const s of t.attributeKeys){const o=i.getEventAttributeValue(e,s),c=y(o)?i.userAttributes[s]??n[s]:o;y(c)||(r[s]=c)}return{collected:r,missingKeys:ue(t,r)}}function Qe(i,e){Promise.resolve(i.selectPlacements(e)).catch(t=>{const n=t instanceof Error?t.message:String(t);i.log({message:`Rokt Kit: Preselect selectPlacements call failed: ${n}`,code:"PRESELECT_DISPATCH_FAILED"})})}function he(i,e,t,n,r,s){const o=Ye(e,t),c=Ge(o),u=!!c&&JSON.stringify(c.attributes)===JSON.stringify(r);if(c&&c.expiresAt>Date.now()&&u){i.logPlacementDiagnostic(A("skipped","active_preselection"));return}je(o,r),i.logPlacementDiagnostic(A("fired",s)),Qe(i,{attributes:r,preselect:!0,identifier:n,omitUrl:!0})}function Xe(i,e){if(!e.accountId||!e.isKitReady())return;const t=We(e.accountId);if(!t)return;if(i.pending.some(o=>o.pathname===t.pathname)){v(e.accountId);return}if(!e.isPreselectionEnabled()){v(e.accountId);return}if(!B(e.filteredUser)||(v(e.accountId),le(e.filteredUser)!==t.mpid))return;const n=ae(e.accountId,t.pathname);if(!n||n.targetPageIdentifier!==t.identifier)return;const r=I(t.attributes),s=ue(n,r);if(s.length>0){for(const o of s)e.logPlacementDiagnostic(A("missed",`missing_persisted_attribute:${o}`));return}he(e,e.accountId,t.identifier,t.identifier,r,"recovered")}function ge(i,e,t,n=window.location.pathname){const r=ae(e.accountId,n);if(!r)return;if(!e.isKitReady()){const c=[],u=le(e.filteredUser);if(e.accountId&&u&&B(e.filteredUser)){const{collected:l,missingKeys:p}=de(e,t,r);if(p.length===0){const w=I(l);ze(e.accountId,n,r.targetPageIdentifier,w,u)||c.push(A("queued","persist_failed"))}}J(i,{event:t,pathname:n,storedDiagnostics:c});return}if(!e.isPreselectionEnabled())return;if(!B(e.filteredUser)){e.logPlacementDiagnostic(A("missed","no_valid_identity")),J(i,{event:t,pathname:n});return}const{collected:s,missingKeys:o}=de(e,t,r);if(o.length>0){for(const c of o)e.logPlacementDiagnostic(A("missed",`missing_attribute:${c}`));J(i,{event:t,pathname:n});return}he(e,e.accountId||"",n,r.targetPageIdentifier,s,"fired")}function Ze(i,e,t=window.location.pathname){if(Xe(i,e),i.pending.length===0)return;const n=i.pending;i.pending=[],n.forEach(({event:r,pathname:s,storedDiagnostics:o})=>{s===t&&(e.isKitReady()&&e.isPreselectionEnabled()&&o?.forEach(c=>e.logPlacementDiagnostic(c)),ge(i,e,r,s))})}function et(){return{context:null,lifecycle:"idle",recreateInFlight:null}}function tt(i,e){i.context={accountId:e.accountId,launcherOptions:{...e.launcherOptions},legacyRoktExtensions:[...e.legacyRoktExtensions]}}function it(i){i.lifecycle="attached"}function nt(i){i.lifecycle!=="idle"&&(i.lifecycle="terminated")}function rt(i){i.lifecycle="terminated"}function st(i){i.context=null,i.lifecycle="idle",i.recreateInFlight=null}function ot(i,e,t){if(i.recreateInFlight)return i.recreateInFlight;if(i.lifecycle!=="terminated"||!i.context||!e)return;i.lifecycle="recreating";const n=i.context;return i.recreateInFlight=t(n).finally(()=>{i.recreateInFlight=null}),i.recreateInFlight}const h="Rokt",M=181,ct="selectPlacements",at="apps.roktecommerce.com",lt=.1,ut="ThankYouPageJourney",dt="rokt-launcher",ht="rokt-thank-you-element",gt="userIdentifiedInWorkspace",ft=3,pt=2,mt="page_events",Et="page_view_attributes",_t="mparticle_session_id",It="mparticle_device_id",fe=500,Q={UNKNOWN_ERROR:"UNKNOWN_ERROR",UNHANDLED_EXCEPTION:"UNHANDLED_EXCEPTION",IDENTITY_REQUEST:"IDENTITY_REQUEST",LOG_DELIVERY_FAILURE:"LOG_DELIVERY_FAILURE"},P={ERROR:"ERROR",INFO:"INFO",WARNING:"WARNING"},yt="apps.rokt-api.com",St="/v1/log",At="/v1/errors",Pt=10;function a(){return window.mParticle}function pe(i,e){const n=[F(i),"/wsdk/integrations/launcher.js"].join("");return!e||e.length===0?n:n+"?extensions="+e.join(",")}function me(i){return[F(i),"/rokt-elements/rokt-element-thank-you.js"].join("")}function F(i){const e=i!==void 0?i:yt;return e.includes("://")?e.replace(/\/+$/,""):["https://",e].join("")}function Ee(i,e,t){if(i)return i.startsWith("http://")||i.startsWith("https://")?i:"https://"+i;const r=e?.includes("://")&&!/^https?:\/\//i.test(e)?void 0:e;return F(r)+t}function _e(i,e,t){if(document.getElementById(i))return;const n=document.head||document.body,r=document.createElement("script");r.id=i,r.type="text/javascript",r.src=e,r.async=!0,r.crossOrigin="anonymous",r.fetchPriority="high",t?.onLoad&&(r.onload=t.onLoad),t?.onError&&(r.onerror=t.onError),n.appendChild(r)}function x(i){if(!i)return[];try{return JSON.parse(i.replace(/"/g,'"'))}catch{console.error("Settings string contains invalid JSON")}return[]}function Ie(i){const e=i?x(i):[],t=[],n=[];let r=!1;for(let s=0;s<e.length;s++){const o=e[s].value;o==="thank-you-journey"?(r=!0,n.push(ut)):t.push(o)}return{roktExtensionsQueryParams:t,legacyRoktExtensions:n,loadThankYouElement:r}}async function bt(i,e){const t=[];if(e)for(const n of i)t.push(e.use(n));return Promise.all(t)}function ye(i){if(!i)return{};const e={};for(let t=0;t<i.length;t++){const n=i[t];e[n.jsmap]=n.value}return e}function Se(i){const e={};if(!Array.isArray(i))return e;for(let t=0;t<i.length;t++){const n=i[t];if(!n||!g(n.value)||!g(n.map))continue;const r=n.value,s=n.map;e[r]||(e[r]=[]),e[r].push({eventAttributeKey:s,conditions:Array.isArray(n.conditions)?n.conditions:[]})}return e}function Ae(i,e,t){return a().generateHash([i,e,t].join(""))}function Rt(i){let n="mParticle_wsdkv_"+a().getVersion()+"_kitv_"+"3.8.0";return i&&(n+="_"+i),n}function X(i){const e=document.createElement("iframe");e.style.display="none",e.setAttribute("sandbox","allow-scripts allow-same-origin"),e.src=i,e.onload=function(){e.onload=null,e.parentNode&&e.parentNode.removeChild(e)};const t=document.body||document.head;t&&t.appendChild(e)}function Pe(i,e){const t=ee(window.location.origin);if(b._allowedOriginHashes.indexOf(t)===-1||Math.random()>=lt)return;const r=window.__rokt_li_guid__;if(!r||i&&i.includes("://")&&!/^https:\/\//i.test(i))return;const s=window.location.href.split("?")[0].split("#")[0],o="version="+encodeURIComponent(e??"")+"&launcherInstanceGuid="+encodeURIComponent(r)+"&pageUrl="+encodeURIComponent(s),c=i?F(i):"https://apps.rokt.com";X(c+"/v1/wsdk-init/index.html?"+o),X("https://"+at+"/v1/wsdk-init/index.html?"+o+"&isControl=true")}function kt(){return typeof window<"u"&&!!window.location?.search?.toLowerCase().includes("mp_enable_logging=true")}function vt(){return typeof window<"u"?window.location?.href:void 0}function wt(){return typeof window<"u"?window.navigator?.userAgent:void 0}class be{constructor(){this._logCount={}}incrementAndCheck(e){const n=(this._logCount[e]||0)+1;return this._logCount[e]=n,n>Pt}}class Y{constructor(e,t,n,r,s){this._reporter="mp-wsdk";const o=e.isLoggingEnabled;this._integrationName=t||"",this._launcherInstanceGuid=n,this._accountId=r||null,this._rateLimiter=s||new be,this._isEnabled=kt()||o}send(e,t,n,r,s,o){if(!(!this._isEnabled||this._rateLimiter.incrementAndCheck(t)))try{const c={additionalInformation:{message:n,version:this._integrationName},severity:t,code:r||Q.UNKNOWN_ERROR,url:vt(),deviceInfo:wt(),stackTrace:s,reporter:this._reporter,integration:this._integrationName},u={Accept:"text/plain;charset=UTF-8","Content-Type":"application/json","rokt-launcher-version":this._integrationName,"rokt-wsdk-version":"joint"};this._launcherInstanceGuid&&(u["rokt-launcher-instance-guid"]=this._launcherInstanceGuid),this._accountId&&(u["rokt-account-id"]=this._accountId),fetch(e,{method:"POST",headers:u,body:JSON.stringify(c)}).then(l=>{if(!l.ok){const p=new Error("HTTP "+l.status+" from log endpoint");throw p.statusCode=l.status,p}}).catch(l=>{console.error("ReportingTransport: Failed to send log",l),o&&o(l)})}catch(c){console.error("ReportingTransport: Failed to send log",c),o&&o(c)}}}class Re{constructor(e,t,n,r,s){this._transport=new Y(e,t,n,r,s),this._errorUrl=Ee(e?.errorUrl,e?.integrationDomain,At)}report(e){if(!e)return;const t=e.severity||P.ERROR;this._transport.send(this._errorUrl,t,e.message,e.code,e.stackTrace)}}class ke{constructor(e,t,n,r,s,o){this._transport=new Y(e,n,r,s,o),this._placementDiagnosticTransport=new Y(e,n,r,s),this._loggingUrl=Ee(e?.loggingUrl,e?.integrationDomain,St),this._errorReportingService=t}log(e){e&&this._send(this._transport,e)}logPlacementDiagnostic(e){e&&this._send(this._placementDiagnosticTransport,e)}_send(e,t){e.send(this._loggingUrl,P.INFO,t.message,t.code,void 0,n=>{if(this._errorReportingService){const r=typeof n.statusCode=="number";this._errorReportingService.report({message:"LoggingService: Failed to send log: "+n.message,code:Q.LOG_DELIVERY_FAILURE,severity:r?P.ERROR:P.WARNING})}})}}function Tt(i){const e=H(window.location.href),t=i.EventAttributes?.title||document.title,n=Me(),r=i.ActiveTimeOnSite;return{pageUrl:e,sourceMessageId:i.SourceMessageId,timestamp:i.Timestamp,...t?{pageTitle:t}:{},...n!==void 0?{canonicalUrl:n}:{},...Number.isFinite(r)?{activeTimeOnSite:r}:{}}}const E=class E{constructor(){this.name=h,this.id=M,this.moduleId=M,this.isInitialized=!1,this.launcher=null,this.filters={},this.userAttributes={},this.userIdentifiedInWorkspace=!1,this.testHelpers=null,this.placementEventMappingLookup={},this.placementEventAttributeMappingLookup={},this.integrationName=null,this.errorReportingService=null,this.loggingService=null,this._thankYouElementOnLoadCallback=null,this._isThankYouElementLoaded=!1,this._workspaceSearchInFlightPromise=null,this._launcherAttachState=et(),this.accountId=null,this._preselectState=Be()}getEventAttributeValue(e,t){const n=e&&e.EventAttributes;return!n||n[t]===void 0?null:n[t]}doesEventAttributeConditionMatch(e,t){if(!e||!g(e.operator))return!1;const n=e.operator.toLowerCase(),r=e.attributeValue;return n==="exists"?t!==null:t==null?!1:n==="equals"?String(t)===String(r):n==="contains"?String(t).indexOf(String(r))!==-1:!1}doesEventMatchRule(e,t){if(!t||!g(t.eventAttributeKey))return!1;const n=t.conditions;if(!Array.isArray(n))return!1;const r=this.getEventAttributeValue(e,t.eventAttributeKey);if(n.length===0)return r!==null;for(let s=0;s<n.length;s++)if(!this.doesEventAttributeConditionMatch(n[s],r))return!1;return!0}applyPlacementEventAttributeMapping(e){const t=Object.keys(this.placementEventAttributeMappingLookup);for(let n=0;n<t.length;n++){const r=t[n],s=this.placementEventAttributeMappingLookup[r];if(y(s))continue;let o=!0;for(let c=0;c<s.length;c++)if(!this.doesEventMatchRule(e,s[c])){o=!1;break}o&&a().Rokt.setLocalSessionAttribute?.(r,!0)}}capturePageView(e){let t;try{t=H(window.location.href);const n=se(),r=Tt(e);n.push(r);const s=Math.min(n.length,ne),o=Ue(n);if(o===0){const c=V()?"quota":"ls_unavailable";this.loggingService?.log({message:`Rokt Kit: Failed to persist page view for ${t} [reason: ${c}]`,code:"PAGE_VIEW_CAPTURE_FAILED"})}else o<s&&this.loggingService?.log({message:`Rokt Kit: Page view storage reduced from ${s} to ${o} record(s) under quota pressure [reason: quota_eviction]`,code:"PAGE_VIEW_QUOTA_EVICTION"})}catch(n){const r=V()?"exception":"ls_unavailable",s=n instanceof Error?n.message:String(n);this.loggingService?.log({message:`Rokt Kit: Failed to capture page view for ${t}: ${s} [reason: ${r}]`,code:"PAGE_VIEW_CAPTURE_FAILED"})}}isPreselectionEnabled(){return this.launcher?.enablePreselection===!0}buildCacheMatchKeys(e){if(!this.isPreselectionEnabled())return;const t=qe(this.accountId,e);if(t)return t.attributeKeys}buildPreselectHost(){return{accountId:this.accountId,filteredUser:this.filters.filteredUser,userAttributes:this.userAttributes,isKitReady:()=>this.isKitReady(),isPreselectionEnabled:()=>this.isPreselectionEnabled(),getEventAttributeValue:(e,t)=>this.getEventAttributeValue(e,t),logPlacementDiagnostic:e=>this.loggingService?.logPlacementDiagnostic(e),log:e=>this.loggingService?.log(e),selectPlacements:e=>this.selectPlacements(e)}}flushPendingPreselectDispatches(){Ze(this._preselectState,this.buildPreselectHost())}isLauncherReadyToAttach(){return!!window.Rokt&&N(window.Rokt.createLauncher)}returnUserIdentities(e){if(!e||!e.getUserIdentities)return{};const t=e.getUserIdentities().userIdentities;return this.replaceOtherIdentityWithEmailsha256(t)}returnLocalSessionAttributes(){return!a().Rokt||typeof a().Rokt.getLocalSessionAttributes!="function"?{}:a().Rokt.getLocalSessionAttributes()}replaceOtherIdentityWithEmailsha256(e){const t={...e||{}},n=this._mappedEmailSha256Key;return n&&e[n]&&(t[E.EMAIL_SHA256_KEY]=e[n]),n&&delete t[n],t}logSelectPlacementsEvent(e){if(!window.mParticle||typeof a().logEvent!="function"||!f(e))return;const t=a().EventType.Other;a().logEvent(ct,t,e)}setRoktSessionId(e){if(!(!e||typeof e!="string"))try{const t=a().getInstance();t&&N(t.setIntegrationAttribute)&&t.setIntegrationAttribute(M,{roktSessionId:e})}catch{}}readMpSessionId(){const e=a()?.sessionManager,t=e?.getSessionId??e?.getSession;if(N(t))return t.call(e)||void 0}readMpDeviceId(){return a()?.getDeviceId?.()||void 0}attachLauncher(e,t,n=[]){tt(this._launcherAttachState,{accountId:e,launcherOptions:t||{},legacyRoktExtensions:n});const r={accountId:e,...t||{}};let s;return this.isPartnerInLocalLauncherTestGroup()?s=Promise.resolve(window.Rokt.createLocalLauncher(r)):s=window.Rokt.createLauncher(r),s.then(async o=>{await bt([...n],o),this.initRoktLauncher(o)}).catch(o=>{const c=this._launcherAttachState.lifecycle==="attached";if(rt(this._launcherAttachState),!c){const u=o instanceof Error?o.message:String(o);this.loggingService?.log({message:`Rokt Kit: Failed to attach Rokt launcher: ${u}`,code:"LAUNCHER_ATTACH_FAILED"})}console.error("Error creating Rokt launcher:",o)})}recreateLauncherIfTerminated(){return ot(this._launcherAttachState,this.isLauncherReadyToAttach(),e=>this.attachLauncher(e.accountId,e.launcherOptions,e.legacyRoktExtensions))}initRoktLauncher(e){window.Rokt&&(window.Rokt.currentLauncher=e),this.launcher=e,it(this._launcherAttachState);const t=a().Rokt?.filters;t?(this.filters=t,t.filteredUser?this._workspaceSearchInFlightPromise=this.search(t.filteredUser):console.warn("Rokt Kit: No filtered user has been set.")):console.warn("Rokt Kit: No filters have been set."),this.isInitialized=!0,Pe(this.domain,this.integrationName),a().Rokt.attachKit(this),this.flushPendingPreselectDispatches()}fetchOptimizely(){const e=a()._getActiveForwarders().filter(t=>t.name==="Optimizely");try{if(e.length>0&&window.optimizely){const t=window.optimizely.get("state");return!t||!t.getActiveExperimentIds?{}:t.getActiveExperimentIds().reduce((s,o)=>(s["rokt.custom.optimizely.experiment."+o+".variationId"]=t.getVariationMap()[o].id,s),{})}}catch(t){console.error("Error fetching Optimizely attributes:",t)}return{}}isKitReady(){return!!(this.isInitialized&&this.launcher)}isTargetingDisabled(){return a().Rokt?.launcherOptions?.noTargeting===!0}isPartnerInLocalLauncherTestGroup(){return!!(a().config&&a().config.isLocalLauncherEnabled&&this.isAssignedToSampleGroup())}isAssignedToSampleGroup(){return Math.random()>.5}captureTiming(e){window&&a()&&a().captureTiming&&e&&a().captureTiming(e)}init(e,t,n,r,s){const o=e,c=o.accountId;this.accountId=c||null,this.userAttributes=I(s),this._onboardingExpProvider=o.onboardingExpProvider;const u=x(o.placementEventMapping);this.placementEventMappingLookup=ye(u);const l=x(o.placementEventAttributeMapping);this.placementEventAttributeMappingLookup=Se(l),o.hashedEmailUserIdentityType&&(this._mappedEmailSha256Key=o.hashedEmailUserIdentityType.toLowerCase()),this._workspaceIdSyncApiKey=g(o.workspaceIdSyncApiKey)?o.workspaceIdSyncApiKey:void 0;const p=a().Rokt?.domain,{roktExtensionsQueryParams:w,legacyRoktExtensions:T,loadThankYouElement:G}=Ie(o.roktExtensions),_={...a().Rokt?.launcherOptions||{}};this.integrationName=Rt(_.integrationName),_.integrationName=this.integrationName,this.domain=p;const L={loggingUrl:o.loggingUrl,errorUrl:o.errorUrl,integrationDomain:p,isLoggingEnabled:a().config?.isLoggingEnabled===!0},R=new Re(L,this.integrationName,window.__rokt_li_guid__,o.accountId),O=new ke(L,R,this.integrationName,window.__rokt_li_guid__,o.accountId);if(this.errorReportingService=R,this.loggingService=O,this.isTargetingDisabled())try{oe(),ce()}catch(m){this.errorReportingService?.report({message:"Rokt Kit: Failed to clear page views when targeting is disabled",code:"PAGE_VIEW_CAPTURE_FAILED",severity:P.INFO,stackTrace:m instanceof Error?m.stack:void 0})}return a()._registerErrorReportingService&&a()._registerErrorReportingService(R),a()._registerLoggingService&&a()._registerLoggingService(O),n?(this.testHelpers={generateLauncherScript:pe,generateThankYouElementScript:me,extractRoktExtensionConfig:Ie,hashEventMessage:Ae,parseSettingsString:x,generateMappedEventLookup:ye,generateMappedEventAttributeLookup:Se,sendAdBlockMeasurementSignals:Pe,createAutoRemovedIframe:X,djb2:ee,setAllowedOriginHashes:m=>{E._allowedOriginHashes=m},ReportingTransport:Y,ErrorReportingService:Re,LoggingService:ke,RateLimiter:be,ErrorCodes:Q,WSDKErrorSeverity:P,resetLauncherAttachState:()=>st(this._launcherAttachState)},this.attachLauncher(c,_),"Successfully initialized: "+h):(G&&(a().Rokt.flushOnShoppableAdsReadyMessageQueue?.(this),_e(ht,me(p),{onLoad:()=>{this._isThankYouElementLoaded=!0,this._thankYouElementOnLoadCallback&&this._thankYouElementOnLoadCallback()},onError:m=>{console.error("Error loading Rokt Thank You Element script:",m)}})),this.isLauncherReadyToAttach()?this.attachLauncher(c,_,T):(_e(dt,pe(p,w),{onLoad:()=>{this.isLauncherReadyToAttach()?this.attachLauncher(c,_,T):console.error("Rokt object is not available after script load.")},onError:m=>{console.error("Error loading Rokt launcher script:",m)}}),this.captureTiming(E.PERFORMANCE_MARKS.RoktScriptAppended)),"Successfully initialized: "+h)}process(e){if(this.isTargetingDisabled()||(e.EventDataType===ft&&(Ce(this.loggingService),this.capturePageView(e),ge(this._preselectState,this.buildPreselectHost(),e)),e.EventDataType===pt&&(oe(),ce(),this.accountId&&v(this.accountId))),!this.isKitReady())return"Kit not ready for forwarder: "+h;if(N(a().Rokt?.setLocalSessionAttribute)&&(y(this.placementEventAttributeMappingLookup)||this.applyPlacementEventAttributeMapping(e),!y(this.placementEventMappingLookup))){const t=Ae(e.EventDataType,e.EventCategory,e.EventName??"");this.placementEventMappingLookup[String(t)]&&a().Rokt.setLocalSessionAttribute?.(this.placementEventMappingLookup[String(t)],!0)}return"Successfully sent to forwarder: "+h}setExtensionData(e){if(!this.isKitReady()){console.error("Rokt Kit: Not initialized");return}window.Rokt.setExtensionData(e)}setUserAttribute(e,t){return Z(e)||(this.userAttributes[e]=t),Je(this.accountId,e)&&this.flushPendingPreselectDispatches(),"Successfully set user attribute for forwarder: "+h}removeUserAttribute(e){return delete this.userAttributes[e],"Successfully removed user attribute for forwarder: "+h}handleIdentityComplete(e,t){return this.userAttributes=I(e.getAllUserAttributes()),"Successfully called "+t+" for forwarder: "+h}onUserIdentified(e){const t=e;this.filters.filteredUser=t,this._workspaceSearchInFlightPromise=this.search(t);const n=this.handleIdentityComplete(e,"onUserIdentified");return this.flushPendingPreselectDispatches(),n}search(e){const t=this._workspaceIdSyncApiKey;if(!t)return this.userIdentifiedInWorkspace=!1,this._workspaceLastSearchedIdentitiesKey=void 0,Promise.resolve();const n=a().Identity?.search;if(typeof n!="function")return this.userIdentifiedInWorkspace=!1,this._workspaceLastSearchedIdentitiesKey=void 0,Promise.resolve();const r=e.getUserIdentities?e.getUserIdentities().userIdentities:null,s={};if(r)for(const u of Object.keys(r)){const l=r[u];g(l)&&l.length>0&&(s[u]=l)}const o=Object.keys(s);if(o.length===0)return this.userIdentifiedInWorkspace=!1,this._workspaceLastSearchedIdentitiesKey=void 0,Promise.resolve();const c=o.sort().map(u=>`${u}=${s[u]}`).join("&");return c===this._workspaceLastSearchedIdentitiesKey?this._workspaceSearchInFlightPromise||Promise.resolve():(this.userIdentifiedInWorkspace=!1,this._workspaceLastSearchedIdentitiesKey=c,new Promise(u=>{try{n(t,s,l=>{l?.httpCode===200&&(this.userIdentifiedInWorkspace=!0),u()})}catch(l){console.error("Rokt Kit: Workspace IDSync search failed",l),this._workspaceLastSearchedIdentitiesKey=void 0,u()}}))}onLoginComplete(e,t){return this.handleIdentityComplete(e,"onLoginComplete")}onLogoutComplete(e,t){return this.userIdentifiedInWorkspace=!1,this._workspaceSearchInFlightPromise=null,this._workspaceLastSearchedIdentitiesKey=void 0,this.accountId&&v(this.accountId),this.handleIdentityComplete(e,"onLogoutComplete")}onModifyComplete(e,t){return this.handleIdentityComplete(e,"onModifyComplete")}selectPlacements(e){const t=this.recreateLauncherIfTerminated();if(t){const n=this._workspaceSearchInFlightPromise,r=n?Promise.race([n,new Promise(s=>setTimeout(s,fe))]):Promise.resolve();return Promise.all([t,r]).then(()=>this._dispatchPlacements(e))}if(this._workspaceSearchInFlightPromise){const n=this._workspaceSearchInFlightPromise;return Promise.race([n,new Promise(r=>setTimeout(r,fe))]).then(()=>this._dispatchPlacements(e))}return this._dispatchPlacements(e)}_dispatchPlacements(e){const t=e&&e.attributes||{},r={...I(this.userAttributes),...t},s=this.filters||{},o=s.userAttributeFilters||[],c=s.filteredUser||null,u=c?c.getMPID():null;let l;s?s.filterUserAttributes?l=s.filterUserAttributes(r,o):l=r:(console.warn("Rokt Kit: No filters available, using user attributes"),l=r),this.userAttributes=I(l);const p=this._onboardingExpProvider==="Optimizely"?this.fetchOptimizely():{},w=this.returnUserIdentities(c),T=this.returnLocalSessionAttributes(),G=Ke(se()),_=De(),L=this.readMpSessionId(),R=this.readMpDeviceId(),O={...w,...l,...p,...T,...G.length?{[mt]:JSON.stringify(G)}:{},..._?{[Et]:_}:{},...this.userIdentifiedInWorkspace?{[gt]:!0}:{},...L?{[_t]:L}:{},...R?{[It]:R}:{},mpid:u},m=this.buildCacheMatchKeys(typeof e.identifier=="string"?e.identifier:void 0),Nt={...e,attributes:O,...m!==void 0?{cacheMatchKeys:m}:{}},ve=this.launcher.selectPlacements(Nt),we=e.preselect===!0,Ut=()=>{we||this.logSelectPlacementsEvent(O)};return Promise.resolve(ve).then(Kt=>{if(!we)return Kt?.context?.sessionId?.then(Ct=>this.setRoktSessionId(Ct))}).catch(()=>{}).finally(Ut),ve}hashAttributes(e){return this.isKitReady()?this.launcher.hashAttributes(e):(console.error("Rokt Kit: Not initialized"),null)}use(e){return this.isKitReady()?!e||!g(e)?Promise.reject(new Error("Rokt Kit: Invalid extension name")):this.launcher.use(e):(console.error("Rokt Kit: Not initialized"),Promise.reject(new Error("Rokt Kit: Not initialized")))}terminate(){return this.isKitReady()?(nt(this._launcherAttachState),this.launcher.terminate()):(console.error("Rokt Kit: Not initialized"),Promise.resolve())}onShoppableAdsReady(e){this._isThankYouElementLoaded?e():this._thankYouElementOnLoadCallback=e}};E._allowedOriginHashes=[-553112570,549508659],E.PERFORMANCE_MARKS={RoktScriptAppended:"mp:RoktScriptAppended"},E.EMAIL_SHA256_KEY="emailsha256";let b=E;function Lt(){return M}function Ot(i){if(!i){window.console.log("You must pass a config object to register the kit "+h);return}if(!f(i)){window.console.log("'config' must be an object. You passed in a "+typeof i);return}f(i.kits)?i.kits[h]={constructor:b}:(i.kits={},i.kits[h]={constructor:b}),window.console.log("Successfully registered "+h+" to your mParticle configuration")}return typeof window<"u"&&window.mParticle&&a().addForwarder&&a().addForwarder({name:h,constructor:b,getId:Lt}),j.register=Ot,Object.defineProperty(j,Symbol.toStringTag,{value:"Module"}),j})({});
|
|
2
2
|
//# sourceMappingURL=Rokt-Kit.iife.js.map
|