@mparticle/web-rokt-kit 1.34.1 → 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 pe=["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"],fe=new Set(pe);function ee(i){return fe.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];ee(s)||(e[s]=t[s])}return e}function I(i){return typeof i=="object"&&i!==null&&!Array.isArray(i)}function m(i){return typeof i=="string"}function L(i){return typeof i=="function"}function U(i){return i==null?!0:typeof i=="object"?Object.keys(i).length===0:!1}function K(i){try{const e=new URL(i);return e.search="",e.toString()}catch{return i}}const Y="__rokt_ls_probe__";function x(){try{return window.localStorage.setItem(Y,"1"),window.localStorage.removeItem(Y),!0}catch{return!1}}function O(i){try{const e=window.localStorage.getItem(i);return e===null?null:JSON.parse(e)}catch{return null}}function te(i,e){try{return window.localStorage.setItem(i,JSON.stringify(e)),!0}catch{return!1}}function ie(i){try{window.localStorage.removeItem(i)}catch{}}function ne(i,e){const t=O(i);return I(t)?t[e]:void 0}function re(i,e,t){const n=O(i),r=I(n)?{...n}:{};return r[e]=t,te(i,r)}function me(i,e){const t=O(i);if(!I(t)||!(e in t))return;const n={...t};delete n[e],Object.keys(n).length===0?ie(i):te(i,n)}const A="mp-rokt-kit",k="pageViews",G="mpPageViews",se=25;function oe(i){return i.slice(-se)}function ae(i){const e=O(G);if(e===null)return;!(ne(A,k)!==void 0)&&Array.isArray(e)&&(i?.log({message:"Rokt Kit: Migrating legacy page-view storage",code:"PAGE_VIEW_LEGACY_MIGRATION"}),re(A,k,e)||i?.log({message:"Rokt Kit: Failed to migrate legacy page-view storage [reason: migration_retry]",code:"PAGE_VIEW_CAPTURE_FAILED"})),ie(G)}function W(i){ae(i);const e=ne(A,k);return Array.isArray(e)?e:[]}function Ee(i){const e=oe(i);for(let t=0;t<e.length;t++){const n=e.slice(t);if(re(A,k,n))return n.length}return 0}function V(){me(A,k)}function _e(i){const e=oe(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 Ie(){const e=document.querySelector('link[rel="canonical"]')?.href;if(e)return K(e)}const d="Rokt",T=181,Se="selectPlacements",ye="apps.roktecommerce.com",Ae=.1,ke="ThankYouPageJourney",ve="rokt-launcher",Re="rokt-thank-you-element",we="userIdentifiedInWorkspace",be=3,Le=2,Te="page_events",Pe="mparticle_session_id",Oe="mparticle_device_id",Ne=500,D={UNKNOWN_ERROR:"UNKNOWN_ERROR",UNHANDLED_EXCEPTION:"UNHANDLED_EXCEPTION",IDENTITY_REQUEST:"IDENTITY_REQUEST",LOG_DELIVERY_FAILURE:"LOG_DELIVERY_FAILURE"},_={ERROR:"ERROR",INFO:"INFO",WARNING:"WARNING"},Ce="apps.rokt-api.com",Ue="/v1/log",Me="/v1/errors",Ke=10;function a(){return window.mParticle}function j(i,e){const n=[N(i),"/wsdk/integrations/launcher.js"].join("");return!e||e.length===0?n:n+"?extensions="+e.join(",")}function H(i){return[N(i),"/rokt-elements/rokt-element-thank-you.js"].join("")}function N(i){const e=typeof i<"u"?i:Ce;return e.includes("://")?e.replace(/\/+$/,""):["https://",e].join("")}function ce(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 N(r)+t}function z(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 q(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(ke)):t.push(o)}return{roktExtensionsQueryParams:t,legacyRoktExtensions:n,loadThankYouElement:r}}async function De(i,e){const t=[];if(e)for(const n of i)t.push(e.use(n));return Promise.all(t)}function J(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 $(i){const e={};if(!Array.isArray(i))return e;for(let t=0;t<i.length;t++){const n=i[t];if(!n||!m(n.value)||!m(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 B(i,e,t){return a().generateHash([i,e,t].join(""))}function Fe(i){let n="mParticle_wsdkv_"+a().getVersion()+"_kitv_"+"1.34.1";return i&&(n+="_"+i),n}function le(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 M(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 Q(i,e){const t=le(window.location.origin);if(S._allowedOriginHashes.indexOf(t)===-1||Math.random()>=Ae)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?N(i):"https://apps.rokt.com";M(c+"/v1/wsdk-init/index.html?"+o),M("https://"+ye+"/v1/wsdk-init/index.html?"+o+"&isControl=true")}function Ye(){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 Ge(){return typeof window<"u"?window.navigator?.userAgent:void 0}class ue{constructor(){this._logCount={}}incrementAndCheck(e){const n=(this._logCount[e]||0)+1;return this._logCount[e]=n,n>Ke}}class F{constructor(e,t,n,r,s){this._reporter="mp-wsdk";const o=e.isLoggingEnabled;this._integrationName=t||"",this._launcherInstanceGuid=n,this._accountId=r||null,this._rateLimiter=s||new ue,this._isEnabled=Ye()||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||D.UNKNOWN_ERROR,url:xe(),deviceInfo:Ge(),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 X{constructor(e,t,n,r,s){this._transport=new F(e,t,n,r,s),this._errorUrl=ce(e?.errorUrl,e?.integrationDomain,Me)}report(e){if(!e)return;const t=e.severity||_.ERROR;this._transport.send(this._errorUrl,t,e.message,e.code,e.stackTrace)}}class Z{constructor(e,t,n,r,s,o){this._transport=new F(e,n,r,s,o),this._loggingUrl=ce(e?.loggingUrl,e?.integrationDomain,Ue),this._errorReportingService=t}log(e){e&&this._transport.send(this._loggingUrl,_.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:D.LOG_DELIVERY_FAILURE,severity:n?_.ERROR:_.WARNING})}})}}function We(i){const e=K(window.location.href),t=i.EventAttributes?.title||document.title,n=Ie(),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=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}getEventAttributeValue(e,t){const n=e&&e.EventAttributes;return!n||typeof n[t]>"u"?null:n[t]}doesEventAttributeConditionMatch(e,t){if(!e||!m(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||!m(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(U(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=K(window.location.href);const n=W(this.loggingService),r=We(e);n.push(r);const s=Math.min(n.length,se),o=Ee(n);if(o===0){const c=x()?"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=x()?"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&&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[f.EMAIL_SHA256_KEY]=e[n]),n&&delete t[n],t}logSelectPlacementsEvent(e){if(!window.mParticle||typeof a().logEvent!="function"||!I(e))return;const t=a().EventType.Other;a().logEvent(Se,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=[]){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 De(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,Q(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=J(u);const l=P(o.placementEventAttributeMapping);this.placementEventAttributeMappingLookup=$(l),o.hashedEmailUserIdentityType&&(this._mappedEmailSha256Key=o.hashedEmailUserIdentityType.toLowerCase()),this._workspaceIdSyncApiKey=m(o.workspaceIdSyncApiKey)?o.workspaceIdSyncApiKey:void 0;const g=a().Rokt?.domain,{roktExtensionsQueryParams:C,legacyRoktExtensions:v,loadThankYouElement:R}=q(o.roktExtensions),p={...a().Rokt?.launcherOptions||{}};this.integrationName=Fe(p.integrationName),p.integrationName=this.integrationName,this.domain=g;const y={loggingUrl:o.loggingUrl,errorUrl:o.errorUrl,integrationDomain:g,isLoggingEnabled:a().config?.isLoggingEnabled===!0},E=new X(y,this.integrationName,window.__rokt_li_guid__,o.accountId),w=new Z(y,E,this.integrationName,window.__rokt_li_guid__,o.accountId);if(this.errorReportingService=E,this.loggingService=w,this.isTargetingDisabled())try{V()}catch(h){this.errorReportingService?.report({message:"Rokt Kit: Failed to clear page views when targeting is disabled",code:"PAGE_VIEW_CAPTURE_FAILED",severity:_.INFO,stackTrace:h instanceof Error?h.stack:void 0})}return a()._registerErrorReportingService&&a()._registerErrorReportingService(E),a()._registerLoggingService&&a()._registerLoggingService(w),n?(this.testHelpers={generateLauncherScript:j,generateThankYouElementScript:H,extractRoktExtensionConfig:q,hashEventMessage:B,parseSettingsString:P,generateMappedEventLookup:J,generateMappedEventAttributeLookup:$,sendAdBlockMeasurementSignals:Q,createAutoRemovedIframe:M,djb2:le,setAllowedOriginHashes:h=>{f._allowedOriginHashes=h},ReportingTransport:F,ErrorReportingService:X,LoggingService:Z,RateLimiter:ue,ErrorCodes:D,WSDKErrorSeverity:_},this.attachLauncher(c,p),"Successfully initialized: "+d):(R&&(a().Rokt.flushOnShoppableAdsReadyMessageQueue?.(this),z(Re,H(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,p,v):(z(ve,j(g,C),{onLoad:()=>{this.isLauncherReadyToAttach()?this.attachLauncher(c,p,v):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===be&&this.capturePageView(e),e.EventDataType===Le&&(ae(this.loggingService),V())),!this.isKitReady())return"Kit not ready for forwarder: "+d;if(L(a().Rokt?.setLocalSessionAttribute)&&(U(this.placementEventAttributeMappingLookup)||this.applyPlacementEventAttributeMapping(e),!U(this.placementEventMappingLookup))){const t=B(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 ee(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];m(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,Ne))]).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():{},C=this.returnUserIdentities(c),v=this.returnLocalSessionAttributes(),R=_e(W(this.loggingService)),p=this.readMpSessionId(),y=this.readMpDeviceId(),E={...C,...l,...g,...v,...R.length?{[Te]:JSON.stringify(R)}:{},...this.userIdentifiedInWorkspace?{[we]:!0}:{},...p?{[Pe]:p}:{},...y?{[Oe]:y}:{},mpid:u},w={...e,attributes:E},h=this.launcher.selectPlacements(w),de=()=>this.logSelectPlacementsEvent(E);return Promise.resolve(h).then(he=>he?.context?.sessionId?.then(ge=>this.setRoktSessionId(ge))).catch(()=>{}).finally(de),h}hashAttributes(e){return this.isKitReady()?this.launcher.hashAttributes(e):(console.error("Rokt Kit: Not initialized"),null)}use(e){return this.isKitReady()?!e||!m(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 Ve(){return T}function je(i){if(!i){window.console.log("You must pass a config object to register the kit "+d);return}if(!I(i)){window.console.log("'config' must be an object. You passed in a "+typeof i);return}I(i.kits)?i.kits[d]={constructor:S}:(i.kits={},i.kits[d]={constructor:S}),window.console.log("Successfully registered "+d+" to your mParticle configuration")}typeof window<"u"&&window.mParticle&&a().addForwarder&&a().addForwarder({name:d,constructor:S,getId:Ve});exports.register=je;
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 pe = [
1
+ const Ie = [
2
2
  "active_time_on_site_ms",
3
3
  "billingaddress1",
4
4
  "billingaddress2",
@@ -23,31 +23,31 @@ const pe = [
23
23
  "shippingstate",
24
24
  "shippingzipcode",
25
25
  "totalprice"
26
- ], fe = new Set(pe);
27
- function ee(i) {
28
- return fe.has(i.toLowerCase());
26
+ ], Se = new Set(Ie);
27
+ function se(i) {
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
- ee(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
  }
38
- function I(i) {
38
+ function _(i) {
39
39
  return typeof i == "object" && i !== null && !Array.isArray(i);
40
40
  }
41
- function m(i) {
41
+ function E(i) {
42
42
  return typeof i == "string";
43
43
  }
44
- function L(i) {
44
+ function T(i) {
45
45
  return typeof i == "function";
46
46
  }
47
- function U(i) {
47
+ function K(i) {
48
48
  return i == null ? !0 : typeof i == "object" ? Object.keys(i).length === 0 : !1;
49
49
  }
50
- function K(i) {
50
+ function x(i) {
51
51
  try {
52
52
  const e = new URL(i);
53
53
  return e.search = "", e.toString();
@@ -55,10 +55,10 @@ function K(i) {
55
55
  return i;
56
56
  }
57
57
  }
58
- const Y = "__rokt_ls_probe__";
59
- function x() {
58
+ const j = "__rokt_ls_probe__";
59
+ function F() {
60
60
  try {
61
- return window.localStorage.setItem(Y, "1"), window.localStorage.removeItem(Y), !0;
61
+ return window.localStorage.setItem(j, "1"), window.localStorage.removeItem(j), !0;
62
62
  } catch {
63
63
  return !1;
64
64
  }
@@ -71,118 +71,186 @@ function N(i) {
71
71
  return null;
72
72
  }
73
73
  }
74
- function te(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 ie(i) {
81
+ function ce(i) {
82
82
  try {
83
83
  window.localStorage.removeItem(i);
84
84
  } catch {
85
85
  }
86
86
  }
87
- function ne(i, e) {
87
+ function U(i, e) {
88
88
  const t = N(i);
89
- return I(t) ? t[e] : void 0;
89
+ return _(t) ? t[e] : void 0;
90
90
  }
91
- function re(i, e, t) {
92
- const n = N(i), r = I(n) ? { ...n } : {};
93
- return r[e] = t, te(i, r);
91
+ function Y(i, e, t) {
92
+ const n = N(i), r = _(n) ? { ...n } : {};
93
+ return r[e] = t, ae(i, r);
94
94
  }
95
- function me(i, e) {
95
+ function le(i, e) {
96
96
  const t = N(i);
97
- if (!I(t) || !(e in t))
97
+ if (!_(t) || !(e in t))
98
98
  return;
99
99
  const n = { ...t };
100
- delete n[e], Object.keys(n).length === 0 ? ie(i) : te(i, n);
100
+ delete n[e], Object.keys(n).length === 0 ? ce(i) : ae(i, n);
101
101
  }
102
- const A = "mp-rokt-kit", k = "pageViews", G = "mpPageViews", se = 25;
103
- function oe(i) {
104
- return i.slice(-se);
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"];
103
+ function de(i) {
104
+ return i.slice(-ue);
105
105
  }
106
- function ae(i) {
107
- const e = N(G);
106
+ function he(i) {
107
+ const e = N(H);
108
108
  if (e === null)
109
109
  return;
110
- !(ne(A, k) !== void 0) && Array.isArray(e) && (i?.log({
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
- }), re(A, k, 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
- })), ie(G);
116
+ })), ce(H);
117
117
  }
118
- function W(i) {
119
- ae(i);
120
- const e = ne(A, k);
118
+ function z(i) {
119
+ he(i);
120
+ const e = U(p, R);
121
121
  return Array.isArray(e) ? e : [];
122
122
  }
123
- function Ee(i) {
124
- const e = oe(i);
123
+ function ye(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 (re(A, k, n))
127
+ if (Y(p, R, n))
128
128
  return n.length;
129
129
  }
130
130
  return 0;
131
131
  }
132
- function V() {
133
- me(A, k);
132
+ function q() {
133
+ le(p, R);
134
134
  }
135
- function _e(i) {
136
- const e = oe(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 Ie() {
150
+ function Re(i) {
151
+ if (U(p, O) !== void 0)
152
+ return;
153
+ const e = new URLSearchParams(window.location.search), t = {};
154
+ for (const r of Ae) {
155
+ const o = e.get(r);
156
+ o && (t[r] = o);
157
+ }
158
+ if (Object.keys(t).length === 0)
159
+ return;
160
+ const n = Object.keys(t).join(", ");
161
+ if (!Y(p, O, t)) {
162
+ const r = F() ? "quota" : "ls_unavailable";
163
+ i?.log({
164
+ message: `Rokt Kit: Failed to persist UTM params [reason: ${r}]`,
165
+ code: "UTM_CAPTURE_FAILED"
166
+ });
167
+ return;
168
+ }
169
+ i?.log({
170
+ message: `Rokt Kit: Captured UTM params [${n}]`,
171
+ code: "UTM_CAPTURE_SUCCESS"
172
+ });
173
+ }
174
+ function ve() {
175
+ const i = U(p, O);
176
+ return _(i) ? i : null;
177
+ }
178
+ function $() {
179
+ le(p, O);
180
+ }
181
+ function we() {
151
182
  const e = document.querySelector('link[rel="canonical"]')?.href;
152
183
  if (e)
153
- return K(e);
184
+ return x(e);
185
+ }
186
+ function Le() {
187
+ return {
188
+ context: null,
189
+ lifecycle: "idle",
190
+ recreateInFlight: null
191
+ };
154
192
  }
155
- const d = "Rokt", T = 181, Se = "selectPlacements", ye = "apps.roktecommerce.com", Ae = 0.1, ke = "ThankYouPageJourney", ve = "rokt-launcher", Re = "rokt-thank-you-element", we = "userIdentifiedInWorkspace", be = 3, Le = 2, Te = "page_events", Pe = "mparticle_session_id", Ne = "mparticle_device_id", Oe = 500, D = {
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;
222
+ }
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 = {
156
224
  UNKNOWN_ERROR: "UNKNOWN_ERROR",
157
225
  UNHANDLED_EXCEPTION: "UNHANDLED_EXCEPTION",
158
226
  IDENTITY_REQUEST: "IDENTITY_REQUEST",
159
227
  LOG_DELIVERY_FAILURE: "LOG_DELIVERY_FAILURE"
160
- }, _ = {
228
+ }, S = {
161
229
  ERROR: "ERROR",
162
230
  INFO: "INFO",
163
231
  WARNING: "WARNING"
164
- }, Ce = "apps.rokt-api.com", Ue = "/v1/log", Me = "/v1/errors", Ke = 10;
232
+ }, qe = "apps.rokt-api.com", $e = "/v1/log", Je = "/v1/errors", Be = 10;
165
233
  function a() {
166
234
  return window.mParticle;
167
235
  }
168
- function j(i, e) {
169
- const n = [O(i), "/wsdk/integrations/launcher.js"].join("");
236
+ function B(i, e) {
237
+ const n = [C(i), "/wsdk/integrations/launcher.js"].join("");
170
238
  return !e || e.length === 0 ? n : n + "?extensions=" + e.join(",");
171
239
  }
172
- function H(i) {
173
- return [O(i), "/rokt-elements/rokt-element-thank-you.js"].join("");
240
+ function Q(i) {
241
+ return [C(i), "/rokt-elements/rokt-element-thank-you.js"].join("");
174
242
  }
175
- function O(i) {
176
- const e = typeof i < "u" ? i : Ce;
243
+ function C(i) {
244
+ const e = typeof i < "u" ? i : qe;
177
245
  return e.includes("://") ? e.replace(/\/+$/, "") : ["https://", e].join("");
178
246
  }
179
- function ce(i, e, t) {
247
+ function ge(i, e, t) {
180
248
  if (i)
181
249
  return i.startsWith("http://") || i.startsWith("https://") ? i : "https://" + i;
182
250
  const r = e?.includes("://") && !/^https?:\/\//i.test(e) ? void 0 : e;
183
- return O(r) + t;
251
+ return C(r) + t;
184
252
  }
185
- function z(i, e, t) {
253
+ function X(i, e, t) {
186
254
  if (document.getElementById(i)) return;
187
255
  const n = document.head || document.body, r = document.createElement("script");
188
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);
@@ -197,12 +265,12 @@ function P(i) {
197
265
  }
198
266
  return [];
199
267
  }
200
- function q(i) {
268
+ function Z(i) {
201
269
  const e = i ? P(i) : [], t = [], n = [];
202
270
  let r = !1;
203
- for (let s = 0; s < e.length; s++) {
204
- const o = e[s].value;
205
- o === "thank-you-journey" ? (r = !0, n.push(ke)) : 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);
206
274
  }
207
275
  return {
208
276
  roktExtensionsQueryParams: t,
@@ -210,14 +278,14 @@ function q(i) {
210
278
  loadThankYouElement: r
211
279
  };
212
280
  }
213
- async function De(i, e) {
281
+ async function Qe(i, e) {
214
282
  const t = [];
215
283
  if (e)
216
284
  for (const n of i)
217
285
  t.push(e.use(n));
218
286
  return Promise.all(t);
219
287
  }
220
- function J(i) {
288
+ function ee(i) {
221
289
  if (!i)
222
290
  return {};
223
291
  const e = {};
@@ -227,36 +295,36 @@ function J(i) {
227
295
  }
228
296
  return e;
229
297
  }
230
- function $(i) {
298
+ function te(i) {
231
299
  const e = {};
232
300
  if (!Array.isArray(i))
233
301
  return e;
234
302
  for (let t = 0; t < i.length; t++) {
235
303
  const n = i[t];
236
- if (!n || !m(n.value) || !m(n.map))
304
+ if (!n || !E(n.value) || !E(n.map))
237
305
  continue;
238
- const r = n.value, s = n.map;
306
+ const r = n.value, o = n.map;
239
307
  e[r] || (e[r] = []), e[r].push({
240
- eventAttributeKey: s,
308
+ eventAttributeKey: o,
241
309
  conditions: Array.isArray(n.conditions) ? n.conditions : []
242
310
  });
243
311
  }
244
312
  return e;
245
313
  }
246
- function B(i, e, t) {
314
+ function ie(i, e, t) {
247
315
  return a().generateHash([i, e, t].join(""));
248
316
  }
249
- function Fe(i) {
250
- let n = "mParticle_wsdkv_" + a().getVersion() + "_kitv_" + "1.34.1";
317
+ function Xe(i) {
318
+ let n = "mParticle_wsdkv_" + a().getVersion() + "_kitv_" + "1.36.0";
251
319
  return i && (n += "_" + i), n;
252
320
  }
253
- function le(i) {
321
+ function pe(i) {
254
322
  let e = 5381;
255
323
  for (let t = 0; t < i.length; t++)
256
324
  e = (e << 5) + e + i.charCodeAt(t), e = e & e;
257
325
  return e;
258
326
  }
259
- function M(i) {
327
+ function D(i) {
260
328
  const e = document.createElement("iframe");
261
329
  e.style.display = "none", e.setAttribute("sandbox", "allow-scripts allow-same-origin"), e.src = i, e.onload = function() {
262
330
  e.onload = null, e.parentNode && e.parentNode.removeChild(e);
@@ -264,43 +332,43 @@ function M(i) {
264
332
  const t = document.body || document.head;
265
333
  t && t.appendChild(e);
266
334
  }
267
- function Q(i, e) {
268
- const t = le(window.location.origin);
269
- if (S._allowedOriginHashes.indexOf(t) === -1 || Math.random() >= Ae)
335
+ function ne(i, e) {
336
+ const t = pe(window.location.origin);
337
+ if (A._allowedOriginHashes.indexOf(t) === -1 || Math.random() >= Ke)
270
338
  return;
271
339
  const r = window.__rokt_li_guid__;
272
340
  if (!r || i && i.includes("://") && !/^https:\/\//i.test(i))
273
341
  return;
274
- 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";
275
- M(c + "/v1/wsdk-init/index.html?" + o), M(
276
- "https://" + ye + "/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"
277
345
  );
278
346
  }
279
- function Ye() {
347
+ function Ze() {
280
348
  return typeof window < "u" && !!window.location?.search?.toLowerCase().includes("mp_enable_logging=true");
281
349
  }
282
- function xe() {
350
+ function et() {
283
351
  return typeof window < "u" ? window.location?.href : void 0;
284
352
  }
285
- function Ge() {
353
+ function tt() {
286
354
  return typeof window < "u" ? window.navigator?.userAgent : void 0;
287
355
  }
288
- class ue {
356
+ class fe {
289
357
  constructor() {
290
358
  this._logCount = {};
291
359
  }
292
360
  incrementAndCheck(e) {
293
361
  const n = (this._logCount[e] || 0) + 1;
294
- return this._logCount[e] = n, n > Ke;
362
+ return this._logCount[e] = n, n > Be;
295
363
  }
296
364
  }
297
- class F {
298
- constructor(e, t, n, r, s) {
365
+ class W {
366
+ constructor(e, t, n, r, o) {
299
367
  this._reporter = "mp-wsdk";
300
- const o = e.isLoggingEnabled;
301
- this._integrationName = t || "", this._launcherInstanceGuid = n, this._accountId = r || null, this._rateLimiter = s || new ue(), this._isEnabled = Ye() || 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;
302
370
  }
303
- send(e, t, n, r, s, o) {
371
+ send(e, t, n, r, o, s) {
304
372
  if (!(!this._isEnabled || this._rateLimiter.incrementAndCheck(t)))
305
373
  try {
306
374
  const c = {
@@ -309,10 +377,10 @@ class F {
309
377
  version: this._integrationName
310
378
  },
311
379
  severity: t,
312
- code: r || D.UNKNOWN_ERROR,
313
- url: xe(),
314
- deviceInfo: Ge(),
315
- stackTrace: s,
380
+ code: r || G.UNKNOWN_ERROR,
381
+ url: et(),
382
+ deviceInfo: tt(),
383
+ stackTrace: o,
316
384
  reporter: this._reporter,
317
385
  integration: this._integrationName
318
386
  }, u = {
@@ -331,31 +399,31 @@ class F {
331
399
  throw g.statusCode = l.status, g;
332
400
  }
333
401
  }).catch((l) => {
334
- console.error("ReportingTransport: Failed to send log", l), o && o(l);
402
+ console.error("ReportingTransport: Failed to send log", l), s && s(l);
335
403
  });
336
404
  } catch (c) {
337
- console.error("ReportingTransport: Failed to send log", c), o && o(c);
405
+ console.error("ReportingTransport: Failed to send log", c), s && s(c);
338
406
  }
339
407
  }
340
408
  }
341
- class X {
342
- constructor(e, t, n, r, s) {
343
- this._transport = new F(e, t, n, r, s), this._errorUrl = ce(e?.errorUrl, e?.integrationDomain, Me);
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);
344
412
  }
345
413
  report(e) {
346
414
  if (!e) return;
347
- const t = e.severity || _.ERROR;
415
+ const t = e.severity || S.ERROR;
348
416
  this._transport.send(this._errorUrl, t, e.message, e.code, e.stackTrace);
349
417
  }
350
418
  }
351
- class Z {
352
- constructor(e, t, n, r, s, o) {
353
- this._transport = new F(e, n, r, s, o), this._loggingUrl = ce(e?.loggingUrl, e?.integrationDomain, Ue), 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;
354
422
  }
355
423
  log(e) {
356
424
  e && this._transport.send(
357
425
  this._loggingUrl,
358
- _.INFO,
426
+ S.INFO,
359
427
  e.message,
360
428
  e.code,
361
429
  void 0,
@@ -364,16 +432,16 @@ class Z {
364
432
  const n = typeof t.statusCode == "number";
365
433
  this._errorReportingService.report({
366
434
  message: "LoggingService: Failed to send log: " + t.message,
367
- code: D.LOG_DELIVERY_FAILURE,
368
- severity: n ? _.ERROR : _.WARNING
435
+ code: G.LOG_DELIVERY_FAILURE,
436
+ severity: n ? S.ERROR : S.WARNING
369
437
  });
370
438
  }
371
439
  }
372
440
  );
373
441
  }
374
442
  }
375
- function We(i) {
376
- const e = K(window.location.href), t = i.EventAttributes?.title || document.title, n = Ie(), 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;
377
445
  return {
378
446
  pageUrl: e,
379
447
  sourceMessageId: i.SourceMessageId,
@@ -383,9 +451,9 @@ function We(i) {
383
451
  ...Number.isFinite(r) ? { activeTimeOnSite: r } : {}
384
452
  };
385
453
  }
386
- const f = class f {
454
+ const m = class m {
387
455
  constructor() {
388
- 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;
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();
389
457
  }
390
458
  // ---- Private helpers ----
391
459
  getEventAttributeValue(e, t) {
@@ -393,13 +461,13 @@ const f = class f {
393
461
  return !n || typeof n[t] > "u" ? null : n[t];
394
462
  }
395
463
  doesEventAttributeConditionMatch(e, t) {
396
- if (!e || !m(e.operator))
464
+ if (!e || !E(e.operator))
397
465
  return !1;
398
466
  const n = e.operator.toLowerCase(), r = e.attributeValue;
399
467
  return n === "exists" ? t !== null : t == null ? !1 : n === "equals" ? String(t) === String(r) : n === "contains" ? String(t).indexOf(String(r)) !== -1 : !1;
400
468
  }
401
469
  doesEventMatchRule(e, t) {
402
- if (!t || !m(t.eventAttributeKey))
470
+ if (!t || !E(t.eventAttributeKey))
403
471
  return !1;
404
472
  const n = t.conditions;
405
473
  if (!Array.isArray(n))
@@ -407,53 +475,53 @@ const f = class f {
407
475
  const r = this.getEventAttributeValue(e, t.eventAttributeKey);
408
476
  if (n.length === 0)
409
477
  return r !== null;
410
- for (let s = 0; s < n.length; s++)
411
- if (!this.doesEventAttributeConditionMatch(n[s], r))
478
+ for (let o = 0; o < n.length; o++)
479
+ if (!this.doesEventAttributeConditionMatch(n[o], r))
412
480
  return !1;
413
481
  return !0;
414
482
  }
415
483
  applyPlacementEventAttributeMapping(e) {
416
484
  const t = Object.keys(this.placementEventAttributeMappingLookup);
417
485
  for (let n = 0; n < t.length; n++) {
418
- const r = t[n], s = this.placementEventAttributeMappingLookup[r];
419
- if (U(s))
486
+ const r = t[n], o = this.placementEventAttributeMappingLookup[r];
487
+ if (K(o))
420
488
  continue;
421
- let o = !0;
422
- for (let c = 0; c < s.length; c++)
423
- if (!this.doesEventMatchRule(e, s[c])) {
424
- 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;
425
493
  break;
426
494
  }
427
- o && a().Rokt.setLocalSessionAttribute?.(r, !0);
495
+ s && a().Rokt.setLocalSessionAttribute?.(r, !0);
428
496
  }
429
497
  }
430
498
  capturePageView(e) {
431
499
  let t;
432
500
  try {
433
- t = K(window.location.href);
434
- const n = W(this.loggingService), r = We(e);
501
+ t = x(window.location.href);
502
+ const n = z(this.loggingService), r = it(e);
435
503
  n.push(r);
436
- const s = Math.min(n.length, se), o = Ee(n);
437
- if (o === 0) {
438
- const c = x() ? "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";
439
507
  this.loggingService?.log({
440
508
  message: `Rokt Kit: Failed to persist page view for ${t} [reason: ${c}]`,
441
509
  code: "PAGE_VIEW_CAPTURE_FAILED"
442
510
  });
443
- } else o < s && this.loggingService?.log({
444
- 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]`,
445
513
  code: "PAGE_VIEW_QUOTA_EVICTION"
446
514
  });
447
515
  } catch (n) {
448
- const r = x() ? "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);
449
517
  this.loggingService?.log({
450
- 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}]`,
451
519
  code: "PAGE_VIEW_CAPTURE_FAILED"
452
520
  });
453
521
  }
454
522
  }
455
523
  isLauncherReadyToAttach() {
456
- return !!window.Rokt && L(window.Rokt.createLauncher);
524
+ return !!window.Rokt && T(window.Rokt.createLauncher);
457
525
  }
458
526
  /**
459
527
  * Returns the user identities from the filtered user, if any.
@@ -469,19 +537,19 @@ const f = class f {
469
537
  }
470
538
  replaceOtherIdentityWithEmailsha256(e) {
471
539
  const t = { ...e || {} }, n = this._mappedEmailSha256Key;
472
- return n && e[n] && (t[f.EMAIL_SHA256_KEY] = e[n]), n && delete t[n], t;
540
+ return n && e[n] && (t[m.EMAIL_SHA256_KEY] = e[n]), n && delete t[n], t;
473
541
  }
474
542
  logSelectPlacementsEvent(e) {
475
- if (!window.mParticle || typeof a().logEvent != "function" || !I(e))
543
+ if (!window.mParticle || typeof a().logEvent != "function" || !_(e))
476
544
  return;
477
545
  const t = a().EventType.Other;
478
- a().logEvent(Se, t, e);
546
+ a().logEvent(Ce, t, e);
479
547
  }
480
548
  setRoktSessionId(e) {
481
549
  if (!(!e || typeof e != "string"))
482
550
  try {
483
551
  const t = a().getInstance();
484
- t && L(t.setIntegrationAttribute) && t.setIntegrationAttribute(T, {
552
+ t && T(t.setIntegrationAttribute) && t.setIntegrationAttribute(b, {
485
553
  roktSessionId: e
486
554
  });
487
555
  } catch {
@@ -489,35 +557,47 @@ const f = class f {
489
557
  }
490
558
  readMpSessionId() {
491
559
  const e = a()?.sessionManager, t = e?.getSessionId ?? e?.getSession;
492
- if (L(t))
560
+ if (T(t))
493
561
  return t.call(e) || void 0;
494
562
  }
495
563
  readMpDeviceId() {
496
564
  return a()?.getDeviceId?.() || void 0;
497
565
  }
498
566
  attachLauncher(e, t, n = []) {
567
+ Te(this._launcherAttachState, {
568
+ accountId: e,
569
+ launcherOptions: t || {},
570
+ legacyRoktExtensions: n
571
+ });
499
572
  const r = {
500
573
  accountId: e,
501
574
  ...t || {}
502
575
  };
503
- let s;
504
- this.isPartnerInLocalLauncherTestGroup() ? s = Promise.resolve(window.Rokt.createLocalLauncher(r)) : s = window.Rokt.createLauncher(r), s.then(async (o) => {
505
- await De(n, o), this.initRoktLauncher(o);
506
- }).catch((o) => {
507
- 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);
508
581
  });
509
582
  }
583
+ recreateLauncherIfTerminated() {
584
+ return Ue(
585
+ this._launcherAttachState,
586
+ this.isLauncherReadyToAttach(),
587
+ (e) => this.attachLauncher(e.accountId, e.launcherOptions, e.legacyRoktExtensions)
588
+ );
589
+ }
510
590
  initRoktLauncher(e) {
511
- window.Rokt && (window.Rokt.currentLauncher = e), this.launcher = e;
591
+ window.Rokt && (window.Rokt.currentLauncher = e), this.launcher = e, be(this._launcherAttachState);
512
592
  const t = a().Rokt?.filters;
513
- 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, Q(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);
514
594
  }
515
595
  fetchOptimizely() {
516
596
  const e = a()._getActiveForwarders().filter((t) => t.name === "Optimizely");
517
597
  try {
518
598
  if (e.length > 0 && window.optimizely) {
519
599
  const t = window.optimizely.get("state");
520
- 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), {});
521
601
  }
522
602
  } catch (t) {
523
603
  console.error("Error fetching Optimizely attributes:", t);
@@ -545,90 +625,91 @@ const f = class f {
545
625
  /**
546
626
  * Initializes the Rokt forwarder with settings from the mParticle server.
547
627
  */
548
- init(e, t, n, r, s) {
549
- const o = e, c = o.accountId;
550
- this.userAttributes = b(s), this._onboardingExpProvider = o.onboardingExpProvider;
551
- const u = P(o.placementEventMapping);
552
- this.placementEventMappingLookup = J(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);
553
633
  const l = P(
554
- o.placementEventAttributeMapping
634
+ s.placementEventAttributeMapping
555
635
  );
556
- this.placementEventAttributeMappingLookup = $(l), o.hashedEmailUserIdentityType && (this._mappedEmailSha256Key = o.hashedEmailUserIdentityType.toLowerCase()), this._workspaceIdSyncApiKey = m(o.workspaceIdSyncApiKey) ? o.workspaceIdSyncApiKey : void 0;
557
- const g = a().Rokt?.domain, { roktExtensionsQueryParams: C, legacyRoktExtensions: v, loadThankYouElement: R } = q(
558
- o.roktExtensions
559
- ), p = {
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
639
+ ), f = {
560
640
  ...a().Rokt?.launcherOptions || {}
561
641
  };
562
- this.integrationName = Fe(p.integrationName), p.integrationName = this.integrationName, this.domain = g;
642
+ this.integrationName = Xe(f.integrationName), f.integrationName = this.integrationName, this.domain = g;
563
643
  const y = {
564
- loggingUrl: o.loggingUrl,
565
- errorUrl: o.errorUrl,
644
+ loggingUrl: s.loggingUrl,
645
+ errorUrl: s.errorUrl,
566
646
  integrationDomain: g,
567
647
  isLoggingEnabled: a().config?.isLoggingEnabled === !0
568
- }, E = new X(
648
+ }, I = new re(
569
649
  y,
570
650
  this.integrationName,
571
651
  window.__rokt_li_guid__,
572
- o.accountId
573
- ), w = new Z(
652
+ s.accountId
653
+ ), k = new oe(
574
654
  y,
575
- E,
655
+ I,
576
656
  this.integrationName,
577
657
  window.__rokt_li_guid__,
578
- o.accountId
658
+ s.accountId
579
659
  );
580
- if (this.errorReportingService = E, this.loggingService = w, this.isTargetingDisabled())
660
+ if (this.errorReportingService = I, this.loggingService = k, this.isTargetingDisabled())
581
661
  try {
582
- V();
662
+ q(), $();
583
663
  } catch (h) {
584
664
  this.errorReportingService?.report({
585
665
  message: "Rokt Kit: Failed to clear page views when targeting is disabled",
586
666
  code: "PAGE_VIEW_CAPTURE_FAILED",
587
- severity: _.INFO,
667
+ severity: S.INFO,
588
668
  stackTrace: h instanceof Error ? h.stack : void 0
589
669
  });
590
670
  }
591
- return a()._registerErrorReportingService && a()._registerErrorReportingService(E), a()._registerLoggingService && a()._registerLoggingService(w), n ? (this.testHelpers = {
592
- generateLauncherScript: j,
593
- generateThankYouElementScript: H,
594
- extractRoktExtensionConfig: q,
595
- hashEventMessage: B,
671
+ return a()._registerErrorReportingService && a()._registerErrorReportingService(I), a()._registerLoggingService && a()._registerLoggingService(k), n ? (this.testHelpers = {
672
+ generateLauncherScript: B,
673
+ generateThankYouElementScript: Q,
674
+ extractRoktExtensionConfig: Z,
675
+ hashEventMessage: ie,
596
676
  parseSettingsString: P,
597
- generateMappedEventLookup: J,
598
- generateMappedEventAttributeLookup: $,
599
- sendAdBlockMeasurementSignals: Q,
600
- createAutoRemovedIframe: M,
601
- djb2: le,
677
+ generateMappedEventLookup: ee,
678
+ generateMappedEventAttributeLookup: te,
679
+ sendAdBlockMeasurementSignals: ne,
680
+ createAutoRemovedIframe: D,
681
+ djb2: pe,
602
682
  setAllowedOriginHashes: (h) => {
603
- f._allowedOriginHashes = h;
683
+ m._allowedOriginHashes = h;
604
684
  },
605
- ReportingTransport: F,
606
- ErrorReportingService: X,
607
- LoggingService: Z,
608
- RateLimiter: ue,
609
- ErrorCodes: D,
610
- WSDKErrorSeverity: _
611
- }, this.attachLauncher(c, p), "Successfully initialized: " + d) : (R && (a().Rokt.flushOnShoppableAdsReadyMessageQueue?.(this), z(Re, H(g), {
685
+ ReportingTransport: W,
686
+ ErrorReportingService: re,
687
+ LoggingService: oe,
688
+ RateLimiter: fe,
689
+ ErrorCodes: 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), {
612
693
  onLoad: () => {
613
694
  this._isThankYouElementLoaded = !0, this._thankYouElementOnLoadCallback && this._thankYouElementOnLoadCallback();
614
695
  },
615
696
  onError: (h) => {
616
697
  console.error("Error loading Rokt Thank You Element script:", h);
617
698
  }
618
- })), this.isLauncherReadyToAttach() ? this.attachLauncher(c, p, v) : (z(ve, j(g, C), {
699
+ })), this.isLauncherReadyToAttach() ? this.attachLauncher(c, f, v) : (X(De, B(g, M), {
619
700
  onLoad: () => {
620
- this.isLauncherReadyToAttach() ? this.attachLauncher(c, p, v) : console.error("Rokt object is not available after script load.");
701
+ this.isLauncherReadyToAttach() ? this.attachLauncher(c, f, v) : console.error("Rokt object is not available after script load.");
621
702
  },
622
703
  onError: (h) => {
623
704
  console.error("Error loading Rokt launcher script:", h);
624
705
  }
625
- }), this.captureTiming(f.PERFORMANCE_MARKS.RoktScriptAppended)), "Successfully initialized: " + d);
706
+ }), this.captureTiming(m.PERFORMANCE_MARKS.RoktScriptAppended)), "Successfully initialized: " + d);
626
707
  }
627
708
  process(e) {
628
- if (this.isTargetingDisabled() || (e.EventDataType === be && this.capturePageView(e), e.EventDataType === Le && (ae(this.loggingService), V())), !this.isKitReady())
709
+ if (this.isTargetingDisabled() || (e.EventDataType === Ge && (Re(this.loggingService), this.capturePageView(e)), e.EventDataType === We && (he(this.loggingService), q(), $())), !this.isKitReady())
629
710
  return "Kit not ready for forwarder: " + d;
630
- if (L(a().Rokt?.setLocalSessionAttribute) && (U(this.placementEventAttributeMappingLookup) || this.applyPlacementEventAttributeMapping(e), !U(this.placementEventMappingLookup))) {
631
- const t = B(e.EventDataType, e.EventCategory, e.EventName ?? "");
711
+ if (T(a().Rokt?.setLocalSessionAttribute) && (K(this.placementEventAttributeMappingLookup) || this.applyPlacementEventAttributeMapping(e), !K(this.placementEventMappingLookup))) {
712
+ const t = ie(e.EventDataType, e.EventCategory, e.EventName ?? "");
632
713
  this.placementEventMappingLookup[String(t)] && a().Rokt.setLocalSessionAttribute?.(this.placementEventMappingLookup[String(t)], !0);
633
714
  }
634
715
  return "Successfully sent to forwarder: " + d;
@@ -641,13 +722,13 @@ const f = class f {
641
722
  window.Rokt.setExtensionData(e);
642
723
  }
643
724
  setUserAttribute(e, t) {
644
- return ee(e) || (this.userAttributes[e] = t), "Successfully set user attribute for forwarder: " + d;
725
+ return se(e) || (this.userAttributes[e] = t), "Successfully set user attribute for forwarder: " + d;
645
726
  }
646
727
  removeUserAttribute(e) {
647
728
  return delete this.userAttributes[e], "Successfully removed user attribute for forwarder: " + d;
648
729
  }
649
730
  handleIdentityComplete(e, t) {
650
- 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;
651
732
  }
652
733
  onUserIdentified(e) {
653
734
  const t = e;
@@ -660,19 +741,19 @@ const f = class f {
660
741
  const n = a().Identity?.search;
661
742
  if (typeof n != "function")
662
743
  return this.userIdentifiedInWorkspace = !1, this._workspaceLastSearchedIdentitiesKey = void 0, Promise.resolve();
663
- const r = e.getUserIdentities ? e.getUserIdentities().userIdentities : null, s = {};
744
+ const r = e.getUserIdentities ? e.getUserIdentities().userIdentities : null, o = {};
664
745
  if (r)
665
746
  for (const u of Object.keys(r)) {
666
747
  const l = r[u];
667
- m(l) && l.length > 0 && (s[u] = l);
748
+ E(l) && l.length > 0 && (o[u] = l);
668
749
  }
669
- const o = Object.keys(s);
670
- if (o.length === 0)
750
+ const s = Object.keys(o);
751
+ if (s.length === 0)
671
752
  return this.userIdentifiedInWorkspace = !1, this._workspaceLastSearchedIdentitiesKey = void 0, Promise.resolve();
672
- const c = o.sort().map((u) => `${u}=${s[u]}`).join("&");
753
+ const c = s.sort().map((u) => `${u}=${o[u]}`).join("&");
673
754
  return c === this._workspaceLastSearchedIdentitiesKey ? this._workspaceSearchInFlightPromise || Promise.resolve() : (this.userIdentifiedInWorkspace = !1, this._workspaceLastSearchedIdentitiesKey = c, new Promise((u) => {
674
755
  try {
675
- n(t, s, (l) => {
756
+ n(t, o, (l) => {
676
757
  l?.httpCode === 200 && (this.userIdentifiedInWorkspace = !0), u();
677
758
  });
678
759
  } catch (l) {
@@ -710,35 +791,47 @@ const f = class f {
710
791
  * rejects it as the awaited return of an async function (TS1058) —
711
792
  * working around that would require a cast or wrapping every return in
712
793
  * `Promise.resolve(...)`. The inner work runs in `_dispatchPlacements`;
713
- * 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.
714
796
  */
715
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
+ }
716
808
  if (this._workspaceSearchInFlightPromise) {
717
- const t = this._workspaceSearchInFlightPromise;
809
+ const n = this._workspaceSearchInFlightPromise;
718
810
  return Promise.race([
719
- t,
720
- new Promise((n) => setTimeout(n, Oe))
811
+ n,
812
+ new Promise((r) => setTimeout(r, J))
721
813
  ]).then(() => this._dispatchPlacements(e));
722
814
  }
723
815
  return this._dispatchPlacements(e);
724
816
  }
725
817
  _dispatchPlacements(e) {
726
- 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;
727
819
  let l;
728
- 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);
729
- const g = this._onboardingExpProvider === "Optimizely" ? this.fetchOptimizely() : {}, C = this.returnUserIdentities(c), v = this.returnLocalSessionAttributes(), R = _e(W(this.loggingService)), p = this.readMpSessionId(), y = this.readMpDeviceId(), E = {
730
- ...C,
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 = {
822
+ ...M,
731
823
  ...l,
732
824
  ...g,
733
825
  ...v,
734
- ...R.length ? { [Te]: JSON.stringify(R) } : {},
735
- ...this.userIdentifiedInWorkspace ? { [we]: !0 } : {},
736
- ...p ? { [Pe]: p } : {},
737
- ...y ? { [Ne]: y } : {},
826
+ ...w.length ? { [Ve]: JSON.stringify(w) } : {},
827
+ ...f ? { [je]: f } : {},
828
+ ...this.userIdentifiedInWorkspace ? { [Ye]: !0 } : {},
829
+ ...y ? { [He]: y } : {},
830
+ ...I ? { [ze]: I } : {},
738
831
  mpid: u
739
- }, w = { ...e, attributes: E }, h = this.launcher.selectPlacements(w), de = () => this.logSelectPlacementsEvent(E);
740
- return Promise.resolve(h).then((he) => he?.context?.sessionId?.then((ge) => this.setRoktSessionId(ge))).catch(() => {
741
- }).finally(de), h;
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;
742
835
  }
743
836
  /**
744
837
  * Passes attributes to the Rokt Web SDK for client-side hashing.
@@ -752,7 +845,19 @@ const f = class f {
752
845
  * @deprecated This functionality has been internalized and will be removed in a future release.
753
846
  */
754
847
  use(e) {
755
- return this.isKitReady() ? !e || !m(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")));
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")));
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());
756
861
  }
757
862
  /**
758
863
  * Registers a callback to be invoked once rokt-thank-you-element.js becomes available.
@@ -761,34 +866,34 @@ const f = class f {
761
866
  this._isThankYouElementLoaded ? e() : this._thankYouElementOnLoadCallback = e;
762
867
  }
763
868
  };
764
- f._allowedOriginHashes = [-553112570, 549508659], f.PERFORMANCE_MARKS = {
869
+ m._allowedOriginHashes = [-553112570, 549508659], m.PERFORMANCE_MARKS = {
765
870
  RoktScriptAppended: "mp:RoktScriptAppended"
766
- }, f.EMAIL_SHA256_KEY = "emailsha256";
767
- let S = f;
768
- function Ve() {
769
- return T;
871
+ }, m.EMAIL_SHA256_KEY = "emailsha256";
872
+ let A = m;
873
+ function nt() {
874
+ return b;
770
875
  }
771
- function je(i) {
876
+ function rt(i) {
772
877
  if (!i) {
773
878
  window.console.log("You must pass a config object to register the kit " + d);
774
879
  return;
775
880
  }
776
- if (!I(i)) {
881
+ if (!_(i)) {
777
882
  window.console.log("'config' must be an object. You passed in a " + typeof i);
778
883
  return;
779
884
  }
780
- I(i.kits) ? i.kits[d] = {
781
- constructor: S
885
+ _(i.kits) ? i.kits[d] = {
886
+ constructor: A
782
887
  } : (i.kits = {}, i.kits[d] = {
783
- constructor: S
888
+ constructor: A
784
889
  }), window.console.log("Successfully registered " + d + " to your mParticle configuration");
785
890
  }
786
891
  typeof window < "u" && window.mParticle && a().addForwarder && a().addForwarder({
787
892
  name: d,
788
- constructor: S,
789
- getId: Ve
893
+ constructor: A,
894
+ getId: nt
790
895
  });
791
896
  export {
792
- je as register
897
+ rt as register
793
898
  };
794
899
  //# sourceMappingURL=Rokt-Kit.esm.js.map
@@ -1,2 +1,2 @@
1
- var RoktKit=(function(C){"use strict";const he=["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"],ge=new Set(he);function G(i){return ge.has(i.toLowerCase())}function v(i){const e={},t=i||{},n=Object.keys(t);for(let r=0;r<n.length;r++){const s=n[r];G(s)||(e[s]=t[s])}return e}function E(i){return typeof i=="object"&&i!==null&&!Array.isArray(i)}function m(i){return typeof i=="string"}function R(i){return typeof i=="function"}function U(i){return i==null?!0:typeof i=="object"?Object.keys(i).length===0:!1}function M(i){try{const e=new URL(i);return e.search="",e.toString()}catch{return i}}const x="__rokt_ls_probe__";function W(){try{return window.localStorage.setItem(x,"1"),window.localStorage.removeItem(x),!0}catch{return!1}}function w(i){try{const e=window.localStorage.getItem(i);return e===null?null:JSON.parse(e)}catch{return null}}function V(i,e){try{return window.localStorage.setItem(i,JSON.stringify(e)),!0}catch{return!1}}function j(i){try{window.localStorage.removeItem(i)}catch{}}function H(i,e){const t=w(i);return E(t)?t[e]:void 0}function z(i,e,t){const n=w(i),r=E(n)?{...n}:{};return r[e]=t,V(i,r)}function pe(i,e){const t=w(i);if(!E(t)||!(e in t))return;const n={...t};delete n[e],Object.keys(n).length===0?j(i):V(i,n)}const y="mp-rokt-kit",A="pageViews",q="mpPageViews",J=25;function $(i){return i.slice(-J)}function B(i){const e=w(q);if(e===null)return;!(H(y,A)!==void 0)&&Array.isArray(e)&&(i?.log({message:"Rokt Kit: Migrating legacy page-view storage",code:"PAGE_VIEW_LEGACY_MIGRATION"}),z(y,A,e)||i?.log({message:"Rokt Kit: Failed to migrate legacy page-view storage [reason: migration_retry]",code:"PAGE_VIEW_CAPTURE_FAILED"})),j(q)}function Q(i){B(i);const e=H(y,A);return Array.isArray(e)?e:[]}function fe(i){const e=$(i);for(let t=0;t<e.length;t++){const n=e.slice(t);if(z(y,A,n))return n.length}return 0}function X(){pe(y,A)}function me(i){const e=$(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 Ee(){const e=document.querySelector('link[rel="canonical"]')?.href;if(e)return M(e)}const d="Rokt",b=181,_e="selectPlacements",Ie="apps.roktecommerce.com",Se=.1,ye="ThankYouPageJourney",Ae="rokt-launcher",ke="rokt-thank-you-element",ve="userIdentifiedInWorkspace",Re=3,we=2,be="page_events",Le="mparticle_session_id",Te="mparticle_device_id",Pe=500,K={UNKNOWN_ERROR:"UNKNOWN_ERROR",UNHANDLED_EXCEPTION:"UNHANDLED_EXCEPTION",IDENTITY_REQUEST:"IDENTITY_REQUEST",LOG_DELIVERY_FAILURE:"LOG_DELIVERY_FAILURE"},_={ERROR:"ERROR",INFO:"INFO",WARNING:"WARNING"},Oe="apps.rokt-api.com",Ne="/v1/log",Ce="/v1/errors",Ue=10;function a(){return window.mParticle}function Z(i,e){const n=[L(i),"/wsdk/integrations/launcher.js"].join("");return!e||e.length===0?n:n+"?extensions="+e.join(",")}function ee(i){return[L(i),"/rokt-elements/rokt-element-thank-you.js"].join("")}function L(i){const e=typeof i<"u"?i:Oe;return e.includes("://")?e.replace(/\/+$/,""):["https://",e].join("")}function te(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 L(r)+t}function ie(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 T(i){if(!i)return[];try{return JSON.parse(i.replace(/&quot;/g,'"'))}catch{console.error("Settings string contains invalid JSON")}return[]}function ne(i){const e=i?T(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(ye)):t.push(o)}return{roktExtensionsQueryParams:t,legacyRoktExtensions:n,loadThankYouElement:r}}async function Me(i,e){const t=[];if(e)for(const n of i)t.push(e.use(n));return Promise.all(t)}function re(i){if(!i)return{};const e={};for(let t=0;t<i.length;t++){const n=i[t];e[n.jsmap]=n.value}return e}function se(i){const e={};if(!Array.isArray(i))return e;for(let t=0;t<i.length;t++){const n=i[t];if(!n||!m(n.value)||!m(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 oe(i,e,t){return a().generateHash([i,e,t].join(""))}function Ke(i){let n="mParticle_wsdkv_"+a().getVersion()+"_kitv_"+"1.34.1";return i&&(n+="_"+i),n}function ae(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 ce(i,e){const t=ae(window.location.origin);if(I._allowedOriginHashes.indexOf(t)===-1||Math.random()>=Se)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?L(i):"https://apps.rokt.com";D(c+"/v1/wsdk-init/index.html?"+o),D("https://"+Ie+"/v1/wsdk-init/index.html?"+o+"&isControl=true")}function De(){return typeof window<"u"&&!!window.location?.search?.toLowerCase().includes("mp_enable_logging=true")}function Fe(){return typeof window<"u"?window.location?.href:void 0}function Ye(){return typeof window<"u"?window.navigator?.userAgent:void 0}class le{constructor(){this._logCount={}}incrementAndCheck(e){const n=(this._logCount[e]||0)+1;return this._logCount[e]=n,n>Ue}}class F{constructor(e,t,n,r,s){this._reporter="mp-wsdk";const o=e.isLoggingEnabled;this._integrationName=t||"",this._launcherInstanceGuid=n,this._accountId=r||null,this._rateLimiter=s||new le,this._isEnabled=De()||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||K.UNKNOWN_ERROR,url:Fe(),deviceInfo:Ye(),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 ue{constructor(e,t,n,r,s){this._transport=new F(e,t,n,r,s),this._errorUrl=te(e?.errorUrl,e?.integrationDomain,Ce)}report(e){if(!e)return;const t=e.severity||_.ERROR;this._transport.send(this._errorUrl,t,e.message,e.code,e.stackTrace)}}class de{constructor(e,t,n,r,s,o){this._transport=new F(e,n,r,s,o),this._loggingUrl=te(e?.loggingUrl,e?.integrationDomain,Ne),this._errorReportingService=t}log(e){e&&this._transport.send(this._loggingUrl,_.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:K.LOG_DELIVERY_FAILURE,severity:n?_.ERROR:_.WARNING})}})}}function Ge(i){const e=M(window.location.href),t=i.EventAttributes?.title||document.title,n=Ee(),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 p=class p{constructor(){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}getEventAttributeValue(e,t){const n=e&&e.EventAttributes;return!n||typeof n[t]>"u"?null:n[t]}doesEventAttributeConditionMatch(e,t){if(!e||!m(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||!m(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(U(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=M(window.location.href);const n=Q(this.loggingService),r=Ge(e);n.push(r);const s=Math.min(n.length,J),o=fe(n);if(o===0){const c=W()?"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=W()?"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&&R(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[p.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(_e,t,e)}setRoktSessionId(e){if(!(!e||typeof e!="string"))try{const t=a().getInstance();t&&R(t.setIntegrationAttribute)&&t.setIntegrationAttribute(b,{roktSessionId:e})}catch{}}readMpSessionId(){const e=a()?.sessionManager,t=e?.getSessionId??e?.getSession;if(R(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 Me(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,ce(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=v(s),this._onboardingExpProvider=o.onboardingExpProvider;const u=T(o.placementEventMapping);this.placementEventMappingLookup=re(u);const l=T(o.placementEventAttributeMapping);this.placementEventAttributeMappingLookup=se(l),o.hashedEmailUserIdentityType&&(this._mappedEmailSha256Key=o.hashedEmailUserIdentityType.toLowerCase()),this._workspaceIdSyncApiKey=m(o.workspaceIdSyncApiKey)?o.workspaceIdSyncApiKey:void 0;const g=a().Rokt?.domain,{roktExtensionsQueryParams:Y,legacyRoktExtensions:P,loadThankYouElement:O}=ne(o.roktExtensions),f={...a().Rokt?.launcherOptions||{}};this.integrationName=Ke(f.integrationName),f.integrationName=this.integrationName,this.domain=g;const k={loggingUrl:o.loggingUrl,errorUrl:o.errorUrl,integrationDomain:g,isLoggingEnabled:a().config?.isLoggingEnabled===!0},S=new ue(k,this.integrationName,window.__rokt_li_guid__,o.accountId),N=new de(k,S,this.integrationName,window.__rokt_li_guid__,o.accountId);if(this.errorReportingService=S,this.loggingService=N,this.isTargetingDisabled())try{X()}catch(h){this.errorReportingService?.report({message:"Rokt Kit: Failed to clear page views when targeting is disabled",code:"PAGE_VIEW_CAPTURE_FAILED",severity:_.INFO,stackTrace:h instanceof Error?h.stack:void 0})}return a()._registerErrorReportingService&&a()._registerErrorReportingService(S),a()._registerLoggingService&&a()._registerLoggingService(N),n?(this.testHelpers={generateLauncherScript:Z,generateThankYouElementScript:ee,extractRoktExtensionConfig:ne,hashEventMessage:oe,parseSettingsString:T,generateMappedEventLookup:re,generateMappedEventAttributeLookup:se,sendAdBlockMeasurementSignals:ce,createAutoRemovedIframe:D,djb2:ae,setAllowedOriginHashes:h=>{p._allowedOriginHashes=h},ReportingTransport:F,ErrorReportingService:ue,LoggingService:de,RateLimiter:le,ErrorCodes:K,WSDKErrorSeverity:_},this.attachLauncher(c,f),"Successfully initialized: "+d):(O&&(a().Rokt.flushOnShoppableAdsReadyMessageQueue?.(this),ie(ke,ee(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,P):(ie(Ae,Z(g,Y),{onLoad:()=>{this.isLauncherReadyToAttach()?this.attachLauncher(c,f,P):console.error("Rokt object is not available after script load.")},onError:h=>{console.error("Error loading Rokt launcher script:",h)}}),this.captureTiming(p.PERFORMANCE_MARKS.RoktScriptAppended)),"Successfully initialized: "+d)}process(e){if(this.isTargetingDisabled()||(e.EventDataType===Re&&this.capturePageView(e),e.EventDataType===we&&(B(this.loggingService),X())),!this.isKitReady())return"Kit not ready for forwarder: "+d;if(R(a().Rokt?.setLocalSessionAttribute)&&(U(this.placementEventAttributeMappingLookup)||this.applyPlacementEventAttributeMapping(e),!U(this.placementEventMappingLookup))){const t=oe(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 G(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,s={};if(r)for(const u of Object.keys(r)){const l=r[u];m(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,Pe))]).then(()=>this._dispatchPlacements(e))}return this._dispatchPlacements(e)}_dispatchPlacements(e){const t=e&&e.attributes||{},r={...v(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=v(l);const g=this._onboardingExpProvider==="Optimizely"?this.fetchOptimizely():{},Y=this.returnUserIdentities(c),P=this.returnLocalSessionAttributes(),O=me(Q(this.loggingService)),f=this.readMpSessionId(),k=this.readMpDeviceId(),S={...Y,...l,...g,...P,...O.length?{[be]:JSON.stringify(O)}:{},...this.userIdentifiedInWorkspace?{[ve]:!0}:{},...f?{[Le]:f}:{},...k?{[Te]:k}:{},mpid:u},N={...e,attributes:S},h=this.launcher.selectPlacements(N),Ve=()=>this.logSelectPlacementsEvent(S);return Promise.resolve(h).then(je=>je?.context?.sessionId?.then(He=>this.setRoktSessionId(He))).catch(()=>{}).finally(Ve),h}hashAttributes(e){return this.isKitReady()?this.launcher.hashAttributes(e):(console.error("Rokt Kit: Not initialized"),null)}use(e){return this.isKitReady()?!e||!m(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}};p._allowedOriginHashes=[-553112570,549508659],p.PERFORMANCE_MARKS={RoktScriptAppended:"mp:RoktScriptAppended"},p.EMAIL_SHA256_KEY="emailsha256";let I=p;function xe(){return b}function We(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:I}:(i.kits={},i.kits[d]={constructor:I}),window.console.log("Successfully registered "+d+" to your mParticle configuration")}return typeof window<"u"&&window.mParticle&&a().addForwarder&&a().addForwarder({name:d,constructor:I,getId:xe}),C.register=We,Object.defineProperty(C,Symbol.toStringTag,{value:"Module"}),C})({});
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.34.1",
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",