@mparticle/web-rokt-kit 1.32.0 → 1.33.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 ae=["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"],ce=new Set(ae);function X(i){return ce.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];X(s)||(e[s]=t[s])}return e}function y(i){return typeof i=="object"&&i!==null&&!Array.isArray(i)}function m(i){return typeof i=="string"}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}}function N(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 ee(i){try{window.localStorage.removeItem(i)}catch{}}function te(i,e){const t=N(i);return y(t)?t[e]:void 0}function C(i,e,t){const n=N(i),r=y(n)?{...n}:{};return r[e]=t,Z(i,r)}function le(i,e){const t=N(i);if(!y(t)||!(e in t))return;const n={...t};delete n[e],Object.keys(n).length===0?ee(i):Z(i,n)}function ue(i,e,t,n){const r=t.slice(),s=()=>r.length<=1?!1:(r.shift(),!0);let o=JSON.stringify(r).length>n;for(;o&&s();)o=JSON.stringify(r).length>n;let c=C(i,e,r);for(;!c&&s();)c=C(i,e,r);return c}const I="mp-rokt-kit",k="pageViews",Y="mpPageViews",de=100*1024;function ie(i){const e=N(Y);if(e===null)return;if(!(te(I,k)!==void 0)&&Array.isArray(e)&&!C(I,k,e)){i?.log({message:"Rokt Kit: Failed to migrate legacy page-view storage; retaining legacy key for retry",code:"PAGE_VIEW_CAPTURE_FAILED"});return}ee(Y)}function x(i){ie(i);const e=te(I,k);return Array.isArray(e)?e:[]}function he(i){return ue(I,k,i,de)}function G(){le(I,k)}function ge(i){return i.map((e,t)=>{const n=e.activeTimeOnSite,r=n!==void 0&&Number.isFinite(n),o=i[t+1]?.activeTimeOnSite,c=o!==void 0&&Number.isFinite(o),u=r&&c?o-n:void 0;return{pageUrl:e.pageUrl,sourceMessageId:e.sourceMessageId,timestamp:e.timestamp,...e.pageTitle!==void 0?{pageTitle:e.pageTitle}:{},...e.canonicalUrl!==void 0?{canonicalUrl:e.canonicalUrl}:{},...r?{activeTimeOnSite:n}:{},...u!==void 0&&u>=0?{activeTimeOnPage:u}:{}}})}function pe(){const e=document.querySelector('link[rel="canonical"]')?.href;if(e)return K(e)}const d="Rokt",L=181,fe="selectPlacements",me="apps.roktecommerce.com",Ee=.1,_e="ThankYouPageJourney",ye="rokt-launcher",Se="rokt-thank-you-element",Ie="userIdentifiedInWorkspace",ke=3,Ae=2,Re="page_events",ve=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"},we="apps.rokt-api.com",be="/v1/log",Le="/v1/errors",Te=10;function a(){return window.mParticle}function W(i,e){const n=[O(i),"/wsdk/integrations/launcher.js"].join("");return!e||e.length===0?n:n+"?extensions="+e.join(",")}function j(i){return[O(i),"/rokt-elements/rokt-element-thank-you.js"].join("")}function O(i){const e=typeof i<"u"?i:we;return e.includes("://")?e.replace(/\/+$/,""):["https://",e].join("")}function ne(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 H(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 V(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(_e)):t.push(o)}return{roktExtensionsQueryParams:t,legacyRoktExtensions:n,loadThankYouElement:r}}async function Ne(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 J(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 Oe(i){let n="mParticle_wsdkv_"+a().getVersion()+"_kitv_"+"1.32.0";return i&&(n+="_"+i),n}function re(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=re(window.location.origin);if(S._allowedOriginHashes.indexOf(t)===-1||Math.random()>=Ee)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";M(c+"/v1/wsdk-init/index.html?"+o),M("https://"+me+"/v1/wsdk-init/index.html?"+o+"&isControl=true")}function Pe(){return typeof window<"u"&&!!window.location?.search?.toLowerCase().includes("mp_enable_logging=true")}function Ue(){return typeof window<"u"?window.location?.href:void 0}function Ce(){return typeof window<"u"?window.navigator?.userAgent:void 0}class se{constructor(){this._logCount={}}incrementAndCheck(e){const n=(this._logCount[e]||0)+1;return this._logCount[e]=n,n>Te}}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 se,this._isEnabled=Pe()||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:Ue(),deviceInfo:Ce(),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 ${constructor(e,t,n,r,s){this._transport=new F(e,t,n,r,s),this._errorUrl=ne(e?.errorUrl,e?.integrationDomain,Le)}report(e){if(!e)return;const t=e.severity||_.ERROR;this._transport.send(this._errorUrl,t,e.message,e.code,e.stackTrace)}}class Q{constructor(e,t,n,r,s,o){this._transport=new F(e,n,r,s,o),this._loggingUrl=ne(e?.loggingUrl,e?.integrationDomain,be),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 Me(i){const e=K(window.location.href),t=i.EventAttributes?.title||document.title,n=pe(),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=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||!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=x(this.loggingService),r=Me(e);n.push(r),he(n)||this.loggingService?.log({message:`Rokt Kit: Failed to persist page view for ${t}`,code:"PAGE_VIEW_CAPTURE_FAILED"})}catch(n){this.loggingService?.log({message:`Rokt Kit: Failed to capture page view for ${t}: ${n instanceof Error?n.message:String(n)}`,code:"PAGE_VIEW_CAPTURE_FAILED"})}}isLauncherReadyToAttach(){return!!window.Rokt&&typeof window.Rokt.createLauncher=="function"}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"||!y(e))return;const t=a().EventType.Other;a().logEvent(fe,t,e)}setRoktSessionId(e){if(!(!e||typeof e!="string"))try{const t=a().getInstance();t&&typeof t.setIntegrationAttribute=="function"&&t.setIntegrationAttribute(L,{roktSessionId:e})}catch{}}attachLauncher(e,t,n=[]){const r=a()&&a().sessionManager&&typeof a().sessionManager.getSession=="function"?a().sessionManager.getSession():void 0,s={accountId:e,...t||{},...r?{mpSessionId:r}:{}};let o;this.isPartnerInLocalLauncherTestGroup()?o=Promise.resolve(window.Rokt.createLocalLauncher(s)):o=window.Rokt.createLauncher(s),o.then(async c=>{await Ne(n,c),this.initRoktLauncher(c)}).catch(c=>{console.error("Error creating Rokt launcher:",c)})}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=T(o.placementEventMapping);this.placementEventMappingLookup=z(u);const l=T(o.placementEventAttributeMapping);this.placementEventAttributeMappingLookup=J(l),o.hashedEmailUserIdentityType&&(this._mappedEmailSha256Key=o.hashedEmailUserIdentityType.toLowerCase()),this._workspaceIdSyncApiKey=m(o.workspaceIdSyncApiKey)?o.workspaceIdSyncApiKey:void 0;const g=a().Rokt?.domain,{roktExtensionsQueryParams:P,legacyRoktExtensions:A,loadThankYouElement:R}=V(o.roktExtensions),p={...a().Rokt?.launcherOptions||{}};this.integrationName=Oe(p.integrationName),p.integrationName=this.integrationName,this.domain=g;const v={loggingUrl:o.loggingUrl,errorUrl:o.errorUrl,integrationDomain:g,isLoggingEnabled:a().config?.isLoggingEnabled===!0},E=new $(v,this.integrationName,window.__rokt_li_guid__,o.accountId),w=new Q(v,E,this.integrationName,window.__rokt_li_guid__,o.accountId);if(this.errorReportingService=E,this.loggingService=w,this.isTargetingDisabled())try{G()}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:W,generateThankYouElementScript:j,extractRoktExtensionConfig:V,hashEventMessage:B,parseSettingsString:T,generateMappedEventLookup:z,generateMappedEventAttributeLookup:J,sendAdBlockMeasurementSignals:q,createAutoRemovedIframe:M,djb2:re,setAllowedOriginHashes:h=>{f._allowedOriginHashes=h},ReportingTransport:F,ErrorReportingService:$,LoggingService:Q,RateLimiter:se,ErrorCodes:D,WSDKErrorSeverity:_},this.attachLauncher(c,p),"Successfully initialized: "+d):(R&&(a().Rokt.flushOnShoppableAdsReadyMessageQueue?.(this),H(Se,j(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,A):(H(ye,W(g,P),{onLoad:()=>{this.isLauncherReadyToAttach()?this.attachLauncher(c,p,A):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===ke&&this.capturePageView(e),e.EventDataType===Ae&&(ie(this.loggingService),G())),!this.isKitReady())return"Kit not ready for forwarder: "+d;if(typeof a().Rokt?.setLocalSessionAttribute=="function"&&(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 X(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,ve))]).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():{},P=this.returnUserIdentities(c),A=this.returnLocalSessionAttributes(),R=ge(x(this.loggingService)),p={...P,...l,...g,...A,...R.length?{[Re]:JSON.stringify(R)}:{},...this.userIdentifiedInWorkspace?{[Ie]:!0}:{},mpid:u},v={...e,attributes:p},E=this.launcher.selectPlacements(v),w=()=>this.logSelectPlacementsEvent(p);return Promise.resolve(E).then(h=>h?.context?.sessionId?.then(oe=>this.setRoktSessionId(oe))).catch(()=>{}).finally(w),E}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 Ke(){return L}function De(i){if(!i){window.console.log("You must pass a config object to register the kit "+d);return}if(!y(i)){window.console.log("'config' must be an object. You passed in a "+typeof i);return}y(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:Ke});exports.register=De;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const le=["active_time_on_site_ms","billingaddress1","billingaddress2","billingcity","billingstate","billingzipcode","cartitems","ccbin","confirmationref","conversiontype","country","couponcode","currency","language","paymentserviceprovider","paymentserviceproviderattribute","paymenttype","shippingaddress1","shippingcity","shippingcountry","shippingmethod","shippingstate","shippingzipcode","totalprice"],ue=new Set(le);function Z(i){return ue.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];Z(s)||(e[s]=t[s])}return e}function _(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 C(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}}function O(i){try{const e=window.localStorage.getItem(i);return e===null?null:JSON.parse(e)}catch{return null}}function ee(i,e){try{return window.localStorage.setItem(i,JSON.stringify(e)),!0}catch{return!1}}function te(i){try{window.localStorage.removeItem(i)}catch{}}function ie(i,e){const t=O(i);return _(t)?t[e]:void 0}function M(i,e,t){const n=O(i),r=_(n)?{...n}:{};return r[e]=t,ee(i,r)}function de(i,e){const t=O(i);if(!_(t)||!(e in t))return;const n={...t};delete n[e],Object.keys(n).length===0?te(i):ee(i,n)}function he(i,e,t,n){const r=t.slice(),s=()=>r.length<=1?!1:(r.shift(),!0);let o=JSON.stringify(r).length>n;for(;o&&s();)o=JSON.stringify(r).length>n;let c=M(i,e,r);for(;!c&&s();)c=M(i,e,r);return c}const k="mp-rokt-kit",R="pageViews",x="mpPageViews",ge=100*1024;function ne(i){const e=O(x);if(e===null)return;if(!(ie(k,R)!==void 0)&&Array.isArray(e)&&!M(k,R,e)){i?.log({message:"Rokt Kit: Failed to migrate legacy page-view storage; retaining legacy key for retry",code:"PAGE_VIEW_CAPTURE_FAILED"});return}te(x)}function G(i){ne(i);const e=ie(k,R);return Array.isArray(e)?e:[]}function pe(i){return he(k,R,i,ge)}function W(){de(k,R)}function fe(i){return i.map((e,t)=>{const n=e.activeTimeOnSite,r=n!==void 0&&Number.isFinite(n),o=i[t+1]?.activeTimeOnSite,c=o!==void 0&&Number.isFinite(o),u=r&&c?o-n:void 0;return{pageUrl:e.pageUrl,sourceMessageId:e.sourceMessageId,timestamp:e.timestamp,...e.pageTitle!==void 0?{pageTitle:e.pageTitle}:{},...e.canonicalUrl!==void 0?{canonicalUrl:e.canonicalUrl}:{},...r?{activeTimeOnSite:n}:{},...u!==void 0&&u>=0?{activeTimeOnPage:u}:{}}})}function me(){const e=document.querySelector('link[rel="canonical"]')?.href;if(e)return D(e)}const d="Rokt",T=181,Ee="selectPlacements",_e="apps.roktecommerce.com",ye=.1,Ie="ThankYouPageJourney",Se="rokt-launcher",Ae="rokt-thank-you-element",ke="userIdentifiedInWorkspace",Re=3,ve=2,we="page_events",be="mparticle_session_id",Le=500,F={UNKNOWN_ERROR:"UNKNOWN_ERROR",UNHANDLED_EXCEPTION:"UNHANDLED_EXCEPTION",IDENTITY_REQUEST:"IDENTITY_REQUEST",LOG_DELIVERY_FAILURE:"LOG_DELIVERY_FAILURE"},E={ERROR:"ERROR",INFO:"INFO",WARNING:"WARNING"},Te="apps.rokt-api.com",Ne="/v1/log",Oe="/v1/errors",Pe=10;function a(){return window.mParticle}function j(i,e){const n=[P(i),"/wsdk/integrations/launcher.js"].join("");return!e||e.length===0?n:n+"?extensions="+e.join(",")}function H(i){return[P(i),"/rokt-elements/rokt-element-thank-you.js"].join("")}function P(i){const e=typeof i<"u"?i:Te;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 P(r)+t}function V(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 z(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(Ie)):t.push(o)}return{roktExtensionsQueryParams:t,legacyRoktExtensions:n,loadThankYouElement:r}}async function Ue(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 B(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 q(i,e,t){return a().generateHash([i,e,t].join(""))}function Ce(i){let n="mParticle_wsdkv_"+a().getVersion()+"_kitv_"+"1.33.0";return i&&(n+="_"+i),n}function se(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 K(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 $(i,e){const t=se(window.location.origin);if(y._allowedOriginHashes.indexOf(t)===-1||Math.random()>=ye)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?P(i):"https://apps.rokt.com";K(c+"/v1/wsdk-init/index.html?"+o),K("https://"+_e+"/v1/wsdk-init/index.html?"+o+"&isControl=true")}function Me(){return typeof window<"u"&&!!window.location?.search?.toLowerCase().includes("mp_enable_logging=true")}function Ke(){return typeof window<"u"?window.location?.href:void 0}function De(){return typeof window<"u"?window.navigator?.userAgent:void 0}class oe{constructor(){this._logCount={}}incrementAndCheck(e){const n=(this._logCount[e]||0)+1;return this._logCount[e]=n,n>Pe}}class Y{constructor(e,t,n,r,s){this._reporter="mp-wsdk";const o=e.isLoggingEnabled;this._integrationName=t||"",this._launcherInstanceGuid=n,this._accountId=r||null,this._rateLimiter=s||new oe,this._isEnabled=Me()||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||F.UNKNOWN_ERROR,url:Ke(),deviceInfo:De(),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 Q{constructor(e,t,n,r,s){this._transport=new Y(e,t,n,r,s),this._errorUrl=re(e?.errorUrl,e?.integrationDomain,Oe)}report(e){if(!e)return;const t=e.severity||E.ERROR;this._transport.send(this._errorUrl,t,e.message,e.code,e.stackTrace)}}class X{constructor(e,t,n,r,s,o){this._transport=new Y(e,n,r,s,o),this._loggingUrl=re(e?.loggingUrl,e?.integrationDomain,Ne),this._errorReportingService=t}log(e){e&&this._transport.send(this._loggingUrl,E.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:F.LOG_DELIVERY_FAILURE,severity:n?E.ERROR:E.WARNING})}})}}function Fe(i){const e=D(window.location.href),t=i.EventAttributes?.title||document.title,n=me(),r=i.ActiveTimeOnSite;return{pageUrl:e,sourceMessageId:i.SourceMessageId,timestamp:i.Timestamp,...t?{pageTitle:t}:{},...n!==void 0?{canonicalUrl:n}:{},...Number.isFinite(r)?{activeTimeOnSite:r}:{}}}const 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(C(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=G(this.loggingService),r=Fe(e);n.push(r),pe(n)||this.loggingService?.log({message:`Rokt Kit: Failed to persist page view for ${t}`,code:"PAGE_VIEW_CAPTURE_FAILED"})}catch(n){this.loggingService?.log({message:`Rokt Kit: Failed to capture page view for ${t}: ${n instanceof Error?n.message:String(n)}`,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"||!_(e))return;const t=a().EventType.Other;a().logEvent(Ee,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;if(!(!e||!L(e.getSessionId)))return e.getSessionId()||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 Ue(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,$(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=N(o.placementEventMapping);this.placementEventMappingLookup=J(u);const l=N(o.placementEventAttributeMapping);this.placementEventAttributeMappingLookup=B(l),o.hashedEmailUserIdentityType&&(this._mappedEmailSha256Key=o.hashedEmailUserIdentityType.toLowerCase()),this._workspaceIdSyncApiKey=m(o.workspaceIdSyncApiKey)?o.workspaceIdSyncApiKey:void 0;const g=a().Rokt?.domain,{roktExtensionsQueryParams:U,legacyRoktExtensions:v,loadThankYouElement:w}=z(o.roktExtensions),p={...a().Rokt?.launcherOptions||{}};this.integrationName=Ce(p.integrationName),p.integrationName=this.integrationName,this.domain=g;const I={loggingUrl:o.loggingUrl,errorUrl:o.errorUrl,integrationDomain:g,isLoggingEnabled:a().config?.isLoggingEnabled===!0},S=new Q(I,this.integrationName,window.__rokt_li_guid__,o.accountId),A=new X(I,S,this.integrationName,window.__rokt_li_guid__,o.accountId);if(this.errorReportingService=S,this.loggingService=A,this.isTargetingDisabled())try{W()}catch(h){this.errorReportingService?.report({message:"Rokt Kit: Failed to clear page views when targeting is disabled",code:"PAGE_VIEW_CAPTURE_FAILED",severity:E.INFO,stackTrace:h instanceof Error?h.stack:void 0})}return a()._registerErrorReportingService&&a()._registerErrorReportingService(S),a()._registerLoggingService&&a()._registerLoggingService(A),n?(this.testHelpers={generateLauncherScript:j,generateThankYouElementScript:H,extractRoktExtensionConfig:z,hashEventMessage:q,parseSettingsString:N,generateMappedEventLookup:J,generateMappedEventAttributeLookup:B,sendAdBlockMeasurementSignals:$,createAutoRemovedIframe:K,djb2:se,setAllowedOriginHashes:h=>{f._allowedOriginHashes=h},ReportingTransport:Y,ErrorReportingService:Q,LoggingService:X,RateLimiter:oe,ErrorCodes:F,WSDKErrorSeverity:E},this.attachLauncher(c,p),"Successfully initialized: "+d):(w&&(a().Rokt.flushOnShoppableAdsReadyMessageQueue?.(this),V(Ae,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):(V(Se,j(g,U),{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===Re&&this.capturePageView(e),e.EventDataType===ve&&(ne(this.loggingService),W())),!this.isKitReady())return"Kit not ready for forwarder: "+d;if(L(a().Rokt?.setLocalSessionAttribute)&&(C(this.placementEventAttributeMappingLookup)||this.applyPlacementEventAttributeMapping(e),!C(this.placementEventMappingLookup))){const t=q(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 Z(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,Le))]).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():{},U=this.returnUserIdentities(c),v=this.returnLocalSessionAttributes(),w=fe(G(this.loggingService)),p=this.readMpSessionId(),I={...U,...l,...g,...v,...w.length?{[we]:JSON.stringify(w)}:{},...this.userIdentifiedInWorkspace?{[ke]:!0}:{},...p?{[be]:p}:{},mpid:u},S={...e,attributes:I},A=this.launcher.selectPlacements(S),h=()=>this.logSelectPlacementsEvent(I);return Promise.resolve(A).then(ae=>ae?.context?.sessionId?.then(ce=>this.setRoktSessionId(ce))).catch(()=>{}).finally(h),A}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 y=f;function Ye(){return T}function xe(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:Ye});exports.register=xe;
2
2
  //# sourceMappingURL=Rokt-Kit.common.js.map
@@ -1,4 +1,4 @@
1
- const ae = [
1
+ const le = [
2
2
  "active_time_on_site_ms",
3
3
  "billingaddress1",
4
4
  "billingaddress2",
@@ -23,28 +23,31 @@ const ae = [
23
23
  "shippingstate",
24
24
  "shippingzipcode",
25
25
  "totalprice"
26
- ], ce = new Set(ae);
27
- function X(i) {
28
- return ce.has(i.toLowerCase());
26
+ ], ue = new Set(le);
27
+ function Z(i) {
28
+ return ue.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
- X(s) || (e[s] = t[s]);
34
+ Z(s) || (e[s] = t[s]);
35
35
  }
36
36
  return e;
37
37
  }
38
- function y(i) {
38
+ function _(i) {
39
39
  return typeof i == "object" && i !== null && !Array.isArray(i);
40
40
  }
41
41
  function m(i) {
42
42
  return typeof i == "string";
43
43
  }
44
- function U(i) {
44
+ function L(i) {
45
+ return typeof i == "function";
46
+ }
47
+ function C(i) {
45
48
  return i == null ? !0 : typeof i == "object" ? Object.keys(i).length === 0 : !1;
46
49
  }
47
- function K(i) {
50
+ function D(i) {
48
51
  try {
49
52
  const e = new URL(i);
50
53
  return e.search = "", e.toString();
@@ -52,7 +55,7 @@ function K(i) {
52
55
  return i;
53
56
  }
54
57
  }
55
- function N(i) {
58
+ function O(i) {
56
59
  try {
57
60
  const e = window.localStorage.getItem(i);
58
61
  return e === null ? null : JSON.parse(e);
@@ -60,70 +63,70 @@ function N(i) {
60
63
  return null;
61
64
  }
62
65
  }
63
- function Z(i, e) {
66
+ function ee(i, e) {
64
67
  try {
65
68
  return window.localStorage.setItem(i, JSON.stringify(e)), !0;
66
69
  } catch {
67
70
  return !1;
68
71
  }
69
72
  }
70
- function ee(i) {
73
+ function te(i) {
71
74
  try {
72
75
  window.localStorage.removeItem(i);
73
76
  } catch {
74
77
  }
75
78
  }
76
- function te(i, e) {
77
- const t = N(i);
78
- return y(t) ? t[e] : void 0;
79
+ function ie(i, e) {
80
+ const t = O(i);
81
+ return _(t) ? t[e] : void 0;
79
82
  }
80
- function C(i, e, t) {
81
- const n = N(i), r = y(n) ? { ...n } : {};
82
- return r[e] = t, Z(i, r);
83
+ function M(i, e, t) {
84
+ const n = O(i), r = _(n) ? { ...n } : {};
85
+ return r[e] = t, ee(i, r);
83
86
  }
84
- function le(i, e) {
85
- const t = N(i);
86
- if (!y(t) || !(e in t))
87
+ function de(i, e) {
88
+ const t = O(i);
89
+ if (!_(t) || !(e in t))
87
90
  return;
88
91
  const n = { ...t };
89
- delete n[e], Object.keys(n).length === 0 ? ee(i) : Z(i, n);
92
+ delete n[e], Object.keys(n).length === 0 ? te(i) : ee(i, n);
90
93
  }
91
- function ue(i, e, t, n) {
94
+ function he(i, e, t, n) {
92
95
  const r = t.slice(), s = () => r.length <= 1 ? !1 : (r.shift(), !0);
93
96
  let o = JSON.stringify(r).length > n;
94
97
  for (; o && s(); )
95
98
  o = JSON.stringify(r).length > n;
96
- let c = C(i, e, r);
99
+ let c = M(i, e, r);
97
100
  for (; !c && s(); )
98
- c = C(i, e, r);
101
+ c = M(i, e, r);
99
102
  return c;
100
103
  }
101
- const S = "mp-rokt-kit", k = "pageViews", x = "mpPageViews", de = 100 * 1024;
102
- function ie(i) {
103
- const e = N(x);
104
+ const k = "mp-rokt-kit", R = "pageViews", x = "mpPageViews", pe = 100 * 1024;
105
+ function ne(i) {
106
+ const e = O(x);
104
107
  if (e === null)
105
108
  return;
106
- if (!(te(S, k) !== void 0) && Array.isArray(e) && !C(S, k, e)) {
109
+ if (!(ie(k, R) !== void 0) && Array.isArray(e) && !M(k, R, e)) {
107
110
  i?.log({
108
111
  message: "Rokt Kit: Failed to migrate legacy page-view storage; retaining legacy key for retry",
109
112
  code: "PAGE_VIEW_CAPTURE_FAILED"
110
113
  });
111
114
  return;
112
115
  }
113
- ee(x);
116
+ te(x);
114
117
  }
115
- function Y(i) {
116
- ie(i);
117
- const e = te(S, k);
118
+ function G(i) {
119
+ ne(i);
120
+ const e = ie(k, R);
118
121
  return Array.isArray(e) ? e : [];
119
122
  }
120
- function he(i) {
121
- return ue(S, k, i, de);
123
+ function ge(i) {
124
+ return he(k, R, i, pe);
122
125
  }
123
- function G() {
124
- le(S, k);
126
+ function W() {
127
+ de(k, R);
125
128
  }
126
- function ge(i) {
129
+ function fe(i) {
127
130
  return i.map((e, t) => {
128
131
  const n = e.activeTimeOnSite, r = n !== void 0 && Number.isFinite(n), o = i[t + 1]?.activeTimeOnSite, c = o !== void 0 && Number.isFinite(o), u = r && c ? o - n : void 0;
129
132
  return {
@@ -137,47 +140,47 @@ function ge(i) {
137
140
  };
138
141
  });
139
142
  }
140
- function pe() {
143
+ function me() {
141
144
  const e = document.querySelector('link[rel="canonical"]')?.href;
142
145
  if (e)
143
- return K(e);
146
+ return D(e);
144
147
  }
145
- const d = "Rokt", L = 181, fe = "selectPlacements", me = "apps.roktecommerce.com", Ee = 0.1, _e = "ThankYouPageJourney", ye = "rokt-launcher", Ie = "rokt-thank-you-element", Se = "userIdentifiedInWorkspace", ke = 3, Ae = 2, Re = "page_events", ve = 500, D = {
148
+ const d = "Rokt", T = 181, Ee = "selectPlacements", _e = "apps.roktecommerce.com", Ie = 0.1, ye = "ThankYouPageJourney", Se = "rokt-launcher", Ae = "rokt-thank-you-element", ke = "userIdentifiedInWorkspace", Re = 3, ve = 2, we = "page_events", be = "mparticle_session_id", Le = 500, F = {
146
149
  UNKNOWN_ERROR: "UNKNOWN_ERROR",
147
150
  UNHANDLED_EXCEPTION: "UNHANDLED_EXCEPTION",
148
151
  IDENTITY_REQUEST: "IDENTITY_REQUEST",
149
152
  LOG_DELIVERY_FAILURE: "LOG_DELIVERY_FAILURE"
150
- }, _ = {
153
+ }, E = {
151
154
  ERROR: "ERROR",
152
155
  INFO: "INFO",
153
156
  WARNING: "WARNING"
154
- }, we = "apps.rokt-api.com", be = "/v1/log", Le = "/v1/errors", Te = 10;
157
+ }, Te = "apps.rokt-api.com", Ne = "/v1/log", Oe = "/v1/errors", Pe = 10;
155
158
  function a() {
156
159
  return window.mParticle;
157
160
  }
158
- function W(i, e) {
159
- const n = [O(i), "/wsdk/integrations/launcher.js"].join("");
161
+ function j(i, e) {
162
+ const n = [P(i), "/wsdk/integrations/launcher.js"].join("");
160
163
  return !e || e.length === 0 ? n : n + "?extensions=" + e.join(",");
161
164
  }
162
- function j(i) {
163
- return [O(i), "/rokt-elements/rokt-element-thank-you.js"].join("");
165
+ function H(i) {
166
+ return [P(i), "/rokt-elements/rokt-element-thank-you.js"].join("");
164
167
  }
165
- function O(i) {
166
- const e = typeof i < "u" ? i : we;
168
+ function P(i) {
169
+ const e = typeof i < "u" ? i : Te;
167
170
  return e.includes("://") ? e.replace(/\/+$/, "") : ["https://", e].join("");
168
171
  }
169
- function ne(i, e, t) {
172
+ function re(i, e, t) {
170
173
  if (i)
171
174
  return i.startsWith("http://") || i.startsWith("https://") ? i : "https://" + i;
172
175
  const r = e?.includes("://") && !/^https?:\/\//i.test(e) ? void 0 : e;
173
- return O(r) + t;
176
+ return P(r) + t;
174
177
  }
175
- function H(i, e, t) {
178
+ function V(i, e, t) {
176
179
  if (document.getElementById(i)) return;
177
180
  const n = document.head || document.body, r = document.createElement("script");
178
181
  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);
179
182
  }
180
- function T(i) {
183
+ function N(i) {
181
184
  if (!i)
182
185
  return [];
183
186
  try {
@@ -187,12 +190,12 @@ function T(i) {
187
190
  }
188
191
  return [];
189
192
  }
190
- function V(i) {
191
- const e = i ? T(i) : [], t = [], n = [];
193
+ function z(i) {
194
+ const e = i ? N(i) : [], t = [], n = [];
192
195
  let r = !1;
193
196
  for (let s = 0; s < e.length; s++) {
194
197
  const o = e[s].value;
195
- o === "thank-you-journey" ? (r = !0, n.push(_e)) : t.push(o);
198
+ o === "thank-you-journey" ? (r = !0, n.push(ye)) : t.push(o);
196
199
  }
197
200
  return {
198
201
  roktExtensionsQueryParams: t,
@@ -200,14 +203,14 @@ function V(i) {
200
203
  loadThankYouElement: r
201
204
  };
202
205
  }
203
- async function Ne(i, e) {
206
+ async function Ue(i, e) {
204
207
  const t = [];
205
208
  if (e)
206
209
  for (const n of i)
207
210
  t.push(e.use(n));
208
211
  return Promise.all(t);
209
212
  }
210
- function z(i) {
213
+ function J(i) {
211
214
  if (!i)
212
215
  return {};
213
216
  const e = {};
@@ -217,7 +220,7 @@ function z(i) {
217
220
  }
218
221
  return e;
219
222
  }
220
- function J(i) {
223
+ function B(i) {
221
224
  const e = {};
222
225
  if (!Array.isArray(i))
223
226
  return e;
@@ -233,20 +236,20 @@ function J(i) {
233
236
  }
234
237
  return e;
235
238
  }
236
- function B(i, e, t) {
239
+ function q(i, e, t) {
237
240
  return a().generateHash([i, e, t].join(""));
238
241
  }
239
- function Oe(i) {
240
- let n = "mParticle_wsdkv_" + a().getVersion() + "_kitv_" + "1.32.0";
242
+ function Ce(i) {
243
+ let n = "mParticle_wsdkv_" + a().getVersion() + "_kitv_" + "1.33.0";
241
244
  return i && (n += "_" + i), n;
242
245
  }
243
- function re(i) {
246
+ function se(i) {
244
247
  let e = 5381;
245
248
  for (let t = 0; t < i.length; t++)
246
249
  e = (e << 5) + e + i.charCodeAt(t), e = e & e;
247
250
  return e;
248
251
  }
249
- function M(i) {
252
+ function K(i) {
250
253
  const e = document.createElement("iframe");
251
254
  e.style.display = "none", e.setAttribute("sandbox", "allow-scripts allow-same-origin"), e.src = i, e.onload = function() {
252
255
  e.onload = null, e.parentNode && e.parentNode.removeChild(e);
@@ -254,41 +257,41 @@ function M(i) {
254
257
  const t = document.body || document.head;
255
258
  t && t.appendChild(e);
256
259
  }
257
- function q(i, e) {
258
- const t = re(window.location.origin);
259
- if (I._allowedOriginHashes.indexOf(t) === -1 || Math.random() >= Ee)
260
+ function $(i, e) {
261
+ const t = se(window.location.origin);
262
+ if (I._allowedOriginHashes.indexOf(t) === -1 || Math.random() >= Ie)
260
263
  return;
261
264
  const r = window.__rokt_li_guid__;
262
265
  if (!r || i && i.includes("://") && !/^https:\/\//i.test(i))
263
266
  return;
264
- 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";
265
- M(c + "/v1/wsdk-init/index.html?" + o), M(
266
- "https://" + me + "/v1/wsdk-init/index.html?" + o + "&isControl=true"
267
+ const s = window.location.href.split("?")[0].split("#")[0], o = "version=" + encodeURIComponent(e ?? "") + "&launcherInstanceGuid=" + encodeURIComponent(r) + "&pageUrl=" + encodeURIComponent(s), c = i ? P(i) : "https://apps.rokt.com";
268
+ K(c + "/v1/wsdk-init/index.html?" + o), K(
269
+ "https://" + _e + "/v1/wsdk-init/index.html?" + o + "&isControl=true"
267
270
  );
268
271
  }
269
- function Pe() {
272
+ function Me() {
270
273
  return typeof window < "u" && !!window.location?.search?.toLowerCase().includes("mp_enable_logging=true");
271
274
  }
272
- function Ue() {
275
+ function Ke() {
273
276
  return typeof window < "u" ? window.location?.href : void 0;
274
277
  }
275
- function Ce() {
278
+ function De() {
276
279
  return typeof window < "u" ? window.navigator?.userAgent : void 0;
277
280
  }
278
- class se {
281
+ class oe {
279
282
  constructor() {
280
283
  this._logCount = {};
281
284
  }
282
285
  incrementAndCheck(e) {
283
286
  const n = (this._logCount[e] || 0) + 1;
284
- return this._logCount[e] = n, n > Te;
287
+ return this._logCount[e] = n, n > Pe;
285
288
  }
286
289
  }
287
- class F {
290
+ class Y {
288
291
  constructor(e, t, n, r, s) {
289
292
  this._reporter = "mp-wsdk";
290
293
  const o = e.isLoggingEnabled;
291
- this._integrationName = t || "", this._launcherInstanceGuid = n, this._accountId = r || null, this._rateLimiter = s || new se(), this._isEnabled = Pe() || o;
294
+ this._integrationName = t || "", this._launcherInstanceGuid = n, this._accountId = r || null, this._rateLimiter = s || new oe(), this._isEnabled = Me() || o;
292
295
  }
293
296
  send(e, t, n, r, s, o) {
294
297
  if (!(!this._isEnabled || this._rateLimiter.incrementAndCheck(t)))
@@ -299,9 +302,9 @@ class F {
299
302
  version: this._integrationName
300
303
  },
301
304
  severity: t,
302
- code: r || D.UNKNOWN_ERROR,
303
- url: Ue(),
304
- deviceInfo: Ce(),
305
+ code: r || F.UNKNOWN_ERROR,
306
+ url: Ke(),
307
+ deviceInfo: De(),
305
308
  stackTrace: s,
306
309
  reporter: this._reporter,
307
310
  integration: this._integrationName
@@ -317,8 +320,8 @@ class F {
317
320
  body: JSON.stringify(c)
318
321
  }).then((l) => {
319
322
  if (!l.ok) {
320
- const g = new Error("HTTP " + l.status + " from log endpoint");
321
- throw g.statusCode = l.status, g;
323
+ const p = new Error("HTTP " + l.status + " from log endpoint");
324
+ throw p.statusCode = l.status, p;
322
325
  }
323
326
  }).catch((l) => {
324
327
  console.error("ReportingTransport: Failed to send log", l), o && o(l);
@@ -328,24 +331,24 @@ class F {
328
331
  }
329
332
  }
330
333
  }
331
- class $ {
334
+ class Q {
332
335
  constructor(e, t, n, r, s) {
333
- this._transport = new F(e, t, n, r, s), this._errorUrl = ne(e?.errorUrl, e?.integrationDomain, Le);
336
+ this._transport = new Y(e, t, n, r, s), this._errorUrl = re(e?.errorUrl, e?.integrationDomain, Oe);
334
337
  }
335
338
  report(e) {
336
339
  if (!e) return;
337
- const t = e.severity || _.ERROR;
340
+ const t = e.severity || E.ERROR;
338
341
  this._transport.send(this._errorUrl, t, e.message, e.code, e.stackTrace);
339
342
  }
340
343
  }
341
- class Q {
344
+ class X {
342
345
  constructor(e, t, n, r, s, o) {
343
- this._transport = new F(e, n, r, s, o), this._loggingUrl = ne(e?.loggingUrl, e?.integrationDomain, be), this._errorReportingService = t;
346
+ this._transport = new Y(e, n, r, s, o), this._loggingUrl = re(e?.loggingUrl, e?.integrationDomain, Ne), this._errorReportingService = t;
344
347
  }
345
348
  log(e) {
346
349
  e && this._transport.send(
347
350
  this._loggingUrl,
348
- _.INFO,
351
+ E.INFO,
349
352
  e.message,
350
353
  e.code,
351
354
  void 0,
@@ -354,16 +357,16 @@ class Q {
354
357
  const n = typeof t.statusCode == "number";
355
358
  this._errorReportingService.report({
356
359
  message: "LoggingService: Failed to send log: " + t.message,
357
- code: D.LOG_DELIVERY_FAILURE,
358
- severity: n ? _.ERROR : _.WARNING
360
+ code: F.LOG_DELIVERY_FAILURE,
361
+ severity: n ? E.ERROR : E.WARNING
359
362
  });
360
363
  }
361
364
  }
362
365
  );
363
366
  }
364
367
  }
365
- function Me(i) {
366
- const e = K(window.location.href), t = i.EventAttributes?.title || document.title, n = pe(), r = i.ActiveTimeOnSite;
368
+ function Fe(i) {
369
+ const e = D(window.location.href), t = i.EventAttributes?.title || document.title, n = me(), r = i.ActiveTimeOnSite;
367
370
  return {
368
371
  pageUrl: e,
369
372
  sourceMessageId: i.SourceMessageId,
@@ -375,7 +378,7 @@ function Me(i) {
375
378
  }
376
379
  const f = class f {
377
380
  constructor() {
378
- 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;
381
+ 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;
379
382
  }
380
383
  // ---- Private helpers ----
381
384
  getEventAttributeValue(e, t) {
@@ -406,7 +409,7 @@ const f = class f {
406
409
  const t = Object.keys(this.placementEventAttributeMappingLookup);
407
410
  for (let n = 0; n < t.length; n++) {
408
411
  const r = t[n], s = this.placementEventAttributeMappingLookup[r];
409
- if (U(s))
412
+ if (C(s))
410
413
  continue;
411
414
  let o = !0;
412
415
  for (let c = 0; c < s.length; c++)
@@ -420,9 +423,9 @@ const f = class f {
420
423
  capturePageView(e) {
421
424
  let t;
422
425
  try {
423
- t = K(window.location.href);
424
- const n = Y(this.loggingService), r = Me(e);
425
- n.push(r), he(n) || this.loggingService?.log({
426
+ t = D(window.location.href);
427
+ const n = G(this.loggingService), r = Fe(e);
428
+ n.push(r), ge(n) || this.loggingService?.log({
426
429
  message: `Rokt Kit: Failed to persist page view for ${t}`,
427
430
  code: "PAGE_VIEW_CAPTURE_FAILED"
428
431
  });
@@ -434,7 +437,7 @@ const f = class f {
434
437
  }
435
438
  }
436
439
  isLauncherReadyToAttach() {
437
- return !!window.Rokt && typeof window.Rokt.createLauncher == "function";
440
+ return !!window.Rokt && L(window.Rokt.createLauncher);
438
441
  }
439
442
  /**
440
443
  * Returns the user identities from the filtered user, if any.
@@ -453,38 +456,42 @@ const f = class f {
453
456
  return n && e[n] && (t[f.EMAIL_SHA256_KEY] = e[n]), n && delete t[n], t;
454
457
  }
455
458
  logSelectPlacementsEvent(e) {
456
- if (!window.mParticle || typeof a().logEvent != "function" || !y(e))
459
+ if (!window.mParticle || typeof a().logEvent != "function" || !_(e))
457
460
  return;
458
461
  const t = a().EventType.Other;
459
- a().logEvent(fe, t, e);
462
+ a().logEvent(Ee, t, e);
460
463
  }
461
464
  setRoktSessionId(e) {
462
465
  if (!(!e || typeof e != "string"))
463
466
  try {
464
467
  const t = a().getInstance();
465
- t && typeof t.setIntegrationAttribute == "function" && t.setIntegrationAttribute(L, {
468
+ t && L(t.setIntegrationAttribute) && t.setIntegrationAttribute(T, {
466
469
  roktSessionId: e
467
470
  });
468
471
  } catch {
469
472
  }
470
473
  }
474
+ readMpSessionId() {
475
+ const e = a()?.sessionManager;
476
+ if (!(!e || !L(e.getSessionId)))
477
+ return e.getSessionId() || void 0;
478
+ }
471
479
  attachLauncher(e, t, n = []) {
472
- const r = a() && a().sessionManager && typeof a().sessionManager.getSession == "function" ? a().sessionManager.getSession() : void 0, s = {
480
+ const r = {
473
481
  accountId: e,
474
- ...t || {},
475
- ...r ? { mpSessionId: r } : {}
482
+ ...t || {}
476
483
  };
477
- let o;
478
- this.isPartnerInLocalLauncherTestGroup() ? o = Promise.resolve(window.Rokt.createLocalLauncher(s)) : o = window.Rokt.createLauncher(s), o.then(async (c) => {
479
- await Ne(n, c), this.initRoktLauncher(c);
480
- }).catch((c) => {
481
- console.error("Error creating Rokt launcher:", c);
484
+ let s;
485
+ this.isPartnerInLocalLauncherTestGroup() ? s = Promise.resolve(window.Rokt.createLocalLauncher(r)) : s = window.Rokt.createLauncher(r), s.then(async (o) => {
486
+ await Ue(n, o), this.initRoktLauncher(o);
487
+ }).catch((o) => {
488
+ console.error("Error creating Rokt launcher:", o);
482
489
  });
483
490
  }
484
491
  initRoktLauncher(e) {
485
492
  window.Rokt && (window.Rokt.currentLauncher = e), this.launcher = e;
486
493
  const t = a().Rokt?.filters;
487
- 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);
494
+ 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, $(this.domain, this.integrationName), a().Rokt.attachKit(this);
488
495
  }
489
496
  fetchOptimizely() {
490
497
  const e = a()._getActiveForwarders().filter((t) => t.name === "Optimizely");
@@ -522,76 +529,76 @@ const f = class f {
522
529
  init(e, t, n, r, s) {
523
530
  const o = e, c = o.accountId;
524
531
  this.userAttributes = b(s), this._onboardingExpProvider = o.onboardingExpProvider;
525
- const u = T(o.placementEventMapping);
526
- this.placementEventMappingLookup = z(u);
527
- const l = T(
532
+ const u = N(o.placementEventMapping);
533
+ this.placementEventMappingLookup = J(u);
534
+ const l = N(
528
535
  o.placementEventAttributeMapping
529
536
  );
530
- this.placementEventAttributeMappingLookup = J(l), o.hashedEmailUserIdentityType && (this._mappedEmailSha256Key = o.hashedEmailUserIdentityType.toLowerCase()), this._workspaceIdSyncApiKey = m(o.workspaceIdSyncApiKey) ? o.workspaceIdSyncApiKey : void 0;
531
- const g = a().Rokt?.domain, { roktExtensionsQueryParams: P, legacyRoktExtensions: A, loadThankYouElement: R } = V(
537
+ this.placementEventAttributeMappingLookup = B(l), o.hashedEmailUserIdentityType && (this._mappedEmailSha256Key = o.hashedEmailUserIdentityType.toLowerCase()), this._workspaceIdSyncApiKey = m(o.workspaceIdSyncApiKey) ? o.workspaceIdSyncApiKey : void 0;
538
+ const p = a().Rokt?.domain, { roktExtensionsQueryParams: U, legacyRoktExtensions: v, loadThankYouElement: w } = z(
532
539
  o.roktExtensions
533
- ), p = {
540
+ ), g = {
534
541
  ...a().Rokt?.launcherOptions || {}
535
542
  };
536
- this.integrationName = Oe(p.integrationName), p.integrationName = this.integrationName, this.domain = g;
537
- const v = {
543
+ this.integrationName = Ce(g.integrationName), g.integrationName = this.integrationName, this.domain = p;
544
+ const y = {
538
545
  loggingUrl: o.loggingUrl,
539
546
  errorUrl: o.errorUrl,
540
- integrationDomain: g,
547
+ integrationDomain: p,
541
548
  isLoggingEnabled: a().config?.isLoggingEnabled === !0
542
- }, E = new $(
543
- v,
549
+ }, S = new Q(
550
+ y,
544
551
  this.integrationName,
545
552
  window.__rokt_li_guid__,
546
553
  o.accountId
547
- ), w = new Q(
548
- v,
549
- E,
554
+ ), A = new X(
555
+ y,
556
+ S,
550
557
  this.integrationName,
551
558
  window.__rokt_li_guid__,
552
559
  o.accountId
553
560
  );
554
- if (this.errorReportingService = E, this.loggingService = w, this.isTargetingDisabled())
561
+ if (this.errorReportingService = S, this.loggingService = A, this.isTargetingDisabled())
555
562
  try {
556
- G();
563
+ W();
557
564
  } catch (h) {
558
565
  this.errorReportingService?.report({
559
566
  message: "Rokt Kit: Failed to clear page views when targeting is disabled",
560
567
  code: "PAGE_VIEW_CAPTURE_FAILED",
561
- severity: _.INFO,
568
+ severity: E.INFO,
562
569
  stackTrace: h instanceof Error ? h.stack : void 0
563
570
  });
564
571
  }
565
- return a()._registerErrorReportingService && a()._registerErrorReportingService(E), a()._registerLoggingService && a()._registerLoggingService(w), n ? (this.testHelpers = {
566
- generateLauncherScript: W,
567
- generateThankYouElementScript: j,
568
- extractRoktExtensionConfig: V,
569
- hashEventMessage: B,
570
- parseSettingsString: T,
571
- generateMappedEventLookup: z,
572
- generateMappedEventAttributeLookup: J,
573
- sendAdBlockMeasurementSignals: q,
574
- createAutoRemovedIframe: M,
575
- djb2: re,
572
+ return a()._registerErrorReportingService && a()._registerErrorReportingService(S), a()._registerLoggingService && a()._registerLoggingService(A), n ? (this.testHelpers = {
573
+ generateLauncherScript: j,
574
+ generateThankYouElementScript: H,
575
+ extractRoktExtensionConfig: z,
576
+ hashEventMessage: q,
577
+ parseSettingsString: N,
578
+ generateMappedEventLookup: J,
579
+ generateMappedEventAttributeLookup: B,
580
+ sendAdBlockMeasurementSignals: $,
581
+ createAutoRemovedIframe: K,
582
+ djb2: se,
576
583
  setAllowedOriginHashes: (h) => {
577
584
  f._allowedOriginHashes = h;
578
585
  },
579
- ReportingTransport: F,
580
- ErrorReportingService: $,
581
- LoggingService: Q,
582
- RateLimiter: se,
583
- ErrorCodes: D,
584
- WSDKErrorSeverity: _
585
- }, this.attachLauncher(c, p), "Successfully initialized: " + d) : (R && (a().Rokt.flushOnShoppableAdsReadyMessageQueue?.(this), H(Ie, j(g), {
586
+ ReportingTransport: Y,
587
+ ErrorReportingService: Q,
588
+ LoggingService: X,
589
+ RateLimiter: oe,
590
+ ErrorCodes: F,
591
+ WSDKErrorSeverity: E
592
+ }, this.attachLauncher(c, g), "Successfully initialized: " + d) : (w && (a().Rokt.flushOnShoppableAdsReadyMessageQueue?.(this), V(Ae, H(p), {
586
593
  onLoad: () => {
587
594
  this._isThankYouElementLoaded = !0, this._thankYouElementOnLoadCallback && this._thankYouElementOnLoadCallback();
588
595
  },
589
596
  onError: (h) => {
590
597
  console.error("Error loading Rokt Thank You Element script:", h);
591
598
  }
592
- })), this.isLauncherReadyToAttach() ? this.attachLauncher(c, p, A) : (H(ye, W(g, P), {
599
+ })), this.isLauncherReadyToAttach() ? this.attachLauncher(c, g, v) : (V(Se, j(p, U), {
593
600
  onLoad: () => {
594
- this.isLauncherReadyToAttach() ? this.attachLauncher(c, p, A) : console.error("Rokt object is not available after script load.");
601
+ this.isLauncherReadyToAttach() ? this.attachLauncher(c, g, v) : console.error("Rokt object is not available after script load.");
595
602
  },
596
603
  onError: (h) => {
597
604
  console.error("Error loading Rokt launcher script:", h);
@@ -599,10 +606,10 @@ const f = class f {
599
606
  }), this.captureTiming(f.PERFORMANCE_MARKS.RoktScriptAppended)), "Successfully initialized: " + d);
600
607
  }
601
608
  process(e) {
602
- if (this.isTargetingDisabled() || (e.EventDataType === ke && this.capturePageView(e), e.EventDataType === Ae && (ie(this.loggingService), G())), !this.isKitReady())
609
+ if (this.isTargetingDisabled() || (e.EventDataType === Re && this.capturePageView(e), e.EventDataType === ve && (ne(this.loggingService), W())), !this.isKitReady())
603
610
  return "Kit not ready for forwarder: " + d;
604
- if (typeof a().Rokt?.setLocalSessionAttribute == "function" && (U(this.placementEventAttributeMappingLookup) || this.applyPlacementEventAttributeMapping(e), !U(this.placementEventMappingLookup))) {
605
- const t = B(e.EventDataType, e.EventCategory, e.EventName ?? "");
611
+ if (L(a().Rokt?.setLocalSessionAttribute) && (C(this.placementEventAttributeMappingLookup) || this.applyPlacementEventAttributeMapping(e), !C(this.placementEventMappingLookup))) {
612
+ const t = q(e.EventDataType, e.EventCategory, e.EventName ?? "");
606
613
  this.placementEventMappingLookup[String(t)] && a().Rokt.setLocalSessionAttribute?.(this.placementEventMappingLookup[String(t)], !0);
607
614
  }
608
615
  return "Successfully sent to forwarder: " + d;
@@ -615,7 +622,7 @@ const f = class f {
615
622
  window.Rokt.setExtensionData(e);
616
623
  }
617
624
  setUserAttribute(e, t) {
618
- return X(e) || (this.userAttributes[e] = t), "Successfully set user attribute for forwarder: " + d;
625
+ return Z(e) || (this.userAttributes[e] = t), "Successfully set user attribute for forwarder: " + d;
619
626
  }
620
627
  removeUserAttribute(e) {
621
628
  return delete this.userAttributes[e], "Successfully removed user attribute for forwarder: " + d;
@@ -691,7 +698,7 @@ const f = class f {
691
698
  const t = this._workspaceSearchInFlightPromise;
692
699
  return Promise.race([
693
700
  t,
694
- new Promise((n) => setTimeout(n, ve))
701
+ new Promise((n) => setTimeout(n, Le))
695
702
  ]).then(() => this._dispatchPlacements(e));
696
703
  }
697
704
  return this._dispatchPlacements(e);
@@ -700,17 +707,18 @@ const f = class f {
700
707
  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;
701
708
  let l;
702
709
  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);
703
- const g = this._onboardingExpProvider === "Optimizely" ? this.fetchOptimizely() : {}, P = this.returnUserIdentities(c), A = this.returnLocalSessionAttributes(), R = ge(Y(this.loggingService)), p = {
704
- ...P,
710
+ const p = this._onboardingExpProvider === "Optimizely" ? this.fetchOptimizely() : {}, U = this.returnUserIdentities(c), v = this.returnLocalSessionAttributes(), w = fe(G(this.loggingService)), g = this.readMpSessionId(), y = {
711
+ ...U,
705
712
  ...l,
706
- ...g,
707
- ...A,
708
- ...R.length ? { [Re]: JSON.stringify(R) } : {},
709
- ...this.userIdentifiedInWorkspace ? { [Se]: !0 } : {},
713
+ ...p,
714
+ ...v,
715
+ ...w.length ? { [we]: JSON.stringify(w) } : {},
716
+ ...this.userIdentifiedInWorkspace ? { [ke]: !0 } : {},
717
+ ...g ? { [be]: g } : {},
710
718
  mpid: u
711
- }, v = { ...e, attributes: p }, E = this.launcher.selectPlacements(v), w = () => this.logSelectPlacementsEvent(p);
712
- return Promise.resolve(E).then((h) => h?.context?.sessionId?.then((oe) => this.setRoktSessionId(oe))).catch(() => {
713
- }).finally(w), E;
719
+ }, S = { ...e, attributes: y }, A = this.launcher.selectPlacements(S), h = () => this.logSelectPlacementsEvent(y);
720
+ return Promise.resolve(A).then((ae) => ae?.context?.sessionId?.then((ce) => this.setRoktSessionId(ce))).catch(() => {
721
+ }).finally(h), A;
714
722
  }
715
723
  /**
716
724
  * Passes attributes to the Rokt Web SDK for client-side hashing.
@@ -737,19 +745,19 @@ f._allowedOriginHashes = [-553112570, 549508659], f.PERFORMANCE_MARKS = {
737
745
  RoktScriptAppended: "mp:RoktScriptAppended"
738
746
  }, f.EMAIL_SHA256_KEY = "emailsha256";
739
747
  let I = f;
740
- function Ke() {
741
- return L;
748
+ function Ye() {
749
+ return T;
742
750
  }
743
- function De(i) {
751
+ function xe(i) {
744
752
  if (!i) {
745
753
  window.console.log("You must pass a config object to register the kit " + d);
746
754
  return;
747
755
  }
748
- if (!y(i)) {
756
+ if (!_(i)) {
749
757
  window.console.log("'config' must be an object. You passed in a " + typeof i);
750
758
  return;
751
759
  }
752
- y(i.kits) ? i.kits[d] = {
760
+ _(i.kits) ? i.kits[d] = {
753
761
  constructor: I
754
762
  } : (i.kits = {}, i.kits[d] = {
755
763
  constructor: I
@@ -758,9 +766,9 @@ function De(i) {
758
766
  typeof window < "u" && window.mParticle && a().addForwarder && a().addForwarder({
759
767
  name: d,
760
768
  constructor: I,
761
- getId: Ke
769
+ getId: Ye
762
770
  });
763
771
  export {
764
- De as register
772
+ xe as register
765
773
  };
766
774
  //# sourceMappingURL=Rokt-Kit.esm.js.map
@@ -1,2 +1,2 @@
1
- var RoktKit=(function(P){"use strict";const ae=["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"],ce=new Set(ae);function G(i){return ce.has(i.toLowerCase())}function A(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 U(i){return i==null?!0:typeof i=="object"?Object.keys(i).length===0:!1}function C(i){try{const e=new URL(i);return e.search="",e.toString()}catch{return i}}function R(i){try{const e=window.localStorage.getItem(i);return e===null?null:JSON.parse(e)}catch{return null}}function x(i,e){try{return window.localStorage.setItem(i,JSON.stringify(e)),!0}catch{return!1}}function W(i){try{window.localStorage.removeItem(i)}catch{}}function j(i,e){const t=R(i);return E(t)?t[e]:void 0}function M(i,e,t){const n=R(i),r=E(n)?{...n}:{};return r[e]=t,x(i,r)}function le(i,e){const t=R(i);if(!E(t)||!(e in t))return;const n={...t};delete n[e],Object.keys(n).length===0?W(i):x(i,n)}function ue(i,e,t,n){const r=t.slice(),s=()=>r.length<=1?!1:(r.shift(),!0);let o=JSON.stringify(r).length>n;for(;o&&s();)o=JSON.stringify(r).length>n;let c=M(i,e,r);for(;!c&&s();)c=M(i,e,r);return c}const I="mp-rokt-kit",k="pageViews",H="mpPageViews",de=100*1024;function V(i){const e=R(H);if(e===null)return;if(!(j(I,k)!==void 0)&&Array.isArray(e)&&!M(I,k,e)){i?.log({message:"Rokt Kit: Failed to migrate legacy page-view storage; retaining legacy key for retry",code:"PAGE_VIEW_CAPTURE_FAILED"});return}W(H)}function z(i){V(i);const e=j(I,k);return Array.isArray(e)?e:[]}function he(i){return ue(I,k,i,de)}function J(){le(I,k)}function ge(i){return i.map((e,t)=>{const n=e.activeTimeOnSite,r=n!==void 0&&Number.isFinite(n),o=i[t+1]?.activeTimeOnSite,c=o!==void 0&&Number.isFinite(o),u=r&&c?o-n:void 0;return{pageUrl:e.pageUrl,sourceMessageId:e.sourceMessageId,timestamp:e.timestamp,...e.pageTitle!==void 0?{pageTitle:e.pageTitle}:{},...e.canonicalUrl!==void 0?{canonicalUrl:e.canonicalUrl}:{},...r?{activeTimeOnSite:n}:{},...u!==void 0&&u>=0?{activeTimeOnPage:u}:{}}})}function pe(){const e=document.querySelector('link[rel="canonical"]')?.href;if(e)return C(e)}const d="Rokt",v=181,fe="selectPlacements",me="apps.roktecommerce.com",Ee=.1,_e="ThankYouPageJourney",ye="rokt-launcher",Se="rokt-thank-you-element",Ie="userIdentifiedInWorkspace",ke=3,Ae=2,Re="page_events",ve=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"},we="apps.rokt-api.com",be="/v1/log",Le="/v1/errors",Te=10;function a(){return window.mParticle}function B(i,e){const n=[w(i),"/wsdk/integrations/launcher.js"].join("");return!e||e.length===0?n:n+"?extensions="+e.join(",")}function q(i){return[w(i),"/rokt-elements/rokt-element-thank-you.js"].join("")}function w(i){const e=typeof i<"u"?i:we;return e.includes("://")?e.replace(/\/+$/,""):["https://",e].join("")}function $(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 w(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 b(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?b(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(_e)):t.push(o)}return{roktExtensionsQueryParams:t,legacyRoktExtensions:n,loadThankYouElement:r}}async function Ne(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||!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 te(i,e,t){return a().generateHash([i,e,t].join(""))}function Oe(i){let n="mParticle_wsdkv_"+a().getVersion()+"_kitv_"+"1.32.0";return i&&(n+="_"+i),n}function ie(i){let e=5381;for(let t=0;t<i.length;t++)e=(e<<5)+e+i.charCodeAt(t),e=e&e;return e}function D(i){const e=document.createElement("iframe");e.style.display="none",e.setAttribute("sandbox","allow-scripts allow-same-origin"),e.src=i,e.onload=function(){e.onload=null,e.parentNode&&e.parentNode.removeChild(e)};const t=document.body||document.head;t&&t.appendChild(e)}function ne(i,e){const t=ie(window.location.origin);if(y._allowedOriginHashes.indexOf(t)===-1||Math.random()>=Ee)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?w(i):"https://apps.rokt.com";D(c+"/v1/wsdk-init/index.html?"+o),D("https://"+me+"/v1/wsdk-init/index.html?"+o+"&isControl=true")}function Pe(){return typeof window<"u"&&!!window.location?.search?.toLowerCase().includes("mp_enable_logging=true")}function Ue(){return typeof window<"u"?window.location?.href:void 0}function Ce(){return typeof window<"u"?window.navigator?.userAgent:void 0}class re{constructor(){this._logCount={}}incrementAndCheck(e){const n=(this._logCount[e]||0)+1;return this._logCount[e]=n,n>Te}}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 re,this._isEnabled=Pe()||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:Ue(),deviceInfo:Ce(),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 se{constructor(e,t,n,r,s){this._transport=new F(e,t,n,r,s),this._errorUrl=$(e?.errorUrl,e?.integrationDomain,Le)}report(e){if(!e)return;const t=e.severity||_.ERROR;this._transport.send(this._errorUrl,t,e.message,e.code,e.stackTrace)}}class oe{constructor(e,t,n,r,s,o){this._transport=new F(e,n,r,s,o),this._loggingUrl=$(e?.loggingUrl,e?.integrationDomain,be),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 Me(i){const e=C(window.location.href),t=i.EventAttributes?.title||document.title,n=pe(),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=v,this.moduleId=v,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=C(window.location.href);const n=z(this.loggingService),r=Me(e);n.push(r),he(n)||this.loggingService?.log({message:`Rokt Kit: Failed to persist page view for ${t}`,code:"PAGE_VIEW_CAPTURE_FAILED"})}catch(n){this.loggingService?.log({message:`Rokt Kit: Failed to capture page view for ${t}: ${n instanceof Error?n.message:String(n)}`,code:"PAGE_VIEW_CAPTURE_FAILED"})}}isLauncherReadyToAttach(){return!!window.Rokt&&typeof window.Rokt.createLauncher=="function"}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(fe,t,e)}setRoktSessionId(e){if(!(!e||typeof e!="string"))try{const t=a().getInstance();t&&typeof t.setIntegrationAttribute=="function"&&t.setIntegrationAttribute(v,{roktSessionId:e})}catch{}}attachLauncher(e,t,n=[]){const r=a()&&a().sessionManager&&typeof a().sessionManager.getSession=="function"?a().sessionManager.getSession():void 0,s={accountId:e,...t||{},...r?{mpSessionId:r}:{}};let o;this.isPartnerInLocalLauncherTestGroup()?o=Promise.resolve(window.Rokt.createLocalLauncher(s)):o=window.Rokt.createLauncher(s),o.then(async c=>{await Ne(n,c),this.initRoktLauncher(c)}).catch(c=>{console.error("Error creating Rokt launcher:",c)})}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,ne(this.domain,this.integrationName),a().Rokt.attachKit(this)}fetchOptimizely(){const e=a()._getActiveForwarders().filter(t=>t.name==="Optimizely");try{if(e.length>0&&window.optimizely){const t=window.optimizely.get("state");return!t||!t.getActiveExperimentIds?{}:t.getActiveExperimentIds().reduce((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=A(s),this._onboardingExpProvider=o.onboardingExpProvider;const u=b(o.placementEventMapping);this.placementEventMappingLookup=Z(u);const l=b(o.placementEventAttributeMapping);this.placementEventAttributeMappingLookup=ee(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:L,loadThankYouElement:T}=X(o.roktExtensions),f={...a().Rokt?.launcherOptions||{}};this.integrationName=Oe(f.integrationName),f.integrationName=this.integrationName,this.domain=g;const N={loggingUrl:o.loggingUrl,errorUrl:o.errorUrl,integrationDomain:g,isLoggingEnabled:a().config?.isLoggingEnabled===!0},S=new se(N,this.integrationName,window.__rokt_li_guid__,o.accountId),O=new oe(N,S,this.integrationName,window.__rokt_li_guid__,o.accountId);if(this.errorReportingService=S,this.loggingService=O,this.isTargetingDisabled())try{J()}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(O),n?(this.testHelpers={generateLauncherScript:B,generateThankYouElementScript:q,extractRoktExtensionConfig:X,hashEventMessage:te,parseSettingsString:b,generateMappedEventLookup:Z,generateMappedEventAttributeLookup:ee,sendAdBlockMeasurementSignals:ne,createAutoRemovedIframe:D,djb2:ie,setAllowedOriginHashes:h=>{p._allowedOriginHashes=h},ReportingTransport:F,ErrorReportingService:se,LoggingService:oe,RateLimiter:re,ErrorCodes:K,WSDKErrorSeverity:_},this.attachLauncher(c,f),"Successfully initialized: "+d):(T&&(a().Rokt.flushOnShoppableAdsReadyMessageQueue?.(this),Q(Se,q(g),{onLoad:()=>{this._isThankYouElementLoaded=!0,this._thankYouElementOnLoadCallback&&this._thankYouElementOnLoadCallback()},onError:h=>{console.error("Error loading Rokt Thank You Element script:",h)}})),this.isLauncherReadyToAttach()?this.attachLauncher(c,f,L):(Q(ye,B(g,Y),{onLoad:()=>{this.isLauncherReadyToAttach()?this.attachLauncher(c,f,L):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===ke&&this.capturePageView(e),e.EventDataType===Ae&&(V(this.loggingService),J())),!this.isKitReady())return"Kit not ready for forwarder: "+d;if(typeof a().Rokt?.setLocalSessionAttribute=="function"&&(U(this.placementEventAttributeMappingLookup)||this.applyPlacementEventAttributeMapping(e),!U(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 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=A(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,ve))]).then(()=>this._dispatchPlacements(e))}return this._dispatchPlacements(e)}_dispatchPlacements(e){const t=e&&e.attributes||{},r={...A(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=A(l);const g=this._onboardingExpProvider==="Optimizely"?this.fetchOptimizely():{},Y=this.returnUserIdentities(c),L=this.returnLocalSessionAttributes(),T=ge(z(this.loggingService)),f={...Y,...l,...g,...L,...T.length?{[Re]:JSON.stringify(T)}:{},...this.userIdentifiedInWorkspace?{[Ie]:!0}:{},mpid:u},N={...e,attributes:f},S=this.launcher.selectPlacements(N),O=()=>this.logSelectPlacementsEvent(f);return Promise.resolve(S).then(h=>h?.context?.sessionId?.then(Fe=>this.setRoktSessionId(Fe))).catch(()=>{}).finally(O),S}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 y=p;function Ke(){return v}function De(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:y}:(i.kits={},i.kits[d]={constructor:y}),window.console.log("Successfully registered "+d+" to your mParticle configuration")}return typeof window<"u"&&window.mParticle&&a().addForwarder&&a().addForwarder({name:d,constructor:y,getId:Ke}),P.register=De,Object.defineProperty(P,Symbol.toStringTag,{value:"Module"}),P})({});
1
+ var RoktKit=(function(U){"use strict";const ce=["active_time_on_site_ms","billingaddress1","billingaddress2","billingcity","billingstate","billingzipcode","cartitems","ccbin","confirmationref","conversiontype","country","couponcode","currency","language","paymentserviceprovider","paymentserviceproviderattribute","paymenttype","shippingaddress1","shippingcity","shippingcountry","shippingmethod","shippingstate","shippingzipcode","totalprice"],le=new Set(ce);function x(i){return le.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];x(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 w(i){return typeof i=="function"}function C(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}}function b(i){try{const e=window.localStorage.getItem(i);return e===null?null:JSON.parse(e)}catch{return null}}function W(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=b(i);return E(t)?t[e]:void 0}function K(i,e,t){const n=b(i),r=E(n)?{...n}:{};return r[e]=t,W(i,r)}function ue(i,e){const t=b(i);if(!E(t)||!(e in t))return;const n={...t};delete n[e],Object.keys(n).length===0?j(i):W(i,n)}function de(i,e,t,n){const r=t.slice(),s=()=>r.length<=1?!1:(r.shift(),!0);let o=JSON.stringify(r).length>n;for(;o&&s();)o=JSON.stringify(r).length>n;let c=K(i,e,r);for(;!c&&s();)c=K(i,e,r);return c}const I="mp-rokt-kit",S="pageViews",V="mpPageViews",he=100*1024;function z(i){const e=b(V);if(e===null)return;if(!(H(I,S)!==void 0)&&Array.isArray(e)&&!K(I,S,e)){i?.log({message:"Rokt Kit: Failed to migrate legacy page-view storage; retaining legacy key for retry",code:"PAGE_VIEW_CAPTURE_FAILED"});return}j(V)}function J(i){z(i);const e=H(I,S);return Array.isArray(e)?e:[]}function ge(i){return de(I,S,i,he)}function B(){ue(I,S)}function pe(i){return i.map((e,t)=>{const n=e.activeTimeOnSite,r=n!==void 0&&Number.isFinite(n),o=i[t+1]?.activeTimeOnSite,c=o!==void 0&&Number.isFinite(o),u=r&&c?o-n:void 0;return{pageUrl:e.pageUrl,sourceMessageId:e.sourceMessageId,timestamp:e.timestamp,...e.pageTitle!==void 0?{pageTitle:e.pageTitle}:{},...e.canonicalUrl!==void 0?{canonicalUrl:e.canonicalUrl}:{},...r?{activeTimeOnSite:n}:{},...u!==void 0&&u>=0?{activeTimeOnPage:u}:{}}})}function fe(){const e=document.querySelector('link[rel="canonical"]')?.href;if(e)return M(e)}const d="Rokt",L=181,me="selectPlacements",Ee="apps.roktecommerce.com",_e=.1,ye="ThankYouPageJourney",Ie="rokt-launcher",Se="rokt-thank-you-element",ke="userIdentifiedInWorkspace",Ae=3,Re=2,ve="page_events",we="mparticle_session_id",be=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"},Le="apps.rokt-api.com",Te="/v1/log",Ne="/v1/errors",Oe=10;function a(){return window.mParticle}function q(i,e){const n=[T(i),"/wsdk/integrations/launcher.js"].join("");return!e||e.length===0?n:n+"?extensions="+e.join(",")}function $(i){return[T(i),"/rokt-elements/rokt-element-thank-you.js"].join("")}function T(i){const e=typeof i<"u"?i:Le;return e.includes("://")?e.replace(/\/+$/,""):["https://",e].join("")}function Q(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 T(r)+t}function X(i,e,t){if(document.getElementById(i))return;const n=document.head||document.body,r=document.createElement("script");r.id=i,r.type="text/javascript",r.src=e,r.async=!0,r.crossOrigin="anonymous",r.fetchPriority="high",t?.onLoad&&(r.onload=t.onLoad),t?.onError&&(r.onerror=t.onError),n.appendChild(r)}function N(i){if(!i)return[];try{return JSON.parse(i.replace(/&quot;/g,'"'))}catch{console.error("Settings string contains invalid JSON")}return[]}function Z(i){const e=i?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(ye)):t.push(o)}return{roktExtensionsQueryParams:t,legacyRoktExtensions:n,loadThankYouElement:r}}async function Pe(i,e){const t=[];if(e)for(const n of i)t.push(e.use(n));return Promise.all(t)}function ee(i){if(!i)return{};const e={};for(let t=0;t<i.length;t++){const n=i[t];e[n.jsmap]=n.value}return e}function te(i){const e={};if(!Array.isArray(i))return e;for(let t=0;t<i.length;t++){const n=i[t];if(!n||!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 ie(i,e,t){return a().generateHash([i,e,t].join(""))}function Ue(i){let n="mParticle_wsdkv_"+a().getVersion()+"_kitv_"+"1.33.0";return i&&(n+="_"+i),n}function ne(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 re(i,e){const t=ne(window.location.origin);if(y._allowedOriginHashes.indexOf(t)===-1||Math.random()>=_e)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?T(i):"https://apps.rokt.com";F(c+"/v1/wsdk-init/index.html?"+o),F("https://"+Ee+"/v1/wsdk-init/index.html?"+o+"&isControl=true")}function Ce(){return typeof window<"u"&&!!window.location?.search?.toLowerCase().includes("mp_enable_logging=true")}function Me(){return typeof window<"u"?window.location?.href:void 0}function Ke(){return typeof window<"u"?window.navigator?.userAgent:void 0}class se{constructor(){this._logCount={}}incrementAndCheck(e){const n=(this._logCount[e]||0)+1;return this._logCount[e]=n,n>Oe}}class Y{constructor(e,t,n,r,s){this._reporter="mp-wsdk";const o=e.isLoggingEnabled;this._integrationName=t||"",this._launcherInstanceGuid=n,this._accountId=r||null,this._rateLimiter=s||new se,this._isEnabled=Ce()||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:Me(),deviceInfo:Ke(),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 oe{constructor(e,t,n,r,s){this._transport=new Y(e,t,n,r,s),this._errorUrl=Q(e?.errorUrl,e?.integrationDomain,Ne)}report(e){if(!e)return;const t=e.severity||_.ERROR;this._transport.send(this._errorUrl,t,e.message,e.code,e.stackTrace)}}class ae{constructor(e,t,n,r,s,o){this._transport=new Y(e,n,r,s,o),this._loggingUrl=Q(e?.loggingUrl,e?.integrationDomain,Te),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 De(i){const e=M(window.location.href),t=i.EventAttributes?.title||document.title,n=fe(),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=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||!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(C(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=J(this.loggingService),r=De(e);n.push(r),ge(n)||this.loggingService?.log({message:`Rokt Kit: Failed to persist page view for ${t}`,code:"PAGE_VIEW_CAPTURE_FAILED"})}catch(n){this.loggingService?.log({message:`Rokt Kit: Failed to capture page view for ${t}: ${n instanceof Error?n.message:String(n)}`,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[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(me,t,e)}setRoktSessionId(e){if(!(!e||typeof e!="string"))try{const t=a().getInstance();t&&w(t.setIntegrationAttribute)&&t.setIntegrationAttribute(L,{roktSessionId:e})}catch{}}readMpSessionId(){const e=a()?.sessionManager;if(!(!e||!w(e.getSessionId)))return e.getSessionId()||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 Pe(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,re(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=N(o.placementEventMapping);this.placementEventMappingLookup=ee(u);const l=N(o.placementEventAttributeMapping);this.placementEventAttributeMappingLookup=te(l),o.hashedEmailUserIdentityType&&(this._mappedEmailSha256Key=o.hashedEmailUserIdentityType.toLowerCase()),this._workspaceIdSyncApiKey=m(o.workspaceIdSyncApiKey)?o.workspaceIdSyncApiKey:void 0;const g=a().Rokt?.domain,{roktExtensionsQueryParams:G,legacyRoktExtensions:O,loadThankYouElement:P}=Z(o.roktExtensions),f={...a().Rokt?.launcherOptions||{}};this.integrationName=Ue(f.integrationName),f.integrationName=this.integrationName,this.domain=g;const k={loggingUrl:o.loggingUrl,errorUrl:o.errorUrl,integrationDomain:g,isLoggingEnabled:a().config?.isLoggingEnabled===!0},A=new oe(k,this.integrationName,window.__rokt_li_guid__,o.accountId),R=new ae(k,A,this.integrationName,window.__rokt_li_guid__,o.accountId);if(this.errorReportingService=A,this.loggingService=R,this.isTargetingDisabled())try{B()}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(A),a()._registerLoggingService&&a()._registerLoggingService(R),n?(this.testHelpers={generateLauncherScript:q,generateThankYouElementScript:$,extractRoktExtensionConfig:Z,hashEventMessage:ie,parseSettingsString:N,generateMappedEventLookup:ee,generateMappedEventAttributeLookup:te,sendAdBlockMeasurementSignals:re,createAutoRemovedIframe:F,djb2:ne,setAllowedOriginHashes:h=>{p._allowedOriginHashes=h},ReportingTransport:Y,ErrorReportingService:oe,LoggingService:ae,RateLimiter:se,ErrorCodes:D,WSDKErrorSeverity:_},this.attachLauncher(c,f),"Successfully initialized: "+d):(P&&(a().Rokt.flushOnShoppableAdsReadyMessageQueue?.(this),X(Se,$(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,O):(X(Ie,q(g,G),{onLoad:()=>{this.isLauncherReadyToAttach()?this.attachLauncher(c,f,O):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===Ae&&this.capturePageView(e),e.EventDataType===Re&&(z(this.loggingService),B())),!this.isKitReady())return"Kit not ready for forwarder: "+d;if(w(a().Rokt?.setLocalSessionAttribute)&&(C(this.placementEventAttributeMappingLookup)||this.applyPlacementEventAttributeMapping(e),!C(this.placementEventMappingLookup))){const t=ie(e.EventDataType,e.EventCategory,e.EventName??"");this.placementEventMappingLookup[String(t)]&&a().Rokt.setLocalSessionAttribute?.(this.placementEventMappingLookup[String(t)],!0)}return"Successfully sent to forwarder: "+d}setExtensionData(e){if(!this.isKitReady()){console.error("Rokt Kit: Not initialized");return}window.Rokt.setExtensionData(e)}setUserAttribute(e,t){return x(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,be))]).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():{},G=this.returnUserIdentities(c),O=this.returnLocalSessionAttributes(),P=pe(J(this.loggingService)),f=this.readMpSessionId(),k={...G,...l,...g,...O,...P.length?{[ve]:JSON.stringify(P)}:{},...this.userIdentifiedInWorkspace?{[ke]:!0}:{},...f?{[we]:f}:{},mpid:u},A={...e,attributes:k},R=this.launcher.selectPlacements(A),h=()=>this.logSelectPlacementsEvent(k);return Promise.resolve(R).then(Ge=>Ge?.context?.sessionId?.then(xe=>this.setRoktSessionId(xe))).catch(()=>{}).finally(h),R}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 y=p;function Fe(){return L}function Ye(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:y}:(i.kits={},i.kits[d]={constructor:y}),window.console.log("Successfully registered "+d+" to your mParticle configuration")}return typeof window<"u"&&window.mParticle&&a().addForwarder&&a().addForwarder({name:d,constructor:y,getId:Fe}),U.register=Ye,Object.defineProperty(U,Symbol.toStringTag,{value:"Module"}),U})({});
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.32.0",
3
+ "version": "1.33.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",