@mparticle/web-rokt-kit 1.34.1 → 1.35.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 _e=["active_time_on_site_ms","billingaddress1","billingaddress2","billingcity","billingstate","billingzipcode","cartitems","ccbin","confirmationref","conversiontype","country","couponcode","currency","language","paymentserviceprovider","paymentserviceproviderattribute","paymenttype","shippingaddress1","shippingcity","shippingcountry","shippingmethod","shippingstate","shippingzipcode","totalprice"],Ie=new Set(_e);function se(i){return Ie.has(i.toLowerCase())}function b(i){const e={},t=i||{},n=Object.keys(t);for(let r=0;r<n.length;r++){const s=n[r];se(s)||(e[s]=t[s])}return e}function _(i){return typeof i=="object"&&i!==null&&!Array.isArray(i)}function E(i){return typeof i=="string"}function T(i){return typeof i=="function"}function K(i){return i==null?!0:typeof i=="object"?Object.keys(i).length===0:!1}function Y(i){try{const e=new URL(i);return e.search="",e.toString()}catch{return i}}const V="__rokt_ls_probe__";function D(){try{return window.localStorage.setItem(V,"1"),window.localStorage.removeItem(V),!0}catch{return!1}}function N(i){try{const e=window.localStorage.getItem(i);return e===null?null:JSON.parse(e)}catch{return null}}function oe(i,e){try{return window.localStorage.setItem(i,JSON.stringify(e)),!0}catch{return!1}}function ae(i){try{window.localStorage.removeItem(i)}catch{}}function U(i,e){const t=N(i);return _(t)?t[e]:void 0}function G(i,e,t){const n=N(i),r=_(n)?{...n}:{};return r[e]=t,oe(i,r)}function ce(i,e){const t=N(i);if(!_(t)||!(e in t))return;const n={...t};delete n[e],Object.keys(n).length===0?ae(i):oe(i,n)}const p="mp-rokt-kit",v="pageViews",O="utmParams",H="mpPageViews",le=25,Se=["utm_source","utm_medium","utm_campaign","utm_term","utm_content"];function ue(i){return i.slice(-le)}function de(i){const e=N(H);if(e===null)return;!(U(p,v)!==void 0)&&Array.isArray(e)&&(i?.log({message:"Rokt Kit: Migrating legacy page-view storage",code:"PAGE_VIEW_LEGACY_MIGRATION"}),G(p,v,e)||i?.log({message:"Rokt Kit: Failed to migrate legacy page-view storage [reason: migration_retry]",code:"PAGE_VIEW_CAPTURE_FAILED"})),ae(H)}function z(i){de(i);const e=U(p,v);return Array.isArray(e)?e:[]}function ye(i){const e=ue(i);for(let t=0;t<e.length;t++){const n=e.slice(t);if(G(p,v,n))return n.length}return 0}function q(){ce(p,v)}function Ae(i){const e=ue(i);return e.map((t,n)=>{const r=t.activeTimeOnSite,s=r!==void 0&&Number.isFinite(r),c=e[n+1]?.activeTimeOnSite,u=c!==void 0&&Number.isFinite(c),l=s&&u?c-r:void 0;return{pageUrl:t.pageUrl,sourceMessageId:t.sourceMessageId,timestamp:t.timestamp,...t.pageTitle!==void 0?{pageTitle:t.pageTitle}:{},...t.canonicalUrl!==void 0?{canonicalUrl:t.canonicalUrl}:{},...s?{activeTimeOnSite:r}:{},...l!==void 0&&l>=0?{activeTimeOnPage:l}:{}}})}function ke(i){if(U(p,O)!==void 0)return;const e=new URLSearchParams(window.location.search),t={};for(const r of Se){const s=e.get(r);s&&(t[r]=s)}if(Object.keys(t).length===0)return;const n=Object.keys(t).join(", ");if(!G(p,O,t)){const r=D()?"quota":"ls_unavailable";i?.log({message:`Rokt Kit: Failed to persist UTM params [reason: ${r}]`,code:"UTM_CAPTURE_FAILED"});return}i?.log({message:`Rokt Kit: Captured UTM params [${n}]`,code:"UTM_CAPTURE_SUCCESS"})}function ve(){const i=U(p,O);return _(i)?i:null}function $(){ce(p,O)}function Re(){const e=document.querySelector('link[rel="canonical"]')?.href;if(e)return Y(e)}const d="Rokt",L=181,we="selectPlacements",be="apps.roktecommerce.com",Te=.1,Le="ThankYouPageJourney",Pe="rokt-launcher",Oe="rokt-thank-you-element",Ne="userIdentifiedInWorkspace",Ue=3,Ce=2,Me="page_events",Ke="page_view_attributes",De="mparticle_session_id",Fe="mparticle_device_id",Ye=500,x={UNKNOWN_ERROR:"UNKNOWN_ERROR",UNHANDLED_EXCEPTION:"UNHANDLED_EXCEPTION",IDENTITY_REQUEST:"IDENTITY_REQUEST",LOG_DELIVERY_FAILURE:"LOG_DELIVERY_FAILURE"},S={ERROR:"ERROR",INFO:"INFO",WARNING:"WARNING"},Ge="apps.rokt-api.com",xe="/v1/log",We="/v1/errors",je=10;function a(){return window.mParticle}function J(i,e){const n=[C(i),"/wsdk/integrations/launcher.js"].join("");return!e||e.length===0?n:n+"?extensions="+e.join(",")}function B(i){return[C(i),"/rokt-elements/rokt-element-thank-you.js"].join("")}function C(i){const e=typeof i<"u"?i:Ge;return e.includes("://")?e.replace(/\/+$/,""):["https://",e].join("")}function he(i,e,t){if(i)return i.startsWith("http://")||i.startsWith("https://")?i:"https://"+i;const r=e?.includes("://")&&!/^https?:\/\//i.test(e)?void 0:e;return C(r)+t}function Q(i,e,t){if(document.getElementById(i))return;const n=document.head||document.body,r=document.createElement("script");r.id=i,r.type="text/javascript",r.src=e,r.async=!0,r.crossOrigin="anonymous",r.fetchPriority="high",t?.onLoad&&(r.onload=t.onLoad),t?.onError&&(r.onerror=t.onError),n.appendChild(r)}function P(i){if(!i)return[];try{return JSON.parse(i.replace(/&quot;/g,'"'))}catch{console.error("Settings string contains invalid JSON")}return[]}function X(i){const e=i?P(i):[],t=[],n=[];let r=!1;for(let s=0;s<e.length;s++){const o=e[s].value;o==="thank-you-journey"?(r=!0,n.push(Le)):t.push(o)}return{roktExtensionsQueryParams:t,legacyRoktExtensions:n,loadThankYouElement:r}}async function Ve(i,e){const t=[];if(e)for(const n of i)t.push(e.use(n));return Promise.all(t)}function Z(i){if(!i)return{};const e={};for(let t=0;t<i.length;t++){const n=i[t];e[n.jsmap]=n.value}return e}function ee(i){const e={};if(!Array.isArray(i))return e;for(let t=0;t<i.length;t++){const n=i[t];if(!n||!E(n.value)||!E(n.map))continue;const r=n.value,s=n.map;e[r]||(e[r]=[]),e[r].push({eventAttributeKey:s,conditions:Array.isArray(n.conditions)?n.conditions:[]})}return e}function te(i,e,t){return a().generateHash([i,e,t].join(""))}function He(i){let n="mParticle_wsdkv_"+a().getVersion()+"_kitv_"+"1.35.0";return i&&(n+="_"+i),n}function ge(i){let e=5381;for(let t=0;t<i.length;t++)e=(e<<5)+e+i.charCodeAt(t),e=e&e;return e}function F(i){const e=document.createElement("iframe");e.style.display="none",e.setAttribute("sandbox","allow-scripts allow-same-origin"),e.src=i,e.onload=function(){e.onload=null,e.parentNode&&e.parentNode.removeChild(e)};const t=document.body||document.head;t&&t.appendChild(e)}function ie(i,e){const t=ge(window.location.origin);if(y._allowedOriginHashes.indexOf(t)===-1||Math.random()>=Te)return;const r=window.__rokt_li_guid__;if(!r||i&&i.includes("://")&&!/^https:\/\//i.test(i))return;const s=window.location.href.split("?")[0].split("#")[0],o="version="+encodeURIComponent(e??"")+"&launcherInstanceGuid="+encodeURIComponent(r)+"&pageUrl="+encodeURIComponent(s),c=i?C(i):"https://apps.rokt.com";F(c+"/v1/wsdk-init/index.html?"+o),F("https://"+be+"/v1/wsdk-init/index.html?"+o+"&isControl=true")}function ze(){return typeof window<"u"&&!!window.location?.search?.toLowerCase().includes("mp_enable_logging=true")}function qe(){return typeof window<"u"?window.location?.href:void 0}function $e(){return typeof window<"u"?window.navigator?.userAgent:void 0}class pe{constructor(){this._logCount={}}incrementAndCheck(e){const n=(this._logCount[e]||0)+1;return this._logCount[e]=n,n>je}}class W{constructor(e,t,n,r,s){this._reporter="mp-wsdk";const o=e.isLoggingEnabled;this._integrationName=t||"",this._launcherInstanceGuid=n,this._accountId=r||null,this._rateLimiter=s||new pe,this._isEnabled=ze()||o}send(e,t,n,r,s,o){if(!(!this._isEnabled||this._rateLimiter.incrementAndCheck(t)))try{const c={additionalInformation:{message:n,version:this._integrationName},severity:t,code:r||x.UNKNOWN_ERROR,url:qe(),deviceInfo:$e(),stackTrace:s,reporter:this._reporter,integration:this._integrationName},u={Accept:"text/plain;charset=UTF-8","Content-Type":"application/json","rokt-launcher-version":this._integrationName,"rokt-wsdk-version":"joint"};this._launcherInstanceGuid&&(u["rokt-launcher-instance-guid"]=this._launcherInstanceGuid),this._accountId&&(u["rokt-account-id"]=this._accountId),fetch(e,{method:"POST",headers:u,body:JSON.stringify(c)}).then(l=>{if(!l.ok){const g=new Error("HTTP "+l.status+" from log endpoint");throw g.statusCode=l.status,g}}).catch(l=>{console.error("ReportingTransport: Failed to send log",l),o&&o(l)})}catch(c){console.error("ReportingTransport: Failed to send log",c),o&&o(c)}}}class ne{constructor(e,t,n,r,s){this._transport=new W(e,t,n,r,s),this._errorUrl=he(e?.errorUrl,e?.integrationDomain,We)}report(e){if(!e)return;const t=e.severity||S.ERROR;this._transport.send(this._errorUrl,t,e.message,e.code,e.stackTrace)}}class re{constructor(e,t,n,r,s,o){this._transport=new W(e,n,r,s,o),this._loggingUrl=he(e?.loggingUrl,e?.integrationDomain,xe),this._errorReportingService=t}log(e){e&&this._transport.send(this._loggingUrl,S.INFO,e.message,e.code,void 0,t=>{if(this._errorReportingService){const n=typeof t.statusCode=="number";this._errorReportingService.report({message:"LoggingService: Failed to send log: "+t.message,code:x.LOG_DELIVERY_FAILURE,severity:n?S.ERROR:S.WARNING})}})}}function Je(i){const e=Y(window.location.href),t=i.EventAttributes?.title||document.title,n=Re(),r=i.ActiveTimeOnSite;return{pageUrl:e,sourceMessageId:i.SourceMessageId,timestamp:i.Timestamp,...t?{pageTitle:t}:{},...n!==void 0?{canonicalUrl:n}:{},...Number.isFinite(r)?{activeTimeOnSite:r}:{}}}const m=class m{constructor(){this.name=d,this.id=L,this.moduleId=L,this.isInitialized=!1,this.launcher=null,this.filters={},this.userAttributes={},this.userIdentifiedInWorkspace=!1,this.testHelpers=null,this.placementEventMappingLookup={},this.placementEventAttributeMappingLookup={},this.integrationName=null,this.errorReportingService=null,this.loggingService=null,this._thankYouElementOnLoadCallback=null,this._isThankYouElementLoaded=!1,this._workspaceSearchInFlightPromise=null}getEventAttributeValue(e,t){const n=e&&e.EventAttributes;return!n||typeof n[t]>"u"?null:n[t]}doesEventAttributeConditionMatch(e,t){if(!e||!E(e.operator))return!1;const n=e.operator.toLowerCase(),r=e.attributeValue;return n==="exists"?t!==null:t==null?!1:n==="equals"?String(t)===String(r):n==="contains"?String(t).indexOf(String(r))!==-1:!1}doesEventMatchRule(e,t){if(!t||!E(t.eventAttributeKey))return!1;const n=t.conditions;if(!Array.isArray(n))return!1;const r=this.getEventAttributeValue(e,t.eventAttributeKey);if(n.length===0)return r!==null;for(let s=0;s<n.length;s++)if(!this.doesEventAttributeConditionMatch(n[s],r))return!1;return!0}applyPlacementEventAttributeMapping(e){const t=Object.keys(this.placementEventAttributeMappingLookup);for(let n=0;n<t.length;n++){const r=t[n],s=this.placementEventAttributeMappingLookup[r];if(K(s))continue;let o=!0;for(let c=0;c<s.length;c++)if(!this.doesEventMatchRule(e,s[c])){o=!1;break}o&&a().Rokt.setLocalSessionAttribute?.(r,!0)}}capturePageView(e){let t;try{t=Y(window.location.href);const n=z(this.loggingService),r=Je(e);n.push(r);const s=Math.min(n.length,le),o=ye(n);if(o===0){const c=D()?"quota":"ls_unavailable";this.loggingService?.log({message:`Rokt Kit: Failed to persist page view for ${t} [reason: ${c}]`,code:"PAGE_VIEW_CAPTURE_FAILED"})}else o<s&&this.loggingService?.log({message:`Rokt Kit: Page view storage reduced from ${s} to ${o} record(s) under quota pressure [reason: quota_eviction]`,code:"PAGE_VIEW_QUOTA_EVICTION"})}catch(n){const r=D()?"exception":"ls_unavailable",s=n instanceof Error?n.message:String(n);this.loggingService?.log({message:`Rokt Kit: Failed to capture page view for ${t}: ${s} [reason: ${r}]`,code:"PAGE_VIEW_CAPTURE_FAILED"})}}isLauncherReadyToAttach(){return!!window.Rokt&&T(window.Rokt.createLauncher)}returnUserIdentities(e){if(!e||!e.getUserIdentities)return{};const t=e.getUserIdentities().userIdentities;return this.replaceOtherIdentityWithEmailsha256(t)}returnLocalSessionAttributes(){return!a().Rokt||typeof a().Rokt.getLocalSessionAttributes!="function"?{}:a().Rokt.getLocalSessionAttributes()}replaceOtherIdentityWithEmailsha256(e){const t={...e||{}},n=this._mappedEmailSha256Key;return n&&e[n]&&(t[m.EMAIL_SHA256_KEY]=e[n]),n&&delete t[n],t}logSelectPlacementsEvent(e){if(!window.mParticle||typeof a().logEvent!="function"||!_(e))return;const t=a().EventType.Other;a().logEvent(we,t,e)}setRoktSessionId(e){if(!(!e||typeof e!="string"))try{const t=a().getInstance();t&&T(t.setIntegrationAttribute)&&t.setIntegrationAttribute(L,{roktSessionId:e})}catch{}}readMpSessionId(){const e=a()?.sessionManager,t=e?.getSessionId??e?.getSession;if(T(t))return t.call(e)||void 0}readMpDeviceId(){return a()?.getDeviceId?.()||void 0}attachLauncher(e,t,n=[]){const r={accountId:e,...t||{}};let s;this.isPartnerInLocalLauncherTestGroup()?s=Promise.resolve(window.Rokt.createLocalLauncher(r)):s=window.Rokt.createLauncher(r),s.then(async o=>{await Ve(n,o),this.initRoktLauncher(o)}).catch(o=>{console.error("Error creating Rokt launcher:",o)})}initRoktLauncher(e){window.Rokt&&(window.Rokt.currentLauncher=e),this.launcher=e;const t=a().Rokt?.filters;t?(this.filters=t,t.filteredUser?this._workspaceSearchInFlightPromise=this.search(t.filteredUser):console.warn("Rokt Kit: No filtered user has been set.")):console.warn("Rokt Kit: No filters have been set."),this.isInitialized=!0,ie(this.domain,this.integrationName),a().Rokt.attachKit(this)}fetchOptimizely(){const e=a()._getActiveForwarders().filter(t=>t.name==="Optimizely");try{if(e.length>0&&window.optimizely){const t=window.optimizely.get("state");return!t||!t.getActiveExperimentIds?{}:t.getActiveExperimentIds().reduce((s,o)=>(s["rokt.custom.optimizely.experiment."+o+".variationId"]=t.getVariationMap()[o].id,s),{})}}catch(t){console.error("Error fetching Optimizely attributes:",t)}return{}}isKitReady(){return!!(this.isInitialized&&this.launcher)}isTargetingDisabled(){return a().Rokt?.launcherOptions?.noTargeting===!0}isPartnerInLocalLauncherTestGroup(){return!!(a().config&&a().config.isLocalLauncherEnabled&&this.isAssignedToSampleGroup())}isAssignedToSampleGroup(){return Math.random()>.5}captureTiming(e){window&&a()&&a().captureTiming&&e&&a().captureTiming(e)}init(e,t,n,r,s){const o=e,c=o.accountId;this.userAttributes=b(s),this._onboardingExpProvider=o.onboardingExpProvider;const u=P(o.placementEventMapping);this.placementEventMappingLookup=Z(u);const l=P(o.placementEventAttributeMapping);this.placementEventAttributeMappingLookup=ee(l),o.hashedEmailUserIdentityType&&(this._mappedEmailSha256Key=o.hashedEmailUserIdentityType.toLowerCase()),this._workspaceIdSyncApiKey=E(o.workspaceIdSyncApiKey)?o.workspaceIdSyncApiKey:void 0;const g=a().Rokt?.domain,{roktExtensionsQueryParams:M,legacyRoktExtensions:R,loadThankYouElement:w}=X(o.roktExtensions),f={...a().Rokt?.launcherOptions||{}};this.integrationName=He(f.integrationName),f.integrationName=this.integrationName,this.domain=g;const A={loggingUrl:o.loggingUrl,errorUrl:o.errorUrl,integrationDomain:g,isLoggingEnabled:a().config?.isLoggingEnabled===!0},I=new ne(A,this.integrationName,window.__rokt_li_guid__,o.accountId),k=new re(A,I,this.integrationName,window.__rokt_li_guid__,o.accountId);if(this.errorReportingService=I,this.loggingService=k,this.isTargetingDisabled())try{q(),$()}catch(h){this.errorReportingService?.report({message:"Rokt Kit: Failed to clear page views when targeting is disabled",code:"PAGE_VIEW_CAPTURE_FAILED",severity:S.INFO,stackTrace:h instanceof Error?h.stack:void 0})}return a()._registerErrorReportingService&&a()._registerErrorReportingService(I),a()._registerLoggingService&&a()._registerLoggingService(k),n?(this.testHelpers={generateLauncherScript:J,generateThankYouElementScript:B,extractRoktExtensionConfig:X,hashEventMessage:te,parseSettingsString:P,generateMappedEventLookup:Z,generateMappedEventAttributeLookup:ee,sendAdBlockMeasurementSignals:ie,createAutoRemovedIframe:F,djb2:ge,setAllowedOriginHashes:h=>{m._allowedOriginHashes=h},ReportingTransport:W,ErrorReportingService:ne,LoggingService:re,RateLimiter:pe,ErrorCodes:x,WSDKErrorSeverity:S},this.attachLauncher(c,f),"Successfully initialized: "+d):(w&&(a().Rokt.flushOnShoppableAdsReadyMessageQueue?.(this),Q(Oe,B(g),{onLoad:()=>{this._isThankYouElementLoaded=!0,this._thankYouElementOnLoadCallback&&this._thankYouElementOnLoadCallback()},onError:h=>{console.error("Error loading Rokt Thank You Element script:",h)}})),this.isLauncherReadyToAttach()?this.attachLauncher(c,f,R):(Q(Pe,J(g,M),{onLoad:()=>{this.isLauncherReadyToAttach()?this.attachLauncher(c,f,R):console.error("Rokt object is not available after script load.")},onError:h=>{console.error("Error loading Rokt launcher script:",h)}}),this.captureTiming(m.PERFORMANCE_MARKS.RoktScriptAppended)),"Successfully initialized: "+d)}process(e){if(this.isTargetingDisabled()||(e.EventDataType===Ue&&(ke(this.loggingService),this.capturePageView(e)),e.EventDataType===Ce&&(de(this.loggingService),q(),$())),!this.isKitReady())return"Kit not ready for forwarder: "+d;if(T(a().Rokt?.setLocalSessionAttribute)&&(K(this.placementEventAttributeMappingLookup)||this.applyPlacementEventAttributeMapping(e),!K(this.placementEventMappingLookup))){const t=te(e.EventDataType,e.EventCategory,e.EventName??"");this.placementEventMappingLookup[String(t)]&&a().Rokt.setLocalSessionAttribute?.(this.placementEventMappingLookup[String(t)],!0)}return"Successfully sent to forwarder: "+d}setExtensionData(e){if(!this.isKitReady()){console.error("Rokt Kit: Not initialized");return}window.Rokt.setExtensionData(e)}setUserAttribute(e,t){return se(e)||(this.userAttributes[e]=t),"Successfully set user attribute for forwarder: "+d}removeUserAttribute(e){return delete this.userAttributes[e],"Successfully removed user attribute for forwarder: "+d}handleIdentityComplete(e,t){return this.userAttributes=b(e.getAllUserAttributes()),"Successfully called "+t+" for forwarder: "+d}onUserIdentified(e){const t=e;return this.filters.filteredUser=t,this._workspaceSearchInFlightPromise=this.search(t),this.handleIdentityComplete(e,"onUserIdentified")}search(e){const t=this._workspaceIdSyncApiKey;if(!t)return this.userIdentifiedInWorkspace=!1,this._workspaceLastSearchedIdentitiesKey=void 0,Promise.resolve();const n=a().Identity?.search;if(typeof n!="function")return this.userIdentifiedInWorkspace=!1,this._workspaceLastSearchedIdentitiesKey=void 0,Promise.resolve();const r=e.getUserIdentities?e.getUserIdentities().userIdentities:null,s={};if(r)for(const u of Object.keys(r)){const l=r[u];E(l)&&l.length>0&&(s[u]=l)}const o=Object.keys(s);if(o.length===0)return this.userIdentifiedInWorkspace=!1,this._workspaceLastSearchedIdentitiesKey=void 0,Promise.resolve();const c=o.sort().map(u=>`${u}=${s[u]}`).join("&");return c===this._workspaceLastSearchedIdentitiesKey?this._workspaceSearchInFlightPromise||Promise.resolve():(this.userIdentifiedInWorkspace=!1,this._workspaceLastSearchedIdentitiesKey=c,new Promise(u=>{try{n(t,s,l=>{l?.httpCode===200&&(this.userIdentifiedInWorkspace=!0),u()})}catch(l){console.error("Rokt Kit: Workspace IDSync search failed",l),this._workspaceLastSearchedIdentitiesKey=void 0,u()}}))}onLoginComplete(e,t){return this.handleIdentityComplete(e,"onLoginComplete")}onLogoutComplete(e,t){return this.userIdentifiedInWorkspace=!1,this._workspaceSearchInFlightPromise=null,this._workspaceLastSearchedIdentitiesKey=void 0,this.handleIdentityComplete(e,"onLogoutComplete")}onModifyComplete(e,t){return this.handleIdentityComplete(e,"onModifyComplete")}selectPlacements(e){if(this._workspaceSearchInFlightPromise){const t=this._workspaceSearchInFlightPromise;return Promise.race([t,new Promise(n=>setTimeout(n,Ye))]).then(()=>this._dispatchPlacements(e))}return this._dispatchPlacements(e)}_dispatchPlacements(e){const t=e&&e.attributes||{},r={...b(this.userAttributes),...t},s=this.filters||{},o=s.userAttributeFilters||[],c=s.filteredUser||null,u=c?c.getMPID():null;let l;s?s.filterUserAttributes?l=s.filterUserAttributes(r,o):l=r:(console.warn("Rokt Kit: No filters available, using user attributes"),l=r),this.userAttributes=b(l);const g=this._onboardingExpProvider==="Optimizely"?this.fetchOptimizely():{},M=this.returnUserIdentities(c),R=this.returnLocalSessionAttributes(),w=Ae(z(this.loggingService)),f=ve(),A=this.readMpSessionId(),I=this.readMpDeviceId(),k={...M,...l,...g,...R,...w.length?{[Me]:JSON.stringify(w)}:{},...f?{[Ke]:f}:{},...this.userIdentifiedInWorkspace?{[Ne]:!0}:{},...A?{[De]:A}:{},...I?{[Fe]:I}:{},mpid:u},h={...e,attributes:k},j=this.launcher.selectPlacements(h),fe=()=>this.logSelectPlacementsEvent(k);return Promise.resolve(j).then(me=>me?.context?.sessionId?.then(Ee=>this.setRoktSessionId(Ee))).catch(()=>{}).finally(fe),j}hashAttributes(e){return this.isKitReady()?this.launcher.hashAttributes(e):(console.error("Rokt Kit: Not initialized"),null)}use(e){return this.isKitReady()?!e||!E(e)?Promise.reject(new Error("Rokt Kit: Invalid extension name")):this.launcher.use(e):(console.error("Rokt Kit: Not initialized"),Promise.reject(new Error("Rokt Kit: Not initialized")))}onShoppableAdsReady(e){this._isThankYouElementLoaded?e():this._thankYouElementOnLoadCallback=e}};m._allowedOriginHashes=[-553112570,549508659],m.PERFORMANCE_MARKS={RoktScriptAppended:"mp:RoktScriptAppended"},m.EMAIL_SHA256_KEY="emailsha256";let y=m;function Be(){return L}function Qe(i){if(!i){window.console.log("You must pass a config object to register the kit "+d);return}if(!_(i)){window.console.log("'config' must be an object. You passed in a "+typeof i);return}_(i.kits)?i.kits[d]={constructor:y}:(i.kits={},i.kits[d]={constructor:y}),window.console.log("Successfully registered "+d+" to your mParticle configuration")}typeof window<"u"&&window.mParticle&&a().addForwarder&&a().addForwarder({name:d,constructor:y,getId:Be});exports.register=Qe;
2
2
  //# sourceMappingURL=Rokt-Kit.common.js.map
@@ -1,4 +1,4 @@
1
- const pe = [
1
+ const _e = [
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
+ ], Ie = new Set(_e);
27
+ function se(i) {
28
+ return Ie.has(i.toLowerCase());
29
29
  }
30
30
  function b(i) {
31
31
  const e = {}, t = i || {}, n = Object.keys(t);
32
32
  for (let r = 0; r < n.length; r++) {
33
33
  const s = n[r];
34
- ee(s) || (e[s] = t[s]);
34
+ se(s) || (e[s] = t[s]);
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 Y(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 D() {
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,69 +71,69 @@ function N(i) {
71
71
  return null;
72
72
  }
73
73
  }
74
- function te(i, e) {
74
+ function oe(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 ae(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 x(i, e, t) {
92
+ const n = N(i), r = _(n) ? { ...n } : {};
93
+ return r[e] = t, oe(i, r);
94
94
  }
95
- function me(i, e) {
95
+ function ce(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 ? ae(i) : oe(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", le = 25, Se = ["utm_source", "utm_medium", "utm_campaign", "utm_term", "utm_content"];
103
+ function ue(i) {
104
+ return i.slice(-le);
105
105
  }
106
- function ae(i) {
107
- const e = N(G);
106
+ function de(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
+ }), x(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
+ })), ae(H);
117
117
  }
118
- function W(i) {
119
- ae(i);
120
- const e = ne(A, k);
118
+ function z(i) {
119
+ de(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 = ue(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 (x(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
+ ce(p, R);
134
134
  }
135
- function _e(i) {
136
- const e = oe(i);
135
+ function Ae(i) {
136
+ const e = ue(i);
137
137
  return e.map((t, n) => {
138
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;
139
139
  return {
@@ -147,42 +147,73 @@ function _e(i) {
147
147
  };
148
148
  });
149
149
  }
150
- function Ie() {
150
+ function ke(i) {
151
+ if (U(p, O) !== void 0)
152
+ return;
153
+ const e = new URLSearchParams(window.location.search), t = {};
154
+ for (const r of Se) {
155
+ const s = e.get(r);
156
+ s && (t[r] = s);
157
+ }
158
+ if (Object.keys(t).length === 0)
159
+ return;
160
+ const n = Object.keys(t).join(", ");
161
+ if (!x(p, O, t)) {
162
+ const r = D() ? "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 Re() {
175
+ const i = U(p, O);
176
+ return _(i) ? i : null;
177
+ }
178
+ function $() {
179
+ ce(p, O);
180
+ }
181
+ function ve() {
151
182
  const e = document.querySelector('link[rel="canonical"]')?.href;
152
183
  if (e)
153
- return K(e);
184
+ return Y(e);
154
185
  }
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 = {
186
+ const d = "Rokt", L = 181, we = "selectPlacements", be = "apps.roktecommerce.com", Te = 0.1, Le = "ThankYouPageJourney", Pe = "rokt-launcher", Oe = "rokt-thank-you-element", Ne = "userIdentifiedInWorkspace", Ue = 3, Ce = 2, Me = "page_events", Ke = "page_view_attributes", De = "mparticle_session_id", Fe = "mparticle_device_id", Ye = 500, G = {
156
187
  UNKNOWN_ERROR: "UNKNOWN_ERROR",
157
188
  UNHANDLED_EXCEPTION: "UNHANDLED_EXCEPTION",
158
189
  IDENTITY_REQUEST: "IDENTITY_REQUEST",
159
190
  LOG_DELIVERY_FAILURE: "LOG_DELIVERY_FAILURE"
160
- }, _ = {
191
+ }, S = {
161
192
  ERROR: "ERROR",
162
193
  INFO: "INFO",
163
194
  WARNING: "WARNING"
164
- }, Ce = "apps.rokt-api.com", Ue = "/v1/log", Me = "/v1/errors", Ke = 10;
195
+ }, xe = "apps.rokt-api.com", Ge = "/v1/log", We = "/v1/errors", Ve = 10;
165
196
  function a() {
166
197
  return window.mParticle;
167
198
  }
168
- function j(i, e) {
169
- const n = [O(i), "/wsdk/integrations/launcher.js"].join("");
199
+ function J(i, e) {
200
+ const n = [C(i), "/wsdk/integrations/launcher.js"].join("");
170
201
  return !e || e.length === 0 ? n : n + "?extensions=" + e.join(",");
171
202
  }
172
- function H(i) {
173
- return [O(i), "/rokt-elements/rokt-element-thank-you.js"].join("");
203
+ function B(i) {
204
+ return [C(i), "/rokt-elements/rokt-element-thank-you.js"].join("");
174
205
  }
175
- function O(i) {
176
- const e = typeof i < "u" ? i : Ce;
206
+ function C(i) {
207
+ const e = typeof i < "u" ? i : xe;
177
208
  return e.includes("://") ? e.replace(/\/+$/, "") : ["https://", e].join("");
178
209
  }
179
- function ce(i, e, t) {
210
+ function he(i, e, t) {
180
211
  if (i)
181
212
  return i.startsWith("http://") || i.startsWith("https://") ? i : "https://" + i;
182
213
  const r = e?.includes("://") && !/^https?:\/\//i.test(e) ? void 0 : e;
183
- return O(r) + t;
214
+ return C(r) + t;
184
215
  }
185
- function z(i, e, t) {
216
+ function Q(i, e, t) {
186
217
  if (document.getElementById(i)) return;
187
218
  const n = document.head || document.body, r = document.createElement("script");
188
219
  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 +228,12 @@ function P(i) {
197
228
  }
198
229
  return [];
199
230
  }
200
- function q(i) {
231
+ function X(i) {
201
232
  const e = i ? P(i) : [], t = [], n = [];
202
233
  let r = !1;
203
234
  for (let s = 0; s < e.length; s++) {
204
235
  const o = e[s].value;
205
- o === "thank-you-journey" ? (r = !0, n.push(ke)) : t.push(o);
236
+ o === "thank-you-journey" ? (r = !0, n.push(Le)) : t.push(o);
206
237
  }
207
238
  return {
208
239
  roktExtensionsQueryParams: t,
@@ -210,14 +241,14 @@ function q(i) {
210
241
  loadThankYouElement: r
211
242
  };
212
243
  }
213
- async function De(i, e) {
244
+ async function je(i, e) {
214
245
  const t = [];
215
246
  if (e)
216
247
  for (const n of i)
217
248
  t.push(e.use(n));
218
249
  return Promise.all(t);
219
250
  }
220
- function J(i) {
251
+ function Z(i) {
221
252
  if (!i)
222
253
  return {};
223
254
  const e = {};
@@ -227,13 +258,13 @@ function J(i) {
227
258
  }
228
259
  return e;
229
260
  }
230
- function $(i) {
261
+ function ee(i) {
231
262
  const e = {};
232
263
  if (!Array.isArray(i))
233
264
  return e;
234
265
  for (let t = 0; t < i.length; t++) {
235
266
  const n = i[t];
236
- if (!n || !m(n.value) || !m(n.map))
267
+ if (!n || !E(n.value) || !E(n.map))
237
268
  continue;
238
269
  const r = n.value, s = n.map;
239
270
  e[r] || (e[r] = []), e[r].push({
@@ -243,20 +274,20 @@ function $(i) {
243
274
  }
244
275
  return e;
245
276
  }
246
- function B(i, e, t) {
277
+ function te(i, e, t) {
247
278
  return a().generateHash([i, e, t].join(""));
248
279
  }
249
- function Fe(i) {
250
- let n = "mParticle_wsdkv_" + a().getVersion() + "_kitv_" + "1.34.1";
280
+ function He(i) {
281
+ let n = "mParticle_wsdkv_" + a().getVersion() + "_kitv_" + "1.35.0";
251
282
  return i && (n += "_" + i), n;
252
283
  }
253
- function le(i) {
284
+ function ge(i) {
254
285
  let e = 5381;
255
286
  for (let t = 0; t < i.length; t++)
256
287
  e = (e << 5) + e + i.charCodeAt(t), e = e & e;
257
288
  return e;
258
289
  }
259
- function M(i) {
290
+ function F(i) {
260
291
  const e = document.createElement("iframe");
261
292
  e.style.display = "none", e.setAttribute("sandbox", "allow-scripts allow-same-origin"), e.src = i, e.onload = function() {
262
293
  e.onload = null, e.parentNode && e.parentNode.removeChild(e);
@@ -264,41 +295,41 @@ function M(i) {
264
295
  const t = document.body || document.head;
265
296
  t && t.appendChild(e);
266
297
  }
267
- function Q(i, e) {
268
- const t = le(window.location.origin);
269
- if (S._allowedOriginHashes.indexOf(t) === -1 || Math.random() >= Ae)
298
+ function ie(i, e) {
299
+ const t = ge(window.location.origin);
300
+ if (y._allowedOriginHashes.indexOf(t) === -1 || Math.random() >= Te)
270
301
  return;
271
302
  const r = window.__rokt_li_guid__;
272
303
  if (!r || i && i.includes("://") && !/^https:\/\//i.test(i))
273
304
  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"
305
+ const s = window.location.href.split("?")[0].split("#")[0], o = "version=" + encodeURIComponent(e ?? "") + "&launcherInstanceGuid=" + encodeURIComponent(r) + "&pageUrl=" + encodeURIComponent(s), c = i ? C(i) : "https://apps.rokt.com";
306
+ F(c + "/v1/wsdk-init/index.html?" + o), F(
307
+ "https://" + be + "/v1/wsdk-init/index.html?" + o + "&isControl=true"
277
308
  );
278
309
  }
279
- function Ye() {
310
+ function ze() {
280
311
  return typeof window < "u" && !!window.location?.search?.toLowerCase().includes("mp_enable_logging=true");
281
312
  }
282
- function xe() {
313
+ function qe() {
283
314
  return typeof window < "u" ? window.location?.href : void 0;
284
315
  }
285
- function Ge() {
316
+ function $e() {
286
317
  return typeof window < "u" ? window.navigator?.userAgent : void 0;
287
318
  }
288
- class ue {
319
+ class pe {
289
320
  constructor() {
290
321
  this._logCount = {};
291
322
  }
292
323
  incrementAndCheck(e) {
293
324
  const n = (this._logCount[e] || 0) + 1;
294
- return this._logCount[e] = n, n > Ke;
325
+ return this._logCount[e] = n, n > Ve;
295
326
  }
296
327
  }
297
- class F {
328
+ class W {
298
329
  constructor(e, t, n, r, s) {
299
330
  this._reporter = "mp-wsdk";
300
331
  const o = e.isLoggingEnabled;
301
- this._integrationName = t || "", this._launcherInstanceGuid = n, this._accountId = r || null, this._rateLimiter = s || new ue(), this._isEnabled = Ye() || o;
332
+ this._integrationName = t || "", this._launcherInstanceGuid = n, this._accountId = r || null, this._rateLimiter = s || new pe(), this._isEnabled = ze() || o;
302
333
  }
303
334
  send(e, t, n, r, s, o) {
304
335
  if (!(!this._isEnabled || this._rateLimiter.incrementAndCheck(t)))
@@ -309,9 +340,9 @@ class F {
309
340
  version: this._integrationName
310
341
  },
311
342
  severity: t,
312
- code: r || D.UNKNOWN_ERROR,
313
- url: xe(),
314
- deviceInfo: Ge(),
343
+ code: r || G.UNKNOWN_ERROR,
344
+ url: qe(),
345
+ deviceInfo: $e(),
315
346
  stackTrace: s,
316
347
  reporter: this._reporter,
317
348
  integration: this._integrationName
@@ -338,24 +369,24 @@ class F {
338
369
  }
339
370
  }
340
371
  }
341
- class X {
372
+ class ne {
342
373
  constructor(e, t, n, r, s) {
343
- this._transport = new F(e, t, n, r, s), this._errorUrl = ce(e?.errorUrl, e?.integrationDomain, Me);
374
+ this._transport = new W(e, t, n, r, s), this._errorUrl = he(e?.errorUrl, e?.integrationDomain, We);
344
375
  }
345
376
  report(e) {
346
377
  if (!e) return;
347
- const t = e.severity || _.ERROR;
378
+ const t = e.severity || S.ERROR;
348
379
  this._transport.send(this._errorUrl, t, e.message, e.code, e.stackTrace);
349
380
  }
350
381
  }
351
- class Z {
382
+ class re {
352
383
  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;
384
+ this._transport = new W(e, n, r, s, o), this._loggingUrl = he(e?.loggingUrl, e?.integrationDomain, Ge), this._errorReportingService = t;
354
385
  }
355
386
  log(e) {
356
387
  e && this._transport.send(
357
388
  this._loggingUrl,
358
- _.INFO,
389
+ S.INFO,
359
390
  e.message,
360
391
  e.code,
361
392
  void 0,
@@ -364,16 +395,16 @@ class Z {
364
395
  const n = typeof t.statusCode == "number";
365
396
  this._errorReportingService.report({
366
397
  message: "LoggingService: Failed to send log: " + t.message,
367
- code: D.LOG_DELIVERY_FAILURE,
368
- severity: n ? _.ERROR : _.WARNING
398
+ code: G.LOG_DELIVERY_FAILURE,
399
+ severity: n ? S.ERROR : S.WARNING
369
400
  });
370
401
  }
371
402
  }
372
403
  );
373
404
  }
374
405
  }
375
- function We(i) {
376
- const e = K(window.location.href), t = i.EventAttributes?.title || document.title, n = Ie(), r = i.ActiveTimeOnSite;
406
+ function Je(i) {
407
+ const e = Y(window.location.href), t = i.EventAttributes?.title || document.title, n = ve(), r = i.ActiveTimeOnSite;
377
408
  return {
378
409
  pageUrl: e,
379
410
  sourceMessageId: i.SourceMessageId,
@@ -383,9 +414,9 @@ function We(i) {
383
414
  ...Number.isFinite(r) ? { activeTimeOnSite: r } : {}
384
415
  };
385
416
  }
386
- const f = class f {
417
+ const m = class m {
387
418
  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;
419
+ this.name = d, this.id = L, this.moduleId = L, this.isInitialized = !1, this.launcher = null, this.filters = {}, this.userAttributes = {}, this.userIdentifiedInWorkspace = !1, this.testHelpers = null, this.placementEventMappingLookup = {}, this.placementEventAttributeMappingLookup = {}, this.integrationName = null, this.errorReportingService = null, this.loggingService = null, this._thankYouElementOnLoadCallback = null, this._isThankYouElementLoaded = !1, this._workspaceSearchInFlightPromise = null;
389
420
  }
390
421
  // ---- Private helpers ----
391
422
  getEventAttributeValue(e, t) {
@@ -393,13 +424,13 @@ const f = class f {
393
424
  return !n || typeof n[t] > "u" ? null : n[t];
394
425
  }
395
426
  doesEventAttributeConditionMatch(e, t) {
396
- if (!e || !m(e.operator))
427
+ if (!e || !E(e.operator))
397
428
  return !1;
398
429
  const n = e.operator.toLowerCase(), r = e.attributeValue;
399
430
  return n === "exists" ? t !== null : t == null ? !1 : n === "equals" ? String(t) === String(r) : n === "contains" ? String(t).indexOf(String(r)) !== -1 : !1;
400
431
  }
401
432
  doesEventMatchRule(e, t) {
402
- if (!t || !m(t.eventAttributeKey))
433
+ if (!t || !E(t.eventAttributeKey))
403
434
  return !1;
404
435
  const n = t.conditions;
405
436
  if (!Array.isArray(n))
@@ -416,7 +447,7 @@ const f = class f {
416
447
  const t = Object.keys(this.placementEventAttributeMappingLookup);
417
448
  for (let n = 0; n < t.length; n++) {
418
449
  const r = t[n], s = this.placementEventAttributeMappingLookup[r];
419
- if (U(s))
450
+ if (K(s))
420
451
  continue;
421
452
  let o = !0;
422
453
  for (let c = 0; c < s.length; c++)
@@ -430,12 +461,12 @@ const f = class f {
430
461
  capturePageView(e) {
431
462
  let t;
432
463
  try {
433
- t = K(window.location.href);
434
- const n = W(this.loggingService), r = We(e);
464
+ t = Y(window.location.href);
465
+ const n = z(this.loggingService), r = Je(e);
435
466
  n.push(r);
436
- const s = Math.min(n.length, se), o = Ee(n);
467
+ const s = Math.min(n.length, le), o = ye(n);
437
468
  if (o === 0) {
438
- const c = x() ? "quota" : "ls_unavailable";
469
+ const c = D() ? "quota" : "ls_unavailable";
439
470
  this.loggingService?.log({
440
471
  message: `Rokt Kit: Failed to persist page view for ${t} [reason: ${c}]`,
441
472
  code: "PAGE_VIEW_CAPTURE_FAILED"
@@ -445,7 +476,7 @@ const f = class f {
445
476
  code: "PAGE_VIEW_QUOTA_EVICTION"
446
477
  });
447
478
  } catch (n) {
448
- const r = x() ? "exception" : "ls_unavailable", s = n instanceof Error ? n.message : String(n);
479
+ const r = D() ? "exception" : "ls_unavailable", s = n instanceof Error ? n.message : String(n);
449
480
  this.loggingService?.log({
450
481
  message: `Rokt Kit: Failed to capture page view for ${t}: ${s} [reason: ${r}]`,
451
482
  code: "PAGE_VIEW_CAPTURE_FAILED"
@@ -453,7 +484,7 @@ const f = class f {
453
484
  }
454
485
  }
455
486
  isLauncherReadyToAttach() {
456
- return !!window.Rokt && L(window.Rokt.createLauncher);
487
+ return !!window.Rokt && T(window.Rokt.createLauncher);
457
488
  }
458
489
  /**
459
490
  * Returns the user identities from the filtered user, if any.
@@ -469,19 +500,19 @@ const f = class f {
469
500
  }
470
501
  replaceOtherIdentityWithEmailsha256(e) {
471
502
  const t = { ...e || {} }, n = this._mappedEmailSha256Key;
472
- return n && e[n] && (t[f.EMAIL_SHA256_KEY] = e[n]), n && delete t[n], t;
503
+ return n && e[n] && (t[m.EMAIL_SHA256_KEY] = e[n]), n && delete t[n], t;
473
504
  }
474
505
  logSelectPlacementsEvent(e) {
475
- if (!window.mParticle || typeof a().logEvent != "function" || !I(e))
506
+ if (!window.mParticle || typeof a().logEvent != "function" || !_(e))
476
507
  return;
477
508
  const t = a().EventType.Other;
478
- a().logEvent(Se, t, e);
509
+ a().logEvent(we, t, e);
479
510
  }
480
511
  setRoktSessionId(e) {
481
512
  if (!(!e || typeof e != "string"))
482
513
  try {
483
514
  const t = a().getInstance();
484
- t && L(t.setIntegrationAttribute) && t.setIntegrationAttribute(T, {
515
+ t && T(t.setIntegrationAttribute) && t.setIntegrationAttribute(L, {
485
516
  roktSessionId: e
486
517
  });
487
518
  } catch {
@@ -489,7 +520,7 @@ const f = class f {
489
520
  }
490
521
  readMpSessionId() {
491
522
  const e = a()?.sessionManager, t = e?.getSessionId ?? e?.getSession;
492
- if (L(t))
523
+ if (T(t))
493
524
  return t.call(e) || void 0;
494
525
  }
495
526
  readMpDeviceId() {
@@ -502,7 +533,7 @@ const f = class f {
502
533
  };
503
534
  let s;
504
535
  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);
536
+ await je(n, o), this.initRoktLauncher(o);
506
537
  }).catch((o) => {
507
538
  console.error("Error creating Rokt launcher:", o);
508
539
  });
@@ -510,7 +541,7 @@ const f = class f {
510
541
  initRoktLauncher(e) {
511
542
  window.Rokt && (window.Rokt.currentLauncher = e), this.launcher = e;
512
543
  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);
544
+ t ? (this.filters = t, t.filteredUser ? this._workspaceSearchInFlightPromise = this.search(t.filteredUser) : console.warn("Rokt Kit: No filtered user has been set.")) : console.warn("Rokt Kit: No filters have been set."), this.isInitialized = !0, ie(this.domain, this.integrationName), a().Rokt.attachKit(this);
514
545
  }
515
546
  fetchOptimizely() {
516
547
  const e = a()._getActiveForwarders().filter((t) => t.name === "Optimizely");
@@ -549,86 +580,86 @@ const f = class f {
549
580
  const o = e, c = o.accountId;
550
581
  this.userAttributes = b(s), this._onboardingExpProvider = o.onboardingExpProvider;
551
582
  const u = P(o.placementEventMapping);
552
- this.placementEventMappingLookup = J(u);
583
+ this.placementEventMappingLookup = Z(u);
553
584
  const l = P(
554
585
  o.placementEventAttributeMapping
555
586
  );
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(
587
+ this.placementEventAttributeMappingLookup = ee(l), o.hashedEmailUserIdentityType && (this._mappedEmailSha256Key = o.hashedEmailUserIdentityType.toLowerCase()), this._workspaceIdSyncApiKey = E(o.workspaceIdSyncApiKey) ? o.workspaceIdSyncApiKey : void 0;
588
+ const g = a().Rokt?.domain, { roktExtensionsQueryParams: M, legacyRoktExtensions: v, loadThankYouElement: w } = X(
558
589
  o.roktExtensions
559
- ), p = {
590
+ ), f = {
560
591
  ...a().Rokt?.launcherOptions || {}
561
592
  };
562
- this.integrationName = Fe(p.integrationName), p.integrationName = this.integrationName, this.domain = g;
563
- const y = {
593
+ this.integrationName = He(f.integrationName), f.integrationName = this.integrationName, this.domain = g;
594
+ const A = {
564
595
  loggingUrl: o.loggingUrl,
565
596
  errorUrl: o.errorUrl,
566
597
  integrationDomain: g,
567
598
  isLoggingEnabled: a().config?.isLoggingEnabled === !0
568
- }, E = new X(
569
- y,
599
+ }, I = new ne(
600
+ A,
570
601
  this.integrationName,
571
602
  window.__rokt_li_guid__,
572
603
  o.accountId
573
- ), w = new Z(
574
- y,
575
- E,
604
+ ), k = new re(
605
+ A,
606
+ I,
576
607
  this.integrationName,
577
608
  window.__rokt_li_guid__,
578
609
  o.accountId
579
610
  );
580
- if (this.errorReportingService = E, this.loggingService = w, this.isTargetingDisabled())
611
+ if (this.errorReportingService = I, this.loggingService = k, this.isTargetingDisabled())
581
612
  try {
582
- V();
613
+ q(), $();
583
614
  } catch (h) {
584
615
  this.errorReportingService?.report({
585
616
  message: "Rokt Kit: Failed to clear page views when targeting is disabled",
586
617
  code: "PAGE_VIEW_CAPTURE_FAILED",
587
- severity: _.INFO,
618
+ severity: S.INFO,
588
619
  stackTrace: h instanceof Error ? h.stack : void 0
589
620
  });
590
621
  }
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,
622
+ return a()._registerErrorReportingService && a()._registerErrorReportingService(I), a()._registerLoggingService && a()._registerLoggingService(k), n ? (this.testHelpers = {
623
+ generateLauncherScript: J,
624
+ generateThankYouElementScript: B,
625
+ extractRoktExtensionConfig: X,
626
+ hashEventMessage: te,
596
627
  parseSettingsString: P,
597
- generateMappedEventLookup: J,
598
- generateMappedEventAttributeLookup: $,
599
- sendAdBlockMeasurementSignals: Q,
600
- createAutoRemovedIframe: M,
601
- djb2: le,
628
+ generateMappedEventLookup: Z,
629
+ generateMappedEventAttributeLookup: ee,
630
+ sendAdBlockMeasurementSignals: ie,
631
+ createAutoRemovedIframe: F,
632
+ djb2: ge,
602
633
  setAllowedOriginHashes: (h) => {
603
- f._allowedOriginHashes = h;
634
+ m._allowedOriginHashes = h;
604
635
  },
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), {
636
+ ReportingTransport: W,
637
+ ErrorReportingService: ne,
638
+ LoggingService: re,
639
+ RateLimiter: pe,
640
+ ErrorCodes: G,
641
+ WSDKErrorSeverity: S
642
+ }, this.attachLauncher(c, f), "Successfully initialized: " + d) : (w && (a().Rokt.flushOnShoppableAdsReadyMessageQueue?.(this), Q(Oe, B(g), {
612
643
  onLoad: () => {
613
644
  this._isThankYouElementLoaded = !0, this._thankYouElementOnLoadCallback && this._thankYouElementOnLoadCallback();
614
645
  },
615
646
  onError: (h) => {
616
647
  console.error("Error loading Rokt Thank You Element script:", h);
617
648
  }
618
- })), this.isLauncherReadyToAttach() ? this.attachLauncher(c, p, v) : (z(ve, j(g, C), {
649
+ })), this.isLauncherReadyToAttach() ? this.attachLauncher(c, f, v) : (Q(Pe, J(g, M), {
619
650
  onLoad: () => {
620
- this.isLauncherReadyToAttach() ? this.attachLauncher(c, p, v) : console.error("Rokt object is not available after script load.");
651
+ this.isLauncherReadyToAttach() ? this.attachLauncher(c, f, v) : console.error("Rokt object is not available after script load.");
621
652
  },
622
653
  onError: (h) => {
623
654
  console.error("Error loading Rokt launcher script:", h);
624
655
  }
625
- }), this.captureTiming(f.PERFORMANCE_MARKS.RoktScriptAppended)), "Successfully initialized: " + d);
656
+ }), this.captureTiming(m.PERFORMANCE_MARKS.RoktScriptAppended)), "Successfully initialized: " + d);
626
657
  }
627
658
  process(e) {
628
- if (this.isTargetingDisabled() || (e.EventDataType === be && this.capturePageView(e), e.EventDataType === Le && (ae(this.loggingService), V())), !this.isKitReady())
659
+ if (this.isTargetingDisabled() || (e.EventDataType === Ue && (ke(this.loggingService), this.capturePageView(e)), e.EventDataType === Ce && (de(this.loggingService), q(), $())), !this.isKitReady())
629
660
  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 ?? "");
661
+ if (T(a().Rokt?.setLocalSessionAttribute) && (K(this.placementEventAttributeMappingLookup) || this.applyPlacementEventAttributeMapping(e), !K(this.placementEventMappingLookup))) {
662
+ const t = te(e.EventDataType, e.EventCategory, e.EventName ?? "");
632
663
  this.placementEventMappingLookup[String(t)] && a().Rokt.setLocalSessionAttribute?.(this.placementEventMappingLookup[String(t)], !0);
633
664
  }
634
665
  return "Successfully sent to forwarder: " + d;
@@ -641,7 +672,7 @@ const f = class f {
641
672
  window.Rokt.setExtensionData(e);
642
673
  }
643
674
  setUserAttribute(e, t) {
644
- return ee(e) || (this.userAttributes[e] = t), "Successfully set user attribute for forwarder: " + d;
675
+ return se(e) || (this.userAttributes[e] = t), "Successfully set user attribute for forwarder: " + d;
645
676
  }
646
677
  removeUserAttribute(e) {
647
678
  return delete this.userAttributes[e], "Successfully removed user attribute for forwarder: " + d;
@@ -664,7 +695,7 @@ const f = class f {
664
695
  if (r)
665
696
  for (const u of Object.keys(r)) {
666
697
  const l = r[u];
667
- m(l) && l.length > 0 && (s[u] = l);
698
+ E(l) && l.length > 0 && (s[u] = l);
668
699
  }
669
700
  const o = Object.keys(s);
670
701
  if (o.length === 0)
@@ -717,7 +748,7 @@ const f = class f {
717
748
  const t = this._workspaceSearchInFlightPromise;
718
749
  return Promise.race([
719
750
  t,
720
- new Promise((n) => setTimeout(n, Oe))
751
+ new Promise((n) => setTimeout(n, Ye))
721
752
  ]).then(() => this._dispatchPlacements(e));
722
753
  }
723
754
  return this._dispatchPlacements(e);
@@ -726,19 +757,20 @@ const f = class f {
726
757
  const t = e && e.attributes || {}, r = { ...b(this.userAttributes), ...t }, s = this.filters || {}, o = s.userAttributeFilters || [], c = s.filteredUser || null, u = c ? c.getMPID() : null;
727
758
  let l;
728
759
  s ? s.filterUserAttributes ? l = s.filterUserAttributes(r, o) : l = r : (console.warn("Rokt Kit: No filters available, using user attributes"), l = r), this.userAttributes = b(l);
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,
760
+ const g = this._onboardingExpProvider === "Optimizely" ? this.fetchOptimizely() : {}, M = this.returnUserIdentities(c), v = this.returnLocalSessionAttributes(), w = Ae(z(this.loggingService)), f = Re(), A = this.readMpSessionId(), I = this.readMpDeviceId(), k = {
761
+ ...M,
731
762
  ...l,
732
763
  ...g,
733
764
  ...v,
734
- ...R.length ? { [Te]: JSON.stringify(R) } : {},
735
- ...this.userIdentifiedInWorkspace ? { [we]: !0 } : {},
736
- ...p ? { [Pe]: p } : {},
737
- ...y ? { [Ne]: y } : {},
765
+ ...w.length ? { [Me]: JSON.stringify(w) } : {},
766
+ ...f ? { [Ke]: f } : {},
767
+ ...this.userIdentifiedInWorkspace ? { [Ne]: !0 } : {},
768
+ ...A ? { [De]: A } : {},
769
+ ...I ? { [Fe]: I } : {},
738
770
  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;
771
+ }, h = { ...e, attributes: k }, V = this.launcher.selectPlacements(h), fe = () => this.logSelectPlacementsEvent(k);
772
+ return Promise.resolve(V).then((me) => me?.context?.sessionId?.then((Ee) => this.setRoktSessionId(Ee))).catch(() => {
773
+ }).finally(fe), V;
742
774
  }
743
775
  /**
744
776
  * Passes attributes to the Rokt Web SDK for client-side hashing.
@@ -752,7 +784,7 @@ const f = class f {
752
784
  * @deprecated This functionality has been internalized and will be removed in a future release.
753
785
  */
754
786
  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")));
787
+ 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")));
756
788
  }
757
789
  /**
758
790
  * Registers a callback to be invoked once rokt-thank-you-element.js becomes available.
@@ -761,34 +793,34 @@ const f = class f {
761
793
  this._isThankYouElementLoaded ? e() : this._thankYouElementOnLoadCallback = e;
762
794
  }
763
795
  };
764
- f._allowedOriginHashes = [-553112570, 549508659], f.PERFORMANCE_MARKS = {
796
+ m._allowedOriginHashes = [-553112570, 549508659], m.PERFORMANCE_MARKS = {
765
797
  RoktScriptAppended: "mp:RoktScriptAppended"
766
- }, f.EMAIL_SHA256_KEY = "emailsha256";
767
- let S = f;
768
- function Ve() {
769
- return T;
798
+ }, m.EMAIL_SHA256_KEY = "emailsha256";
799
+ let y = m;
800
+ function Be() {
801
+ return L;
770
802
  }
771
- function je(i) {
803
+ function Qe(i) {
772
804
  if (!i) {
773
805
  window.console.log("You must pass a config object to register the kit " + d);
774
806
  return;
775
807
  }
776
- if (!I(i)) {
808
+ if (!_(i)) {
777
809
  window.console.log("'config' must be an object. You passed in a " + typeof i);
778
810
  return;
779
811
  }
780
- I(i.kits) ? i.kits[d] = {
781
- constructor: S
812
+ _(i.kits) ? i.kits[d] = {
813
+ constructor: y
782
814
  } : (i.kits = {}, i.kits[d] = {
783
- constructor: S
815
+ constructor: y
784
816
  }), window.console.log("Successfully registered " + d + " to your mParticle configuration");
785
817
  }
786
818
  typeof window < "u" && window.mParticle && a().addForwarder && a().addForwarder({
787
819
  name: d,
788
- constructor: S,
789
- getId: Ve
820
+ constructor: y,
821
+ getId: Be
790
822
  });
791
823
  export {
792
- je as register
824
+ Qe as register
793
825
  };
794
826
  //# 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 me=["active_time_on_site_ms","billingaddress1","billingaddress2","billingcity","billingstate","billingzipcode","cartitems","ccbin","confirmationref","conversiontype","country","couponcode","currency","language","paymentserviceprovider","paymentserviceproviderattribute","paymenttype","shippingaddress1","shippingcity","shippingcountry","shippingmethod","shippingstate","shippingzipcode","totalprice"],Ee=new Set(me);function V(i){return Ee.has(i.toLowerCase())}function R(i){const e={},t=i||{},n=Object.keys(t);for(let r=0;r<n.length;r++){const s=n[r];V(s)||(e[s]=t[s])}return e}function E(i){return typeof i=="object"&&i!==null&&!Array.isArray(i)}function _(i){return typeof i=="string"}function w(i){return typeof i=="function"}function K(i){return i==null?!0:typeof i=="object"?Object.keys(i).length===0:!1}function D(i){try{const e=new URL(i);return e.search="",e.toString()}catch{return i}}const H="__rokt_ls_probe__";function F(){try{return window.localStorage.setItem(H,"1"),window.localStorage.removeItem(H),!0}catch{return!1}}function b(i){try{const e=window.localStorage.getItem(i);return e===null?null:JSON.parse(e)}catch{return null}}function z(i,e){try{return window.localStorage.setItem(i,JSON.stringify(e)),!0}catch{return!1}}function q(i){try{window.localStorage.removeItem(i)}catch{}}function T(i,e){const t=b(i);return E(t)?t[e]:void 0}function Y(i,e,t){const n=b(i),r=E(n)?{...n}:{};return r[e]=t,z(i,r)}function $(i,e){const t=b(i);if(!E(t)||!(e in t))return;const n={...t};delete n[e],Object.keys(n).length===0?q(i):z(i,n)}const g="mp-rokt-kit",A="pageViews",L="utmParams",J="mpPageViews",B=25,_e=["utm_source","utm_medium","utm_campaign","utm_term","utm_content"];function Q(i){return i.slice(-B)}function X(i){const e=b(J);if(e===null)return;!(T(g,A)!==void 0)&&Array.isArray(e)&&(i?.log({message:"Rokt Kit: Migrating legacy page-view storage",code:"PAGE_VIEW_LEGACY_MIGRATION"}),Y(g,A,e)||i?.log({message:"Rokt Kit: Failed to migrate legacy page-view storage [reason: migration_retry]",code:"PAGE_VIEW_CAPTURE_FAILED"})),q(J)}function Z(i){X(i);const e=T(g,A);return Array.isArray(e)?e:[]}function Ie(i){const e=Q(i);for(let t=0;t<e.length;t++){const n=e.slice(t);if(Y(g,A,n))return n.length}return 0}function ee(){$(g,A)}function Se(i){const e=Q(i);return e.map((t,n)=>{const r=t.activeTimeOnSite,s=r!==void 0&&Number.isFinite(r),c=e[n+1]?.activeTimeOnSite,u=c!==void 0&&Number.isFinite(c),l=s&&u?c-r:void 0;return{pageUrl:t.pageUrl,sourceMessageId:t.sourceMessageId,timestamp:t.timestamp,...t.pageTitle!==void 0?{pageTitle:t.pageTitle}:{},...t.canonicalUrl!==void 0?{canonicalUrl:t.canonicalUrl}:{},...s?{activeTimeOnSite:r}:{},...l!==void 0&&l>=0?{activeTimeOnPage:l}:{}}})}function ye(i){if(T(g,L)!==void 0)return;const e=new URLSearchParams(window.location.search),t={};for(const r of _e){const s=e.get(r);s&&(t[r]=s)}if(Object.keys(t).length===0)return;const n=Object.keys(t).join(", ");if(!Y(g,L,t)){const r=F()?"quota":"ls_unavailable";i?.log({message:`Rokt Kit: Failed to persist UTM params [reason: ${r}]`,code:"UTM_CAPTURE_FAILED"});return}i?.log({message:`Rokt Kit: Captured UTM params [${n}]`,code:"UTM_CAPTURE_SUCCESS"})}function Ae(){const i=T(g,L);return E(i)?i:null}function te(){$(g,L)}function ke(){const e=document.querySelector('link[rel="canonical"]')?.href;if(e)return D(e)}const d="Rokt",P=181,ve="selectPlacements",Re="apps.roktecommerce.com",we=.1,be="ThankYouPageJourney",Te="rokt-launcher",Le="rokt-thank-you-element",Pe="userIdentifiedInWorkspace",Oe=3,Ne=2,Ue="page_events",Ce="page_view_attributes",Me="mparticle_session_id",Ke="mparticle_device_id",De=500,G={UNKNOWN_ERROR:"UNKNOWN_ERROR",UNHANDLED_EXCEPTION:"UNHANDLED_EXCEPTION",IDENTITY_REQUEST:"IDENTITY_REQUEST",LOG_DELIVERY_FAILURE:"LOG_DELIVERY_FAILURE"},I={ERROR:"ERROR",INFO:"INFO",WARNING:"WARNING"},Fe="apps.rokt-api.com",Ye="/v1/log",Ge="/v1/errors",xe=10;function a(){return window.mParticle}function ie(i,e){const n=[O(i),"/wsdk/integrations/launcher.js"].join("");return!e||e.length===0?n:n+"?extensions="+e.join(",")}function ne(i){return[O(i),"/rokt-elements/rokt-element-thank-you.js"].join("")}function O(i){const e=typeof i<"u"?i:Fe;return e.includes("://")?e.replace(/\/+$/,""):["https://",e].join("")}function re(i,e,t){if(i)return i.startsWith("http://")||i.startsWith("https://")?i:"https://"+i;const r=e?.includes("://")&&!/^https?:\/\//i.test(e)?void 0:e;return O(r)+t}function se(i,e,t){if(document.getElementById(i))return;const n=document.head||document.body,r=document.createElement("script");r.id=i,r.type="text/javascript",r.src=e,r.async=!0,r.crossOrigin="anonymous",r.fetchPriority="high",t?.onLoad&&(r.onload=t.onLoad),t?.onError&&(r.onerror=t.onError),n.appendChild(r)}function N(i){if(!i)return[];try{return JSON.parse(i.replace(/&quot;/g,'"'))}catch{console.error("Settings string contains invalid JSON")}return[]}function oe(i){const e=i?N(i):[],t=[],n=[];let r=!1;for(let s=0;s<e.length;s++){const o=e[s].value;o==="thank-you-journey"?(r=!0,n.push(be)):t.push(o)}return{roktExtensionsQueryParams:t,legacyRoktExtensions:n,loadThankYouElement:r}}async function We(i,e){const t=[];if(e)for(const n of i)t.push(e.use(n));return Promise.all(t)}function ae(i){if(!i)return{};const e={};for(let t=0;t<i.length;t++){const n=i[t];e[n.jsmap]=n.value}return e}function ce(i){const e={};if(!Array.isArray(i))return e;for(let t=0;t<i.length;t++){const n=i[t];if(!n||!_(n.value)||!_(n.map))continue;const r=n.value,s=n.map;e[r]||(e[r]=[]),e[r].push({eventAttributeKey:s,conditions:Array.isArray(n.conditions)?n.conditions:[]})}return e}function le(i,e,t){return a().generateHash([i,e,t].join(""))}function je(i){let n="mParticle_wsdkv_"+a().getVersion()+"_kitv_"+"1.35.0";return i&&(n+="_"+i),n}function ue(i){let e=5381;for(let t=0;t<i.length;t++)e=(e<<5)+e+i.charCodeAt(t),e=e&e;return e}function x(i){const e=document.createElement("iframe");e.style.display="none",e.setAttribute("sandbox","allow-scripts allow-same-origin"),e.src=i,e.onload=function(){e.onload=null,e.parentNode&&e.parentNode.removeChild(e)};const t=document.body||document.head;t&&t.appendChild(e)}function de(i,e){const t=ue(window.location.origin);if(S._allowedOriginHashes.indexOf(t)===-1||Math.random()>=we)return;const r=window.__rokt_li_guid__;if(!r||i&&i.includes("://")&&!/^https:\/\//i.test(i))return;const s=window.location.href.split("?")[0].split("#")[0],o="version="+encodeURIComponent(e??"")+"&launcherInstanceGuid="+encodeURIComponent(r)+"&pageUrl="+encodeURIComponent(s),c=i?O(i):"https://apps.rokt.com";x(c+"/v1/wsdk-init/index.html?"+o),x("https://"+Re+"/v1/wsdk-init/index.html?"+o+"&isControl=true")}function Ve(){return typeof window<"u"&&!!window.location?.search?.toLowerCase().includes("mp_enable_logging=true")}function He(){return typeof window<"u"?window.location?.href:void 0}function ze(){return typeof window<"u"?window.navigator?.userAgent:void 0}class he{constructor(){this._logCount={}}incrementAndCheck(e){const n=(this._logCount[e]||0)+1;return this._logCount[e]=n,n>xe}}class W{constructor(e,t,n,r,s){this._reporter="mp-wsdk";const o=e.isLoggingEnabled;this._integrationName=t||"",this._launcherInstanceGuid=n,this._accountId=r||null,this._rateLimiter=s||new he,this._isEnabled=Ve()||o}send(e,t,n,r,s,o){if(!(!this._isEnabled||this._rateLimiter.incrementAndCheck(t)))try{const c={additionalInformation:{message:n,version:this._integrationName},severity:t,code:r||G.UNKNOWN_ERROR,url:He(),deviceInfo:ze(),stackTrace:s,reporter:this._reporter,integration:this._integrationName},u={Accept:"text/plain;charset=UTF-8","Content-Type":"application/json","rokt-launcher-version":this._integrationName,"rokt-wsdk-version":"joint"};this._launcherInstanceGuid&&(u["rokt-launcher-instance-guid"]=this._launcherInstanceGuid),this._accountId&&(u["rokt-account-id"]=this._accountId),fetch(e,{method:"POST",headers:u,body:JSON.stringify(c)}).then(l=>{if(!l.ok){const p=new Error("HTTP "+l.status+" from log endpoint");throw p.statusCode=l.status,p}}).catch(l=>{console.error("ReportingTransport: Failed to send log",l),o&&o(l)})}catch(c){console.error("ReportingTransport: Failed to send log",c),o&&o(c)}}}class ge{constructor(e,t,n,r,s){this._transport=new W(e,t,n,r,s),this._errorUrl=re(e?.errorUrl,e?.integrationDomain,Ge)}report(e){if(!e)return;const t=e.severity||I.ERROR;this._transport.send(this._errorUrl,t,e.message,e.code,e.stackTrace)}}class pe{constructor(e,t,n,r,s,o){this._transport=new W(e,n,r,s,o),this._loggingUrl=re(e?.loggingUrl,e?.integrationDomain,Ye),this._errorReportingService=t}log(e){e&&this._transport.send(this._loggingUrl,I.INFO,e.message,e.code,void 0,t=>{if(this._errorReportingService){const n=typeof t.statusCode=="number";this._errorReportingService.report({message:"LoggingService: Failed to send log: "+t.message,code:G.LOG_DELIVERY_FAILURE,severity:n?I.ERROR:I.WARNING})}})}}function qe(i){const e=D(window.location.href),t=i.EventAttributes?.title||document.title,n=ke(),r=i.ActiveTimeOnSite;return{pageUrl:e,sourceMessageId:i.SourceMessageId,timestamp:i.Timestamp,...t?{pageTitle:t}:{},...n!==void 0?{canonicalUrl:n}:{},...Number.isFinite(r)?{activeTimeOnSite:r}:{}}}const f=class f{constructor(){this.name=d,this.id=P,this.moduleId=P,this.isInitialized=!1,this.launcher=null,this.filters={},this.userAttributes={},this.userIdentifiedInWorkspace=!1,this.testHelpers=null,this.placementEventMappingLookup={},this.placementEventAttributeMappingLookup={},this.integrationName=null,this.errorReportingService=null,this.loggingService=null,this._thankYouElementOnLoadCallback=null,this._isThankYouElementLoaded=!1,this._workspaceSearchInFlightPromise=null}getEventAttributeValue(e,t){const n=e&&e.EventAttributes;return!n||typeof n[t]>"u"?null:n[t]}doesEventAttributeConditionMatch(e,t){if(!e||!_(e.operator))return!1;const n=e.operator.toLowerCase(),r=e.attributeValue;return n==="exists"?t!==null:t==null?!1:n==="equals"?String(t)===String(r):n==="contains"?String(t).indexOf(String(r))!==-1:!1}doesEventMatchRule(e,t){if(!t||!_(t.eventAttributeKey))return!1;const n=t.conditions;if(!Array.isArray(n))return!1;const r=this.getEventAttributeValue(e,t.eventAttributeKey);if(n.length===0)return r!==null;for(let s=0;s<n.length;s++)if(!this.doesEventAttributeConditionMatch(n[s],r))return!1;return!0}applyPlacementEventAttributeMapping(e){const t=Object.keys(this.placementEventAttributeMappingLookup);for(let n=0;n<t.length;n++){const r=t[n],s=this.placementEventAttributeMappingLookup[r];if(K(s))continue;let o=!0;for(let c=0;c<s.length;c++)if(!this.doesEventMatchRule(e,s[c])){o=!1;break}o&&a().Rokt.setLocalSessionAttribute?.(r,!0)}}capturePageView(e){let t;try{t=D(window.location.href);const n=Z(this.loggingService),r=qe(e);n.push(r);const s=Math.min(n.length,B),o=Ie(n);if(o===0){const c=F()?"quota":"ls_unavailable";this.loggingService?.log({message:`Rokt Kit: Failed to persist page view for ${t} [reason: ${c}]`,code:"PAGE_VIEW_CAPTURE_FAILED"})}else o<s&&this.loggingService?.log({message:`Rokt Kit: Page view storage reduced from ${s} to ${o} record(s) under quota pressure [reason: quota_eviction]`,code:"PAGE_VIEW_QUOTA_EVICTION"})}catch(n){const r=F()?"exception":"ls_unavailable",s=n instanceof Error?n.message:String(n);this.loggingService?.log({message:`Rokt Kit: Failed to capture page view for ${t}: ${s} [reason: ${r}]`,code:"PAGE_VIEW_CAPTURE_FAILED"})}}isLauncherReadyToAttach(){return!!window.Rokt&&w(window.Rokt.createLauncher)}returnUserIdentities(e){if(!e||!e.getUserIdentities)return{};const t=e.getUserIdentities().userIdentities;return this.replaceOtherIdentityWithEmailsha256(t)}returnLocalSessionAttributes(){return!a().Rokt||typeof a().Rokt.getLocalSessionAttributes!="function"?{}:a().Rokt.getLocalSessionAttributes()}replaceOtherIdentityWithEmailsha256(e){const t={...e||{}},n=this._mappedEmailSha256Key;return n&&e[n]&&(t[f.EMAIL_SHA256_KEY]=e[n]),n&&delete t[n],t}logSelectPlacementsEvent(e){if(!window.mParticle||typeof a().logEvent!="function"||!E(e))return;const t=a().EventType.Other;a().logEvent(ve,t,e)}setRoktSessionId(e){if(!(!e||typeof e!="string"))try{const t=a().getInstance();t&&w(t.setIntegrationAttribute)&&t.setIntegrationAttribute(P,{roktSessionId:e})}catch{}}readMpSessionId(){const e=a()?.sessionManager,t=e?.getSessionId??e?.getSession;if(w(t))return t.call(e)||void 0}readMpDeviceId(){return a()?.getDeviceId?.()||void 0}attachLauncher(e,t,n=[]){const r={accountId:e,...t||{}};let s;this.isPartnerInLocalLauncherTestGroup()?s=Promise.resolve(window.Rokt.createLocalLauncher(r)):s=window.Rokt.createLauncher(r),s.then(async o=>{await We(n,o),this.initRoktLauncher(o)}).catch(o=>{console.error("Error creating Rokt launcher:",o)})}initRoktLauncher(e){window.Rokt&&(window.Rokt.currentLauncher=e),this.launcher=e;const t=a().Rokt?.filters;t?(this.filters=t,t.filteredUser?this._workspaceSearchInFlightPromise=this.search(t.filteredUser):console.warn("Rokt Kit: No filtered user has been set.")):console.warn("Rokt Kit: No filters have been set."),this.isInitialized=!0,de(this.domain,this.integrationName),a().Rokt.attachKit(this)}fetchOptimizely(){const e=a()._getActiveForwarders().filter(t=>t.name==="Optimizely");try{if(e.length>0&&window.optimizely){const t=window.optimizely.get("state");return!t||!t.getActiveExperimentIds?{}:t.getActiveExperimentIds().reduce((s,o)=>(s["rokt.custom.optimizely.experiment."+o+".variationId"]=t.getVariationMap()[o].id,s),{})}}catch(t){console.error("Error fetching Optimizely attributes:",t)}return{}}isKitReady(){return!!(this.isInitialized&&this.launcher)}isTargetingDisabled(){return a().Rokt?.launcherOptions?.noTargeting===!0}isPartnerInLocalLauncherTestGroup(){return!!(a().config&&a().config.isLocalLauncherEnabled&&this.isAssignedToSampleGroup())}isAssignedToSampleGroup(){return Math.random()>.5}captureTiming(e){window&&a()&&a().captureTiming&&e&&a().captureTiming(e)}init(e,t,n,r,s){const o=e,c=o.accountId;this.userAttributes=R(s),this._onboardingExpProvider=o.onboardingExpProvider;const u=N(o.placementEventMapping);this.placementEventMappingLookup=ae(u);const l=N(o.placementEventAttributeMapping);this.placementEventAttributeMappingLookup=ce(l),o.hashedEmailUserIdentityType&&(this._mappedEmailSha256Key=o.hashedEmailUserIdentityType.toLowerCase()),this._workspaceIdSyncApiKey=_(o.workspaceIdSyncApiKey)?o.workspaceIdSyncApiKey:void 0;const p=a().Rokt?.domain,{roktExtensionsQueryParams:j,legacyRoktExtensions:U,loadThankYouElement:C}=oe(o.roktExtensions),m={...a().Rokt?.launcherOptions||{}};this.integrationName=je(m.integrationName),m.integrationName=this.integrationName,this.domain=p;const k={loggingUrl:o.loggingUrl,errorUrl:o.errorUrl,integrationDomain:p,isLoggingEnabled:a().config?.isLoggingEnabled===!0},y=new ge(k,this.integrationName,window.__rokt_li_guid__,o.accountId),v=new pe(k,y,this.integrationName,window.__rokt_li_guid__,o.accountId);if(this.errorReportingService=y,this.loggingService=v,this.isTargetingDisabled())try{ee(),te()}catch(h){this.errorReportingService?.report({message:"Rokt Kit: Failed to clear page views when targeting is disabled",code:"PAGE_VIEW_CAPTURE_FAILED",severity:I.INFO,stackTrace:h instanceof Error?h.stack:void 0})}return a()._registerErrorReportingService&&a()._registerErrorReportingService(y),a()._registerLoggingService&&a()._registerLoggingService(v),n?(this.testHelpers={generateLauncherScript:ie,generateThankYouElementScript:ne,extractRoktExtensionConfig:oe,hashEventMessage:le,parseSettingsString:N,generateMappedEventLookup:ae,generateMappedEventAttributeLookup:ce,sendAdBlockMeasurementSignals:de,createAutoRemovedIframe:x,djb2:ue,setAllowedOriginHashes:h=>{f._allowedOriginHashes=h},ReportingTransport:W,ErrorReportingService:ge,LoggingService:pe,RateLimiter:he,ErrorCodes:G,WSDKErrorSeverity:I},this.attachLauncher(c,m),"Successfully initialized: "+d):(C&&(a().Rokt.flushOnShoppableAdsReadyMessageQueue?.(this),se(Le,ne(p),{onLoad:()=>{this._isThankYouElementLoaded=!0,this._thankYouElementOnLoadCallback&&this._thankYouElementOnLoadCallback()},onError:h=>{console.error("Error loading Rokt Thank You Element script:",h)}})),this.isLauncherReadyToAttach()?this.attachLauncher(c,m,U):(se(Te,ie(p,j),{onLoad:()=>{this.isLauncherReadyToAttach()?this.attachLauncher(c,m,U):console.error("Rokt object is not available after script load.")},onError:h=>{console.error("Error loading Rokt launcher script:",h)}}),this.captureTiming(f.PERFORMANCE_MARKS.RoktScriptAppended)),"Successfully initialized: "+d)}process(e){if(this.isTargetingDisabled()||(e.EventDataType===Oe&&(ye(this.loggingService),this.capturePageView(e)),e.EventDataType===Ne&&(X(this.loggingService),ee(),te())),!this.isKitReady())return"Kit not ready for forwarder: "+d;if(w(a().Rokt?.setLocalSessionAttribute)&&(K(this.placementEventAttributeMappingLookup)||this.applyPlacementEventAttributeMapping(e),!K(this.placementEventMappingLookup))){const t=le(e.EventDataType,e.EventCategory,e.EventName??"");this.placementEventMappingLookup[String(t)]&&a().Rokt.setLocalSessionAttribute?.(this.placementEventMappingLookup[String(t)],!0)}return"Successfully sent to forwarder: "+d}setExtensionData(e){if(!this.isKitReady()){console.error("Rokt Kit: Not initialized");return}window.Rokt.setExtensionData(e)}setUserAttribute(e,t){return V(e)||(this.userAttributes[e]=t),"Successfully set user attribute for forwarder: "+d}removeUserAttribute(e){return delete this.userAttributes[e],"Successfully removed user attribute for forwarder: "+d}handleIdentityComplete(e,t){return this.userAttributes=R(e.getAllUserAttributes()),"Successfully called "+t+" for forwarder: "+d}onUserIdentified(e){const t=e;return this.filters.filteredUser=t,this._workspaceSearchInFlightPromise=this.search(t),this.handleIdentityComplete(e,"onUserIdentified")}search(e){const t=this._workspaceIdSyncApiKey;if(!t)return this.userIdentifiedInWorkspace=!1,this._workspaceLastSearchedIdentitiesKey=void 0,Promise.resolve();const n=a().Identity?.search;if(typeof n!="function")return this.userIdentifiedInWorkspace=!1,this._workspaceLastSearchedIdentitiesKey=void 0,Promise.resolve();const r=e.getUserIdentities?e.getUserIdentities().userIdentities:null,s={};if(r)for(const u of Object.keys(r)){const l=r[u];_(l)&&l.length>0&&(s[u]=l)}const o=Object.keys(s);if(o.length===0)return this.userIdentifiedInWorkspace=!1,this._workspaceLastSearchedIdentitiesKey=void 0,Promise.resolve();const c=o.sort().map(u=>`${u}=${s[u]}`).join("&");return c===this._workspaceLastSearchedIdentitiesKey?this._workspaceSearchInFlightPromise||Promise.resolve():(this.userIdentifiedInWorkspace=!1,this._workspaceLastSearchedIdentitiesKey=c,new Promise(u=>{try{n(t,s,l=>{l?.httpCode===200&&(this.userIdentifiedInWorkspace=!0),u()})}catch(l){console.error("Rokt Kit: Workspace IDSync search failed",l),this._workspaceLastSearchedIdentitiesKey=void 0,u()}}))}onLoginComplete(e,t){return this.handleIdentityComplete(e,"onLoginComplete")}onLogoutComplete(e,t){return this.userIdentifiedInWorkspace=!1,this._workspaceSearchInFlightPromise=null,this._workspaceLastSearchedIdentitiesKey=void 0,this.handleIdentityComplete(e,"onLogoutComplete")}onModifyComplete(e,t){return this.handleIdentityComplete(e,"onModifyComplete")}selectPlacements(e){if(this._workspaceSearchInFlightPromise){const t=this._workspaceSearchInFlightPromise;return Promise.race([t,new Promise(n=>setTimeout(n,De))]).then(()=>this._dispatchPlacements(e))}return this._dispatchPlacements(e)}_dispatchPlacements(e){const t=e&&e.attributes||{},r={...R(this.userAttributes),...t},s=this.filters||{},o=s.userAttributeFilters||[],c=s.filteredUser||null,u=c?c.getMPID():null;let l;s?s.filterUserAttributes?l=s.filterUserAttributes(r,o):l=r:(console.warn("Rokt Kit: No filters available, using user attributes"),l=r),this.userAttributes=R(l);const p=this._onboardingExpProvider==="Optimizely"?this.fetchOptimizely():{},j=this.returnUserIdentities(c),U=this.returnLocalSessionAttributes(),C=Se(Z(this.loggingService)),m=Ae(),k=this.readMpSessionId(),y=this.readMpDeviceId(),v={...j,...l,...p,...U,...C.length?{[Ue]:JSON.stringify(C)}:{},...m?{[Ce]:m}:{},...this.userIdentifiedInWorkspace?{[Pe]:!0}:{},...k?{[Me]:k}:{},...y?{[Ke]:y}:{},mpid:u},h={...e,attributes:v},fe=this.launcher.selectPlacements(h),Be=()=>this.logSelectPlacementsEvent(v);return Promise.resolve(fe).then(Qe=>Qe?.context?.sessionId?.then(Xe=>this.setRoktSessionId(Xe))).catch(()=>{}).finally(Be),fe}hashAttributes(e){return this.isKitReady()?this.launcher.hashAttributes(e):(console.error("Rokt Kit: Not initialized"),null)}use(e){return this.isKitReady()?!e||!_(e)?Promise.reject(new Error("Rokt Kit: Invalid extension name")):this.launcher.use(e):(console.error("Rokt Kit: Not initialized"),Promise.reject(new Error("Rokt Kit: Not initialized")))}onShoppableAdsReady(e){this._isThankYouElementLoaded?e():this._thankYouElementOnLoadCallback=e}};f._allowedOriginHashes=[-553112570,549508659],f.PERFORMANCE_MARKS={RoktScriptAppended:"mp:RoktScriptAppended"},f.EMAIL_SHA256_KEY="emailsha256";let S=f;function $e(){return P}function Je(i){if(!i){window.console.log("You must pass a config object to register the kit "+d);return}if(!E(i)){window.console.log("'config' must be an object. You passed in a "+typeof i);return}E(i.kits)?i.kits[d]={constructor:S}:(i.kits={},i.kits[d]={constructor:S}),window.console.log("Successfully registered "+d+" to your mParticle configuration")}return typeof window<"u"&&window.mParticle&&a().addForwarder&&a().addForwarder({name:d,constructor:S,getId:$e}),M.register=Je,Object.defineProperty(M,Symbol.toStringTag,{value:"Module"}),M})({});
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.35.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",