@mparticle/web-rokt-kit 1.35.0 → 1.36.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.
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const _e=["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"],Ie=new Set(_e);function se(i){return Ie.has(i.toLowerCase())}function b(i){const e={},t=i||{},n=Object.keys(t);for(let r=0;r<n.length;r++){const s=n[r];se(s)||(e[s]=t[s])}return e}function _(i){return typeof i=="object"&&i!==null&&!Array.isArray(i)}function E(i){return typeof i=="string"}function T(i){return typeof i=="function"}function K(i){return i==null?!0:typeof i=="object"?Object.keys(i).length===0:!1}function Y(i){try{const e=new URL(i);return e.search="",e.toString()}catch{return i}}const V="__rokt_ls_probe__";function D(){try{return window.localStorage.setItem(V,"1"),window.localStorage.removeItem(V),!0}catch{return!1}}function N(i){try{const e=window.localStorage.getItem(i);return e===null?null:JSON.parse(e)}catch{return null}}function oe(i,e){try{return window.localStorage.setItem(i,JSON.stringify(e)),!0}catch{return!1}}function ae(i){try{window.localStorage.removeItem(i)}catch{}}function U(i,e){const t=N(i);return _(t)?t[e]:void 0}function G(i,e,t){const n=N(i),r=_(n)?{...n}:{};return r[e]=t,oe(i,r)}function ce(i,e){const t=N(i);if(!_(t)||!(e in t))return;const n={...t};delete n[e],Object.keys(n).length===0?ae(i):oe(i,n)}const p="mp-rokt-kit",v="pageViews",O="utmParams",H="mpPageViews",le=25,Se=["utm_source","utm_medium","utm_campaign","utm_term","utm_content"];function ue(i){return i.slice(-le)}function de(i){const e=N(H);if(e===null)return;!(U(p,v)!==void 0)&&Array.isArray(e)&&(i?.log({message:"Rokt Kit: Migrating legacy page-view storage",code:"PAGE_VIEW_LEGACY_MIGRATION"}),G(p,v,e)||i?.log({message:"Rokt Kit: Failed to migrate legacy page-view storage [reason: migration_retry]",code:"PAGE_VIEW_CAPTURE_FAILED"})),ae(H)}function z(i){de(i);const e=U(p,v);return Array.isArray(e)?e:[]}function ye(i){const e=ue(i);for(let t=0;t<e.length;t++){const n=e.slice(t);if(G(p,v,n))return n.length}return 0}function q(){ce(p,v)}function Ae(i){const e=ue(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 ke(i){if(U(p,O)!==void 0)return;const e=new URLSearchParams(window.location.search),t={};for(const r of Se){const s=e.get(r);s&&(t[r]=s)}if(Object.keys(t).length===0)return;const n=Object.keys(t).join(", ");if(!G(p,O,t)){const r=D()?"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 ve(){const i=U(p,O);return _(i)?i:null}function $(){ce(p,O)}function Re(){const e=document.querySelector('link[rel="canonical"]')?.href;if(e)return Y(e)}const d="Rokt",L=181,we="selectPlacements",be="apps.roktecommerce.com",Te=.1,Le="ThankYouPageJourney",Pe="rokt-launcher",Oe="rokt-thank-you-element",Ne="userIdentifiedInWorkspace",Ue=3,Ce=2,Me="page_events",Ke="page_view_attributes",De="mparticle_session_id",Fe="mparticle_device_id",Ye=500,x={UNKNOWN_ERROR:"UNKNOWN_ERROR",UNHANDLED_EXCEPTION:"UNHANDLED_EXCEPTION",IDENTITY_REQUEST:"IDENTITY_REQUEST",LOG_DELIVERY_FAILURE:"LOG_DELIVERY_FAILURE"},S={ERROR:"ERROR",INFO:"INFO",WARNING:"WARNING"},Ge="apps.rokt-api.com",xe="/v1/log",We="/v1/errors",je=10;function a(){return window.mParticle}function J(i,e){const n=[C(i),"/wsdk/integrations/launcher.js"].join("");return!e||e.length===0?n:n+"?extensions="+e.join(",")}function B(i){return[C(i),"/rokt-elements/rokt-element-thank-you.js"].join("")}function C(i){const e=typeof i<"u"?i:Ge;return e.includes("://")?e.replace(/\/+$/,""):["https://",e].join("")}function he(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 C(r)+t}function Q(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 P(i){if(!i)return[];try{return JSON.parse(i.replace(/&quot;/g,'"'))}catch{console.error("Settings string contains invalid JSON")}return[]}function X(i){const e=i?P(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(Le)):t.push(o)}return{roktExtensionsQueryParams:t,legacyRoktExtensions:n,loadThankYouElement:r}}async function Ve(i,e){const t=[];if(e)for(const n of i)t.push(e.use(n));return Promise.all(t)}function Z(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 ee(i){const e={};if(!Array.isArray(i))return e;for(let t=0;t<i.length;t++){const n=i[t];if(!n||!E(n.value)||!E(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 te(i,e,t){return a().generateHash([i,e,t].join(""))}function He(i){let n="mParticle_wsdkv_"+a().getVersion()+"_kitv_"+"1.35.0";return i&&(n+="_"+i),n}function ge(i){let e=5381;for(let t=0;t<i.length;t++)e=(e<<5)+e+i.charCodeAt(t),e=e&e;return e}function F(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 ie(i,e){const t=ge(window.location.origin);if(y._allowedOriginHashes.indexOf(t)===-1||Math.random()>=Te)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?C(i):"https://apps.rokt.com";F(c+"/v1/wsdk-init/index.html?"+o),F("https://"+be+"/v1/wsdk-init/index.html?"+o+"&isControl=true")}function ze(){return typeof window<"u"&&!!window.location?.search?.toLowerCase().includes("mp_enable_logging=true")}function qe(){return typeof window<"u"?window.location?.href:void 0}function $e(){return typeof window<"u"?window.navigator?.userAgent:void 0}class pe{constructor(){this._logCount={}}incrementAndCheck(e){const n=(this._logCount[e]||0)+1;return this._logCount[e]=n,n>je}}class W{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 pe,this._isEnabled=ze()||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||x.UNKNOWN_ERROR,url:qe(),deviceInfo:$e(),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 g=new Error("HTTP "+l.status+" from log endpoint");throw g.statusCode=l.status,g}}).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 ne{constructor(e,t,n,r,s){this._transport=new W(e,t,n,r,s),this._errorUrl=he(e?.errorUrl,e?.integrationDomain,We)}report(e){if(!e)return;const t=e.severity||S.ERROR;this._transport.send(this._errorUrl,t,e.message,e.code,e.stackTrace)}}class re{constructor(e,t,n,r,s,o){this._transport=new W(e,n,r,s,o),this._loggingUrl=he(e?.loggingUrl,e?.integrationDomain,xe),this._errorReportingService=t}log(e){e&&this._transport.send(this._loggingUrl,S.INFO,e.message,e.code,void 0,t=>{if(this._errorReportingService){const n=typeof t.statusCode=="number";this._errorReportingService.report({message:"LoggingService: Failed to send log: "+t.message,code:x.LOG_DELIVERY_FAILURE,severity:n?S.ERROR:S.WARNING})}})}}function Je(i){const e=Y(window.location.href),t=i.EventAttributes?.title||document.title,n=Re(),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 m=class m{constructor(){this.name=d,this.id=L,this.moduleId=L,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}getEventAttributeValue(e,t){const n=e&&e.EventAttributes;return!n||typeof n[t]>"u"?null:n[t]}doesEventAttributeConditionMatch(e,t){if(!e||!E(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||!E(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(K(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=Y(window.location.href);const n=z(this.loggingService),r=Je(e);n.push(r);const s=Math.min(n.length,le),o=ye(n);if(o===0){const c=D()?"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=D()?"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"})}}isLauncherReadyToAttach(){return!!window.Rokt&&T(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[m.EMAIL_SHA256_KEY]=e[n]),n&&delete t[n],t}logSelectPlacementsEvent(e){if(!window.mParticle||typeof a().logEvent!="function"||!_(e))return;const t=a().EventType.Other;a().logEvent(we,t,e)}setRoktSessionId(e){if(!(!e||typeof e!="string"))try{const t=a().getInstance();t&&T(t.setIntegrationAttribute)&&t.setIntegrationAttribute(L,{roktSessionId:e})}catch{}}readMpSessionId(){const e=a()?.sessionManager,t=e?.getSessionId??e?.getSession;if(T(t))return t.call(e)||void 0}readMpDeviceId(){return a()?.getDeviceId?.()||void 0}attachLauncher(e,t,n=[]){const r={accountId:e,...t||{}};let s;this.isPartnerInLocalLauncherTestGroup()?s=Promise.resolve(window.Rokt.createLocalLauncher(r)):s=window.Rokt.createLauncher(r),s.then(async o=>{await Ve(n,o),this.initRoktLauncher(o)}).catch(o=>{console.error("Error creating Rokt launcher:",o)})}initRoktLauncher(e){window.Rokt&&(window.Rokt.currentLauncher=e),this.launcher=e;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,ie(this.domain,this.integrationName),a().Rokt.attachKit(this)}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.userAttributes=b(s),this._onboardingExpProvider=o.onboardingExpProvider;const u=P(o.placementEventMapping);this.placementEventMappingLookup=Z(u);const l=P(o.placementEventAttributeMapping);this.placementEventAttributeMappingLookup=ee(l),o.hashedEmailUserIdentityType&&(this._mappedEmailSha256Key=o.hashedEmailUserIdentityType.toLowerCase()),this._workspaceIdSyncApiKey=E(o.workspaceIdSyncApiKey)?o.workspaceIdSyncApiKey:void 0;const g=a().Rokt?.domain,{roktExtensionsQueryParams:M,legacyRoktExtensions:R,loadThankYouElement:w}=X(o.roktExtensions),f={...a().Rokt?.launcherOptions||{}};this.integrationName=He(f.integrationName),f.integrationName=this.integrationName,this.domain=g;const A={loggingUrl:o.loggingUrl,errorUrl:o.errorUrl,integrationDomain:g,isLoggingEnabled:a().config?.isLoggingEnabled===!0},I=new ne(A,this.integrationName,window.__rokt_li_guid__,o.accountId),k=new re(A,I,this.integrationName,window.__rokt_li_guid__,o.accountId);if(this.errorReportingService=I,this.loggingService=k,this.isTargetingDisabled())try{q(),$()}catch(h){this.errorReportingService?.report({message:"Rokt Kit: Failed to clear page views when targeting is disabled",code:"PAGE_VIEW_CAPTURE_FAILED",severity:S.INFO,stackTrace:h instanceof Error?h.stack:void 0})}return a()._registerErrorReportingService&&a()._registerErrorReportingService(I),a()._registerLoggingService&&a()._registerLoggingService(k),n?(this.testHelpers={generateLauncherScript:J,generateThankYouElementScript:B,extractRoktExtensionConfig:X,hashEventMessage:te,parseSettingsString:P,generateMappedEventLookup:Z,generateMappedEventAttributeLookup:ee,sendAdBlockMeasurementSignals:ie,createAutoRemovedIframe:F,djb2:ge,setAllowedOriginHashes:h=>{m._allowedOriginHashes=h},ReportingTransport:W,ErrorReportingService:ne,LoggingService:re,RateLimiter:pe,ErrorCodes:x,WSDKErrorSeverity:S},this.attachLauncher(c,f),"Successfully initialized: "+d):(w&&(a().Rokt.flushOnShoppableAdsReadyMessageQueue?.(this),Q(Oe,B(g),{onLoad:()=>{this._isThankYouElementLoaded=!0,this._thankYouElementOnLoadCallback&&this._thankYouElementOnLoadCallback()},onError:h=>{console.error("Error loading Rokt Thank You Element script:",h)}})),this.isLauncherReadyToAttach()?this.attachLauncher(c,f,R):(Q(Pe,J(g,M),{onLoad:()=>{this.isLauncherReadyToAttach()?this.attachLauncher(c,f,R):console.error("Rokt object is not available after script load.")},onError:h=>{console.error("Error loading Rokt launcher script:",h)}}),this.captureTiming(m.PERFORMANCE_MARKS.RoktScriptAppended)),"Successfully initialized: "+d)}process(e){if(this.isTargetingDisabled()||(e.EventDataType===Ue&&(ke(this.loggingService),this.capturePageView(e)),e.EventDataType===Ce&&(de(this.loggingService),q(),$())),!this.isKitReady())return"Kit not ready for forwarder: "+d;if(T(a().Rokt?.setLocalSessionAttribute)&&(K(this.placementEventAttributeMappingLookup)||this.applyPlacementEventAttributeMapping(e),!K(this.placementEventMappingLookup))){const t=te(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 se(e)||(this.userAttributes[e]=t),"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=b(e.getAllUserAttributes()),"Successfully called "+t+" for forwarder: "+d}onUserIdentified(e){const t=e;return this.filters.filteredUser=t,this._workspaceSearchInFlightPromise=this.search(t),this.handleIdentityComplete(e,"onUserIdentified")}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];E(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.handleIdentityComplete(e,"onLogoutComplete")}onModifyComplete(e,t){return this.handleIdentityComplete(e,"onModifyComplete")}selectPlacements(e){if(this._workspaceSearchInFlightPromise){const t=this._workspaceSearchInFlightPromise;return Promise.race([t,new Promise(n=>setTimeout(n,Ye))]).then(()=>this._dispatchPlacements(e))}return this._dispatchPlacements(e)}_dispatchPlacements(e){const t=e&&e.attributes||{},r={...b(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=b(l);const g=this._onboardingExpProvider==="Optimizely"?this.fetchOptimizely():{},M=this.returnUserIdentities(c),R=this.returnLocalSessionAttributes(),w=Ae(z(this.loggingService)),f=ve(),A=this.readMpSessionId(),I=this.readMpDeviceId(),k={...M,...l,...g,...R,...w.length?{[Me]:JSON.stringify(w)}:{},...f?{[Ke]:f}:{},...this.userIdentifiedInWorkspace?{[Ne]:!0}:{},...A?{[De]:A}:{},...I?{[Fe]:I}:{},mpid:u},h={...e,attributes:k},j=this.launcher.selectPlacements(h),fe=()=>this.logSelectPlacementsEvent(k);return Promise.resolve(j).then(me=>me?.context?.sessionId?.then(Ee=>this.setRoktSessionId(Ee))).catch(()=>{}).finally(fe),j}hashAttributes(e){return this.isKitReady()?this.launcher.hashAttributes(e):(console.error("Rokt Kit: Not initialized"),null)}use(e){return this.isKitReady()?!e||!E(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")))}onShoppableAdsReady(e){this._isThankYouElementLoaded?e():this._thankYouElementOnLoadCallback=e}};m._allowedOriginHashes=[-553112570,549508659],m.PERFORMANCE_MARKS={RoktScriptAppended:"mp:RoktScriptAppended"},m.EMAIL_SHA256_KEY="emailsha256";let y=m;function Be(){return L}function Qe(i){if(!i){window.console.log("You must pass a config object to register the kit "+d);return}if(!_(i)){window.console.log("'config' must be an object. You passed in a "+typeof i);return}_(i.kits)?i.kits[d]={constructor:y}:(i.kits={},i.kits[d]={constructor:y}),window.console.log("Successfully registered "+d+" to your mParticle configuration")}typeof window<"u"&&window.mParticle&&a().addForwarder&&a().addForwarder({name:d,constructor:y,getId:Be});exports.register=Qe;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const Ie=["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"],Se=new Set(Ie);function se(i){return Se.has(i.toLowerCase())}function b(i){const e={},t=i||{},n=Object.keys(t);for(let r=0;r<n.length;r++){const o=n[r];se(o)||(e[o]=t[o])}return e}function _(i){return typeof i=="object"&&i!==null&&!Array.isArray(i)}function E(i){return typeof i=="string"}function L(i){return typeof i=="function"}function K(i){return i==null?!0:typeof i=="object"?Object.keys(i).length===0:!1}function x(i){try{const e=new URL(i);return e.search="",e.toString()}catch{return i}}const V="__rokt_ls_probe__";function F(){try{return window.localStorage.setItem(V,"1"),window.localStorage.removeItem(V),!0}catch{return!1}}function N(i){try{const e=window.localStorage.getItem(i);return e===null?null:JSON.parse(e)}catch{return null}}function ae(i,e){try{return window.localStorage.setItem(i,JSON.stringify(e)),!0}catch{return!1}}function ce(i){try{window.localStorage.removeItem(i)}catch{}}function U(i,e){const t=N(i);return _(t)?t[e]:void 0}function Y(i,e,t){const n=N(i),r=_(n)?{...n}:{};return r[e]=t,ae(i,r)}function le(i,e){const t=N(i);if(!_(t)||!(e in t))return;const n={...t};delete n[e],Object.keys(n).length===0?ce(i):ae(i,n)}const p="mp-rokt-kit",R="pageViews",O="utmParams",H="mpPageViews",ue=25,ye=["utm_source","utm_medium","utm_campaign","utm_term","utm_content"];function de(i){return i.slice(-ue)}function he(i){const e=N(H);if(e===null)return;!(U(p,R)!==void 0)&&Array.isArray(e)&&(i?.log({message:"Rokt Kit: Migrating legacy page-view storage",code:"PAGE_VIEW_LEGACY_MIGRATION"}),Y(p,R,e)||i?.log({message:"Rokt Kit: Failed to migrate legacy page-view storage [reason: migration_retry]",code:"PAGE_VIEW_CAPTURE_FAILED"})),ce(H)}function z(i){he(i);const e=U(p,R);return Array.isArray(e)?e:[]}function Ae(i){const e=de(i);for(let t=0;t<e.length;t++){const n=e.slice(t);if(Y(p,R,n))return n.length}return 0}function q(){le(p,R)}function ke(i){const e=de(i);return e.map((t,n)=>{const r=t.activeTimeOnSite,o=r!==void 0&&Number.isFinite(r),c=e[n+1]?.activeTimeOnSite,u=c!==void 0&&Number.isFinite(c),l=o&&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}:{},...o?{activeTimeOnSite:r}:{},...l!==void 0&&l>=0?{activeTimeOnPage:l}:{}}})}function Re(i){if(U(p,O)!==void 0)return;const e=new URLSearchParams(window.location.search),t={};for(const r of ye){const o=e.get(r);o&&(t[r]=o)}if(Object.keys(t).length===0)return;const n=Object.keys(t).join(", ");if(!Y(p,O,t)){const r=F()?"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 ve(){const i=U(p,O);return _(i)?i:null}function $(){le(p,O)}function we(){const e=document.querySelector('link[rel="canonical"]')?.href;if(e)return x(e)}function be(){return{context:null,lifecycle:"idle",recreateInFlight:null}}function Le(i,e){i.context={accountId:e.accountId,launcherOptions:{...e.launcherOptions},legacyRoktExtensions:[...e.legacyRoktExtensions]}}function Te(i){i.lifecycle="attached"}function Pe(i){i.lifecycle!=="idle"&&(i.lifecycle="terminated")}function Oe(i){i.lifecycle="terminated"}function Ne(i){i.context=null,i.lifecycle="idle",i.recreateInFlight=null}function Ue(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",T=181,Ce="selectPlacements",Me="apps.roktecommerce.com",Ke=.1,Fe="ThankYouPageJourney",De="rokt-launcher",xe="rokt-thank-you-element",Ye="userIdentifiedInWorkspace",Ge=3,We=2,je="page_events",Ve="page_view_attributes",He="mparticle_session_id",ze="mparticle_device_id",J=500,G={UNKNOWN_ERROR:"UNKNOWN_ERROR",UNHANDLED_EXCEPTION:"UNHANDLED_EXCEPTION",IDENTITY_REQUEST:"IDENTITY_REQUEST",LOG_DELIVERY_FAILURE:"LOG_DELIVERY_FAILURE"},S={ERROR:"ERROR",INFO:"INFO",WARNING:"WARNING"},qe="apps.rokt-api.com",$e="/v1/log",Je="/v1/errors",Be=10;function a(){return window.mParticle}function B(i,e){const n=[C(i),"/wsdk/integrations/launcher.js"].join("");return!e||e.length===0?n:n+"?extensions="+e.join(",")}function Q(i){return[C(i),"/rokt-elements/rokt-element-thank-you.js"].join("")}function C(i){const e=typeof i<"u"?i:qe;return e.includes("://")?e.replace(/\/+$/,""):["https://",e].join("")}function ge(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 C(r)+t}function X(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 P(i){if(!i)return[];try{return JSON.parse(i.replace(/&quot;/g,'"'))}catch{console.error("Settings string contains invalid JSON")}return[]}function Z(i){const e=i?P(i):[],t=[],n=[];let r=!1;for(let o=0;o<e.length;o++){const s=e[o].value;s==="thank-you-journey"?(r=!0,n.push(Fe)):t.push(s)}return{roktExtensionsQueryParams:t,legacyRoktExtensions:n,loadThankYouElement:r}}async function Qe(i,e){const t=[];if(e)for(const n of i)t.push(e.use(n));return Promise.all(t)}function ee(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 te(i){const e={};if(!Array.isArray(i))return e;for(let t=0;t<i.length;t++){const n=i[t];if(!n||!E(n.value)||!E(n.map))continue;const r=n.value,o=n.map;e[r]||(e[r]=[]),e[r].push({eventAttributeKey:o,conditions:Array.isArray(n.conditions)?n.conditions:[]})}return e}function ie(i,e,t){return a().generateHash([i,e,t].join(""))}function Xe(i){let n="mParticle_wsdkv_"+a().getVersion()+"_kitv_"+"1.36.0";return i&&(n+="_"+i),n}function pe(i){let e=5381;for(let t=0;t<i.length;t++)e=(e<<5)+e+i.charCodeAt(t),e=e&e;return e}function D(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 ne(i,e){const t=pe(window.location.origin);if(y._allowedOriginHashes.indexOf(t)===-1||Math.random()>=Ke)return;const r=window.__rokt_li_guid__;if(!r||i&&i.includes("://")&&!/^https:\/\//i.test(i))return;const o=window.location.href.split("?")[0].split("#")[0],s="version="+encodeURIComponent(e??"")+"&launcherInstanceGuid="+encodeURIComponent(r)+"&pageUrl="+encodeURIComponent(o),c=i?C(i):"https://apps.rokt.com";D(c+"/v1/wsdk-init/index.html?"+s),D("https://"+Me+"/v1/wsdk-init/index.html?"+s+"&isControl=true")}function Ze(){return typeof window<"u"&&!!window.location?.search?.toLowerCase().includes("mp_enable_logging=true")}function et(){return typeof window<"u"?window.location?.href:void 0}function tt(){return typeof window<"u"?window.navigator?.userAgent:void 0}class fe{constructor(){this._logCount={}}incrementAndCheck(e){const n=(this._logCount[e]||0)+1;return this._logCount[e]=n,n>Be}}class W{constructor(e,t,n,r,o){this._reporter="mp-wsdk";const s=e.isLoggingEnabled;this._integrationName=t||"",this._launcherInstanceGuid=n,this._accountId=r||null,this._rateLimiter=o||new fe,this._isEnabled=Ze()||s}send(e,t,n,r,o,s){if(!(!this._isEnabled||this._rateLimiter.incrementAndCheck(t)))try{const c={additionalInformation:{message:n,version:this._integrationName},severity:t,code:r||G.UNKNOWN_ERROR,url:et(),deviceInfo:tt(),stackTrace:o,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 g=new Error("HTTP "+l.status+" from log endpoint");throw g.statusCode=l.status,g}}).catch(l=>{console.error("ReportingTransport: Failed to send log",l),s&&s(l)})}catch(c){console.error("ReportingTransport: Failed to send log",c),s&&s(c)}}}class re{constructor(e,t,n,r,o){this._transport=new W(e,t,n,r,o),this._errorUrl=ge(e?.errorUrl,e?.integrationDomain,Je)}report(e){if(!e)return;const t=e.severity||S.ERROR;this._transport.send(this._errorUrl,t,e.message,e.code,e.stackTrace)}}class oe{constructor(e,t,n,r,o,s){this._transport=new W(e,n,r,o,s),this._loggingUrl=ge(e?.loggingUrl,e?.integrationDomain,$e),this._errorReportingService=t}log(e){e&&this._transport.send(this._loggingUrl,S.INFO,e.message,e.code,void 0,t=>{if(this._errorReportingService){const n=typeof t.statusCode=="number";this._errorReportingService.report({message:"LoggingService: Failed to send log: "+t.message,code:G.LOG_DELIVERY_FAILURE,severity:n?S.ERROR:S.WARNING})}})}}function it(i){const e=x(window.location.href),t=i.EventAttributes?.title||document.title,n=we(),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 m=class m{constructor(){this.name=d,this.id=T,this.moduleId=T,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=be()}getEventAttributeValue(e,t){const n=e&&e.EventAttributes;return!n||typeof n[t]>"u"?null:n[t]}doesEventAttributeConditionMatch(e,t){if(!e||!E(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||!E(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 o=0;o<n.length;o++)if(!this.doesEventAttributeConditionMatch(n[o],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],o=this.placementEventAttributeMappingLookup[r];if(K(o))continue;let s=!0;for(let c=0;c<o.length;c++)if(!this.doesEventMatchRule(e,o[c])){s=!1;break}s&&a().Rokt.setLocalSessionAttribute?.(r,!0)}}capturePageView(e){let t;try{t=x(window.location.href);const n=z(this.loggingService),r=it(e);n.push(r);const o=Math.min(n.length,ue),s=Ae(n);if(s===0){const c=F()?"quota":"ls_unavailable";this.loggingService?.log({message:`Rokt Kit: Failed to persist page view for ${t} [reason: ${c}]`,code:"PAGE_VIEW_CAPTURE_FAILED"})}else s<o&&this.loggingService?.log({message:`Rokt Kit: Page view storage reduced from ${o} to ${s} record(s) under quota pressure [reason: quota_eviction]`,code:"PAGE_VIEW_QUOTA_EVICTION"})}catch(n){const r=F()?"exception":"ls_unavailable",o=n instanceof Error?n.message:String(n);this.loggingService?.log({message:`Rokt Kit: Failed to capture page view for ${t}: ${o} [reason: ${r}]`,code:"PAGE_VIEW_CAPTURE_FAILED"})}}isLauncherReadyToAttach(){return!!window.Rokt&&L(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[m.EMAIL_SHA256_KEY]=e[n]),n&&delete t[n],t}logSelectPlacementsEvent(e){if(!window.mParticle||typeof a().logEvent!="function"||!_(e))return;const t=a().EventType.Other;a().logEvent(Ce,t,e)}setRoktSessionId(e){if(!(!e||typeof e!="string"))try{const t=a().getInstance();t&&L(t.setIntegrationAttribute)&&t.setIntegrationAttribute(T,{roktSessionId:e})}catch{}}readMpSessionId(){const e=a()?.sessionManager,t=e?.getSessionId??e?.getSession;if(L(t))return t.call(e)||void 0}readMpDeviceId(){return a()?.getDeviceId?.()||void 0}attachLauncher(e,t,n=[]){Le(this._launcherAttachState,{accountId:e,launcherOptions:t||{},legacyRoktExtensions:n});const r={accountId:e,...t||{}};let o;return this.isPartnerInLocalLauncherTestGroup()?o=Promise.resolve(window.Rokt.createLocalLauncher(r)):o=window.Rokt.createLauncher(r),o.then(async s=>{await Qe([...n],s),this.initRoktLauncher(s)}).catch(s=>{Oe(this._launcherAttachState),console.error("Error creating Rokt launcher:",s)})}recreateLauncherIfTerminated(){return Ue(this._launcherAttachState,this.isLauncherReadyToAttach(),e=>this.attachLauncher(e.accountId,e.launcherOptions,e.legacyRoktExtensions))}initRoktLauncher(e){window.Rokt&&(window.Rokt.currentLauncher=e),this.launcher=e,Te(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,ne(this.domain,this.integrationName),a().Rokt.attachKit(this)}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((o,s)=>(o["rokt.custom.optimizely.experiment."+s+".variationId"]=t.getVariationMap()[s].id,o),{})}}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,o){const s=e,c=s.accountId;this.userAttributes=b(o),this._onboardingExpProvider=s.onboardingExpProvider;const u=P(s.placementEventMapping);this.placementEventMappingLookup=ee(u);const l=P(s.placementEventAttributeMapping);this.placementEventAttributeMappingLookup=te(l),s.hashedEmailUserIdentityType&&(this._mappedEmailSha256Key=s.hashedEmailUserIdentityType.toLowerCase()),this._workspaceIdSyncApiKey=E(s.workspaceIdSyncApiKey)?s.workspaceIdSyncApiKey:void 0;const g=a().Rokt?.domain,{roktExtensionsQueryParams:M,legacyRoktExtensions:v,loadThankYouElement:w}=Z(s.roktExtensions),f={...a().Rokt?.launcherOptions||{}};this.integrationName=Xe(f.integrationName),f.integrationName=this.integrationName,this.domain=g;const A={loggingUrl:s.loggingUrl,errorUrl:s.errorUrl,integrationDomain:g,isLoggingEnabled:a().config?.isLoggingEnabled===!0},I=new re(A,this.integrationName,window.__rokt_li_guid__,s.accountId),k=new oe(A,I,this.integrationName,window.__rokt_li_guid__,s.accountId);if(this.errorReportingService=I,this.loggingService=k,this.isTargetingDisabled())try{q(),$()}catch(h){this.errorReportingService?.report({message:"Rokt Kit: Failed to clear page views when targeting is disabled",code:"PAGE_VIEW_CAPTURE_FAILED",severity:S.INFO,stackTrace:h instanceof Error?h.stack:void 0})}return a()._registerErrorReportingService&&a()._registerErrorReportingService(I),a()._registerLoggingService&&a()._registerLoggingService(k),n?(this.testHelpers={generateLauncherScript:B,generateThankYouElementScript:Q,extractRoktExtensionConfig:Z,hashEventMessage:ie,parseSettingsString:P,generateMappedEventLookup:ee,generateMappedEventAttributeLookup:te,sendAdBlockMeasurementSignals:ne,createAutoRemovedIframe:D,djb2:pe,setAllowedOriginHashes:h=>{m._allowedOriginHashes=h},ReportingTransport:W,ErrorReportingService:re,LoggingService:oe,RateLimiter:fe,ErrorCodes:G,WSDKErrorSeverity:S,resetLauncherAttachState:()=>Ne(this._launcherAttachState)},this.attachLauncher(c,f),"Successfully initialized: "+d):(w&&(a().Rokt.flushOnShoppableAdsReadyMessageQueue?.(this),X(xe,Q(g),{onLoad:()=>{this._isThankYouElementLoaded=!0,this._thankYouElementOnLoadCallback&&this._thankYouElementOnLoadCallback()},onError:h=>{console.error("Error loading Rokt Thank You Element script:",h)}})),this.isLauncherReadyToAttach()?this.attachLauncher(c,f,v):(X(De,B(g,M),{onLoad:()=>{this.isLauncherReadyToAttach()?this.attachLauncher(c,f,v):console.error("Rokt object is not available after script load.")},onError:h=>{console.error("Error loading Rokt launcher script:",h)}}),this.captureTiming(m.PERFORMANCE_MARKS.RoktScriptAppended)),"Successfully initialized: "+d)}process(e){if(this.isTargetingDisabled()||(e.EventDataType===Ge&&(Re(this.loggingService),this.capturePageView(e)),e.EventDataType===We&&(he(this.loggingService),q(),$())),!this.isKitReady())return"Kit not ready for forwarder: "+d;if(L(a().Rokt?.setLocalSessionAttribute)&&(K(this.placementEventAttributeMappingLookup)||this.applyPlacementEventAttributeMapping(e),!K(this.placementEventMappingLookup))){const t=ie(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 se(e)||(this.userAttributes[e]=t),"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=b(e.getAllUserAttributes()),"Successfully called "+t+" for forwarder: "+d}onUserIdentified(e){const t=e;return this.filters.filteredUser=t,this._workspaceSearchInFlightPromise=this.search(t),this.handleIdentityComplete(e,"onUserIdentified")}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,o={};if(r)for(const u of Object.keys(r)){const l=r[u];E(l)&&l.length>0&&(o[u]=l)}const s=Object.keys(o);if(s.length===0)return this.userIdentifiedInWorkspace=!1,this._workspaceLastSearchedIdentitiesKey=void 0,Promise.resolve();const c=s.sort().map(u=>`${u}=${o[u]}`).join("&");return c===this._workspaceLastSearchedIdentitiesKey?this._workspaceSearchInFlightPromise||Promise.resolve():(this.userIdentifiedInWorkspace=!1,this._workspaceLastSearchedIdentitiesKey=c,new Promise(u=>{try{n(t,o,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.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(o=>setTimeout(o,J))]):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,J))]).then(()=>this._dispatchPlacements(e))}return this._dispatchPlacements(e)}_dispatchPlacements(e){const t=e&&e.attributes||{},r={...b(this.userAttributes),...t},o=this.filters||{},s=o.userAttributeFilters||[],c=o.filteredUser||null,u=c?c.getMPID():null;let l;o?o.filterUserAttributes?l=o.filterUserAttributes(r,s):l=r:(console.warn("Rokt Kit: No filters available, using user attributes"),l=r),this.userAttributes=b(l);const g=this._onboardingExpProvider==="Optimizely"?this.fetchOptimizely():{},M=this.returnUserIdentities(c),v=this.returnLocalSessionAttributes(),w=ke(z(this.loggingService)),f=ve(),A=this.readMpSessionId(),I=this.readMpDeviceId(),k={...M,...l,...g,...v,...w.length?{[je]:JSON.stringify(w)}:{},...f?{[Ve]:f}:{},...this.userIdentifiedInWorkspace?{[Ye]:!0}:{},...A?{[He]:A}:{},...I?{[ze]:I}:{},mpid:u},h={...e,attributes:k},j=this.launcher.selectPlacements(h),me=()=>this.logSelectPlacementsEvent(k);return Promise.resolve(j).then(Ee=>Ee?.context?.sessionId?.then(_e=>this.setRoktSessionId(_e))).catch(()=>{}).finally(me),j}hashAttributes(e){return this.isKitReady()?this.launcher.hashAttributes(e):(console.error("Rokt Kit: Not initialized"),null)}use(e){return this.isKitReady()?!e||!E(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()?(Pe(this._launcherAttachState),this.launcher.terminate()):(console.error("Rokt Kit: Not initialized"),Promise.resolve())}onShoppableAdsReady(e){this._isThankYouElementLoaded?e():this._thankYouElementOnLoadCallback=e}};m._allowedOriginHashes=[-553112570,549508659],m.PERFORMANCE_MARKS={RoktScriptAppended:"mp:RoktScriptAppended"},m.EMAIL_SHA256_KEY="emailsha256";let y=m;function nt(){return T}function rt(i){if(!i){window.console.log("You must pass a config object to register the kit "+d);return}if(!_(i)){window.console.log("'config' must be an object. You passed in a "+typeof i);return}_(i.kits)?i.kits[d]={constructor:y}:(i.kits={},i.kits[d]={constructor:y}),window.console.log("Successfully registered "+d+" to your mParticle configuration")}typeof window<"u"&&window.mParticle&&a().addForwarder&&a().addForwarder({name:d,constructor:y,getId:nt});exports.register=rt;
2
2
  //# sourceMappingURL=Rokt-Kit.common.js.map
@@ -1,4 +1,4 @@
1
- const _e = [
1
+ const Ie = [
2
2
  "active_time_on_site_ms",
3
3
  "billingaddress1",
4
4
  "billingaddress2",
@@ -23,15 +23,15 @@ const _e = [
23
23
  "shippingstate",
24
24
  "shippingzipcode",
25
25
  "totalprice"
26
- ], Ie = new Set(_e);
26
+ ], Se = new Set(Ie);
27
27
  function se(i) {
28
- return Ie.has(i.toLowerCase());
28
+ return Se.has(i.toLowerCase());
29
29
  }
30
- function b(i) {
30
+ function L(i) {
31
31
  const e = {}, t = i || {}, n = Object.keys(t);
32
32
  for (let r = 0; r < n.length; r++) {
33
- const s = n[r];
34
- se(s) || (e[s] = t[s]);
33
+ const o = n[r];
34
+ se(o) || (e[o] = t[o]);
35
35
  }
36
36
  return e;
37
37
  }
@@ -47,7 +47,7 @@ function T(i) {
47
47
  function K(i) {
48
48
  return i == null ? !0 : typeof i == "object" ? Object.keys(i).length === 0 : !1;
49
49
  }
50
- function Y(i) {
50
+ function x(i) {
51
51
  try {
52
52
  const e = new URL(i);
53
53
  return e.search = "", e.toString();
@@ -56,7 +56,7 @@ function Y(i) {
56
56
  }
57
57
  }
58
58
  const j = "__rokt_ls_probe__";
59
- function D() {
59
+ function F() {
60
60
  try {
61
61
  return window.localStorage.setItem(j, "1"), window.localStorage.removeItem(j), !0;
62
62
  } catch {
@@ -71,14 +71,14 @@ function N(i) {
71
71
  return null;
72
72
  }
73
73
  }
74
- function oe(i, e) {
74
+ function ae(i, e) {
75
75
  try {
76
76
  return window.localStorage.setItem(i, JSON.stringify(e)), !0;
77
77
  } catch {
78
78
  return !1;
79
79
  }
80
80
  }
81
- function ae(i) {
81
+ function ce(i) {
82
82
  try {
83
83
  window.localStorage.removeItem(i);
84
84
  } catch {
@@ -88,78 +88,78 @@ function U(i, e) {
88
88
  const t = N(i);
89
89
  return _(t) ? t[e] : void 0;
90
90
  }
91
- function x(i, e, t) {
91
+ function Y(i, e, t) {
92
92
  const n = N(i), r = _(n) ? { ...n } : {};
93
- return r[e] = t, oe(i, r);
93
+ return r[e] = t, ae(i, r);
94
94
  }
95
- function ce(i, e) {
95
+ function le(i, e) {
96
96
  const t = N(i);
97
97
  if (!_(t) || !(e in t))
98
98
  return;
99
99
  const n = { ...t };
100
- delete n[e], Object.keys(n).length === 0 ? ae(i) : oe(i, n);
101
- }
102
- const p = "mp-rokt-kit", R = "pageViews", O = "utmParams", H = "mpPageViews", le = 25, Se = ["utm_source", "utm_medium", "utm_campaign", "utm_term", "utm_content"];
103
- function ue(i) {
104
- return i.slice(-le);
100
+ delete n[e], Object.keys(n).length === 0 ? ce(i) : ae(i, n);
105
101
  }
102
+ const p = "mp-rokt-kit", R = "pageViews", O = "utmParams", H = "mpPageViews", ue = 25, Ae = ["utm_source", "utm_medium", "utm_campaign", "utm_term", "utm_content"];
106
103
  function de(i) {
104
+ return i.slice(-ue);
105
+ }
106
+ function he(i) {
107
107
  const e = N(H);
108
108
  if (e === null)
109
109
  return;
110
110
  !(U(p, R) !== void 0) && Array.isArray(e) && (i?.log({
111
111
  message: "Rokt Kit: Migrating legacy page-view storage",
112
112
  code: "PAGE_VIEW_LEGACY_MIGRATION"
113
- }), x(p, R, e) || i?.log({
113
+ }), Y(p, R, e) || i?.log({
114
114
  message: "Rokt Kit: Failed to migrate legacy page-view storage [reason: migration_retry]",
115
115
  code: "PAGE_VIEW_CAPTURE_FAILED"
116
- })), ae(H);
116
+ })), ce(H);
117
117
  }
118
118
  function z(i) {
119
- de(i);
119
+ he(i);
120
120
  const e = U(p, R);
121
121
  return Array.isArray(e) ? e : [];
122
122
  }
123
123
  function ye(i) {
124
- const e = ue(i);
124
+ const e = de(i);
125
125
  for (let t = 0; t < e.length; t++) {
126
126
  const n = e.slice(t);
127
- if (x(p, R, n))
127
+ if (Y(p, R, n))
128
128
  return n.length;
129
129
  }
130
130
  return 0;
131
131
  }
132
132
  function q() {
133
- ce(p, R);
133
+ le(p, R);
134
134
  }
135
- function Ae(i) {
136
- const e = ue(i);
135
+ function ke(i) {
136
+ const e = de(i);
137
137
  return e.map((t, n) => {
138
- 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;
138
+ const r = t.activeTimeOnSite, o = r !== void 0 && Number.isFinite(r), c = e[n + 1]?.activeTimeOnSite, u = c !== void 0 && Number.isFinite(c), l = o && u ? c - r : void 0;
139
139
  return {
140
140
  pageUrl: t.pageUrl,
141
141
  sourceMessageId: t.sourceMessageId,
142
142
  timestamp: t.timestamp,
143
143
  ...t.pageTitle !== void 0 ? { pageTitle: t.pageTitle } : {},
144
144
  ...t.canonicalUrl !== void 0 ? { canonicalUrl: t.canonicalUrl } : {},
145
- ...s ? { activeTimeOnSite: r } : {},
145
+ ...o ? { activeTimeOnSite: r } : {},
146
146
  ...l !== void 0 && l >= 0 ? { activeTimeOnPage: l } : {}
147
147
  };
148
148
  });
149
149
  }
150
- function ke(i) {
150
+ function Re(i) {
151
151
  if (U(p, O) !== void 0)
152
152
  return;
153
153
  const e = new URLSearchParams(window.location.search), t = {};
154
- for (const r of Se) {
155
- const s = e.get(r);
156
- s && (t[r] = s);
154
+ for (const r of Ae) {
155
+ const o = e.get(r);
156
+ o && (t[r] = o);
157
157
  }
158
158
  if (Object.keys(t).length === 0)
159
159
  return;
160
160
  const n = Object.keys(t).join(", ");
161
- if (!x(p, O, t)) {
162
- const r = D() ? "quota" : "ls_unavailable";
161
+ if (!Y(p, O, t)) {
162
+ const r = F() ? "quota" : "ls_unavailable";
163
163
  i?.log({
164
164
  message: `Rokt Kit: Failed to persist UTM params [reason: ${r}]`,
165
165
  code: "UTM_CAPTURE_FAILED"
@@ -171,19 +171,56 @@ function ke(i) {
171
171
  code: "UTM_CAPTURE_SUCCESS"
172
172
  });
173
173
  }
174
- function Re() {
174
+ function ve() {
175
175
  const i = U(p, O);
176
176
  return _(i) ? i : null;
177
177
  }
178
178
  function $() {
179
- ce(p, O);
179
+ le(p, O);
180
180
  }
181
- function ve() {
181
+ function we() {
182
182
  const e = document.querySelector('link[rel="canonical"]')?.href;
183
183
  if (e)
184
- return Y(e);
184
+ return x(e);
185
+ }
186
+ function Le() {
187
+ return {
188
+ context: null,
189
+ lifecycle: "idle",
190
+ recreateInFlight: null
191
+ };
192
+ }
193
+ function Te(i, e) {
194
+ i.context = {
195
+ accountId: e.accountId,
196
+ launcherOptions: { ...e.launcherOptions },
197
+ legacyRoktExtensions: [...e.legacyRoktExtensions]
198
+ };
199
+ }
200
+ function be(i) {
201
+ i.lifecycle = "attached";
202
+ }
203
+ function Pe(i) {
204
+ i.lifecycle !== "idle" && (i.lifecycle = "terminated");
205
+ }
206
+ function Oe(i) {
207
+ i.lifecycle = "terminated";
208
+ }
209
+ function Ne(i) {
210
+ i.context = null, i.lifecycle = "idle", i.recreateInFlight = null;
211
+ }
212
+ function Ue(i, e, t) {
213
+ if (i.recreateInFlight)
214
+ return i.recreateInFlight;
215
+ if (i.lifecycle !== "terminated" || !i.context || !e)
216
+ return;
217
+ i.lifecycle = "recreating";
218
+ const n = i.context;
219
+ return i.recreateInFlight = t(n).finally(() => {
220
+ i.recreateInFlight = null;
221
+ }), i.recreateInFlight;
185
222
  }
186
- const d = "Rokt", L = 181, we = "selectPlacements", be = "apps.roktecommerce.com", Te = 0.1, Le = "ThankYouPageJourney", Pe = "rokt-launcher", Oe = "rokt-thank-you-element", Ne = "userIdentifiedInWorkspace", Ue = 3, Ce = 2, Me = "page_events", Ke = "page_view_attributes", De = "mparticle_session_id", Fe = "mparticle_device_id", Ye = 500, G = {
223
+ const d = "Rokt", b = 181, Ce = "selectPlacements", Me = "apps.roktecommerce.com", Ke = 0.1, Fe = "ThankYouPageJourney", De = "rokt-launcher", xe = "rokt-thank-you-element", Ye = "userIdentifiedInWorkspace", Ge = 3, We = 2, Ve = "page_events", je = "page_view_attributes", He = "mparticle_session_id", ze = "mparticle_device_id", J = 500, G = {
187
224
  UNKNOWN_ERROR: "UNKNOWN_ERROR",
188
225
  UNHANDLED_EXCEPTION: "UNHANDLED_EXCEPTION",
189
226
  IDENTITY_REQUEST: "IDENTITY_REQUEST",
@@ -192,28 +229,28 @@ const d = "Rokt", L = 181, we = "selectPlacements", be = "apps.roktecommerce.com
192
229
  ERROR: "ERROR",
193
230
  INFO: "INFO",
194
231
  WARNING: "WARNING"
195
- }, xe = "apps.rokt-api.com", Ge = "/v1/log", We = "/v1/errors", Ve = 10;
232
+ }, qe = "apps.rokt-api.com", $e = "/v1/log", Je = "/v1/errors", Be = 10;
196
233
  function a() {
197
234
  return window.mParticle;
198
235
  }
199
- function J(i, e) {
236
+ function B(i, e) {
200
237
  const n = [C(i), "/wsdk/integrations/launcher.js"].join("");
201
238
  return !e || e.length === 0 ? n : n + "?extensions=" + e.join(",");
202
239
  }
203
- function B(i) {
240
+ function Q(i) {
204
241
  return [C(i), "/rokt-elements/rokt-element-thank-you.js"].join("");
205
242
  }
206
243
  function C(i) {
207
- const e = typeof i < "u" ? i : xe;
244
+ const e = typeof i < "u" ? i : qe;
208
245
  return e.includes("://") ? e.replace(/\/+$/, "") : ["https://", e].join("");
209
246
  }
210
- function he(i, e, t) {
247
+ function ge(i, e, t) {
211
248
  if (i)
212
249
  return i.startsWith("http://") || i.startsWith("https://") ? i : "https://" + i;
213
250
  const r = e?.includes("://") && !/^https?:\/\//i.test(e) ? void 0 : e;
214
251
  return C(r) + t;
215
252
  }
216
- function Q(i, e, t) {
253
+ function X(i, e, t) {
217
254
  if (document.getElementById(i)) return;
218
255
  const n = document.head || document.body, r = document.createElement("script");
219
256
  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);
@@ -228,12 +265,12 @@ function P(i) {
228
265
  }
229
266
  return [];
230
267
  }
231
- function X(i) {
268
+ function Z(i) {
232
269
  const e = i ? P(i) : [], t = [], n = [];
233
270
  let r = !1;
234
- for (let s = 0; s < e.length; s++) {
235
- const o = e[s].value;
236
- o === "thank-you-journey" ? (r = !0, n.push(Le)) : t.push(o);
271
+ for (let o = 0; o < e.length; o++) {
272
+ const s = e[o].value;
273
+ s === "thank-you-journey" ? (r = !0, n.push(Fe)) : t.push(s);
237
274
  }
238
275
  return {
239
276
  roktExtensionsQueryParams: t,
@@ -241,14 +278,14 @@ function X(i) {
241
278
  loadThankYouElement: r
242
279
  };
243
280
  }
244
- async function je(i, e) {
281
+ async function Qe(i, e) {
245
282
  const t = [];
246
283
  if (e)
247
284
  for (const n of i)
248
285
  t.push(e.use(n));
249
286
  return Promise.all(t);
250
287
  }
251
- function Z(i) {
288
+ function ee(i) {
252
289
  if (!i)
253
290
  return {};
254
291
  const e = {};
@@ -258,7 +295,7 @@ function Z(i) {
258
295
  }
259
296
  return e;
260
297
  }
261
- function ee(i) {
298
+ function te(i) {
262
299
  const e = {};
263
300
  if (!Array.isArray(i))
264
301
  return e;
@@ -266,28 +303,28 @@ function ee(i) {
266
303
  const n = i[t];
267
304
  if (!n || !E(n.value) || !E(n.map))
268
305
  continue;
269
- const r = n.value, s = n.map;
306
+ const r = n.value, o = n.map;
270
307
  e[r] || (e[r] = []), e[r].push({
271
- eventAttributeKey: s,
308
+ eventAttributeKey: o,
272
309
  conditions: Array.isArray(n.conditions) ? n.conditions : []
273
310
  });
274
311
  }
275
312
  return e;
276
313
  }
277
- function te(i, e, t) {
314
+ function ie(i, e, t) {
278
315
  return a().generateHash([i, e, t].join(""));
279
316
  }
280
- function He(i) {
281
- let n = "mParticle_wsdkv_" + a().getVersion() + "_kitv_" + "1.35.0";
317
+ function Xe(i) {
318
+ let n = "mParticle_wsdkv_" + a().getVersion() + "_kitv_" + "1.36.0";
282
319
  return i && (n += "_" + i), n;
283
320
  }
284
- function ge(i) {
321
+ function pe(i) {
285
322
  let e = 5381;
286
323
  for (let t = 0; t < i.length; t++)
287
324
  e = (e << 5) + e + i.charCodeAt(t), e = e & e;
288
325
  return e;
289
326
  }
290
- function F(i) {
327
+ function D(i) {
291
328
  const e = document.createElement("iframe");
292
329
  e.style.display = "none", e.setAttribute("sandbox", "allow-scripts allow-same-origin"), e.src = i, e.onload = function() {
293
330
  e.onload = null, e.parentNode && e.parentNode.removeChild(e);
@@ -295,43 +332,43 @@ function F(i) {
295
332
  const t = document.body || document.head;
296
333
  t && t.appendChild(e);
297
334
  }
298
- function ie(i, e) {
299
- const t = ge(window.location.origin);
300
- if (y._allowedOriginHashes.indexOf(t) === -1 || Math.random() >= Te)
335
+ function ne(i, e) {
336
+ const t = pe(window.location.origin);
337
+ if (A._allowedOriginHashes.indexOf(t) === -1 || Math.random() >= Ke)
301
338
  return;
302
339
  const r = window.__rokt_li_guid__;
303
340
  if (!r || i && i.includes("://") && !/^https:\/\//i.test(i))
304
341
  return;
305
- const s = window.location.href.split("?")[0].split("#")[0], o = "version=" + encodeURIComponent(e ?? "") + "&launcherInstanceGuid=" + encodeURIComponent(r) + "&pageUrl=" + encodeURIComponent(s), c = i ? C(i) : "https://apps.rokt.com";
306
- F(c + "/v1/wsdk-init/index.html?" + o), F(
307
- "https://" + be + "/v1/wsdk-init/index.html?" + o + "&isControl=true"
342
+ const o = window.location.href.split("?")[0].split("#")[0], s = "version=" + encodeURIComponent(e ?? "") + "&launcherInstanceGuid=" + encodeURIComponent(r) + "&pageUrl=" + encodeURIComponent(o), c = i ? C(i) : "https://apps.rokt.com";
343
+ D(c + "/v1/wsdk-init/index.html?" + s), D(
344
+ "https://" + Me + "/v1/wsdk-init/index.html?" + s + "&isControl=true"
308
345
  );
309
346
  }
310
- function ze() {
347
+ function Ze() {
311
348
  return typeof window < "u" && !!window.location?.search?.toLowerCase().includes("mp_enable_logging=true");
312
349
  }
313
- function qe() {
350
+ function et() {
314
351
  return typeof window < "u" ? window.location?.href : void 0;
315
352
  }
316
- function $e() {
353
+ function tt() {
317
354
  return typeof window < "u" ? window.navigator?.userAgent : void 0;
318
355
  }
319
- class pe {
356
+ class fe {
320
357
  constructor() {
321
358
  this._logCount = {};
322
359
  }
323
360
  incrementAndCheck(e) {
324
361
  const n = (this._logCount[e] || 0) + 1;
325
- return this._logCount[e] = n, n > Ve;
362
+ return this._logCount[e] = n, n > Be;
326
363
  }
327
364
  }
328
365
  class W {
329
- constructor(e, t, n, r, s) {
366
+ constructor(e, t, n, r, o) {
330
367
  this._reporter = "mp-wsdk";
331
- const o = e.isLoggingEnabled;
332
- this._integrationName = t || "", this._launcherInstanceGuid = n, this._accountId = r || null, this._rateLimiter = s || new pe(), this._isEnabled = ze() || o;
368
+ const s = e.isLoggingEnabled;
369
+ this._integrationName = t || "", this._launcherInstanceGuid = n, this._accountId = r || null, this._rateLimiter = o || new fe(), this._isEnabled = Ze() || s;
333
370
  }
334
- send(e, t, n, r, s, o) {
371
+ send(e, t, n, r, o, s) {
335
372
  if (!(!this._isEnabled || this._rateLimiter.incrementAndCheck(t)))
336
373
  try {
337
374
  const c = {
@@ -341,9 +378,9 @@ class W {
341
378
  },
342
379
  severity: t,
343
380
  code: r || G.UNKNOWN_ERROR,
344
- url: qe(),
345
- deviceInfo: $e(),
346
- stackTrace: s,
381
+ url: et(),
382
+ deviceInfo: tt(),
383
+ stackTrace: o,
347
384
  reporter: this._reporter,
348
385
  integration: this._integrationName
349
386
  }, u = {
@@ -362,16 +399,16 @@ class W {
362
399
  throw g.statusCode = l.status, g;
363
400
  }
364
401
  }).catch((l) => {
365
- console.error("ReportingTransport: Failed to send log", l), o && o(l);
402
+ console.error("ReportingTransport: Failed to send log", l), s && s(l);
366
403
  });
367
404
  } catch (c) {
368
- console.error("ReportingTransport: Failed to send log", c), o && o(c);
405
+ console.error("ReportingTransport: Failed to send log", c), s && s(c);
369
406
  }
370
407
  }
371
408
  }
372
- class ne {
373
- constructor(e, t, n, r, s) {
374
- this._transport = new W(e, t, n, r, s), this._errorUrl = he(e?.errorUrl, e?.integrationDomain, We);
409
+ class re {
410
+ constructor(e, t, n, r, o) {
411
+ this._transport = new W(e, t, n, r, o), this._errorUrl = ge(e?.errorUrl, e?.integrationDomain, Je);
375
412
  }
376
413
  report(e) {
377
414
  if (!e) return;
@@ -379,9 +416,9 @@ class ne {
379
416
  this._transport.send(this._errorUrl, t, e.message, e.code, e.stackTrace);
380
417
  }
381
418
  }
382
- class re {
383
- constructor(e, t, n, r, s, o) {
384
- this._transport = new W(e, n, r, s, o), this._loggingUrl = he(e?.loggingUrl, e?.integrationDomain, Ge), this._errorReportingService = t;
419
+ class oe {
420
+ constructor(e, t, n, r, o, s) {
421
+ this._transport = new W(e, n, r, o, s), this._loggingUrl = ge(e?.loggingUrl, e?.integrationDomain, $e), this._errorReportingService = t;
385
422
  }
386
423
  log(e) {
387
424
  e && this._transport.send(
@@ -403,8 +440,8 @@ class re {
403
440
  );
404
441
  }
405
442
  }
406
- function Je(i) {
407
- const e = Y(window.location.href), t = i.EventAttributes?.title || document.title, n = ve(), r = i.ActiveTimeOnSite;
443
+ function it(i) {
444
+ const e = x(window.location.href), t = i.EventAttributes?.title || document.title, n = we(), r = i.ActiveTimeOnSite;
408
445
  return {
409
446
  pageUrl: e,
410
447
  sourceMessageId: i.SourceMessageId,
@@ -416,7 +453,7 @@ function Je(i) {
416
453
  }
417
454
  const m = class m {
418
455
  constructor() {
419
- this.name = d, this.id = L, this.moduleId = L, 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;
456
+ this.name = d, this.id = b, this.moduleId = b, 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 = Le();
420
457
  }
421
458
  // ---- Private helpers ----
422
459
  getEventAttributeValue(e, t) {
@@ -438,47 +475,47 @@ const m = class m {
438
475
  const r = this.getEventAttributeValue(e, t.eventAttributeKey);
439
476
  if (n.length === 0)
440
477
  return r !== null;
441
- for (let s = 0; s < n.length; s++)
442
- if (!this.doesEventAttributeConditionMatch(n[s], r))
478
+ for (let o = 0; o < n.length; o++)
479
+ if (!this.doesEventAttributeConditionMatch(n[o], r))
443
480
  return !1;
444
481
  return !0;
445
482
  }
446
483
  applyPlacementEventAttributeMapping(e) {
447
484
  const t = Object.keys(this.placementEventAttributeMappingLookup);
448
485
  for (let n = 0; n < t.length; n++) {
449
- const r = t[n], s = this.placementEventAttributeMappingLookup[r];
450
- if (K(s))
486
+ const r = t[n], o = this.placementEventAttributeMappingLookup[r];
487
+ if (K(o))
451
488
  continue;
452
- let o = !0;
453
- for (let c = 0; c < s.length; c++)
454
- if (!this.doesEventMatchRule(e, s[c])) {
455
- o = !1;
489
+ let s = !0;
490
+ for (let c = 0; c < o.length; c++)
491
+ if (!this.doesEventMatchRule(e, o[c])) {
492
+ s = !1;
456
493
  break;
457
494
  }
458
- o && a().Rokt.setLocalSessionAttribute?.(r, !0);
495
+ s && a().Rokt.setLocalSessionAttribute?.(r, !0);
459
496
  }
460
497
  }
461
498
  capturePageView(e) {
462
499
  let t;
463
500
  try {
464
- t = Y(window.location.href);
465
- const n = z(this.loggingService), r = Je(e);
501
+ t = x(window.location.href);
502
+ const n = z(this.loggingService), r = it(e);
466
503
  n.push(r);
467
- const s = Math.min(n.length, le), o = ye(n);
468
- if (o === 0) {
469
- const c = D() ? "quota" : "ls_unavailable";
504
+ const o = Math.min(n.length, ue), s = ye(n);
505
+ if (s === 0) {
506
+ const c = F() ? "quota" : "ls_unavailable";
470
507
  this.loggingService?.log({
471
508
  message: `Rokt Kit: Failed to persist page view for ${t} [reason: ${c}]`,
472
509
  code: "PAGE_VIEW_CAPTURE_FAILED"
473
510
  });
474
- } else o < s && this.loggingService?.log({
475
- message: `Rokt Kit: Page view storage reduced from ${s} to ${o} record(s) under quota pressure [reason: quota_eviction]`,
511
+ } else s < o && this.loggingService?.log({
512
+ message: `Rokt Kit: Page view storage reduced from ${o} to ${s} record(s) under quota pressure [reason: quota_eviction]`,
476
513
  code: "PAGE_VIEW_QUOTA_EVICTION"
477
514
  });
478
515
  } catch (n) {
479
- const r = D() ? "exception" : "ls_unavailable", s = n instanceof Error ? n.message : String(n);
516
+ const r = F() ? "exception" : "ls_unavailable", o = n instanceof Error ? n.message : String(n);
480
517
  this.loggingService?.log({
481
- message: `Rokt Kit: Failed to capture page view for ${t}: ${s} [reason: ${r}]`,
518
+ message: `Rokt Kit: Failed to capture page view for ${t}: ${o} [reason: ${r}]`,
482
519
  code: "PAGE_VIEW_CAPTURE_FAILED"
483
520
  });
484
521
  }
@@ -506,13 +543,13 @@ const m = class m {
506
543
  if (!window.mParticle || typeof a().logEvent != "function" || !_(e))
507
544
  return;
508
545
  const t = a().EventType.Other;
509
- a().logEvent(we, t, e);
546
+ a().logEvent(Ce, t, e);
510
547
  }
511
548
  setRoktSessionId(e) {
512
549
  if (!(!e || typeof e != "string"))
513
550
  try {
514
551
  const t = a().getInstance();
515
- t && T(t.setIntegrationAttribute) && t.setIntegrationAttribute(L, {
552
+ t && T(t.setIntegrationAttribute) && t.setIntegrationAttribute(b, {
516
553
  roktSessionId: e
517
554
  });
518
555
  } catch {
@@ -527,28 +564,40 @@ const m = class m {
527
564
  return a()?.getDeviceId?.() || void 0;
528
565
  }
529
566
  attachLauncher(e, t, n = []) {
567
+ Te(this._launcherAttachState, {
568
+ accountId: e,
569
+ launcherOptions: t || {},
570
+ legacyRoktExtensions: n
571
+ });
530
572
  const r = {
531
573
  accountId: e,
532
574
  ...t || {}
533
575
  };
534
- let s;
535
- this.isPartnerInLocalLauncherTestGroup() ? s = Promise.resolve(window.Rokt.createLocalLauncher(r)) : s = window.Rokt.createLauncher(r), s.then(async (o) => {
536
- await je(n, o), this.initRoktLauncher(o);
537
- }).catch((o) => {
538
- console.error("Error creating Rokt launcher:", o);
576
+ let o;
577
+ return this.isPartnerInLocalLauncherTestGroup() ? o = Promise.resolve(window.Rokt.createLocalLauncher(r)) : o = window.Rokt.createLauncher(r), o.then(async (s) => {
578
+ await Qe([...n], s), this.initRoktLauncher(s);
579
+ }).catch((s) => {
580
+ Oe(this._launcherAttachState), console.error("Error creating Rokt launcher:", s);
539
581
  });
540
582
  }
583
+ recreateLauncherIfTerminated() {
584
+ return Ue(
585
+ this._launcherAttachState,
586
+ this.isLauncherReadyToAttach(),
587
+ (e) => this.attachLauncher(e.accountId, e.launcherOptions, e.legacyRoktExtensions)
588
+ );
589
+ }
541
590
  initRoktLauncher(e) {
542
- window.Rokt && (window.Rokt.currentLauncher = e), this.launcher = e;
591
+ window.Rokt && (window.Rokt.currentLauncher = e), this.launcher = e, be(this._launcherAttachState);
543
592
  const t = a().Rokt?.filters;
544
- 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, ie(this.domain, this.integrationName), a().Rokt.attachKit(this);
593
+ 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, ne(this.domain, this.integrationName), a().Rokt.attachKit(this);
545
594
  }
546
595
  fetchOptimizely() {
547
596
  const e = a()._getActiveForwarders().filter((t) => t.name === "Optimizely");
548
597
  try {
549
598
  if (e.length > 0 && window.optimizely) {
550
599
  const t = window.optimizely.get("state");
551
- return !t || !t.getActiveExperimentIds ? {} : t.getActiveExperimentIds().reduce((s, o) => (s["rokt.custom.optimizely.experiment." + o + ".variationId"] = t.getVariationMap()[o].id, s), {});
600
+ return !t || !t.getActiveExperimentIds ? {} : t.getActiveExperimentIds().reduce((o, s) => (o["rokt.custom.optimizely.experiment." + s + ".variationId"] = t.getVariationMap()[s].id, o), {});
552
601
  }
553
602
  } catch (t) {
554
603
  console.error("Error fetching Optimizely attributes:", t);
@@ -576,37 +625,37 @@ const m = class m {
576
625
  /**
577
626
  * Initializes the Rokt forwarder with settings from the mParticle server.
578
627
  */
579
- init(e, t, n, r, s) {
580
- const o = e, c = o.accountId;
581
- this.userAttributes = b(s), this._onboardingExpProvider = o.onboardingExpProvider;
582
- const u = P(o.placementEventMapping);
583
- this.placementEventMappingLookup = Z(u);
628
+ init(e, t, n, r, o) {
629
+ const s = e, c = s.accountId;
630
+ this.userAttributes = L(o), this._onboardingExpProvider = s.onboardingExpProvider;
631
+ const u = P(s.placementEventMapping);
632
+ this.placementEventMappingLookup = ee(u);
584
633
  const l = P(
585
- o.placementEventAttributeMapping
634
+ s.placementEventAttributeMapping
586
635
  );
587
- this.placementEventAttributeMappingLookup = ee(l), o.hashedEmailUserIdentityType && (this._mappedEmailSha256Key = o.hashedEmailUserIdentityType.toLowerCase()), this._workspaceIdSyncApiKey = E(o.workspaceIdSyncApiKey) ? o.workspaceIdSyncApiKey : void 0;
588
- const g = a().Rokt?.domain, { roktExtensionsQueryParams: M, legacyRoktExtensions: v, loadThankYouElement: w } = X(
589
- o.roktExtensions
636
+ this.placementEventAttributeMappingLookup = te(l), s.hashedEmailUserIdentityType && (this._mappedEmailSha256Key = s.hashedEmailUserIdentityType.toLowerCase()), this._workspaceIdSyncApiKey = E(s.workspaceIdSyncApiKey) ? s.workspaceIdSyncApiKey : void 0;
637
+ const g = a().Rokt?.domain, { roktExtensionsQueryParams: M, legacyRoktExtensions: v, loadThankYouElement: w } = Z(
638
+ s.roktExtensions
590
639
  ), f = {
591
640
  ...a().Rokt?.launcherOptions || {}
592
641
  };
593
- this.integrationName = He(f.integrationName), f.integrationName = this.integrationName, this.domain = g;
594
- const A = {
595
- loggingUrl: o.loggingUrl,
596
- errorUrl: o.errorUrl,
642
+ this.integrationName = Xe(f.integrationName), f.integrationName = this.integrationName, this.domain = g;
643
+ const y = {
644
+ loggingUrl: s.loggingUrl,
645
+ errorUrl: s.errorUrl,
597
646
  integrationDomain: g,
598
647
  isLoggingEnabled: a().config?.isLoggingEnabled === !0
599
- }, I = new ne(
600
- A,
648
+ }, I = new re(
649
+ y,
601
650
  this.integrationName,
602
651
  window.__rokt_li_guid__,
603
- o.accountId
604
- ), k = new re(
605
- A,
652
+ s.accountId
653
+ ), k = new oe(
654
+ y,
606
655
  I,
607
656
  this.integrationName,
608
657
  window.__rokt_li_guid__,
609
- o.accountId
658
+ s.accountId
610
659
  );
611
660
  if (this.errorReportingService = I, this.loggingService = k, this.isTargetingDisabled())
612
661
  try {
@@ -620,33 +669,34 @@ const m = class m {
620
669
  });
621
670
  }
622
671
  return a()._registerErrorReportingService && a()._registerErrorReportingService(I), a()._registerLoggingService && a()._registerLoggingService(k), n ? (this.testHelpers = {
623
- generateLauncherScript: J,
624
- generateThankYouElementScript: B,
625
- extractRoktExtensionConfig: X,
626
- hashEventMessage: te,
672
+ generateLauncherScript: B,
673
+ generateThankYouElementScript: Q,
674
+ extractRoktExtensionConfig: Z,
675
+ hashEventMessage: ie,
627
676
  parseSettingsString: P,
628
- generateMappedEventLookup: Z,
629
- generateMappedEventAttributeLookup: ee,
630
- sendAdBlockMeasurementSignals: ie,
631
- createAutoRemovedIframe: F,
632
- djb2: ge,
677
+ generateMappedEventLookup: ee,
678
+ generateMappedEventAttributeLookup: te,
679
+ sendAdBlockMeasurementSignals: ne,
680
+ createAutoRemovedIframe: D,
681
+ djb2: pe,
633
682
  setAllowedOriginHashes: (h) => {
634
683
  m._allowedOriginHashes = h;
635
684
  },
636
685
  ReportingTransport: W,
637
- ErrorReportingService: ne,
638
- LoggingService: re,
639
- RateLimiter: pe,
686
+ ErrorReportingService: re,
687
+ LoggingService: oe,
688
+ RateLimiter: fe,
640
689
  ErrorCodes: G,
641
- WSDKErrorSeverity: S
642
- }, this.attachLauncher(c, f), "Successfully initialized: " + d) : (w && (a().Rokt.flushOnShoppableAdsReadyMessageQueue?.(this), Q(Oe, B(g), {
690
+ WSDKErrorSeverity: S,
691
+ resetLauncherAttachState: () => Ne(this._launcherAttachState)
692
+ }, this.attachLauncher(c, f), "Successfully initialized: " + d) : (w && (a().Rokt.flushOnShoppableAdsReadyMessageQueue?.(this), X(xe, Q(g), {
643
693
  onLoad: () => {
644
694
  this._isThankYouElementLoaded = !0, this._thankYouElementOnLoadCallback && this._thankYouElementOnLoadCallback();
645
695
  },
646
696
  onError: (h) => {
647
697
  console.error("Error loading Rokt Thank You Element script:", h);
648
698
  }
649
- })), this.isLauncherReadyToAttach() ? this.attachLauncher(c, f, v) : (Q(Pe, J(g, M), {
699
+ })), this.isLauncherReadyToAttach() ? this.attachLauncher(c, f, v) : (X(De, B(g, M), {
650
700
  onLoad: () => {
651
701
  this.isLauncherReadyToAttach() ? this.attachLauncher(c, f, v) : console.error("Rokt object is not available after script load.");
652
702
  },
@@ -656,10 +706,10 @@ const m = class m {
656
706
  }), this.captureTiming(m.PERFORMANCE_MARKS.RoktScriptAppended)), "Successfully initialized: " + d);
657
707
  }
658
708
  process(e) {
659
- if (this.isTargetingDisabled() || (e.EventDataType === Ue && (ke(this.loggingService), this.capturePageView(e)), e.EventDataType === Ce && (de(this.loggingService), q(), $())), !this.isKitReady())
709
+ if (this.isTargetingDisabled() || (e.EventDataType === Ge && (Re(this.loggingService), this.capturePageView(e)), e.EventDataType === We && (he(this.loggingService), q(), $())), !this.isKitReady())
660
710
  return "Kit not ready for forwarder: " + d;
661
711
  if (T(a().Rokt?.setLocalSessionAttribute) && (K(this.placementEventAttributeMappingLookup) || this.applyPlacementEventAttributeMapping(e), !K(this.placementEventMappingLookup))) {
662
- const t = te(e.EventDataType, e.EventCategory, e.EventName ?? "");
712
+ const t = ie(e.EventDataType, e.EventCategory, e.EventName ?? "");
663
713
  this.placementEventMappingLookup[String(t)] && a().Rokt.setLocalSessionAttribute?.(this.placementEventMappingLookup[String(t)], !0);
664
714
  }
665
715
  return "Successfully sent to forwarder: " + d;
@@ -678,7 +728,7 @@ const m = class m {
678
728
  return delete this.userAttributes[e], "Successfully removed user attribute for forwarder: " + d;
679
729
  }
680
730
  handleIdentityComplete(e, t) {
681
- return this.userAttributes = b(e.getAllUserAttributes()), "Successfully called " + t + " for forwarder: " + d;
731
+ return this.userAttributes = L(e.getAllUserAttributes()), "Successfully called " + t + " for forwarder: " + d;
682
732
  }
683
733
  onUserIdentified(e) {
684
734
  const t = e;
@@ -691,19 +741,19 @@ const m = class m {
691
741
  const n = a().Identity?.search;
692
742
  if (typeof n != "function")
693
743
  return this.userIdentifiedInWorkspace = !1, this._workspaceLastSearchedIdentitiesKey = void 0, Promise.resolve();
694
- const r = e.getUserIdentities ? e.getUserIdentities().userIdentities : null, s = {};
744
+ const r = e.getUserIdentities ? e.getUserIdentities().userIdentities : null, o = {};
695
745
  if (r)
696
746
  for (const u of Object.keys(r)) {
697
747
  const l = r[u];
698
- E(l) && l.length > 0 && (s[u] = l);
748
+ E(l) && l.length > 0 && (o[u] = l);
699
749
  }
700
- const o = Object.keys(s);
701
- if (o.length === 0)
750
+ const s = Object.keys(o);
751
+ if (s.length === 0)
702
752
  return this.userIdentifiedInWorkspace = !1, this._workspaceLastSearchedIdentitiesKey = void 0, Promise.resolve();
703
- const c = o.sort().map((u) => `${u}=${s[u]}`).join("&");
753
+ const c = s.sort().map((u) => `${u}=${o[u]}`).join("&");
704
754
  return c === this._workspaceLastSearchedIdentitiesKey ? this._workspaceSearchInFlightPromise || Promise.resolve() : (this.userIdentifiedInWorkspace = !1, this._workspaceLastSearchedIdentitiesKey = c, new Promise((u) => {
705
755
  try {
706
- n(t, s, (l) => {
756
+ n(t, o, (l) => {
707
757
  l?.httpCode === 200 && (this.userIdentifiedInWorkspace = !0), u();
708
758
  });
709
759
  } catch (l) {
@@ -741,36 +791,47 @@ const m = class m {
741
791
  * rejects it as the awaited return of an async function (TS1058) —
742
792
  * working around that would require a cast or wrapping every return in
743
793
  * `Promise.resolve(...)`. The inner work runs in `_dispatchPlacements`;
744
- * this wrapper just gates it on the in-flight search via `Promise.race`.
794
+ * this wrapper just gates it on the in-flight search via `Promise.race`,
795
+ * and on a post-terminate createLauncher when the SPA needs a new instance.
745
796
  */
746
797
  selectPlacements(e) {
798
+ const t = this.recreateLauncherIfTerminated();
799
+ if (t) {
800
+ const n = this._workspaceSearchInFlightPromise, r = n ? Promise.race([
801
+ n,
802
+ new Promise((o) => setTimeout(o, J))
803
+ ]) : Promise.resolve();
804
+ return Promise.all([t, r]).then(
805
+ () => this._dispatchPlacements(e)
806
+ );
807
+ }
747
808
  if (this._workspaceSearchInFlightPromise) {
748
- const t = this._workspaceSearchInFlightPromise;
809
+ const n = this._workspaceSearchInFlightPromise;
749
810
  return Promise.race([
750
- t,
751
- new Promise((n) => setTimeout(n, Ye))
811
+ n,
812
+ new Promise((r) => setTimeout(r, J))
752
813
  ]).then(() => this._dispatchPlacements(e));
753
814
  }
754
815
  return this._dispatchPlacements(e);
755
816
  }
756
817
  _dispatchPlacements(e) {
757
- const t = e && e.attributes || {}, r = { ...b(this.userAttributes), ...t }, s = this.filters || {}, o = s.userAttributeFilters || [], c = s.filteredUser || null, u = c ? c.getMPID() : null;
818
+ const t = e && e.attributes || {}, r = { ...L(this.userAttributes), ...t }, o = this.filters || {}, s = o.userAttributeFilters || [], c = o.filteredUser || null, u = c ? c.getMPID() : null;
758
819
  let l;
759
- s ? s.filterUserAttributes ? l = s.filterUserAttributes(r, o) : l = r : (console.warn("Rokt Kit: No filters available, using user attributes"), l = r), this.userAttributes = b(l);
760
- const g = this._onboardingExpProvider === "Optimizely" ? this.fetchOptimizely() : {}, M = this.returnUserIdentities(c), v = this.returnLocalSessionAttributes(), w = Ae(z(this.loggingService)), f = Re(), A = this.readMpSessionId(), I = this.readMpDeviceId(), k = {
820
+ o ? o.filterUserAttributes ? l = o.filterUserAttributes(r, s) : l = r : (console.warn("Rokt Kit: No filters available, using user attributes"), l = r), this.userAttributes = L(l);
821
+ const g = this._onboardingExpProvider === "Optimizely" ? this.fetchOptimizely() : {}, M = this.returnUserIdentities(c), v = this.returnLocalSessionAttributes(), w = ke(z(this.loggingService)), f = ve(), y = this.readMpSessionId(), I = this.readMpDeviceId(), k = {
761
822
  ...M,
762
823
  ...l,
763
824
  ...g,
764
825
  ...v,
765
- ...w.length ? { [Me]: JSON.stringify(w) } : {},
766
- ...f ? { [Ke]: f } : {},
767
- ...this.userIdentifiedInWorkspace ? { [Ne]: !0 } : {},
768
- ...A ? { [De]: A } : {},
769
- ...I ? { [Fe]: I } : {},
826
+ ...w.length ? { [Ve]: JSON.stringify(w) } : {},
827
+ ...f ? { [je]: f } : {},
828
+ ...this.userIdentifiedInWorkspace ? { [Ye]: !0 } : {},
829
+ ...y ? { [He]: y } : {},
830
+ ...I ? { [ze]: I } : {},
770
831
  mpid: u
771
- }, h = { ...e, attributes: k }, V = this.launcher.selectPlacements(h), fe = () => this.logSelectPlacementsEvent(k);
772
- return Promise.resolve(V).then((me) => me?.context?.sessionId?.then((Ee) => this.setRoktSessionId(Ee))).catch(() => {
773
- }).finally(fe), V;
832
+ }, h = { ...e, attributes: k }, V = this.launcher.selectPlacements(h), me = () => this.logSelectPlacementsEvent(k);
833
+ return Promise.resolve(V).then((Ee) => Ee?.context?.sessionId?.then((_e) => this.setRoktSessionId(_e))).catch(() => {
834
+ }).finally(me), V;
774
835
  }
775
836
  /**
776
837
  * Passes attributes to the Rokt Web SDK for client-side hashing.
@@ -786,6 +847,18 @@ const m = class m {
786
847
  use(e) {
787
848
  return this.isKitReady() ? !e || !E(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")));
788
849
  }
850
+ /**
851
+ * Tears down the Rokt launcher and the placements it rendered.
852
+ *
853
+ * The kit's launcher reference is left in place so isKitReady() stays true.
854
+ * The Web SDK clears its memoized launcher on terminate, so a later
855
+ * createLauncher (SPA navigation) produces a new instance. The next
856
+ * selectPlacements call re-attaches that instance. Nulling the reference
857
+ * here would flip the kit to not-ready with no drain path for queued calls.
858
+ */
859
+ terminate() {
860
+ return this.isKitReady() ? (Pe(this._launcherAttachState), this.launcher.terminate()) : (console.error("Rokt Kit: Not initialized"), Promise.resolve());
861
+ }
789
862
  /**
790
863
  * Registers a callback to be invoked once rokt-thank-you-element.js becomes available.
791
864
  */
@@ -796,11 +869,11 @@ const m = class m {
796
869
  m._allowedOriginHashes = [-553112570, 549508659], m.PERFORMANCE_MARKS = {
797
870
  RoktScriptAppended: "mp:RoktScriptAppended"
798
871
  }, m.EMAIL_SHA256_KEY = "emailsha256";
799
- let y = m;
800
- function Be() {
801
- return L;
872
+ let A = m;
873
+ function nt() {
874
+ return b;
802
875
  }
803
- function Qe(i) {
876
+ function rt(i) {
804
877
  if (!i) {
805
878
  window.console.log("You must pass a config object to register the kit " + d);
806
879
  return;
@@ -810,17 +883,17 @@ function Qe(i) {
810
883
  return;
811
884
  }
812
885
  _(i.kits) ? i.kits[d] = {
813
- constructor: y
886
+ constructor: A
814
887
  } : (i.kits = {}, i.kits[d] = {
815
- constructor: y
888
+ constructor: A
816
889
  }), window.console.log("Successfully registered " + d + " to your mParticle configuration");
817
890
  }
818
891
  typeof window < "u" && window.mParticle && a().addForwarder && a().addForwarder({
819
892
  name: d,
820
- constructor: y,
821
- getId: Be
893
+ constructor: A,
894
+ getId: nt
822
895
  });
823
896
  export {
824
- Qe as register
897
+ rt as register
825
898
  };
826
899
  //# sourceMappingURL=Rokt-Kit.esm.js.map
@@ -1,2 +1,2 @@
1
- var RoktKit=(function(M){"use strict";const me=["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"],Ee=new Set(me);function V(i){return Ee.has(i.toLowerCase())}function R(i){const e={},t=i||{},n=Object.keys(t);for(let r=0;r<n.length;r++){const s=n[r];V(s)||(e[s]=t[s])}return e}function E(i){return typeof i=="object"&&i!==null&&!Array.isArray(i)}function _(i){return typeof i=="string"}function w(i){return typeof i=="function"}function K(i){return i==null?!0:typeof i=="object"?Object.keys(i).length===0:!1}function D(i){try{const e=new URL(i);return e.search="",e.toString()}catch{return i}}const H="__rokt_ls_probe__";function F(){try{return window.localStorage.setItem(H,"1"),window.localStorage.removeItem(H),!0}catch{return!1}}function b(i){try{const e=window.localStorage.getItem(i);return e===null?null:JSON.parse(e)}catch{return null}}function z(i,e){try{return window.localStorage.setItem(i,JSON.stringify(e)),!0}catch{return!1}}function q(i){try{window.localStorage.removeItem(i)}catch{}}function T(i,e){const t=b(i);return E(t)?t[e]:void 0}function Y(i,e,t){const n=b(i),r=E(n)?{...n}:{};return r[e]=t,z(i,r)}function $(i,e){const t=b(i);if(!E(t)||!(e in t))return;const n={...t};delete n[e],Object.keys(n).length===0?q(i):z(i,n)}const g="mp-rokt-kit",A="pageViews",L="utmParams",J="mpPageViews",B=25,_e=["utm_source","utm_medium","utm_campaign","utm_term","utm_content"];function Q(i){return i.slice(-B)}function X(i){const e=b(J);if(e===null)return;!(T(g,A)!==void 0)&&Array.isArray(e)&&(i?.log({message:"Rokt Kit: Migrating legacy page-view storage",code:"PAGE_VIEW_LEGACY_MIGRATION"}),Y(g,A,e)||i?.log({message:"Rokt Kit: Failed to migrate legacy page-view storage [reason: migration_retry]",code:"PAGE_VIEW_CAPTURE_FAILED"})),q(J)}function Z(i){X(i);const e=T(g,A);return Array.isArray(e)?e:[]}function Ie(i){const e=Q(i);for(let t=0;t<e.length;t++){const n=e.slice(t);if(Y(g,A,n))return n.length}return 0}function ee(){$(g,A)}function Se(i){const e=Q(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 ye(i){if(T(g,L)!==void 0)return;const e=new URLSearchParams(window.location.search),t={};for(const r of _e){const s=e.get(r);s&&(t[r]=s)}if(Object.keys(t).length===0)return;const n=Object.keys(t).join(", ");if(!Y(g,L,t)){const r=F()?"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 Ae(){const i=T(g,L);return E(i)?i:null}function te(){$(g,L)}function ke(){const e=document.querySelector('link[rel="canonical"]')?.href;if(e)return D(e)}const d="Rokt",P=181,ve="selectPlacements",Re="apps.roktecommerce.com",we=.1,be="ThankYouPageJourney",Te="rokt-launcher",Le="rokt-thank-you-element",Pe="userIdentifiedInWorkspace",Oe=3,Ne=2,Ue="page_events",Ce="page_view_attributes",Me="mparticle_session_id",Ke="mparticle_device_id",De=500,G={UNKNOWN_ERROR:"UNKNOWN_ERROR",UNHANDLED_EXCEPTION:"UNHANDLED_EXCEPTION",IDENTITY_REQUEST:"IDENTITY_REQUEST",LOG_DELIVERY_FAILURE:"LOG_DELIVERY_FAILURE"},I={ERROR:"ERROR",INFO:"INFO",WARNING:"WARNING"},Fe="apps.rokt-api.com",Ye="/v1/log",Ge="/v1/errors",xe=10;function a(){return window.mParticle}function ie(i,e){const n=[O(i),"/wsdk/integrations/launcher.js"].join("");return!e||e.length===0?n:n+"?extensions="+e.join(",")}function ne(i){return[O(i),"/rokt-elements/rokt-element-thank-you.js"].join("")}function O(i){const e=typeof i<"u"?i:Fe;return e.includes("://")?e.replace(/\/+$/,""):["https://",e].join("")}function re(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 O(r)+t}function se(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 N(i){if(!i)return[];try{return JSON.parse(i.replace(/&quot;/g,'"'))}catch{console.error("Settings string contains invalid JSON")}return[]}function oe(i){const e=i?N(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(be)):t.push(o)}return{roktExtensionsQueryParams:t,legacyRoktExtensions:n,loadThankYouElement:r}}async function We(i,e){const t=[];if(e)for(const n of i)t.push(e.use(n));return Promise.all(t)}function ae(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 ce(i){const e={};if(!Array.isArray(i))return e;for(let t=0;t<i.length;t++){const n=i[t];if(!n||!_(n.value)||!_(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 le(i,e,t){return a().generateHash([i,e,t].join(""))}function je(i){let n="mParticle_wsdkv_"+a().getVersion()+"_kitv_"+"1.35.0";return i&&(n+="_"+i),n}function ue(i){let e=5381;for(let t=0;t<i.length;t++)e=(e<<5)+e+i.charCodeAt(t),e=e&e;return e}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 de(i,e){const t=ue(window.location.origin);if(S._allowedOriginHashes.indexOf(t)===-1||Math.random()>=we)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?O(i):"https://apps.rokt.com";x(c+"/v1/wsdk-init/index.html?"+o),x("https://"+Re+"/v1/wsdk-init/index.html?"+o+"&isControl=true")}function Ve(){return typeof window<"u"&&!!window.location?.search?.toLowerCase().includes("mp_enable_logging=true")}function He(){return typeof window<"u"?window.location?.href:void 0}function ze(){return typeof window<"u"?window.navigator?.userAgent:void 0}class he{constructor(){this._logCount={}}incrementAndCheck(e){const n=(this._logCount[e]||0)+1;return this._logCount[e]=n,n>xe}}class W{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 he,this._isEnabled=Ve()||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||G.UNKNOWN_ERROR,url:He(),deviceInfo:ze(),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 ge{constructor(e,t,n,r,s){this._transport=new W(e,t,n,r,s),this._errorUrl=re(e?.errorUrl,e?.integrationDomain,Ge)}report(e){if(!e)return;const t=e.severity||I.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 W(e,n,r,s,o),this._loggingUrl=re(e?.loggingUrl,e?.integrationDomain,Ye),this._errorReportingService=t}log(e){e&&this._transport.send(this._loggingUrl,I.INFO,e.message,e.code,void 0,t=>{if(this._errorReportingService){const n=typeof t.statusCode=="number";this._errorReportingService.report({message:"LoggingService: Failed to send log: "+t.message,code:G.LOG_DELIVERY_FAILURE,severity:n?I.ERROR:I.WARNING})}})}}function qe(i){const e=D(window.location.href),t=i.EventAttributes?.title||document.title,n=ke(),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 f=class f{constructor(){this.name=d,this.id=P,this.moduleId=P,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}getEventAttributeValue(e,t){const n=e&&e.EventAttributes;return!n||typeof n[t]>"u"?null:n[t]}doesEventAttributeConditionMatch(e,t){if(!e||!_(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||!_(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(K(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=D(window.location.href);const n=Z(this.loggingService),r=qe(e);n.push(r);const s=Math.min(n.length,B),o=Ie(n);if(o===0){const c=F()?"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=F()?"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"})}}isLauncherReadyToAttach(){return!!window.Rokt&&w(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[f.EMAIL_SHA256_KEY]=e[n]),n&&delete t[n],t}logSelectPlacementsEvent(e){if(!window.mParticle||typeof a().logEvent!="function"||!E(e))return;const t=a().EventType.Other;a().logEvent(ve,t,e)}setRoktSessionId(e){if(!(!e||typeof e!="string"))try{const t=a().getInstance();t&&w(t.setIntegrationAttribute)&&t.setIntegrationAttribute(P,{roktSessionId:e})}catch{}}readMpSessionId(){const e=a()?.sessionManager,t=e?.getSessionId??e?.getSession;if(w(t))return t.call(e)||void 0}readMpDeviceId(){return a()?.getDeviceId?.()||void 0}attachLauncher(e,t,n=[]){const r={accountId:e,...t||{}};let s;this.isPartnerInLocalLauncherTestGroup()?s=Promise.resolve(window.Rokt.createLocalLauncher(r)):s=window.Rokt.createLauncher(r),s.then(async o=>{await We(n,o),this.initRoktLauncher(o)}).catch(o=>{console.error("Error creating Rokt launcher:",o)})}initRoktLauncher(e){window.Rokt&&(window.Rokt.currentLauncher=e),this.launcher=e;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,de(this.domain,this.integrationName),a().Rokt.attachKit(this)}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.userAttributes=R(s),this._onboardingExpProvider=o.onboardingExpProvider;const u=N(o.placementEventMapping);this.placementEventMappingLookup=ae(u);const l=N(o.placementEventAttributeMapping);this.placementEventAttributeMappingLookup=ce(l),o.hashedEmailUserIdentityType&&(this._mappedEmailSha256Key=o.hashedEmailUserIdentityType.toLowerCase()),this._workspaceIdSyncApiKey=_(o.workspaceIdSyncApiKey)?o.workspaceIdSyncApiKey:void 0;const p=a().Rokt?.domain,{roktExtensionsQueryParams:j,legacyRoktExtensions:U,loadThankYouElement:C}=oe(o.roktExtensions),m={...a().Rokt?.launcherOptions||{}};this.integrationName=je(m.integrationName),m.integrationName=this.integrationName,this.domain=p;const k={loggingUrl:o.loggingUrl,errorUrl:o.errorUrl,integrationDomain:p,isLoggingEnabled:a().config?.isLoggingEnabled===!0},y=new ge(k,this.integrationName,window.__rokt_li_guid__,o.accountId),v=new pe(k,y,this.integrationName,window.__rokt_li_guid__,o.accountId);if(this.errorReportingService=y,this.loggingService=v,this.isTargetingDisabled())try{ee(),te()}catch(h){this.errorReportingService?.report({message:"Rokt Kit: Failed to clear page views when targeting is disabled",code:"PAGE_VIEW_CAPTURE_FAILED",severity:I.INFO,stackTrace:h instanceof Error?h.stack:void 0})}return a()._registerErrorReportingService&&a()._registerErrorReportingService(y),a()._registerLoggingService&&a()._registerLoggingService(v),n?(this.testHelpers={generateLauncherScript:ie,generateThankYouElementScript:ne,extractRoktExtensionConfig:oe,hashEventMessage:le,parseSettingsString:N,generateMappedEventLookup:ae,generateMappedEventAttributeLookup:ce,sendAdBlockMeasurementSignals:de,createAutoRemovedIframe:x,djb2:ue,setAllowedOriginHashes:h=>{f._allowedOriginHashes=h},ReportingTransport:W,ErrorReportingService:ge,LoggingService:pe,RateLimiter:he,ErrorCodes:G,WSDKErrorSeverity:I},this.attachLauncher(c,m),"Successfully initialized: "+d):(C&&(a().Rokt.flushOnShoppableAdsReadyMessageQueue?.(this),se(Le,ne(p),{onLoad:()=>{this._isThankYouElementLoaded=!0,this._thankYouElementOnLoadCallback&&this._thankYouElementOnLoadCallback()},onError:h=>{console.error("Error loading Rokt Thank You Element script:",h)}})),this.isLauncherReadyToAttach()?this.attachLauncher(c,m,U):(se(Te,ie(p,j),{onLoad:()=>{this.isLauncherReadyToAttach()?this.attachLauncher(c,m,U):console.error("Rokt object is not available after script load.")},onError:h=>{console.error("Error loading Rokt launcher script:",h)}}),this.captureTiming(f.PERFORMANCE_MARKS.RoktScriptAppended)),"Successfully initialized: "+d)}process(e){if(this.isTargetingDisabled()||(e.EventDataType===Oe&&(ye(this.loggingService),this.capturePageView(e)),e.EventDataType===Ne&&(X(this.loggingService),ee(),te())),!this.isKitReady())return"Kit not ready for forwarder: "+d;if(w(a().Rokt?.setLocalSessionAttribute)&&(K(this.placementEventAttributeMappingLookup)||this.applyPlacementEventAttributeMapping(e),!K(this.placementEventMappingLookup))){const t=le(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 V(e)||(this.userAttributes[e]=t),"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=R(e.getAllUserAttributes()),"Successfully called "+t+" for forwarder: "+d}onUserIdentified(e){const t=e;return this.filters.filteredUser=t,this._workspaceSearchInFlightPromise=this.search(t),this.handleIdentityComplete(e,"onUserIdentified")}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];_(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.handleIdentityComplete(e,"onLogoutComplete")}onModifyComplete(e,t){return this.handleIdentityComplete(e,"onModifyComplete")}selectPlacements(e){if(this._workspaceSearchInFlightPromise){const t=this._workspaceSearchInFlightPromise;return Promise.race([t,new Promise(n=>setTimeout(n,De))]).then(()=>this._dispatchPlacements(e))}return this._dispatchPlacements(e)}_dispatchPlacements(e){const t=e&&e.attributes||{},r={...R(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=R(l);const p=this._onboardingExpProvider==="Optimizely"?this.fetchOptimizely():{},j=this.returnUserIdentities(c),U=this.returnLocalSessionAttributes(),C=Se(Z(this.loggingService)),m=Ae(),k=this.readMpSessionId(),y=this.readMpDeviceId(),v={...j,...l,...p,...U,...C.length?{[Ue]:JSON.stringify(C)}:{},...m?{[Ce]:m}:{},...this.userIdentifiedInWorkspace?{[Pe]:!0}:{},...k?{[Me]:k}:{},...y?{[Ke]:y}:{},mpid:u},h={...e,attributes:v},fe=this.launcher.selectPlacements(h),Be=()=>this.logSelectPlacementsEvent(v);return Promise.resolve(fe).then(Qe=>Qe?.context?.sessionId?.then(Xe=>this.setRoktSessionId(Xe))).catch(()=>{}).finally(Be),fe}hashAttributes(e){return this.isKitReady()?this.launcher.hashAttributes(e):(console.error("Rokt Kit: Not initialized"),null)}use(e){return this.isKitReady()?!e||!_(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")))}onShoppableAdsReady(e){this._isThankYouElementLoaded?e():this._thankYouElementOnLoadCallback=e}};f._allowedOriginHashes=[-553112570,549508659],f.PERFORMANCE_MARKS={RoktScriptAppended:"mp:RoktScriptAppended"},f.EMAIL_SHA256_KEY="emailsha256";let S=f;function $e(){return P}function Je(i){if(!i){window.console.log("You must pass a config object to register the kit "+d);return}if(!E(i)){window.console.log("'config' must be an object. You passed in a "+typeof i);return}E(i.kits)?i.kits[d]={constructor:S}:(i.kits={},i.kits[d]={constructor:S}),window.console.log("Successfully registered "+d+" to your mParticle configuration")}return typeof window<"u"&&window.mParticle&&a().addForwarder&&a().addForwarder({name:d,constructor:S,getId:$e}),M.register=Je,Object.defineProperty(M,Symbol.toStringTag,{value:"Module"}),M})({});
1
+ var RoktKit=(function(M){"use strict";const Ee=["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"],_e=new Set(Ee);function V(i){return _e.has(i.toLowerCase())}function v(i){const e={},t=i||{},n=Object.keys(t);for(let r=0;r<n.length;r++){const o=n[r];V(o)||(e[o]=t[o])}return e}function E(i){return typeof i=="object"&&i!==null&&!Array.isArray(i)}function _(i){return typeof i=="string"}function w(i){return typeof i=="function"}function K(i){return i==null?!0:typeof i=="object"?Object.keys(i).length===0:!1}function F(i){try{const e=new URL(i);return e.search="",e.toString()}catch{return i}}const H="__rokt_ls_probe__";function D(){try{return window.localStorage.setItem(H,"1"),window.localStorage.removeItem(H),!0}catch{return!1}}function b(i){try{const e=window.localStorage.getItem(i);return e===null?null:JSON.parse(e)}catch{return null}}function z(i,e){try{return window.localStorage.setItem(i,JSON.stringify(e)),!0}catch{return!1}}function q(i){try{window.localStorage.removeItem(i)}catch{}}function L(i,e){const t=b(i);return E(t)?t[e]:void 0}function Y(i,e,t){const n=b(i),r=E(n)?{...n}:{};return r[e]=t,z(i,r)}function $(i,e){const t=b(i);if(!E(t)||!(e in t))return;const n={...t};delete n[e],Object.keys(n).length===0?q(i):z(i,n)}const g="mp-rokt-kit",A="pageViews",T="utmParams",J="mpPageViews",B=25,Ie=["utm_source","utm_medium","utm_campaign","utm_term","utm_content"];function Q(i){return i.slice(-B)}function X(i){const e=b(J);if(e===null)return;!(L(g,A)!==void 0)&&Array.isArray(e)&&(i?.log({message:"Rokt Kit: Migrating legacy page-view storage",code:"PAGE_VIEW_LEGACY_MIGRATION"}),Y(g,A,e)||i?.log({message:"Rokt Kit: Failed to migrate legacy page-view storage [reason: migration_retry]",code:"PAGE_VIEW_CAPTURE_FAILED"})),q(J)}function Z(i){X(i);const e=L(g,A);return Array.isArray(e)?e:[]}function Se(i){const e=Q(i);for(let t=0;t<e.length;t++){const n=e.slice(t);if(Y(g,A,n))return n.length}return 0}function ee(){$(g,A)}function ye(i){const e=Q(i);return e.map((t,n)=>{const r=t.activeTimeOnSite,o=r!==void 0&&Number.isFinite(r),c=e[n+1]?.activeTimeOnSite,u=c!==void 0&&Number.isFinite(c),l=o&&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}:{},...o?{activeTimeOnSite:r}:{},...l!==void 0&&l>=0?{activeTimeOnPage:l}:{}}})}function Ae(i){if(L(g,T)!==void 0)return;const e=new URLSearchParams(window.location.search),t={};for(const r of Ie){const o=e.get(r);o&&(t[r]=o)}if(Object.keys(t).length===0)return;const n=Object.keys(t).join(", ");if(!Y(g,T,t)){const r=D()?"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 ke(){const i=L(g,T);return E(i)?i:null}function te(){$(g,T)}function Re(){const e=document.querySelector('link[rel="canonical"]')?.href;if(e)return F(e)}function ve(){return{context:null,lifecycle:"idle",recreateInFlight:null}}function we(i,e){i.context={accountId:e.accountId,launcherOptions:{...e.launcherOptions},legacyRoktExtensions:[...e.legacyRoktExtensions]}}function be(i){i.lifecycle="attached"}function Le(i){i.lifecycle!=="idle"&&(i.lifecycle="terminated")}function Te(i){i.lifecycle="terminated"}function Pe(i){i.context=null,i.lifecycle="idle",i.recreateInFlight=null}function Oe(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",P=181,Ne="selectPlacements",Ue="apps.roktecommerce.com",Ce=.1,Me="ThankYouPageJourney",Ke="rokt-launcher",Fe="rokt-thank-you-element",De="userIdentifiedInWorkspace",Ye=3,xe=2,Ge="page_events",We="page_view_attributes",je="mparticle_session_id",Ve="mparticle_device_id",ie=500,x={UNKNOWN_ERROR:"UNKNOWN_ERROR",UNHANDLED_EXCEPTION:"UNHANDLED_EXCEPTION",IDENTITY_REQUEST:"IDENTITY_REQUEST",LOG_DELIVERY_FAILURE:"LOG_DELIVERY_FAILURE"},I={ERROR:"ERROR",INFO:"INFO",WARNING:"WARNING"},He="apps.rokt-api.com",ze="/v1/log",qe="/v1/errors",$e=10;function a(){return window.mParticle}function ne(i,e){const n=[O(i),"/wsdk/integrations/launcher.js"].join("");return!e||e.length===0?n:n+"?extensions="+e.join(",")}function re(i){return[O(i),"/rokt-elements/rokt-element-thank-you.js"].join("")}function O(i){const e=typeof i<"u"?i:He;return e.includes("://")?e.replace(/\/+$/,""):["https://",e].join("")}function oe(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 O(r)+t}function se(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 N(i){if(!i)return[];try{return JSON.parse(i.replace(/&quot;/g,'"'))}catch{console.error("Settings string contains invalid JSON")}return[]}function ae(i){const e=i?N(i):[],t=[],n=[];let r=!1;for(let o=0;o<e.length;o++){const s=e[o].value;s==="thank-you-journey"?(r=!0,n.push(Me)):t.push(s)}return{roktExtensionsQueryParams:t,legacyRoktExtensions:n,loadThankYouElement:r}}async function Je(i,e){const t=[];if(e)for(const n of i)t.push(e.use(n));return Promise.all(t)}function ce(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 le(i){const e={};if(!Array.isArray(i))return e;for(let t=0;t<i.length;t++){const n=i[t];if(!n||!_(n.value)||!_(n.map))continue;const r=n.value,o=n.map;e[r]||(e[r]=[]),e[r].push({eventAttributeKey:o,conditions:Array.isArray(n.conditions)?n.conditions:[]})}return e}function ue(i,e,t){return a().generateHash([i,e,t].join(""))}function Be(i){let n="mParticle_wsdkv_"+a().getVersion()+"_kitv_"+"1.36.0";return i&&(n+="_"+i),n}function de(i){let e=5381;for(let t=0;t<i.length;t++)e=(e<<5)+e+i.charCodeAt(t),e=e&e;return e}function G(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 he(i,e){const t=de(window.location.origin);if(S._allowedOriginHashes.indexOf(t)===-1||Math.random()>=Ce)return;const r=window.__rokt_li_guid__;if(!r||i&&i.includes("://")&&!/^https:\/\//i.test(i))return;const o=window.location.href.split("?")[0].split("#")[0],s="version="+encodeURIComponent(e??"")+"&launcherInstanceGuid="+encodeURIComponent(r)+"&pageUrl="+encodeURIComponent(o),c=i?O(i):"https://apps.rokt.com";G(c+"/v1/wsdk-init/index.html?"+s),G("https://"+Ue+"/v1/wsdk-init/index.html?"+s+"&isControl=true")}function Qe(){return typeof window<"u"&&!!window.location?.search?.toLowerCase().includes("mp_enable_logging=true")}function Xe(){return typeof window<"u"?window.location?.href:void 0}function Ze(){return typeof window<"u"?window.navigator?.userAgent:void 0}class ge{constructor(){this._logCount={}}incrementAndCheck(e){const n=(this._logCount[e]||0)+1;return this._logCount[e]=n,n>$e}}class W{constructor(e,t,n,r,o){this._reporter="mp-wsdk";const s=e.isLoggingEnabled;this._integrationName=t||"",this._launcherInstanceGuid=n,this._accountId=r||null,this._rateLimiter=o||new ge,this._isEnabled=Qe()||s}send(e,t,n,r,o,s){if(!(!this._isEnabled||this._rateLimiter.incrementAndCheck(t)))try{const c={additionalInformation:{message:n,version:this._integrationName},severity:t,code:r||x.UNKNOWN_ERROR,url:Xe(),deviceInfo:Ze(),stackTrace:o,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),s&&s(l)})}catch(c){console.error("ReportingTransport: Failed to send log",c),s&&s(c)}}}class pe{constructor(e,t,n,r,o){this._transport=new W(e,t,n,r,o),this._errorUrl=oe(e?.errorUrl,e?.integrationDomain,qe)}report(e){if(!e)return;const t=e.severity||I.ERROR;this._transport.send(this._errorUrl,t,e.message,e.code,e.stackTrace)}}class fe{constructor(e,t,n,r,o,s){this._transport=new W(e,n,r,o,s),this._loggingUrl=oe(e?.loggingUrl,e?.integrationDomain,ze),this._errorReportingService=t}log(e){e&&this._transport.send(this._loggingUrl,I.INFO,e.message,e.code,void 0,t=>{if(this._errorReportingService){const n=typeof t.statusCode=="number";this._errorReportingService.report({message:"LoggingService: Failed to send log: "+t.message,code:x.LOG_DELIVERY_FAILURE,severity:n?I.ERROR:I.WARNING})}})}}function et(i){const e=F(window.location.href),t=i.EventAttributes?.title||document.title,n=Re(),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 f=class f{constructor(){this.name=d,this.id=P,this.moduleId=P,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=ve()}getEventAttributeValue(e,t){const n=e&&e.EventAttributes;return!n||typeof n[t]>"u"?null:n[t]}doesEventAttributeConditionMatch(e,t){if(!e||!_(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||!_(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 o=0;o<n.length;o++)if(!this.doesEventAttributeConditionMatch(n[o],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],o=this.placementEventAttributeMappingLookup[r];if(K(o))continue;let s=!0;for(let c=0;c<o.length;c++)if(!this.doesEventMatchRule(e,o[c])){s=!1;break}s&&a().Rokt.setLocalSessionAttribute?.(r,!0)}}capturePageView(e){let t;try{t=F(window.location.href);const n=Z(this.loggingService),r=et(e);n.push(r);const o=Math.min(n.length,B),s=Se(n);if(s===0){const c=D()?"quota":"ls_unavailable";this.loggingService?.log({message:`Rokt Kit: Failed to persist page view for ${t} [reason: ${c}]`,code:"PAGE_VIEW_CAPTURE_FAILED"})}else s<o&&this.loggingService?.log({message:`Rokt Kit: Page view storage reduced from ${o} to ${s} record(s) under quota pressure [reason: quota_eviction]`,code:"PAGE_VIEW_QUOTA_EVICTION"})}catch(n){const r=D()?"exception":"ls_unavailable",o=n instanceof Error?n.message:String(n);this.loggingService?.log({message:`Rokt Kit: Failed to capture page view for ${t}: ${o} [reason: ${r}]`,code:"PAGE_VIEW_CAPTURE_FAILED"})}}isLauncherReadyToAttach(){return!!window.Rokt&&w(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[f.EMAIL_SHA256_KEY]=e[n]),n&&delete t[n],t}logSelectPlacementsEvent(e){if(!window.mParticle||typeof a().logEvent!="function"||!E(e))return;const t=a().EventType.Other;a().logEvent(Ne,t,e)}setRoktSessionId(e){if(!(!e||typeof e!="string"))try{const t=a().getInstance();t&&w(t.setIntegrationAttribute)&&t.setIntegrationAttribute(P,{roktSessionId:e})}catch{}}readMpSessionId(){const e=a()?.sessionManager,t=e?.getSessionId??e?.getSession;if(w(t))return t.call(e)||void 0}readMpDeviceId(){return a()?.getDeviceId?.()||void 0}attachLauncher(e,t,n=[]){we(this._launcherAttachState,{accountId:e,launcherOptions:t||{},legacyRoktExtensions:n});const r={accountId:e,...t||{}};let o;return this.isPartnerInLocalLauncherTestGroup()?o=Promise.resolve(window.Rokt.createLocalLauncher(r)):o=window.Rokt.createLauncher(r),o.then(async s=>{await Je([...n],s),this.initRoktLauncher(s)}).catch(s=>{Te(this._launcherAttachState),console.error("Error creating Rokt launcher:",s)})}recreateLauncherIfTerminated(){return Oe(this._launcherAttachState,this.isLauncherReadyToAttach(),e=>this.attachLauncher(e.accountId,e.launcherOptions,e.legacyRoktExtensions))}initRoktLauncher(e){window.Rokt&&(window.Rokt.currentLauncher=e),this.launcher=e,be(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,he(this.domain,this.integrationName),a().Rokt.attachKit(this)}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((o,s)=>(o["rokt.custom.optimizely.experiment."+s+".variationId"]=t.getVariationMap()[s].id,o),{})}}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,o){const s=e,c=s.accountId;this.userAttributes=v(o),this._onboardingExpProvider=s.onboardingExpProvider;const u=N(s.placementEventMapping);this.placementEventMappingLookup=ce(u);const l=N(s.placementEventAttributeMapping);this.placementEventAttributeMappingLookup=le(l),s.hashedEmailUserIdentityType&&(this._mappedEmailSha256Key=s.hashedEmailUserIdentityType.toLowerCase()),this._workspaceIdSyncApiKey=_(s.workspaceIdSyncApiKey)?s.workspaceIdSyncApiKey:void 0;const p=a().Rokt?.domain,{roktExtensionsQueryParams:j,legacyRoktExtensions:U,loadThankYouElement:C}=ae(s.roktExtensions),m={...a().Rokt?.launcherOptions||{}};this.integrationName=Be(m.integrationName),m.integrationName=this.integrationName,this.domain=p;const k={loggingUrl:s.loggingUrl,errorUrl:s.errorUrl,integrationDomain:p,isLoggingEnabled:a().config?.isLoggingEnabled===!0},y=new pe(k,this.integrationName,window.__rokt_li_guid__,s.accountId),R=new fe(k,y,this.integrationName,window.__rokt_li_guid__,s.accountId);if(this.errorReportingService=y,this.loggingService=R,this.isTargetingDisabled())try{ee(),te()}catch(h){this.errorReportingService?.report({message:"Rokt Kit: Failed to clear page views when targeting is disabled",code:"PAGE_VIEW_CAPTURE_FAILED",severity:I.INFO,stackTrace:h instanceof Error?h.stack:void 0})}return a()._registerErrorReportingService&&a()._registerErrorReportingService(y),a()._registerLoggingService&&a()._registerLoggingService(R),n?(this.testHelpers={generateLauncherScript:ne,generateThankYouElementScript:re,extractRoktExtensionConfig:ae,hashEventMessage:ue,parseSettingsString:N,generateMappedEventLookup:ce,generateMappedEventAttributeLookup:le,sendAdBlockMeasurementSignals:he,createAutoRemovedIframe:G,djb2:de,setAllowedOriginHashes:h=>{f._allowedOriginHashes=h},ReportingTransport:W,ErrorReportingService:pe,LoggingService:fe,RateLimiter:ge,ErrorCodes:x,WSDKErrorSeverity:I,resetLauncherAttachState:()=>Pe(this._launcherAttachState)},this.attachLauncher(c,m),"Successfully initialized: "+d):(C&&(a().Rokt.flushOnShoppableAdsReadyMessageQueue?.(this),se(Fe,re(p),{onLoad:()=>{this._isThankYouElementLoaded=!0,this._thankYouElementOnLoadCallback&&this._thankYouElementOnLoadCallback()},onError:h=>{console.error("Error loading Rokt Thank You Element script:",h)}})),this.isLauncherReadyToAttach()?this.attachLauncher(c,m,U):(se(Ke,ne(p,j),{onLoad:()=>{this.isLauncherReadyToAttach()?this.attachLauncher(c,m,U):console.error("Rokt object is not available after script load.")},onError:h=>{console.error("Error loading Rokt launcher script:",h)}}),this.captureTiming(f.PERFORMANCE_MARKS.RoktScriptAppended)),"Successfully initialized: "+d)}process(e){if(this.isTargetingDisabled()||(e.EventDataType===Ye&&(Ae(this.loggingService),this.capturePageView(e)),e.EventDataType===xe&&(X(this.loggingService),ee(),te())),!this.isKitReady())return"Kit not ready for forwarder: "+d;if(w(a().Rokt?.setLocalSessionAttribute)&&(K(this.placementEventAttributeMappingLookup)||this.applyPlacementEventAttributeMapping(e),!K(this.placementEventMappingLookup))){const t=ue(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 V(e)||(this.userAttributes[e]=t),"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=v(e.getAllUserAttributes()),"Successfully called "+t+" for forwarder: "+d}onUserIdentified(e){const t=e;return this.filters.filteredUser=t,this._workspaceSearchInFlightPromise=this.search(t),this.handleIdentityComplete(e,"onUserIdentified")}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,o={};if(r)for(const u of Object.keys(r)){const l=r[u];_(l)&&l.length>0&&(o[u]=l)}const s=Object.keys(o);if(s.length===0)return this.userIdentifiedInWorkspace=!1,this._workspaceLastSearchedIdentitiesKey=void 0,Promise.resolve();const c=s.sort().map(u=>`${u}=${o[u]}`).join("&");return c===this._workspaceLastSearchedIdentitiesKey?this._workspaceSearchInFlightPromise||Promise.resolve():(this.userIdentifiedInWorkspace=!1,this._workspaceLastSearchedIdentitiesKey=c,new Promise(u=>{try{n(t,o,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.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(o=>setTimeout(o,ie))]):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,ie))]).then(()=>this._dispatchPlacements(e))}return this._dispatchPlacements(e)}_dispatchPlacements(e){const t=e&&e.attributes||{},r={...v(this.userAttributes),...t},o=this.filters||{},s=o.userAttributeFilters||[],c=o.filteredUser||null,u=c?c.getMPID():null;let l;o?o.filterUserAttributes?l=o.filterUserAttributes(r,s):l=r:(console.warn("Rokt Kit: No filters available, using user attributes"),l=r),this.userAttributes=v(l);const p=this._onboardingExpProvider==="Optimizely"?this.fetchOptimizely():{},j=this.returnUserIdentities(c),U=this.returnLocalSessionAttributes(),C=ye(Z(this.loggingService)),m=ke(),k=this.readMpSessionId(),y=this.readMpDeviceId(),R={...j,...l,...p,...U,...C.length?{[Ge]:JSON.stringify(C)}:{},...m?{[We]:m}:{},...this.userIdentifiedInWorkspace?{[De]:!0}:{},...k?{[je]:k}:{},...y?{[Ve]:y}:{},mpid:u},h={...e,attributes:R},me=this.launcher.selectPlacements(h),nt=()=>this.logSelectPlacementsEvent(R);return Promise.resolve(me).then(rt=>rt?.context?.sessionId?.then(ot=>this.setRoktSessionId(ot))).catch(()=>{}).finally(nt),me}hashAttributes(e){return this.isKitReady()?this.launcher.hashAttributes(e):(console.error("Rokt Kit: Not initialized"),null)}use(e){return this.isKitReady()?!e||!_(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()?(Le(this._launcherAttachState),this.launcher.terminate()):(console.error("Rokt Kit: Not initialized"),Promise.resolve())}onShoppableAdsReady(e){this._isThankYouElementLoaded?e():this._thankYouElementOnLoadCallback=e}};f._allowedOriginHashes=[-553112570,549508659],f.PERFORMANCE_MARKS={RoktScriptAppended:"mp:RoktScriptAppended"},f.EMAIL_SHA256_KEY="emailsha256";let S=f;function tt(){return P}function it(i){if(!i){window.console.log("You must pass a config object to register the kit "+d);return}if(!E(i)){window.console.log("'config' must be an object. You passed in a "+typeof i);return}E(i.kits)?i.kits[d]={constructor:S}:(i.kits={},i.kits[d]={constructor:S}),window.console.log("Successfully registered "+d+" to your mParticle configuration")}return typeof window<"u"&&window.mParticle&&a().addForwarder&&a().addForwarder({name:d,constructor:S,getId:tt}),M.register=it,Object.defineProperty(M,Symbol.toStringTag,{value:"Module"}),M})({});
2
2
  //# sourceMappingURL=Rokt-Kit.iife.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mparticle/web-rokt-kit",
3
- "version": "1.35.0",
3
+ "version": "1.36.0",
4
4
  "description": "mParticle integration kit for Rokt",
5
5
  "main": "dist/Rokt-Kit.common.js",
6
6
  "module": "dist/Rokt-Kit.esm.js",