@mparticle/web-rokt-kit 3.2.3 → 3.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Rokt-Kit.common.js +1 -1
- package/dist/Rokt-Kit.esm.js +68 -68
- package/dist/Rokt-Kit.iife.js +1 -1
- package/package.json +1 -1
package/dist/Rokt-Kit.common.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const 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"],Oe=new Set(Le);function me(i){return Oe.has(i.toLowerCase())}function k(i){const e={},t=i||{},n=Object.keys(t);for(let r=0;r<n.length;r++){const s=n[r];me(s)||(e[s]=t[s])}return e}function m(i){return typeof i=="object"&&i!==null&&!Array.isArray(i)}function g(i){return typeof i=="string"}function U(i){return typeof i=="function"}function v(i){return i==null?!0:typeof i=="string"?i.length===0:typeof i=="object"?Object.keys(i).length===0:!1}function z(i){try{const e=new URL(i);return e.search="",e.toString()}catch{return i}}function Ee(i){let e=5381;for(let t=0;t<i.length;t++)e=(e<<5)+e+i.charCodeAt(t),e=e&e;return e}const h="mp-rokt-kit",ee="__rokt_ls_probe__";function V(){try{return window.localStorage.setItem(ee,"1"),window.localStorage.removeItem(ee),!0}catch{return!1}}const P=()=>window.localStorage;function $(i,e=P){try{const t=e().getItem(i);return t===null?null:JSON.parse(t)}catch{return null}}function _e(i,e,t=P){try{return t().setItem(i,JSON.stringify(e)),!0}catch{return!1}}function Ne(i,e=P){try{e().removeItem(i)}catch{}}function T(i,e,t=P){const n=$(i,t);return m(n)?n[e]:void 0}function x(i,e,t,n=P){const r=$(i,n),s=m(r)?{...r}:{};return s[e]=t,_e(i,s,n)}function Y(i,e,t=P){const n=$(i,t);if(!m(n)||!(e in n))return;const r={...n};delete r[e],Object.keys(r).length===0?Ne(i,t):_e(i,r,t)}const q="pageViews",D="utmParams",Ie=25,Ue=["utm_source","utm_medium","utm_campaign","utm_term","utm_content"];function Se(i){return i.slice(-Ie)}function te(){const i=T(h,q);return Array.isArray(i)?i:[]}function Ce(i){const e=Se(i);for(let t=0;t<e.length;t++){const n=e.slice(t);if(x(h,q,n))return n.length}return 0}function ie(){Y(h,q)}function Ke(i){const e=Se(i);return e.map((t,n)=>{const r=t.activeTimeOnSite,s=r!==void 0&&Number.isFinite(r),c=e[n+1]?.activeTimeOnSite,u=c!==void 0&&Number.isFinite(c),l=s&&u?c-r:void 0;return{pageUrl:t.pageUrl,sourceMessageId:t.sourceMessageId,timestamp:t.timestamp,...t.pageTitle!==void 0?{pageTitle:t.pageTitle}:{},...t.canonicalUrl!==void 0?{canonicalUrl:t.canonicalUrl}:{},...s?{activeTimeOnSite:r}:{},...l!==void 0&&l>=0?{activeTimeOnPage:l}:{}}})}function De(i){if(T(h,D)!==void 0)return;const e=new URLSearchParams(window.location.search),t={};for(const r of Ue){const s=e.get(r);s&&(t[r]=s)}if(Object.keys(t).length===0)return;const n=Object.keys(t).join(", ");if(!x(h,D,t)){const r=V()?"quota":"ls_unavailable";i?.log({message:`Rokt Kit: Failed to persist UTM params [reason: ${r}]`,code:"UTM_CAPTURE_FAILED"});return}i?.log({message:`Rokt Kit: Captured UTM params [${n}]`,code:"UTM_CAPTURE_SUCCESS"})}function Me(){const i=T(h,D);return m(i)?i:null}function ne(){Y(h,D)}function Fe(){const e=document.querySelector('link[rel="canonical"]')?.href;if(e)return z(e)}const J=[{accountId:"2919171670744024290",pathname:"/checkout",targetPageIdentifier:"prod.rokt.conf",attributeKeys:["email","amount","concessions_total","customertype","eventvenue","firstname","lastname","member_status","billingzipcode","currency"]}],xe=6e4;function Ye(i){return m(i)&&typeof i.expiresAt=="number"&&m(i.attributes)}function Ge(i,e){return`activePreselect:${i}:${e}`}function je(i){const e=T(h,i);return Ye(e)?e:null}function Ve(i,e){x(h,i,{expiresAt:Date.now()+xe,attributes:e})}const We=2*6e4;function M(){return window.sessionStorage}function He(i){return m(i)&&typeof i.expiresAt=="number"&&g(i.pathname)&&g(i.identifier)&&m(i.attributes)&&g(i.mpid)}function B(i){return`pendingPreselect:${i}`}function ze(i){const e=B(i),t=T(h,e,M);return He(t)?t.expiresAt<=Date.now()?(Y(h,e,M),null):t:null}function $e(i,e,t,n,r){return x(h,B(i),{expiresAt:Date.now()+We,pathname:e,identifier:t,attributes:n,mpid:r},M)}function w(i){Y(h,B(i),M)}function S(i,e){const t={fired:"PRESELECT_FIRED",missed:"PRESELECT_MISSED",queued:"PRESELECT_QUEUED",skipped:"PRESELECT_SKIPPED"};return{message:`Rokt Kit: preselect ${i} [reason=${e}]`,code:t[i]}}function qe(i,e){if(i)return J.find(t=>t.accountId===i&&t.pathname===e)}function Je(i,e){if(!(!i||!g(e)))return J.find(t=>t.accountId===i&&t.targetPageIdentifier===e)}function Be(i,e){return i?J.some(t=>t.accountId===i&&t.attributeKeys.includes(e)):!1}function Qe(){return{pending:[]}}function j(i,e){const t=i.pending.findIndex(n=>n.pathname===e.pathname);if(t>=0){i.pending[t]=e;return}i.pending.push(e)}function W(i){if(!i?.getUserIdentities)return!1;const e=i.getUserIdentities().userIdentities;return e?Object.keys(e).some(t=>{const n=e[t];return g(n)&&n.length>0}):!1}function ye(i){const e=i?.getMPID?.();return e==null?null:String(e)}function re(i,e,t){const n=i.filteredUser?.getAllUserAttributes?.()||{},r={},s=[];for(const o of t.attributeKeys){const c=i.getEventAttributeValue(e,o),u=v(c)?i.userAttributes[o]??n[o]:c;if(v(u)){s.push(o);continue}r[o]=u}return{collected:r,missingKeys:s}}function Xe(i,e){Promise.resolve(i.selectPlacements(e)).catch(t=>{const n=t instanceof Error?t.message:String(t);i.log({message:`Rokt Kit: Preselect selectPlacements call failed: ${n}`,code:"PRESELECT_DISPATCH_FAILED"})})}function Ae(i,e,t,n,r,s){const o=Ge(e,t),c=je(o),u=!!c&&JSON.stringify(c.attributes)===JSON.stringify(r);if(c&&c.expiresAt>Date.now()&&u){i.logPlacementDiagnostic(S("skipped","active_preselection"));return}Ve(o,r),i.logPlacementDiagnostic(S("fired",s)),Xe(i,{attributes:r,preselect:!0,identifier:n,omitUrl:!0})}function Ze(i,e){if(!e.accountId||!e.isKitReady())return;const t=ze(e.accountId);if(t){if(i.pending.some(n=>n.pathname===t.pathname)){w(e.accountId);return}if(!e.isPreselectionEnabled()){w(e.accountId);return}W(e.filteredUser)&&(w(e.accountId),ye(e.filteredUser)===t.mpid&&Ae(e,e.accountId,t.identifier,t.identifier,t.attributes,"recovered"))}}function Pe(i,e,t,n=window.location.pathname){const r=qe(e.accountId,n);if(!r)return;if(!e.isKitReady()){j(i,{event:t,pathname:n}),e.logPlacementDiagnostic(S("queued","not_ready"));const c=ye(e.filteredUser);if(e.accountId&&c&&W(e.filteredUser)){const{collected:u,missingKeys:l}=re(e,t,r);if(l.length===0){const f=k(u);$e(e.accountId,n,r.targetPageIdentifier,f,c)||e.logPlacementDiagnostic(S("queued","persist_failed"))}}return}if(!e.isPreselectionEnabled())return;if(!W(e.filteredUser)){e.logPlacementDiagnostic(S("missed","no_valid_identity")),j(i,{event:t,pathname:n});return}const{collected:s,missingKeys:o}=re(e,t,r);if(o.length>0){for(const c of o)e.logPlacementDiagnostic(S("missed",`missing_attribute:${c}`));j(i,{event:t,pathname:n});return}Ae(e,e.accountId||"",n,r.targetPageIdentifier,s,"fired")}function et(i,e,t=window.location.pathname){if(Ze(i,e),i.pending.length===0)return;const n=i.pending;i.pending=[],n.forEach(({event:r,pathname:s})=>{s===t&&Pe(i,e,r,s)})}function tt(){return{context:null,lifecycle:"idle",recreateInFlight:null}}function it(i,e){i.context={accountId:e.accountId,launcherOptions:{...e.launcherOptions},legacyRoktExtensions:[...e.legacyRoktExtensions]}}function nt(i){i.lifecycle="attached"}function rt(i){i.lifecycle!=="idle"&&(i.lifecycle="terminated")}function st(i){i.lifecycle="terminated"}function ot(i){i.context=null,i.lifecycle="idle",i.recreateInFlight=null}function ct(i,e,t){if(i.recreateInFlight)return i.recreateInFlight;if(i.lifecycle!=="terminated"||!i.context||!e)return;i.lifecycle="recreating";const n=i.context;return i.recreateInFlight=t(n).finally(()=>{i.recreateInFlight=null}),i.recreateInFlight}const d="Rokt",C=181,at="selectPlacements",lt="apps.roktecommerce.com",ut=.1,dt="ThankYouPageJourney",ht="rokt-launcher",gt="rokt-thank-you-element",ft="userIdentifiedInWorkspace",pt=3,mt=2,Et="page_events",_t="page_view_attributes",It="mparticle_session_id",St="mparticle_device_id",se=500,Q={UNKNOWN_ERROR:"UNKNOWN_ERROR",UNHANDLED_EXCEPTION:"UNHANDLED_EXCEPTION",IDENTITY_REQUEST:"IDENTITY_REQUEST",LOG_DELIVERY_FAILURE:"LOG_DELIVERY_FAILURE"},y={ERROR:"ERROR",INFO:"INFO",WARNING:"WARNING"},yt="apps.rokt-api.com",At="/v1/log",Pt="/v1/errors",bt=10;function a(){return window.mParticle}function oe(i,e){const n=[G(i),"/wsdk/integrations/launcher.js"].join("");return!e||e.length===0?n:n+"?extensions="+e.join(",")}function ce(i){return[G(i),"/rokt-elements/rokt-element-thank-you.js"].join("")}function G(i){const e=i!==void 0?i:yt;return e.includes("://")?e.replace(/\/+$/,""):["https://",e].join("")}function be(i,e,t){if(i)return i.startsWith("http://")||i.startsWith("https://")?i:"https://"+i;const r=e?.includes("://")&&!/^https?:\/\//i.test(e)?void 0:e;return G(r)+t}function ae(i,e,t){if(document.getElementById(i))return;const n=document.head||document.body,r=document.createElement("script");r.id=i,r.type="text/javascript",r.src=e,r.async=!0,r.crossOrigin="anonymous",r.fetchPriority="high",t?.onLoad&&(r.onload=t.onLoad),t?.onError&&(r.onerror=t.onError),n.appendChild(r)}function K(i){if(!i)return[];try{return JSON.parse(i.replace(/"/g,'"'))}catch{console.error("Settings string contains invalid JSON")}return[]}function le(i){const e=i?K(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(dt)):t.push(o)}return{roktExtensionsQueryParams:t,legacyRoktExtensions:n,loadThankYouElement:r}}async function Rt(i,e){const t=[];if(e)for(const n of i)t.push(e.use(n));return Promise.all(t)}function ue(i){if(!i)return{};const e={};for(let t=0;t<i.length;t++){const n=i[t];e[n.jsmap]=n.value}return e}function de(i){const e={};if(!Array.isArray(i))return e;for(let t=0;t<i.length;t++){const n=i[t];if(!n||!g(n.value)||!g(n.map))continue;const r=n.value,s=n.map;e[r]||(e[r]=[]),e[r].push({eventAttributeKey:s,conditions:Array.isArray(n.conditions)?n.conditions:[]})}return e}function he(i,e,t){return a().generateHash([i,e,t].join(""))}function kt(i){let n="mParticle_wsdkv_"+a().getVersion()+"_kitv_"+"3.2.3";return i&&(n+="_"+i),n}function H(i){const e=document.createElement("iframe");e.style.display="none",e.setAttribute("sandbox","allow-scripts allow-same-origin"),e.src=i,e.onload=function(){e.onload=null,e.parentNode&&e.parentNode.removeChild(e)};const t=document.body||document.head;t&&t.appendChild(e)}function ge(i,e){const t=Ee(window.location.origin);if(A._allowedOriginHashes.indexOf(t)===-1||Math.random()>=ut)return;const r=window.__rokt_li_guid__;if(!r||i&&i.includes("://")&&!/^https:\/\//i.test(i))return;const s=window.location.href.split("?")[0].split("#")[0],o="version="+encodeURIComponent(e??"")+"&launcherInstanceGuid="+encodeURIComponent(r)+"&pageUrl="+encodeURIComponent(s),c=i?G(i):"https://apps.rokt.com";H(c+"/v1/wsdk-init/index.html?"+o),H("https://"+lt+"/v1/wsdk-init/index.html?"+o+"&isControl=true")}function vt(){return typeof window<"u"&&!!window.location?.search?.toLowerCase().includes("mp_enable_logging=true")}function wt(){return typeof window<"u"?window.location?.href:void 0}function Tt(){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>bt}}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=vt()||o}send(e,t,n,r,s,o){if(!(!this._isEnabled||this._rateLimiter.incrementAndCheck(t)))try{const c={additionalInformation:{message:n,version:this._integrationName},severity:t,code:r||Q.UNKNOWN_ERROR,url:wt(),deviceInfo:Tt(),stackTrace:s,reporter:this._reporter,integration:this._integrationName},u={Accept:"text/plain;charset=UTF-8","Content-Type":"application/json","rokt-launcher-version":this._integrationName,"rokt-wsdk-version":"joint"};this._launcherInstanceGuid&&(u["rokt-launcher-instance-guid"]=this._launcherInstanceGuid),this._accountId&&(u["rokt-account-id"]=this._accountId),fetch(e,{method:"POST",headers:u,body:JSON.stringify(c)}).then(l=>{if(!l.ok){const f=new Error("HTTP "+l.status+" from log endpoint");throw f.statusCode=l.status,f}}).catch(l=>{console.error("ReportingTransport: Failed to send log",l),o&&o(l)})}catch(c){console.error("ReportingTransport: Failed to send log",c),o&&o(c)}}}class fe{constructor(e,t,n,r,s){this._transport=new F(e,t,n,r,s),this._errorUrl=be(e?.errorUrl,e?.integrationDomain,Pt)}report(e){if(!e)return;const t=e.severity||y.ERROR;this._transport.send(this._errorUrl,t,e.message,e.code,e.stackTrace)}}class pe{constructor(e,t,n,r,s,o){this._transport=new F(e,n,r,s,o),this._placementDiagnosticTransport=new F(e,n,r,s),this._loggingUrl=be(e?.loggingUrl,e?.integrationDomain,At),this._errorReportingService=t}log(e){e&&this._send(this._transport,e)}logPlacementDiagnostic(e){e&&this._send(this._placementDiagnosticTransport,e)}_send(e,t){e.send(this._loggingUrl,y.INFO,t.message,t.code,void 0,n=>{if(this._errorReportingService){const r=typeof n.statusCode=="number";this._errorReportingService.report({message:"LoggingService: Failed to send log: "+n.message,code:Q.LOG_DELIVERY_FAILURE,severity:r?y.ERROR:y.WARNING})}})}}function Lt(i){const e=z(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 _=class _{constructor(){this.name=d,this.id=C,this.moduleId=C,this.isInitialized=!1,this.launcher=null,this.filters={},this.userAttributes={},this.userIdentifiedInWorkspace=!1,this.testHelpers=null,this.placementEventMappingLookup={},this.placementEventAttributeMappingLookup={},this.integrationName=null,this.errorReportingService=null,this.loggingService=null,this._thankYouElementOnLoadCallback=null,this._isThankYouElementLoaded=!1,this._workspaceSearchInFlightPromise=null,this._launcherAttachState=tt(),this.accountId=null,this._preselectState=Qe()}getEventAttributeValue(e,t){const n=e&&e.EventAttributes;return!n||n[t]===void 0?null:n[t]}doesEventAttributeConditionMatch(e,t){if(!e||!g(e.operator))return!1;const n=e.operator.toLowerCase(),r=e.attributeValue;return n==="exists"?t!==null:t==null?!1:n==="equals"?String(t)===String(r):n==="contains"?String(t).indexOf(String(r))!==-1:!1}doesEventMatchRule(e,t){if(!t||!g(t.eventAttributeKey))return!1;const n=t.conditions;if(!Array.isArray(n))return!1;const r=this.getEventAttributeValue(e,t.eventAttributeKey);if(n.length===0)return r!==null;for(let s=0;s<n.length;s++)if(!this.doesEventAttributeConditionMatch(n[s],r))return!1;return!0}applyPlacementEventAttributeMapping(e){const t=Object.keys(this.placementEventAttributeMappingLookup);for(let n=0;n<t.length;n++){const r=t[n],s=this.placementEventAttributeMappingLookup[r];if(v(s))continue;let o=!0;for(let c=0;c<s.length;c++)if(!this.doesEventMatchRule(e,s[c])){o=!1;break}o&&a().Rokt.setLocalSessionAttribute?.(r,!0)}}capturePageView(e){let t;try{t=z(window.location.href);const n=te(),r=Lt(e);n.push(r);const s=Math.min(n.length,Ie),o=Ce(n);if(o===0){const c=V()?"quota":"ls_unavailable";this.loggingService?.log({message:`Rokt Kit: Failed to persist page view for ${t} [reason: ${c}]`,code:"PAGE_VIEW_CAPTURE_FAILED"})}else o<s&&this.loggingService?.log({message:`Rokt Kit: Page view storage reduced from ${s} to ${o} record(s) under quota pressure [reason: quota_eviction]`,code:"PAGE_VIEW_QUOTA_EVICTION"})}catch(n){const r=V()?"exception":"ls_unavailable",s=n instanceof Error?n.message:String(n);this.loggingService?.log({message:`Rokt Kit: Failed to capture page view for ${t}: ${s} [reason: ${r}]`,code:"PAGE_VIEW_CAPTURE_FAILED"})}}isPreselectionEnabled(){return this.launcher?.enablePreselection===!0}buildCacheMatchKeys(e){if(!this.isPreselectionEnabled())return;const t=Je(this.accountId,e);if(t)return t.attributeKeys}buildPreselectHost(){return{accountId:this.accountId,filteredUser:this.filters.filteredUser,userAttributes:this.userAttributes,isKitReady:()=>this.isKitReady(),isPreselectionEnabled:()=>this.isPreselectionEnabled(),getEventAttributeValue:(e,t)=>this.getEventAttributeValue(e,t),logPlacementDiagnostic:e=>this.loggingService?.logPlacementDiagnostic(e),log:e=>this.loggingService?.log(e),selectPlacements:e=>this.selectPlacements(e)}}flushPendingPreselectDispatches(){et(this._preselectState,this.buildPreselectHost())}isLauncherReadyToAttach(){return!!window.Rokt&&U(window.Rokt.createLauncher)}returnUserIdentities(e){if(!e||!e.getUserIdentities)return{};const t=e.getUserIdentities().userIdentities;return this.replaceOtherIdentityWithEmailsha256(t)}returnLocalSessionAttributes(){return!a().Rokt||typeof a().Rokt.getLocalSessionAttributes!="function"?{}:a().Rokt.getLocalSessionAttributes()}replaceOtherIdentityWithEmailsha256(e){const t={...e||{}},n=this._mappedEmailSha256Key;return n&&e[n]&&(t[_.EMAIL_SHA256_KEY]=e[n]),n&&delete t[n],t}logSelectPlacementsEvent(e){if(!window.mParticle||typeof a().logEvent!="function"||!m(e))return;const t=a().EventType.Other;a().logEvent(at,t,e)}setRoktSessionId(e){if(!(!e||typeof e!="string"))try{const t=a().getInstance();t&&U(t.setIntegrationAttribute)&&t.setIntegrationAttribute(C,{roktSessionId:e})}catch{}}readMpSessionId(){const e=a()?.sessionManager,t=e?.getSessionId??e?.getSession;if(U(t))return t.call(e)||void 0}readMpDeviceId(){return a()?.getDeviceId?.()||void 0}attachLauncher(e,t,n=[]){it(this._launcherAttachState,{accountId:e,launcherOptions:t||{},legacyRoktExtensions:n});const r={accountId:e,...t||{}};let s;return this.isPartnerInLocalLauncherTestGroup()?s=Promise.resolve(window.Rokt.createLocalLauncher(r)):s=window.Rokt.createLauncher(r),s.then(async o=>{await Rt([...n],o),this.initRoktLauncher(o)}).catch(o=>{st(this._launcherAttachState),console.error("Error creating Rokt launcher:",o)})}recreateLauncherIfTerminated(){return ct(this._launcherAttachState,this.isLauncherReadyToAttach(),e=>this.attachLauncher(e.accountId,e.launcherOptions,e.legacyRoktExtensions))}initRoktLauncher(e){window.Rokt&&(window.Rokt.currentLauncher=e),this.launcher=e,nt(this._launcherAttachState);const t=a().Rokt?.filters;t?(this.filters=t,t.filteredUser?this._workspaceSearchInFlightPromise=this.search(t.filteredUser):console.warn("Rokt Kit: No filtered user has been set.")):console.warn("Rokt Kit: No filters have been set."),this.isInitialized=!0,ge(this.domain,this.integrationName),a().Rokt.attachKit(this),this.flushPendingPreselectDispatches()}fetchOptimizely(){const e=a()._getActiveForwarders().filter(t=>t.name==="Optimizely");try{if(e.length>0&&window.optimizely){const t=window.optimizely.get("state");return!t||!t.getActiveExperimentIds?{}:t.getActiveExperimentIds().reduce((s,o)=>(s["rokt.custom.optimizely.experiment."+o+".variationId"]=t.getVariationMap()[o].id,s),{})}}catch(t){console.error("Error fetching Optimizely attributes:",t)}return{}}isKitReady(){return!!(this.isInitialized&&this.launcher)}isTargetingDisabled(){return a().Rokt?.launcherOptions?.noTargeting===!0}isPartnerInLocalLauncherTestGroup(){return!!(a().config&&a().config.isLocalLauncherEnabled&&this.isAssignedToSampleGroup())}isAssignedToSampleGroup(){return Math.random()>.5}captureTiming(e){window&&a()&&a().captureTiming&&e&&a().captureTiming(e)}init(e,t,n,r,s){const o=e,c=o.accountId;this.accountId=c||null,this.userAttributes=k(s),this._onboardingExpProvider=o.onboardingExpProvider;const u=K(o.placementEventMapping);this.placementEventMappingLookup=ue(u);const l=K(o.placementEventAttributeMapping);this.placementEventAttributeMappingLookup=de(l),o.hashedEmailUserIdentityType&&(this._mappedEmailSha256Key=o.hashedEmailUserIdentityType.toLowerCase()),this._workspaceIdSyncApiKey=g(o.workspaceIdSyncApiKey)?o.workspaceIdSyncApiKey:void 0;const f=a().Rokt?.domain,{roktExtensionsQueryParams:L,legacyRoktExtensions:O,loadThankYouElement:N}=le(o.roktExtensions),E={...a().Rokt?.launcherOptions||{}};this.integrationName=kt(E.integrationName),E.integrationName=this.integrationName,this.domain=f;const b={loggingUrl:o.loggingUrl,errorUrl:o.errorUrl,integrationDomain:f,isLoggingEnabled:a().config?.isLoggingEnabled===!0},I=new fe(b,this.integrationName,window.__rokt_li_guid__,o.accountId),R=new pe(b,I,this.integrationName,window.__rokt_li_guid__,o.accountId);if(this.errorReportingService=I,this.loggingService=R,this.isTargetingDisabled())try{ie(),ne()}catch(p){this.errorReportingService?.report({message:"Rokt Kit: Failed to clear page views when targeting is disabled",code:"PAGE_VIEW_CAPTURE_FAILED",severity:y.INFO,stackTrace:p instanceof Error?p.stack:void 0})}return a()._registerErrorReportingService&&a()._registerErrorReportingService(I),a()._registerLoggingService&&a()._registerLoggingService(R),n?(this.testHelpers={generateLauncherScript:oe,generateThankYouElementScript:ce,extractRoktExtensionConfig:le,hashEventMessage:he,parseSettingsString:K,generateMappedEventLookup:ue,generateMappedEventAttributeLookup:de,sendAdBlockMeasurementSignals:ge,createAutoRemovedIframe:H,djb2:Ee,setAllowedOriginHashes:p=>{_._allowedOriginHashes=p},ReportingTransport:F,ErrorReportingService:fe,LoggingService:pe,RateLimiter:Re,ErrorCodes:Q,WSDKErrorSeverity:y,resetLauncherAttachState:()=>ot(this._launcherAttachState)},this.attachLauncher(c,E),"Successfully initialized: "+d):(N&&(a().Rokt.flushOnShoppableAdsReadyMessageQueue?.(this),ae(gt,ce(f),{onLoad:()=>{this._isThankYouElementLoaded=!0,this._thankYouElementOnLoadCallback&&this._thankYouElementOnLoadCallback()},onError:p=>{console.error("Error loading Rokt Thank You Element script:",p)}})),this.isLauncherReadyToAttach()?this.attachLauncher(c,E,O):(ae(ht,oe(f,L),{onLoad:()=>{this.isLauncherReadyToAttach()?this.attachLauncher(c,E,O):console.error("Rokt object is not available after script load.")},onError:p=>{console.error("Error loading Rokt launcher script:",p)}}),this.captureTiming(_.PERFORMANCE_MARKS.RoktScriptAppended)),"Successfully initialized: "+d)}process(e){if(this.isTargetingDisabled()||(e.EventDataType===pt&&(De(this.loggingService),this.capturePageView(e),Pe(this._preselectState,this.buildPreselectHost(),e)),e.EventDataType===mt&&(ie(),ne(),this.accountId&&w(this.accountId))),!this.isKitReady())return"Kit not ready for forwarder: "+d;if(U(a().Rokt?.setLocalSessionAttribute)&&(v(this.placementEventAttributeMappingLookup)||this.applyPlacementEventAttributeMapping(e),!v(this.placementEventMappingLookup))){const t=he(e.EventDataType,e.EventCategory,e.EventName??"");this.placementEventMappingLookup[String(t)]&&a().Rokt.setLocalSessionAttribute?.(this.placementEventMappingLookup[String(t)],!0)}return"Successfully sent to forwarder: "+d}setExtensionData(e){if(!this.isKitReady()){console.error("Rokt Kit: Not initialized");return}window.Rokt.setExtensionData(e)}setUserAttribute(e,t){return me(e)||(this.userAttributes[e]=t),Be(this.accountId,e)&&this.flushPendingPreselectDispatches(),"Successfully set user attribute for forwarder: "+d}removeUserAttribute(e){return delete this.userAttributes[e],"Successfully removed user attribute for forwarder: "+d}handleIdentityComplete(e,t){return this.userAttributes=k(e.getAllUserAttributes()),"Successfully called "+t+" for forwarder: "+d}onUserIdentified(e){const t=e;this.filters.filteredUser=t,this._workspaceSearchInFlightPromise=this.search(t);const n=this.handleIdentityComplete(e,"onUserIdentified");return this.flushPendingPreselectDispatches(),n}search(e){const t=this._workspaceIdSyncApiKey;if(!t)return this.userIdentifiedInWorkspace=!1,this._workspaceLastSearchedIdentitiesKey=void 0,Promise.resolve();const n=a().Identity?.search;if(typeof n!="function")return this.userIdentifiedInWorkspace=!1,this._workspaceLastSearchedIdentitiesKey=void 0,Promise.resolve();const r=e.getUserIdentities?e.getUserIdentities().userIdentities:null,s={};if(r)for(const u of Object.keys(r)){const l=r[u];g(l)&&l.length>0&&(s[u]=l)}const o=Object.keys(s);if(o.length===0)return this.userIdentifiedInWorkspace=!1,this._workspaceLastSearchedIdentitiesKey=void 0,Promise.resolve();const c=o.sort().map(u=>`${u}=${s[u]}`).join("&");return c===this._workspaceLastSearchedIdentitiesKey?this._workspaceSearchInFlightPromise||Promise.resolve():(this.userIdentifiedInWorkspace=!1,this._workspaceLastSearchedIdentitiesKey=c,new Promise(u=>{try{n(t,s,l=>{l?.httpCode===200&&(this.userIdentifiedInWorkspace=!0),u()})}catch(l){console.error("Rokt Kit: Workspace IDSync search failed",l),this._workspaceLastSearchedIdentitiesKey=void 0,u()}}))}onLoginComplete(e,t){return this.handleIdentityComplete(e,"onLoginComplete")}onLogoutComplete(e,t){return this.userIdentifiedInWorkspace=!1,this._workspaceSearchInFlightPromise=null,this._workspaceLastSearchedIdentitiesKey=void 0,this.accountId&&w(this.accountId),this.handleIdentityComplete(e,"onLogoutComplete")}onModifyComplete(e,t){return this.handleIdentityComplete(e,"onModifyComplete")}selectPlacements(e){const t=this.recreateLauncherIfTerminated();if(t){const n=this._workspaceSearchInFlightPromise,r=n?Promise.race([n,new Promise(s=>setTimeout(s,se))]):Promise.resolve();return Promise.all([t,r]).then(()=>this._dispatchPlacements(e))}if(this._workspaceSearchInFlightPromise){const n=this._workspaceSearchInFlightPromise;return Promise.race([n,new Promise(r=>setTimeout(r,se))]).then(()=>this._dispatchPlacements(e))}return this._dispatchPlacements(e)}_dispatchPlacements(e){const t=e&&e.attributes||{},r={...k(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=k(l);const f=this._onboardingExpProvider==="Optimizely"?this.fetchOptimizely():{},L=this.returnUserIdentities(c),O=this.returnLocalSessionAttributes(),N=Ke(te()),E=Me(),b=this.readMpSessionId(),I=this.readMpDeviceId(),R={...L,...l,...f,...O,...N.length?{[Et]:JSON.stringify(N)}:{},...E?{[_t]:E}:{},...this.userIdentifiedInWorkspace?{[ft]:!0}:{},...b?{[It]:b}:{},...I?{[St]:I}:{},mpid:u},p=this.buildCacheMatchKeys(typeof e.identifier=="string"?e.identifier:void 0),ke={...e,attributes:R,...p!==void 0?{cacheMatchKeys:p}:{}},X=this.launcher.selectPlacements(ke),Z=e.preselect===!0,ve=()=>{Z||this.logSelectPlacementsEvent(R)};return Promise.resolve(X).then(we=>{if(!Z)return we?.context?.sessionId?.then(Te=>this.setRoktSessionId(Te))}).catch(()=>{}).finally(ve),X}hashAttributes(e){return this.isKitReady()?this.launcher.hashAttributes(e):(console.error("Rokt Kit: Not initialized"),null)}use(e){return this.isKitReady()?!e||!g(e)?Promise.reject(new Error("Rokt Kit: Invalid extension name")):this.launcher.use(e):(console.error("Rokt Kit: Not initialized"),Promise.reject(new Error("Rokt Kit: Not initialized")))}terminate(){return this.isKitReady()?(rt(this._launcherAttachState),this.launcher.terminate()):(console.error("Rokt Kit: Not initialized"),Promise.resolve())}onShoppableAdsReady(e){this._isThankYouElementLoaded?e():this._thankYouElementOnLoadCallback=e}};_._allowedOriginHashes=[-553112570,549508659],_.PERFORMANCE_MARKS={RoktScriptAppended:"mp:RoktScriptAppended"},_.EMAIL_SHA256_KEY="emailsha256";let A=_;function Ot(){return C}function Nt(i){if(!i){window.console.log("You must pass a config object to register the kit "+d);return}if(!m(i)){window.console.log("'config' must be an object. You passed in a "+typeof i);return}m(i.kits)?i.kits[d]={constructor:A}:(i.kits={},i.kits[d]={constructor:A}),window.console.log("Successfully registered "+d+" to your mParticle configuration")}typeof window<"u"&&window.mParticle&&a().addForwarder&&a().addForwarder({name:d,constructor:A,getId:Ot});exports.register=Nt;
|
|
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"],Oe=new Set(Le);function me(i){return Oe.has(i.toLowerCase())}function w(i){const e={},t=i||{},n=Object.keys(t);for(let r=0;r<n.length;r++){const s=n[r];me(s)||(e[s]=t[s])}return e}function m(i){return typeof i=="object"&&i!==null&&!Array.isArray(i)}function g(i){return typeof i=="string"}function U(i){return typeof i=="function"}function T(i){return i==null?!0:typeof i=="string"?i.length===0:typeof i=="object"?Object.keys(i).length===0:!1}function z(i){try{const e=new URL(i);return e.search="",e.toString()}catch{return i}}function Ee(i){let e=5381;for(let t=0;t<i.length;t++)e=(e<<5)+e+i.charCodeAt(t),e=e&e;return e}const h="mp-rokt-kit",ee="__rokt_ls_probe__";function V(){try{return window.localStorage.setItem(ee,"1"),window.localStorage.removeItem(ee),!0}catch{return!1}}const P=()=>window.localStorage;function $(i,e=P){try{const t=e().getItem(i);return t===null?null:JSON.parse(t)}catch{return null}}function _e(i,e,t=P){try{return t().setItem(i,JSON.stringify(e)),!0}catch{return!1}}function Ne(i,e=P){try{e().removeItem(i)}catch{}}function O(i,e,t=P){const n=$(i,t);return m(n)?n[e]:void 0}function x(i,e,t,n=P){const r=$(i,n),s=m(r)?{...r}:{};return s[e]=t,_e(i,s,n)}function Y(i,e,t=P){const n=$(i,t);if(!m(n)||!(e in n))return;const r={...n};delete r[e],Object.keys(r).length===0?Ne(i,t):_e(i,r,t)}const q="pageViews",D="utmParams",Ie=25,Ue=["utm_source","utm_medium","utm_campaign","utm_term","utm_content"];function ye(i){return i.slice(-Ie)}function te(){const i=O(h,q);return Array.isArray(i)?i:[]}function Ce(i){const e=ye(i);for(let t=0;t<e.length;t++){const n=e.slice(t);if(x(h,q,n))return n.length}return 0}function ie(){Y(h,q)}function Ke(i){const e=ye(i);return e.map((t,n)=>{const r=t.activeTimeOnSite,s=r!==void 0&&Number.isFinite(r),c=e[n+1]?.activeTimeOnSite,u=c!==void 0&&Number.isFinite(c),l=s&&u?c-r:void 0;return{pageUrl:t.pageUrl,sourceMessageId:t.sourceMessageId,timestamp:t.timestamp,...t.pageTitle!==void 0?{pageTitle:t.pageTitle}:{},...t.canonicalUrl!==void 0?{canonicalUrl:t.canonicalUrl}:{},...s?{activeTimeOnSite:r}:{},...l!==void 0&&l>=0?{activeTimeOnPage:l}:{}}})}function De(i){if(O(h,D)!==void 0)return;const e=new URLSearchParams(window.location.search),t={};for(const r of Ue){const s=e.get(r);s&&(t[r]=s)}if(Object.keys(t).length===0)return;const n=Object.keys(t).join(", ");if(!x(h,D,t)){const r=V()?"quota":"ls_unavailable";i?.log({message:`Rokt Kit: Failed to persist UTM params [reason: ${r}]`,code:"UTM_CAPTURE_FAILED"});return}i?.log({message:`Rokt Kit: Captured UTM params [${n}]`,code:"UTM_CAPTURE_SUCCESS"})}function Me(){const i=O(h,D);return m(i)?i:null}function ne(){Y(h,D)}function Fe(){const e=document.querySelector('link[rel="canonical"]')?.href;if(e)return z(e)}const J=[{accountId:"2919171670744024290",pathname:"/checkout",targetPageIdentifier:"prod.rokt.conf",attributeKeys:["email","amount","concessions_total","customertype","eventvenue","firstname","lastname","member_status","billingzipcode","currency"]}],xe=6e4;function Ye(i){return m(i)&&typeof i.expiresAt=="number"&&m(i.attributes)}function Ge(i,e){return`activePreselect:${i}:${e}`}function je(i){const e=O(h,i);return Ye(e)?e:null}function Ve(i,e){x(h,i,{expiresAt:Date.now()+xe,attributes:e})}const We=2*6e4;function M(){return window.sessionStorage}function He(i){return m(i)&&typeof i.expiresAt=="number"&&g(i.pathname)&&g(i.identifier)&&m(i.attributes)&&g(i.mpid)}function B(i){return`pendingPreselect:${i}`}function ze(i){const e=B(i),t=O(h,e,M);return He(t)?t.expiresAt<=Date.now()?(Y(h,e,M),null):t:null}function $e(i,e,t,n,r){return x(h,B(i),{expiresAt:Date.now()+We,pathname:e,identifier:t,attributes:n,mpid:r},M)}function L(i){Y(h,B(i),M)}function y(i,e){const t={fired:"PRESELECT_FIRED",missed:"PRESELECT_MISSED",queued:"PRESELECT_QUEUED",skipped:"PRESELECT_SKIPPED"};return{message:`Rokt Kit: preselect ${i} [reason=${e}]`,code:t[i]}}function qe(i,e){if(i)return J.find(t=>t.accountId===i&&t.pathname===e)}function Je(i,e){if(!(!i||!g(e)))return J.find(t=>t.accountId===i&&t.targetPageIdentifier===e)}function Be(i,e){return i?J.some(t=>t.accountId===i&&t.attributeKeys.includes(e)):!1}function Qe(){return{pending:[]}}function j(i,e){const t=i.pending.findIndex(n=>n.pathname===e.pathname);if(t>=0){i.pending[t]=e;return}i.pending.push(e)}function W(i){if(!i?.getUserIdentities)return!1;const e=i.getUserIdentities().userIdentities;return e?Object.keys(e).some(t=>{const n=e[t];return g(n)&&n.length>0}):!1}function Se(i){const e=i?.getMPID?.();return e==null?null:String(e)}function re(i,e,t){const n=i.filteredUser?.getAllUserAttributes?.()||{},r={},s=[];for(const o of t.attributeKeys){const c=i.getEventAttributeValue(e,o),u=T(c)?i.userAttributes[o]??n[o]:c;if(T(u)){s.push(o);continue}r[o]=u}return{collected:r,missingKeys:s}}function Xe(i,e){Promise.resolve(i.selectPlacements(e)).catch(t=>{const n=t instanceof Error?t.message:String(t);i.log({message:`Rokt Kit: Preselect selectPlacements call failed: ${n}`,code:"PRESELECT_DISPATCH_FAILED"})})}function Ae(i,e,t,n,r,s){const o=Ge(e,t),c=je(o),u=!!c&&JSON.stringify(c.attributes)===JSON.stringify(r);if(c&&c.expiresAt>Date.now()&&u){i.logPlacementDiagnostic(y("skipped","active_preselection"));return}Ve(o,r),i.logPlacementDiagnostic(y("fired",s)),Xe(i,{attributes:r,preselect:!0,identifier:n,omitUrl:!0})}function Ze(i,e){if(!e.accountId||!e.isKitReady())return;const t=ze(e.accountId);if(t){if(i.pending.some(n=>n.pathname===t.pathname)){L(e.accountId);return}if(!e.isPreselectionEnabled()){L(e.accountId);return}W(e.filteredUser)&&(L(e.accountId),Se(e.filteredUser)===t.mpid&&Ae(e,e.accountId,t.identifier,t.identifier,t.attributes,"recovered"))}}function Pe(i,e,t,n=window.location.pathname){const r=qe(e.accountId,n);if(!r)return;if(!e.isKitReady()){const c=[y("queued","not_ready")],u=Se(e.filteredUser);if(e.accountId&&u&&W(e.filteredUser)){const{collected:l,missingKeys:f}=re(e,t,r);if(f.length===0){const b=w(l);$e(e.accountId,n,r.targetPageIdentifier,b,u)||c.push(y("queued","persist_failed"))}}j(i,{event:t,pathname:n,storedDiagnostics:c});return}if(!e.isPreselectionEnabled())return;if(!W(e.filteredUser)){e.logPlacementDiagnostic(y("missed","no_valid_identity")),j(i,{event:t,pathname:n});return}const{collected:s,missingKeys:o}=re(e,t,r);if(o.length>0){for(const c of o)e.logPlacementDiagnostic(y("missed",`missing_attribute:${c}`));j(i,{event:t,pathname:n});return}Ae(e,e.accountId||"",n,r.targetPageIdentifier,s,"fired")}function et(i,e,t=window.location.pathname){if(Ze(i,e),i.pending.length===0)return;const n=i.pending;i.pending=[],n.forEach(({event:r,pathname:s,storedDiagnostics:o})=>{s===t&&(e.isKitReady()&&e.isPreselectionEnabled()&&o?.forEach(c=>e.logPlacementDiagnostic(c)),Pe(i,e,r,s))})}function tt(){return{context:null,lifecycle:"idle",recreateInFlight:null}}function it(i,e){i.context={accountId:e.accountId,launcherOptions:{...e.launcherOptions},legacyRoktExtensions:[...e.legacyRoktExtensions]}}function nt(i){i.lifecycle="attached"}function rt(i){i.lifecycle!=="idle"&&(i.lifecycle="terminated")}function st(i){i.lifecycle="terminated"}function ot(i){i.context=null,i.lifecycle="idle",i.recreateInFlight=null}function ct(i,e,t){if(i.recreateInFlight)return i.recreateInFlight;if(i.lifecycle!=="terminated"||!i.context||!e)return;i.lifecycle="recreating";const n=i.context;return i.recreateInFlight=t(n).finally(()=>{i.recreateInFlight=null}),i.recreateInFlight}const d="Rokt",C=181,at="selectPlacements",lt="apps.roktecommerce.com",ut=.1,dt="ThankYouPageJourney",ht="rokt-launcher",gt="rokt-thank-you-element",ft="userIdentifiedInWorkspace",pt=3,mt=2,Et="page_events",_t="page_view_attributes",It="mparticle_session_id",yt="mparticle_device_id",se=500,Q={UNKNOWN_ERROR:"UNKNOWN_ERROR",UNHANDLED_EXCEPTION:"UNHANDLED_EXCEPTION",IDENTITY_REQUEST:"IDENTITY_REQUEST",LOG_DELIVERY_FAILURE:"LOG_DELIVERY_FAILURE"},S={ERROR:"ERROR",INFO:"INFO",WARNING:"WARNING"},St="apps.rokt-api.com",At="/v1/log",Pt="/v1/errors",bt=10;function a(){return window.mParticle}function oe(i,e){const n=[G(i),"/wsdk/integrations/launcher.js"].join("");return!e||e.length===0?n:n+"?extensions="+e.join(",")}function ce(i){return[G(i),"/rokt-elements/rokt-element-thank-you.js"].join("")}function G(i){const e=i!==void 0?i:St;return e.includes("://")?e.replace(/\/+$/,""):["https://",e].join("")}function be(i,e,t){if(i)return i.startsWith("http://")||i.startsWith("https://")?i:"https://"+i;const r=e?.includes("://")&&!/^https?:\/\//i.test(e)?void 0:e;return G(r)+t}function ae(i,e,t){if(document.getElementById(i))return;const n=document.head||document.body,r=document.createElement("script");r.id=i,r.type="text/javascript",r.src=e,r.async=!0,r.crossOrigin="anonymous",r.fetchPriority="high",t?.onLoad&&(r.onload=t.onLoad),t?.onError&&(r.onerror=t.onError),n.appendChild(r)}function K(i){if(!i)return[];try{return JSON.parse(i.replace(/"/g,'"'))}catch{console.error("Settings string contains invalid JSON")}return[]}function le(i){const e=i?K(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(dt)):t.push(o)}return{roktExtensionsQueryParams:t,legacyRoktExtensions:n,loadThankYouElement:r}}async function Rt(i,e){const t=[];if(e)for(const n of i)t.push(e.use(n));return Promise.all(t)}function ue(i){if(!i)return{};const e={};for(let t=0;t<i.length;t++){const n=i[t];e[n.jsmap]=n.value}return e}function de(i){const e={};if(!Array.isArray(i))return e;for(let t=0;t<i.length;t++){const n=i[t];if(!n||!g(n.value)||!g(n.map))continue;const r=n.value,s=n.map;e[r]||(e[r]=[]),e[r].push({eventAttributeKey:s,conditions:Array.isArray(n.conditions)?n.conditions:[]})}return e}function he(i,e,t){return a().generateHash([i,e,t].join(""))}function kt(i){let n="mParticle_wsdkv_"+a().getVersion()+"_kitv_"+"3.3.0";return i&&(n+="_"+i),n}function H(i){const e=document.createElement("iframe");e.style.display="none",e.setAttribute("sandbox","allow-scripts allow-same-origin"),e.src=i,e.onload=function(){e.onload=null,e.parentNode&&e.parentNode.removeChild(e)};const t=document.body||document.head;t&&t.appendChild(e)}function ge(i,e){const t=Ee(window.location.origin);if(A._allowedOriginHashes.indexOf(t)===-1||Math.random()>=ut)return;const r=window.__rokt_li_guid__;if(!r||i&&i.includes("://")&&!/^https:\/\//i.test(i))return;const s=window.location.href.split("?")[0].split("#")[0],o="version="+encodeURIComponent(e??"")+"&launcherInstanceGuid="+encodeURIComponent(r)+"&pageUrl="+encodeURIComponent(s),c=i?G(i):"https://apps.rokt.com";H(c+"/v1/wsdk-init/index.html?"+o),H("https://"+lt+"/v1/wsdk-init/index.html?"+o+"&isControl=true")}function vt(){return typeof window<"u"&&!!window.location?.search?.toLowerCase().includes("mp_enable_logging=true")}function wt(){return typeof window<"u"?window.location?.href:void 0}function Tt(){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>bt}}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=vt()||o}send(e,t,n,r,s,o){if(!(!this._isEnabled||this._rateLimiter.incrementAndCheck(t)))try{const c={additionalInformation:{message:n,version:this._integrationName},severity:t,code:r||Q.UNKNOWN_ERROR,url:wt(),deviceInfo:Tt(),stackTrace:s,reporter:this._reporter,integration:this._integrationName},u={Accept:"text/plain;charset=UTF-8","Content-Type":"application/json","rokt-launcher-version":this._integrationName,"rokt-wsdk-version":"joint"};this._launcherInstanceGuid&&(u["rokt-launcher-instance-guid"]=this._launcherInstanceGuid),this._accountId&&(u["rokt-account-id"]=this._accountId),fetch(e,{method:"POST",headers:u,body:JSON.stringify(c)}).then(l=>{if(!l.ok){const f=new Error("HTTP "+l.status+" from log endpoint");throw f.statusCode=l.status,f}}).catch(l=>{console.error("ReportingTransport: Failed to send log",l),o&&o(l)})}catch(c){console.error("ReportingTransport: Failed to send log",c),o&&o(c)}}}class fe{constructor(e,t,n,r,s){this._transport=new F(e,t,n,r,s),this._errorUrl=be(e?.errorUrl,e?.integrationDomain,Pt)}report(e){if(!e)return;const t=e.severity||S.ERROR;this._transport.send(this._errorUrl,t,e.message,e.code,e.stackTrace)}}class pe{constructor(e,t,n,r,s,o){this._transport=new F(e,n,r,s,o),this._placementDiagnosticTransport=new F(e,n,r,s),this._loggingUrl=be(e?.loggingUrl,e?.integrationDomain,At),this._errorReportingService=t}log(e){e&&this._send(this._transport,e)}logPlacementDiagnostic(e){e&&this._send(this._placementDiagnosticTransport,e)}_send(e,t){e.send(this._loggingUrl,S.INFO,t.message,t.code,void 0,n=>{if(this._errorReportingService){const r=typeof n.statusCode=="number";this._errorReportingService.report({message:"LoggingService: Failed to send log: "+n.message,code:Q.LOG_DELIVERY_FAILURE,severity:r?S.ERROR:S.WARNING})}})}}function Lt(i){const e=z(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 _=class _{constructor(){this.name=d,this.id=C,this.moduleId=C,this.isInitialized=!1,this.launcher=null,this.filters={},this.userAttributes={},this.userIdentifiedInWorkspace=!1,this.testHelpers=null,this.placementEventMappingLookup={},this.placementEventAttributeMappingLookup={},this.integrationName=null,this.errorReportingService=null,this.loggingService=null,this._thankYouElementOnLoadCallback=null,this._isThankYouElementLoaded=!1,this._workspaceSearchInFlightPromise=null,this._launcherAttachState=tt(),this.accountId=null,this._preselectState=Qe()}getEventAttributeValue(e,t){const n=e&&e.EventAttributes;return!n||n[t]===void 0?null:n[t]}doesEventAttributeConditionMatch(e,t){if(!e||!g(e.operator))return!1;const n=e.operator.toLowerCase(),r=e.attributeValue;return n==="exists"?t!==null:t==null?!1:n==="equals"?String(t)===String(r):n==="contains"?String(t).indexOf(String(r))!==-1:!1}doesEventMatchRule(e,t){if(!t||!g(t.eventAttributeKey))return!1;const n=t.conditions;if(!Array.isArray(n))return!1;const r=this.getEventAttributeValue(e,t.eventAttributeKey);if(n.length===0)return r!==null;for(let s=0;s<n.length;s++)if(!this.doesEventAttributeConditionMatch(n[s],r))return!1;return!0}applyPlacementEventAttributeMapping(e){const t=Object.keys(this.placementEventAttributeMappingLookup);for(let n=0;n<t.length;n++){const r=t[n],s=this.placementEventAttributeMappingLookup[r];if(T(s))continue;let o=!0;for(let c=0;c<s.length;c++)if(!this.doesEventMatchRule(e,s[c])){o=!1;break}o&&a().Rokt.setLocalSessionAttribute?.(r,!0)}}capturePageView(e){let t;try{t=z(window.location.href);const n=te(),r=Lt(e);n.push(r);const s=Math.min(n.length,Ie),o=Ce(n);if(o===0){const c=V()?"quota":"ls_unavailable";this.loggingService?.log({message:`Rokt Kit: Failed to persist page view for ${t} [reason: ${c}]`,code:"PAGE_VIEW_CAPTURE_FAILED"})}else o<s&&this.loggingService?.log({message:`Rokt Kit: Page view storage reduced from ${s} to ${o} record(s) under quota pressure [reason: quota_eviction]`,code:"PAGE_VIEW_QUOTA_EVICTION"})}catch(n){const r=V()?"exception":"ls_unavailable",s=n instanceof Error?n.message:String(n);this.loggingService?.log({message:`Rokt Kit: Failed to capture page view for ${t}: ${s} [reason: ${r}]`,code:"PAGE_VIEW_CAPTURE_FAILED"})}}isPreselectionEnabled(){return this.launcher?.enablePreselection===!0}buildCacheMatchKeys(e){if(!this.isPreselectionEnabled())return;const t=Je(this.accountId,e);if(t)return t.attributeKeys}buildPreselectHost(){return{accountId:this.accountId,filteredUser:this.filters.filteredUser,userAttributes:this.userAttributes,isKitReady:()=>this.isKitReady(),isPreselectionEnabled:()=>this.isPreselectionEnabled(),getEventAttributeValue:(e,t)=>this.getEventAttributeValue(e,t),logPlacementDiagnostic:e=>this.loggingService?.logPlacementDiagnostic(e),log:e=>this.loggingService?.log(e),selectPlacements:e=>this.selectPlacements(e)}}flushPendingPreselectDispatches(){et(this._preselectState,this.buildPreselectHost())}isLauncherReadyToAttach(){return!!window.Rokt&&U(window.Rokt.createLauncher)}returnUserIdentities(e){if(!e||!e.getUserIdentities)return{};const t=e.getUserIdentities().userIdentities;return this.replaceOtherIdentityWithEmailsha256(t)}returnLocalSessionAttributes(){return!a().Rokt||typeof a().Rokt.getLocalSessionAttributes!="function"?{}:a().Rokt.getLocalSessionAttributes()}replaceOtherIdentityWithEmailsha256(e){const t={...e||{}},n=this._mappedEmailSha256Key;return n&&e[n]&&(t[_.EMAIL_SHA256_KEY]=e[n]),n&&delete t[n],t}logSelectPlacementsEvent(e){if(!window.mParticle||typeof a().logEvent!="function"||!m(e))return;const t=a().EventType.Other;a().logEvent(at,t,e)}setRoktSessionId(e){if(!(!e||typeof e!="string"))try{const t=a().getInstance();t&&U(t.setIntegrationAttribute)&&t.setIntegrationAttribute(C,{roktSessionId:e})}catch{}}readMpSessionId(){const e=a()?.sessionManager,t=e?.getSessionId??e?.getSession;if(U(t))return t.call(e)||void 0}readMpDeviceId(){return a()?.getDeviceId?.()||void 0}attachLauncher(e,t,n=[]){it(this._launcherAttachState,{accountId:e,launcherOptions:t||{},legacyRoktExtensions:n});const r={accountId:e,...t||{}};let s;return this.isPartnerInLocalLauncherTestGroup()?s=Promise.resolve(window.Rokt.createLocalLauncher(r)):s=window.Rokt.createLauncher(r),s.then(async o=>{await Rt([...n],o),this.initRoktLauncher(o)}).catch(o=>{st(this._launcherAttachState),console.error("Error creating Rokt launcher:",o)})}recreateLauncherIfTerminated(){return ct(this._launcherAttachState,this.isLauncherReadyToAttach(),e=>this.attachLauncher(e.accountId,e.launcherOptions,e.legacyRoktExtensions))}initRoktLauncher(e){window.Rokt&&(window.Rokt.currentLauncher=e),this.launcher=e,nt(this._launcherAttachState);const t=a().Rokt?.filters;t?(this.filters=t,t.filteredUser?this._workspaceSearchInFlightPromise=this.search(t.filteredUser):console.warn("Rokt Kit: No filtered user has been set.")):console.warn("Rokt Kit: No filters have been set."),this.isInitialized=!0,ge(this.domain,this.integrationName),a().Rokt.attachKit(this),this.flushPendingPreselectDispatches()}fetchOptimizely(){const e=a()._getActiveForwarders().filter(t=>t.name==="Optimizely");try{if(e.length>0&&window.optimizely){const t=window.optimizely.get("state");return!t||!t.getActiveExperimentIds?{}:t.getActiveExperimentIds().reduce((s,o)=>(s["rokt.custom.optimizely.experiment."+o+".variationId"]=t.getVariationMap()[o].id,s),{})}}catch(t){console.error("Error fetching Optimizely attributes:",t)}return{}}isKitReady(){return!!(this.isInitialized&&this.launcher)}isTargetingDisabled(){return a().Rokt?.launcherOptions?.noTargeting===!0}isPartnerInLocalLauncherTestGroup(){return!!(a().config&&a().config.isLocalLauncherEnabled&&this.isAssignedToSampleGroup())}isAssignedToSampleGroup(){return Math.random()>.5}captureTiming(e){window&&a()&&a().captureTiming&&e&&a().captureTiming(e)}init(e,t,n,r,s){const o=e,c=o.accountId;this.accountId=c||null,this.userAttributes=w(s),this._onboardingExpProvider=o.onboardingExpProvider;const u=K(o.placementEventMapping);this.placementEventMappingLookup=ue(u);const l=K(o.placementEventAttributeMapping);this.placementEventAttributeMappingLookup=de(l),o.hashedEmailUserIdentityType&&(this._mappedEmailSha256Key=o.hashedEmailUserIdentityType.toLowerCase()),this._workspaceIdSyncApiKey=g(o.workspaceIdSyncApiKey)?o.workspaceIdSyncApiKey:void 0;const f=a().Rokt?.domain,{roktExtensionsQueryParams:b,legacyRoktExtensions:R,loadThankYouElement:N}=le(o.roktExtensions),E={...a().Rokt?.launcherOptions||{}};this.integrationName=kt(E.integrationName),E.integrationName=this.integrationName,this.domain=f;const k={loggingUrl:o.loggingUrl,errorUrl:o.errorUrl,integrationDomain:f,isLoggingEnabled:a().config?.isLoggingEnabled===!0},I=new fe(k,this.integrationName,window.__rokt_li_guid__,o.accountId),v=new pe(k,I,this.integrationName,window.__rokt_li_guid__,o.accountId);if(this.errorReportingService=I,this.loggingService=v,this.isTargetingDisabled())try{ie(),ne()}catch(p){this.errorReportingService?.report({message:"Rokt Kit: Failed to clear page views when targeting is disabled",code:"PAGE_VIEW_CAPTURE_FAILED",severity:S.INFO,stackTrace:p instanceof Error?p.stack:void 0})}return a()._registerErrorReportingService&&a()._registerErrorReportingService(I),a()._registerLoggingService&&a()._registerLoggingService(v),n?(this.testHelpers={generateLauncherScript:oe,generateThankYouElementScript:ce,extractRoktExtensionConfig:le,hashEventMessage:he,parseSettingsString:K,generateMappedEventLookup:ue,generateMappedEventAttributeLookup:de,sendAdBlockMeasurementSignals:ge,createAutoRemovedIframe:H,djb2:Ee,setAllowedOriginHashes:p=>{_._allowedOriginHashes=p},ReportingTransport:F,ErrorReportingService:fe,LoggingService:pe,RateLimiter:Re,ErrorCodes:Q,WSDKErrorSeverity:S,resetLauncherAttachState:()=>ot(this._launcherAttachState)},this.attachLauncher(c,E),"Successfully initialized: "+d):(N&&(a().Rokt.flushOnShoppableAdsReadyMessageQueue?.(this),ae(gt,ce(f),{onLoad:()=>{this._isThankYouElementLoaded=!0,this._thankYouElementOnLoadCallback&&this._thankYouElementOnLoadCallback()},onError:p=>{console.error("Error loading Rokt Thank You Element script:",p)}})),this.isLauncherReadyToAttach()?this.attachLauncher(c,E,R):(ae(ht,oe(f,b),{onLoad:()=>{this.isLauncherReadyToAttach()?this.attachLauncher(c,E,R):console.error("Rokt object is not available after script load.")},onError:p=>{console.error("Error loading Rokt launcher script:",p)}}),this.captureTiming(_.PERFORMANCE_MARKS.RoktScriptAppended)),"Successfully initialized: "+d)}process(e){if(this.isTargetingDisabled()||(e.EventDataType===pt&&(De(this.loggingService),this.capturePageView(e),Pe(this._preselectState,this.buildPreselectHost(),e)),e.EventDataType===mt&&(ie(),ne(),this.accountId&&L(this.accountId))),!this.isKitReady())return"Kit not ready for forwarder: "+d;if(U(a().Rokt?.setLocalSessionAttribute)&&(T(this.placementEventAttributeMappingLookup)||this.applyPlacementEventAttributeMapping(e),!T(this.placementEventMappingLookup))){const t=he(e.EventDataType,e.EventCategory,e.EventName??"");this.placementEventMappingLookup[String(t)]&&a().Rokt.setLocalSessionAttribute?.(this.placementEventMappingLookup[String(t)],!0)}return"Successfully sent to forwarder: "+d}setExtensionData(e){if(!this.isKitReady()){console.error("Rokt Kit: Not initialized");return}window.Rokt.setExtensionData(e)}setUserAttribute(e,t){return me(e)||(this.userAttributes[e]=t),Be(this.accountId,e)&&this.flushPendingPreselectDispatches(),"Successfully set user attribute for forwarder: "+d}removeUserAttribute(e){return delete this.userAttributes[e],"Successfully removed user attribute for forwarder: "+d}handleIdentityComplete(e,t){return this.userAttributes=w(e.getAllUserAttributes()),"Successfully called "+t+" for forwarder: "+d}onUserIdentified(e){const t=e;this.filters.filteredUser=t,this._workspaceSearchInFlightPromise=this.search(t);const n=this.handleIdentityComplete(e,"onUserIdentified");return this.flushPendingPreselectDispatches(),n}search(e){const t=this._workspaceIdSyncApiKey;if(!t)return this.userIdentifiedInWorkspace=!1,this._workspaceLastSearchedIdentitiesKey=void 0,Promise.resolve();const n=a().Identity?.search;if(typeof n!="function")return this.userIdentifiedInWorkspace=!1,this._workspaceLastSearchedIdentitiesKey=void 0,Promise.resolve();const r=e.getUserIdentities?e.getUserIdentities().userIdentities:null,s={};if(r)for(const u of Object.keys(r)){const l=r[u];g(l)&&l.length>0&&(s[u]=l)}const o=Object.keys(s);if(o.length===0)return this.userIdentifiedInWorkspace=!1,this._workspaceLastSearchedIdentitiesKey=void 0,Promise.resolve();const c=o.sort().map(u=>`${u}=${s[u]}`).join("&");return c===this._workspaceLastSearchedIdentitiesKey?this._workspaceSearchInFlightPromise||Promise.resolve():(this.userIdentifiedInWorkspace=!1,this._workspaceLastSearchedIdentitiesKey=c,new Promise(u=>{try{n(t,s,l=>{l?.httpCode===200&&(this.userIdentifiedInWorkspace=!0),u()})}catch(l){console.error("Rokt Kit: Workspace IDSync search failed",l),this._workspaceLastSearchedIdentitiesKey=void 0,u()}}))}onLoginComplete(e,t){return this.handleIdentityComplete(e,"onLoginComplete")}onLogoutComplete(e,t){return this.userIdentifiedInWorkspace=!1,this._workspaceSearchInFlightPromise=null,this._workspaceLastSearchedIdentitiesKey=void 0,this.accountId&&L(this.accountId),this.handleIdentityComplete(e,"onLogoutComplete")}onModifyComplete(e,t){return this.handleIdentityComplete(e,"onModifyComplete")}selectPlacements(e){const t=this.recreateLauncherIfTerminated();if(t){const n=this._workspaceSearchInFlightPromise,r=n?Promise.race([n,new Promise(s=>setTimeout(s,se))]):Promise.resolve();return Promise.all([t,r]).then(()=>this._dispatchPlacements(e))}if(this._workspaceSearchInFlightPromise){const n=this._workspaceSearchInFlightPromise;return Promise.race([n,new Promise(r=>setTimeout(r,se))]).then(()=>this._dispatchPlacements(e))}return this._dispatchPlacements(e)}_dispatchPlacements(e){const t=e&&e.attributes||{},r={...w(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=w(l);const f=this._onboardingExpProvider==="Optimizely"?this.fetchOptimizely():{},b=this.returnUserIdentities(c),R=this.returnLocalSessionAttributes(),N=Ke(te()),E=Me(),k=this.readMpSessionId(),I=this.readMpDeviceId(),v={...b,...l,...f,...R,...N.length?{[Et]:JSON.stringify(N)}:{},...E?{[_t]:E}:{},...this.userIdentifiedInWorkspace?{[ft]:!0}:{},...k?{[It]:k}:{},...I?{[yt]:I}:{},mpid:u},p=this.buildCacheMatchKeys(typeof e.identifier=="string"?e.identifier:void 0),ke={...e,attributes:v,...p!==void 0?{cacheMatchKeys:p}:{}},X=this.launcher.selectPlacements(ke),Z=e.preselect===!0,ve=()=>{Z||this.logSelectPlacementsEvent(v)};return Promise.resolve(X).then(we=>{if(!Z)return we?.context?.sessionId?.then(Te=>this.setRoktSessionId(Te))}).catch(()=>{}).finally(ve),X}hashAttributes(e){return this.isKitReady()?this.launcher.hashAttributes(e):(console.error("Rokt Kit: Not initialized"),null)}use(e){return this.isKitReady()?!e||!g(e)?Promise.reject(new Error("Rokt Kit: Invalid extension name")):this.launcher.use(e):(console.error("Rokt Kit: Not initialized"),Promise.reject(new Error("Rokt Kit: Not initialized")))}terminate(){return this.isKitReady()?(rt(this._launcherAttachState),this.launcher.terminate()):(console.error("Rokt Kit: Not initialized"),Promise.resolve())}onShoppableAdsReady(e){this._isThankYouElementLoaded?e():this._thankYouElementOnLoadCallback=e}};_._allowedOriginHashes=[-553112570,549508659],_.PERFORMANCE_MARKS={RoktScriptAppended:"mp:RoktScriptAppended"},_.EMAIL_SHA256_KEY="emailsha256";let A=_;function Ot(){return C}function Nt(i){if(!i){window.console.log("You must pass a config object to register the kit "+d);return}if(!m(i)){window.console.log("'config' must be an object. You passed in a "+typeof i);return}m(i.kits)?i.kits[d]={constructor:A}:(i.kits={},i.kits[d]={constructor:A}),window.console.log("Successfully registered "+d+" to your mParticle configuration")}typeof window<"u"&&window.mParticle&&a().addForwarder&&a().addForwarder({name:d,constructor:A,getId:Ot});exports.register=Nt;
|
|
2
2
|
//# sourceMappingURL=Rokt-Kit.common.js.map
|
package/dist/Rokt-Kit.esm.js
CHANGED
|
@@ -27,7 +27,7 @@ const Le = [
|
|
|
27
27
|
function me(i) {
|
|
28
28
|
return Oe.has(i.toLowerCase());
|
|
29
29
|
}
|
|
30
|
-
function
|
|
30
|
+
function w(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];
|
|
@@ -44,7 +44,7 @@ function g(i) {
|
|
|
44
44
|
function U(i) {
|
|
45
45
|
return typeof i == "function";
|
|
46
46
|
}
|
|
47
|
-
function
|
|
47
|
+
function T(i) {
|
|
48
48
|
return i == null ? !0 : typeof i == "string" ? i.length === 0 : typeof i == "object" ? Object.keys(i).length === 0 : !1;
|
|
49
49
|
}
|
|
50
50
|
function z(i) {
|
|
@@ -91,7 +91,7 @@ function Ne(i, e = P) {
|
|
|
91
91
|
} catch {
|
|
92
92
|
}
|
|
93
93
|
}
|
|
94
|
-
function
|
|
94
|
+
function O(i, e, t = P) {
|
|
95
95
|
const n = $(i, t);
|
|
96
96
|
return m(n) ? n[e] : void 0;
|
|
97
97
|
}
|
|
@@ -107,15 +107,15 @@ function Y(i, e, t = P) {
|
|
|
107
107
|
delete r[e], Object.keys(r).length === 0 ? Ne(i, t) : _e(i, r, t);
|
|
108
108
|
}
|
|
109
109
|
const q = "pageViews", D = "utmParams", Ie = 25, Ue = ["utm_source", "utm_medium", "utm_campaign", "utm_term", "utm_content"];
|
|
110
|
-
function
|
|
110
|
+
function ye(i) {
|
|
111
111
|
return i.slice(-Ie);
|
|
112
112
|
}
|
|
113
113
|
function te() {
|
|
114
|
-
const i =
|
|
114
|
+
const i = O(h, q);
|
|
115
115
|
return Array.isArray(i) ? i : [];
|
|
116
116
|
}
|
|
117
117
|
function Ce(i) {
|
|
118
|
-
const e =
|
|
118
|
+
const e = ye(i);
|
|
119
119
|
for (let t = 0; t < e.length; t++) {
|
|
120
120
|
const n = e.slice(t);
|
|
121
121
|
if (x(h, q, n))
|
|
@@ -127,7 +127,7 @@ function ie() {
|
|
|
127
127
|
Y(h, q);
|
|
128
128
|
}
|
|
129
129
|
function Ke(i) {
|
|
130
|
-
const e =
|
|
130
|
+
const e = ye(i);
|
|
131
131
|
return e.map((t, n) => {
|
|
132
132
|
const r = t.activeTimeOnSite, s = r !== void 0 && Number.isFinite(r), c = e[n + 1]?.activeTimeOnSite, u = c !== void 0 && Number.isFinite(c), l = s && u ? c - r : void 0;
|
|
133
133
|
return {
|
|
@@ -142,7 +142,7 @@ function Ke(i) {
|
|
|
142
142
|
});
|
|
143
143
|
}
|
|
144
144
|
function De(i) {
|
|
145
|
-
if (
|
|
145
|
+
if (O(h, D) !== void 0)
|
|
146
146
|
return;
|
|
147
147
|
const e = new URLSearchParams(window.location.search), t = {};
|
|
148
148
|
for (const r of Ue) {
|
|
@@ -166,7 +166,7 @@ function De(i) {
|
|
|
166
166
|
});
|
|
167
167
|
}
|
|
168
168
|
function Me() {
|
|
169
|
-
const i =
|
|
169
|
+
const i = O(h, D);
|
|
170
170
|
return m(i) ? i : null;
|
|
171
171
|
}
|
|
172
172
|
function ne() {
|
|
@@ -203,7 +203,7 @@ function Ge(i, e) {
|
|
|
203
203
|
return `activePreselect:${i}:${e}`;
|
|
204
204
|
}
|
|
205
205
|
function je(i) {
|
|
206
|
-
const e =
|
|
206
|
+
const e = O(h, i);
|
|
207
207
|
return Ye(e) ? e : null;
|
|
208
208
|
}
|
|
209
209
|
function Ve(i, e) {
|
|
@@ -223,7 +223,7 @@ function B(i) {
|
|
|
223
223
|
return `pendingPreselect:${i}`;
|
|
224
224
|
}
|
|
225
225
|
function ze(i) {
|
|
226
|
-
const e = B(i), t =
|
|
226
|
+
const e = B(i), t = O(h, e, M);
|
|
227
227
|
return He(t) ? t.expiresAt <= Date.now() ? (Y(h, e, M), null) : t : null;
|
|
228
228
|
}
|
|
229
229
|
function $e(i, e, t, n, r) {
|
|
@@ -240,10 +240,10 @@ function $e(i, e, t, n, r) {
|
|
|
240
240
|
M
|
|
241
241
|
);
|
|
242
242
|
}
|
|
243
|
-
function
|
|
243
|
+
function L(i) {
|
|
244
244
|
Y(h, B(i), M);
|
|
245
245
|
}
|
|
246
|
-
function
|
|
246
|
+
function y(i, e) {
|
|
247
247
|
const t = {
|
|
248
248
|
fired: "PRESELECT_FIRED",
|
|
249
249
|
missed: "PRESELECT_MISSED",
|
|
@@ -286,15 +286,15 @@ function W(i) {
|
|
|
286
286
|
return g(n) && n.length > 0;
|
|
287
287
|
}) : !1;
|
|
288
288
|
}
|
|
289
|
-
function
|
|
289
|
+
function Se(i) {
|
|
290
290
|
const e = i?.getMPID?.();
|
|
291
291
|
return e == null ? null : String(e);
|
|
292
292
|
}
|
|
293
293
|
function re(i, e, t) {
|
|
294
294
|
const n = i.filteredUser?.getAllUserAttributes?.() || {}, r = {}, s = [];
|
|
295
295
|
for (const o of t.attributeKeys) {
|
|
296
|
-
const c = i.getEventAttributeValue(e, o), u =
|
|
297
|
-
if (
|
|
296
|
+
const c = i.getEventAttributeValue(e, o), u = T(c) ? i.userAttributes[o] ?? n[o] : c;
|
|
297
|
+
if (T(u)) {
|
|
298
298
|
s.push(o);
|
|
299
299
|
continue;
|
|
300
300
|
}
|
|
@@ -314,10 +314,10 @@ function Xe(i, e) {
|
|
|
314
314
|
function Ae(i, e, t, n, r, s) {
|
|
315
315
|
const o = Ge(e, t), c = je(o), u = !!c && JSON.stringify(c.attributes) === JSON.stringify(r);
|
|
316
316
|
if (c && c.expiresAt > Date.now() && u) {
|
|
317
|
-
i.logPlacementDiagnostic(
|
|
317
|
+
i.logPlacementDiagnostic(y("skipped", "active_preselection"));
|
|
318
318
|
return;
|
|
319
319
|
}
|
|
320
|
-
Ve(o, r), i.logPlacementDiagnostic(
|
|
320
|
+
Ve(o, r), i.logPlacementDiagnostic(y("fired", s)), Xe(i, { attributes: r, preselect: !0, identifier: n, omitUrl: !0 });
|
|
321
321
|
}
|
|
322
322
|
function Ze(i, e) {
|
|
323
323
|
if (!e.accountId || !e.isKitReady())
|
|
@@ -325,14 +325,14 @@ function Ze(i, e) {
|
|
|
325
325
|
const t = ze(e.accountId);
|
|
326
326
|
if (t) {
|
|
327
327
|
if (i.pending.some((n) => n.pathname === t.pathname)) {
|
|
328
|
-
|
|
328
|
+
L(e.accountId);
|
|
329
329
|
return;
|
|
330
330
|
}
|
|
331
331
|
if (!e.isPreselectionEnabled()) {
|
|
332
|
-
|
|
332
|
+
L(e.accountId);
|
|
333
333
|
return;
|
|
334
334
|
}
|
|
335
|
-
W(e.filteredUser) && (
|
|
335
|
+
W(e.filteredUser) && (L(e.accountId), Se(e.filteredUser) === t.mpid && Ae(e, e.accountId, t.identifier, t.identifier, t.attributes, "recovered"));
|
|
336
336
|
}
|
|
337
337
|
}
|
|
338
338
|
function Pe(i, e, t, n = window.location.pathname) {
|
|
@@ -340,33 +340,33 @@ function Pe(i, e, t, n = window.location.pathname) {
|
|
|
340
340
|
if (!r)
|
|
341
341
|
return;
|
|
342
342
|
if (!e.isKitReady()) {
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
const f = k(u);
|
|
343
|
+
const c = [y("queued", "not_ready")], u = Se(e.filteredUser);
|
|
344
|
+
if (e.accountId && u && W(e.filteredUser)) {
|
|
345
|
+
const { collected: l, missingKeys: f } = re(e, t, r);
|
|
346
|
+
if (f.length === 0) {
|
|
347
|
+
const R = w(l);
|
|
349
348
|
$e(
|
|
350
349
|
e.accountId,
|
|
351
350
|
n,
|
|
352
351
|
r.targetPageIdentifier,
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
) ||
|
|
352
|
+
R,
|
|
353
|
+
u
|
|
354
|
+
) || c.push(y("queued", "persist_failed"));
|
|
356
355
|
}
|
|
357
356
|
}
|
|
357
|
+
j(i, { event: t, pathname: n, storedDiagnostics: c });
|
|
358
358
|
return;
|
|
359
359
|
}
|
|
360
360
|
if (!e.isPreselectionEnabled())
|
|
361
361
|
return;
|
|
362
362
|
if (!W(e.filteredUser)) {
|
|
363
|
-
e.logPlacementDiagnostic(
|
|
363
|
+
e.logPlacementDiagnostic(y("missed", "no_valid_identity")), j(i, { event: t, pathname: n });
|
|
364
364
|
return;
|
|
365
365
|
}
|
|
366
366
|
const { collected: s, missingKeys: o } = re(e, t, r);
|
|
367
367
|
if (o.length > 0) {
|
|
368
368
|
for (const c of o)
|
|
369
|
-
e.logPlacementDiagnostic(
|
|
369
|
+
e.logPlacementDiagnostic(y("missed", `missing_attribute:${c}`));
|
|
370
370
|
j(i, { event: t, pathname: n });
|
|
371
371
|
return;
|
|
372
372
|
}
|
|
@@ -376,8 +376,8 @@ function et(i, e, t = window.location.pathname) {
|
|
|
376
376
|
if (Ze(i, e), i.pending.length === 0)
|
|
377
377
|
return;
|
|
378
378
|
const n = i.pending;
|
|
379
|
-
i.pending = [], n.forEach(({ event: r, pathname: s }) => {
|
|
380
|
-
s === t && Pe(i, e, r, s);
|
|
379
|
+
i.pending = [], n.forEach(({ event: r, pathname: s, storedDiagnostics: o }) => {
|
|
380
|
+
s === t && (e.isKitReady() && e.isPreselectionEnabled() && o?.forEach((c) => e.logPlacementDiagnostic(c)), Pe(i, e, r, s));
|
|
381
381
|
});
|
|
382
382
|
}
|
|
383
383
|
function tt() {
|
|
@@ -417,16 +417,16 @@ function ct(i, e, t) {
|
|
|
417
417
|
i.recreateInFlight = null;
|
|
418
418
|
}), i.recreateInFlight;
|
|
419
419
|
}
|
|
420
|
-
const d = "Rokt", C = 181, at = "selectPlacements", lt = "apps.roktecommerce.com", ut = 0.1, dt = "ThankYouPageJourney", ht = "rokt-launcher", gt = "rokt-thank-you-element", ft = "userIdentifiedInWorkspace", pt = 3, mt = 2, Et = "page_events", _t = "page_view_attributes", It = "mparticle_session_id",
|
|
420
|
+
const d = "Rokt", C = 181, at = "selectPlacements", lt = "apps.roktecommerce.com", ut = 0.1, dt = "ThankYouPageJourney", ht = "rokt-launcher", gt = "rokt-thank-you-element", ft = "userIdentifiedInWorkspace", pt = 3, mt = 2, Et = "page_events", _t = "page_view_attributes", It = "mparticle_session_id", yt = "mparticle_device_id", se = 500, Q = {
|
|
421
421
|
UNKNOWN_ERROR: "UNKNOWN_ERROR",
|
|
422
422
|
UNHANDLED_EXCEPTION: "UNHANDLED_EXCEPTION",
|
|
423
423
|
IDENTITY_REQUEST: "IDENTITY_REQUEST",
|
|
424
424
|
LOG_DELIVERY_FAILURE: "LOG_DELIVERY_FAILURE"
|
|
425
|
-
},
|
|
425
|
+
}, S = {
|
|
426
426
|
ERROR: "ERROR",
|
|
427
427
|
INFO: "INFO",
|
|
428
428
|
WARNING: "WARNING"
|
|
429
|
-
},
|
|
429
|
+
}, St = "apps.rokt-api.com", At = "/v1/log", Pt = "/v1/errors", Rt = 10;
|
|
430
430
|
function a() {
|
|
431
431
|
return window.mParticle;
|
|
432
432
|
}
|
|
@@ -438,7 +438,7 @@ function ce(i) {
|
|
|
438
438
|
return [G(i), "/rokt-elements/rokt-element-thank-you.js"].join("");
|
|
439
439
|
}
|
|
440
440
|
function G(i) {
|
|
441
|
-
const e = i !== void 0 ? i :
|
|
441
|
+
const e = i !== void 0 ? i : St;
|
|
442
442
|
return e.includes("://") ? e.replace(/\/+$/, "") : ["https://", e].join("");
|
|
443
443
|
}
|
|
444
444
|
function Re(i, e, t) {
|
|
@@ -512,7 +512,7 @@ function he(i, e, t) {
|
|
|
512
512
|
return a().generateHash([i, e, t].join(""));
|
|
513
513
|
}
|
|
514
514
|
function kt(i) {
|
|
515
|
-
let n = "mParticle_wsdkv_" + a().getVersion() + "_kitv_" + "3.
|
|
515
|
+
let n = "mParticle_wsdkv_" + a().getVersion() + "_kitv_" + "3.3.0";
|
|
516
516
|
return i && (n += "_" + i), n;
|
|
517
517
|
}
|
|
518
518
|
function H(i) {
|
|
@@ -603,7 +603,7 @@ class fe {
|
|
|
603
603
|
}
|
|
604
604
|
report(e) {
|
|
605
605
|
if (!e) return;
|
|
606
|
-
const t = e.severity ||
|
|
606
|
+
const t = e.severity || S.ERROR;
|
|
607
607
|
this._transport.send(this._errorUrl, t, e.message, e.code, e.stackTrace);
|
|
608
608
|
}
|
|
609
609
|
}
|
|
@@ -625,7 +625,7 @@ class pe {
|
|
|
625
625
|
_send(e, t) {
|
|
626
626
|
e.send(
|
|
627
627
|
this._loggingUrl,
|
|
628
|
-
|
|
628
|
+
S.INFO,
|
|
629
629
|
t.message,
|
|
630
630
|
t.code,
|
|
631
631
|
void 0,
|
|
@@ -635,7 +635,7 @@ class pe {
|
|
|
635
635
|
this._errorReportingService.report({
|
|
636
636
|
message: "LoggingService: Failed to send log: " + n.message,
|
|
637
637
|
code: Q.LOG_DELIVERY_FAILURE,
|
|
638
|
-
severity: r ?
|
|
638
|
+
severity: r ? S.ERROR : S.WARNING
|
|
639
639
|
});
|
|
640
640
|
}
|
|
641
641
|
}
|
|
@@ -686,7 +686,7 @@ const _ = class _ {
|
|
|
686
686
|
const t = Object.keys(this.placementEventAttributeMappingLookup);
|
|
687
687
|
for (let n = 0; n < t.length; n++) {
|
|
688
688
|
const r = t[n], s = this.placementEventAttributeMappingLookup[r];
|
|
689
|
-
if (
|
|
689
|
+
if (T(s))
|
|
690
690
|
continue;
|
|
691
691
|
let o = !0;
|
|
692
692
|
for (let c = 0; c < s.length; c++)
|
|
@@ -855,48 +855,48 @@ const _ = class _ {
|
|
|
855
855
|
*/
|
|
856
856
|
init(e, t, n, r, s) {
|
|
857
857
|
const o = e, c = o.accountId;
|
|
858
|
-
this.accountId = c || null, this.userAttributes =
|
|
858
|
+
this.accountId = c || null, this.userAttributes = w(s), this._onboardingExpProvider = o.onboardingExpProvider;
|
|
859
859
|
const u = K(o.placementEventMapping);
|
|
860
860
|
this.placementEventMappingLookup = ue(u);
|
|
861
861
|
const l = K(
|
|
862
862
|
o.placementEventAttributeMapping
|
|
863
863
|
);
|
|
864
864
|
this.placementEventAttributeMappingLookup = de(l), o.hashedEmailUserIdentityType && (this._mappedEmailSha256Key = o.hashedEmailUserIdentityType.toLowerCase()), this._workspaceIdSyncApiKey = g(o.workspaceIdSyncApiKey) ? o.workspaceIdSyncApiKey : void 0;
|
|
865
|
-
const f = a().Rokt?.domain, { roktExtensionsQueryParams:
|
|
865
|
+
const f = a().Rokt?.domain, { roktExtensionsQueryParams: R, legacyRoktExtensions: b, loadThankYouElement: N } = le(
|
|
866
866
|
o.roktExtensions
|
|
867
867
|
), E = {
|
|
868
868
|
...a().Rokt?.launcherOptions || {}
|
|
869
869
|
};
|
|
870
870
|
this.integrationName = kt(E.integrationName), E.integrationName = this.integrationName, this.domain = f;
|
|
871
|
-
const
|
|
871
|
+
const k = {
|
|
872
872
|
loggingUrl: o.loggingUrl,
|
|
873
873
|
errorUrl: o.errorUrl,
|
|
874
874
|
integrationDomain: f,
|
|
875
875
|
isLoggingEnabled: a().config?.isLoggingEnabled === !0
|
|
876
876
|
}, I = new fe(
|
|
877
|
-
|
|
877
|
+
k,
|
|
878
878
|
this.integrationName,
|
|
879
879
|
window.__rokt_li_guid__,
|
|
880
880
|
o.accountId
|
|
881
|
-
),
|
|
882
|
-
|
|
881
|
+
), v = new pe(
|
|
882
|
+
k,
|
|
883
883
|
I,
|
|
884
884
|
this.integrationName,
|
|
885
885
|
window.__rokt_li_guid__,
|
|
886
886
|
o.accountId
|
|
887
887
|
);
|
|
888
|
-
if (this.errorReportingService = I, this.loggingService =
|
|
888
|
+
if (this.errorReportingService = I, this.loggingService = v, this.isTargetingDisabled())
|
|
889
889
|
try {
|
|
890
890
|
ie(), ne();
|
|
891
891
|
} catch (p) {
|
|
892
892
|
this.errorReportingService?.report({
|
|
893
893
|
message: "Rokt Kit: Failed to clear page views when targeting is disabled",
|
|
894
894
|
code: "PAGE_VIEW_CAPTURE_FAILED",
|
|
895
|
-
severity:
|
|
895
|
+
severity: S.INFO,
|
|
896
896
|
stackTrace: p instanceof Error ? p.stack : void 0
|
|
897
897
|
});
|
|
898
898
|
}
|
|
899
|
-
return a()._registerErrorReportingService && a()._registerErrorReportingService(I), a()._registerLoggingService && a()._registerLoggingService(
|
|
899
|
+
return a()._registerErrorReportingService && a()._registerErrorReportingService(I), a()._registerLoggingService && a()._registerLoggingService(v), n ? (this.testHelpers = {
|
|
900
900
|
generateLauncherScript: oe,
|
|
901
901
|
generateThankYouElementScript: ce,
|
|
902
902
|
extractRoktExtensionConfig: le,
|
|
@@ -915,7 +915,7 @@ const _ = class _ {
|
|
|
915
915
|
LoggingService: pe,
|
|
916
916
|
RateLimiter: be,
|
|
917
917
|
ErrorCodes: Q,
|
|
918
|
-
WSDKErrorSeverity:
|
|
918
|
+
WSDKErrorSeverity: S,
|
|
919
919
|
resetLauncherAttachState: () => ot(this._launcherAttachState)
|
|
920
920
|
}, this.attachLauncher(c, E), "Successfully initialized: " + d) : (N && (a().Rokt.flushOnShoppableAdsReadyMessageQueue?.(this), ae(gt, ce(f), {
|
|
921
921
|
onLoad: () => {
|
|
@@ -924,9 +924,9 @@ const _ = class _ {
|
|
|
924
924
|
onError: (p) => {
|
|
925
925
|
console.error("Error loading Rokt Thank You Element script:", p);
|
|
926
926
|
}
|
|
927
|
-
})), this.isLauncherReadyToAttach() ? this.attachLauncher(c, E,
|
|
927
|
+
})), this.isLauncherReadyToAttach() ? this.attachLauncher(c, E, b) : (ae(ht, oe(f, R), {
|
|
928
928
|
onLoad: () => {
|
|
929
|
-
this.isLauncherReadyToAttach() ? this.attachLauncher(c, E,
|
|
929
|
+
this.isLauncherReadyToAttach() ? this.attachLauncher(c, E, b) : console.error("Rokt object is not available after script load.");
|
|
930
930
|
},
|
|
931
931
|
onError: (p) => {
|
|
932
932
|
console.error("Error loading Rokt launcher script:", p);
|
|
@@ -934,9 +934,9 @@ const _ = class _ {
|
|
|
934
934
|
}), this.captureTiming(_.PERFORMANCE_MARKS.RoktScriptAppended)), "Successfully initialized: " + d);
|
|
935
935
|
}
|
|
936
936
|
process(e) {
|
|
937
|
-
if (this.isTargetingDisabled() || (e.EventDataType === pt && (De(this.loggingService), this.capturePageView(e), Pe(this._preselectState, this.buildPreselectHost(), e)), e.EventDataType === mt && (ie(), ne(), this.accountId &&
|
|
937
|
+
if (this.isTargetingDisabled() || (e.EventDataType === pt && (De(this.loggingService), this.capturePageView(e), Pe(this._preselectState, this.buildPreselectHost(), e)), e.EventDataType === mt && (ie(), ne(), this.accountId && L(this.accountId))), !this.isKitReady())
|
|
938
938
|
return "Kit not ready for forwarder: " + d;
|
|
939
|
-
if (U(a().Rokt?.setLocalSessionAttribute) && (
|
|
939
|
+
if (U(a().Rokt?.setLocalSessionAttribute) && (T(this.placementEventAttributeMappingLookup) || this.applyPlacementEventAttributeMapping(e), !T(this.placementEventMappingLookup))) {
|
|
940
940
|
const t = he(e.EventDataType, e.EventCategory, e.EventName ?? "");
|
|
941
941
|
this.placementEventMappingLookup[String(t)] && a().Rokt.setLocalSessionAttribute?.(this.placementEventMappingLookup[String(t)], !0);
|
|
942
942
|
}
|
|
@@ -956,7 +956,7 @@ const _ = class _ {
|
|
|
956
956
|
return delete this.userAttributes[e], "Successfully removed user attribute for forwarder: " + d;
|
|
957
957
|
}
|
|
958
958
|
handleIdentityComplete(e, t) {
|
|
959
|
-
return this.userAttributes =
|
|
959
|
+
return this.userAttributes = w(e.getAllUserAttributes()), "Successfully called " + t + " for forwarder: " + d;
|
|
960
960
|
}
|
|
961
961
|
onUserIdentified(e) {
|
|
962
962
|
const t = e;
|
|
@@ -995,7 +995,7 @@ const _ = class _ {
|
|
|
995
995
|
return this.handleIdentityComplete(e, "onLoginComplete");
|
|
996
996
|
}
|
|
997
997
|
onLogoutComplete(e, t) {
|
|
998
|
-
return this.userIdentifiedInWorkspace = !1, this._workspaceSearchInFlightPromise = null, this._workspaceLastSearchedIdentitiesKey = void 0, this.accountId &&
|
|
998
|
+
return this.userIdentifiedInWorkspace = !1, this._workspaceSearchInFlightPromise = null, this._workspaceLastSearchedIdentitiesKey = void 0, this.accountId && L(this.accountId), this.handleIdentityComplete(e, "onLogoutComplete");
|
|
999
999
|
}
|
|
1000
1000
|
onModifyComplete(e, t) {
|
|
1001
1001
|
return this.handleIdentityComplete(e, "onModifyComplete");
|
|
@@ -1045,26 +1045,26 @@ const _ = class _ {
|
|
|
1045
1045
|
return this._dispatchPlacements(e);
|
|
1046
1046
|
}
|
|
1047
1047
|
_dispatchPlacements(e) {
|
|
1048
|
-
const t = e && e.attributes || {}, r = { ...
|
|
1048
|
+
const t = e && e.attributes || {}, r = { ...w(this.userAttributes), ...t }, s = this.filters || {}, o = s.userAttributeFilters || [], c = s.filteredUser || null, u = c ? c.getMPID() : null;
|
|
1049
1049
|
let l;
|
|
1050
|
-
s ? s.filterUserAttributes ? l = s.filterUserAttributes(r, o) : l = r : (console.warn("Rokt Kit: No filters available, using user attributes"), l = r), this.userAttributes =
|
|
1051
|
-
const f = this._onboardingExpProvider === "Optimizely" ? this.fetchOptimizely() : {},
|
|
1052
|
-
...
|
|
1050
|
+
s ? s.filterUserAttributes ? l = s.filterUserAttributes(r, o) : l = r : (console.warn("Rokt Kit: No filters available, using user attributes"), l = r), this.userAttributes = w(l);
|
|
1051
|
+
const f = this._onboardingExpProvider === "Optimizely" ? this.fetchOptimizely() : {}, R = this.returnUserIdentities(c), b = this.returnLocalSessionAttributes(), N = Ke(te()), E = Me(), k = this.readMpSessionId(), I = this.readMpDeviceId(), v = {
|
|
1052
|
+
...R,
|
|
1053
1053
|
...l,
|
|
1054
1054
|
...f,
|
|
1055
|
-
...
|
|
1055
|
+
...b,
|
|
1056
1056
|
...N.length ? { [Et]: JSON.stringify(N) } : {},
|
|
1057
1057
|
...E ? { [_t]: E } : {},
|
|
1058
1058
|
...this.userIdentifiedInWorkspace ? { [ft]: !0 } : {},
|
|
1059
|
-
...
|
|
1060
|
-
...I ? { [
|
|
1059
|
+
...k ? { [It]: k } : {},
|
|
1060
|
+
...I ? { [yt]: I } : {},
|
|
1061
1061
|
mpid: u
|
|
1062
1062
|
}, p = this.buildCacheMatchKeys(typeof e.identifier == "string" ? e.identifier : void 0), ke = {
|
|
1063
1063
|
...e,
|
|
1064
|
-
attributes:
|
|
1064
|
+
attributes: v,
|
|
1065
1065
|
...p !== void 0 ? { cacheMatchKeys: p } : {}
|
|
1066
1066
|
}, X = this.launcher.selectPlacements(ke), Z = e.preselect === !0, ve = () => {
|
|
1067
|
-
Z || this.logSelectPlacementsEvent(
|
|
1067
|
+
Z || this.logSelectPlacementsEvent(v);
|
|
1068
1068
|
};
|
|
1069
1069
|
return Promise.resolve(X).then((we) => {
|
|
1070
1070
|
if (!Z)
|
package/dist/Rokt-Kit.iife.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var RoktKit=(function(j){"use strict";const ve=["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"],we=new Set(ve);function Z(i){return we.has(i.toLowerCase())}function R(i){const e={},t=i||{},n=Object.keys(t);for(let r=0;r<n.length;r++){const s=n[r];Z(s)||(e[s]=t[s])}return e}function f(i){return typeof i=="object"&&i!==null&&!Array.isArray(i)}function g(i){return typeof i=="string"}function L(i){return typeof i=="function"}function b(i){return i==null?!0:typeof i=="string"?i.length===0:typeof i=="object"?Object.keys(i).length===0:!1}function V(i){try{const e=new URL(i);return e.search="",e.toString()}catch{return i}}function ee(i){let e=5381;for(let t=0;t<i.length;t++)e=(e<<5)+e+i.charCodeAt(t),e=e&e;return e}const d="mp-rokt-kit",te="__rokt_ls_probe__";function W(){try{return window.localStorage.setItem(te,"1"),window.localStorage.removeItem(te),!0}catch{return!1}}const I=()=>window.localStorage;function H(i,e=I){try{const t=e().getItem(i);return t===null?null:JSON.parse(t)}catch{return null}}function ie(i,e,t=I){try{return t().setItem(i,JSON.stringify(e)),!0}catch{return!1}}function Te(i,e=I){try{e().removeItem(i)}catch{}}function k(i,e,t=I){const n=H(i,t);return f(n)?n[e]:void 0}function O(i,e,t,n=I){const r=H(i,n),s=f(r)?{...r}:{};return s[e]=t,ie(i,s,n)}function N(i,e,t=I){const n=H(i,t);if(!f(n)||!(e in n))return;const r={...n};delete r[e],Object.keys(r).length===0?Te(i,t):ie(i,r,t)}const z="pageViews",U="utmParams",ne=25,Le=["utm_source","utm_medium","utm_campaign","utm_term","utm_content"];function re(i){return i.slice(-ne)}function se(){const i=k(d,z);return Array.isArray(i)?i:[]}function Oe(i){const e=re(i);for(let t=0;t<e.length;t++){const n=e.slice(t);if(O(d,z,n))return n.length}return 0}function oe(){N(d,z)}function Ne(i){const e=re(i);return e.map((t,n)=>{const r=t.activeTimeOnSite,s=r!==void 0&&Number.isFinite(r),c=e[n+1]?.activeTimeOnSite,u=c!==void 0&&Number.isFinite(c),l=s&&u?c-r:void 0;return{pageUrl:t.pageUrl,sourceMessageId:t.sourceMessageId,timestamp:t.timestamp,...t.pageTitle!==void 0?{pageTitle:t.pageTitle}:{},...t.canonicalUrl!==void 0?{canonicalUrl:t.canonicalUrl}:{},...s?{activeTimeOnSite:r}:{},...l!==void 0&&l>=0?{activeTimeOnPage:l}:{}}})}function Ue(i){if(k(d,U)!==void 0)return;const e=new URLSearchParams(window.location.search),t={};for(const r of Le){const s=e.get(r);s&&(t[r]=s)}if(Object.keys(t).length===0)return;const n=Object.keys(t).join(", ");if(!O(d,U,t)){const r=W()?"quota":"ls_unavailable";i?.log({message:`Rokt Kit: Failed to persist UTM params [reason: ${r}]`,code:"UTM_CAPTURE_FAILED"});return}i?.log({message:`Rokt Kit: Captured UTM params [${n}]`,code:"UTM_CAPTURE_SUCCESS"})}function Ce(){const i=k(d,U);return f(i)?i:null}function ce(){N(d,U)}function Ke(){const e=document.querySelector('link[rel="canonical"]')?.href;if(e)return V(e)}const $=[{accountId:"2919171670744024290",pathname:"/checkout",targetPageIdentifier:"prod.rokt.conf",attributeKeys:["email","amount","concessions_total","customertype","eventvenue","firstname","lastname","member_status","billingzipcode","currency"]}],De=6e4;function Me(i){return f(i)&&typeof i.expiresAt=="number"&&f(i.attributes)}function Fe(i,e){return`activePreselect:${i}:${e}`}function xe(i){const e=k(d,i);return Me(e)?e:null}function Ye(i,e){O(d,i,{expiresAt:Date.now()+De,attributes:e})}const Ge=2*6e4;function C(){return window.sessionStorage}function je(i){return f(i)&&typeof i.expiresAt=="number"&&g(i.pathname)&&g(i.identifier)&&f(i.attributes)&&g(i.mpid)}function q(i){return`pendingPreselect:${i}`}function Ve(i){const e=q(i),t=k(d,e,C);return je(t)?t.expiresAt<=Date.now()?(N(d,e,C),null):t:null}function We(i,e,t,n,r){return O(d,q(i),{expiresAt:Date.now()+Ge,pathname:e,identifier:t,attributes:n,mpid:r},C)}function v(i){N(d,q(i),C)}function S(i,e){const t={fired:"PRESELECT_FIRED",missed:"PRESELECT_MISSED",queued:"PRESELECT_QUEUED",skipped:"PRESELECT_SKIPPED"};return{message:`Rokt Kit: preselect ${i} [reason=${e}]`,code:t[i]}}function He(i,e){if(i)return $.find(t=>t.accountId===i&&t.pathname===e)}function ze(i,e){if(!(!i||!g(e)))return $.find(t=>t.accountId===i&&t.targetPageIdentifier===e)}function $e(i,e){return i?$.some(t=>t.accountId===i&&t.attributeKeys.includes(e)):!1}function qe(){return{pending:[]}}function J(i,e){const t=i.pending.findIndex(n=>n.pathname===e.pathname);if(t>=0){i.pending[t]=e;return}i.pending.push(e)}function B(i){if(!i?.getUserIdentities)return!1;const e=i.getUserIdentities().userIdentities;return e?Object.keys(e).some(t=>{const n=e[t];return g(n)&&n.length>0}):!1}function ae(i){const e=i?.getMPID?.();return e==null?null:String(e)}function le(i,e,t){const n=i.filteredUser?.getAllUserAttributes?.()||{},r={},s=[];for(const o of t.attributeKeys){const c=i.getEventAttributeValue(e,o),u=b(c)?i.userAttributes[o]??n[o]:c;if(b(u)){s.push(o);continue}r[o]=u}return{collected:r,missingKeys:s}}function Je(i,e){Promise.resolve(i.selectPlacements(e)).catch(t=>{const n=t instanceof Error?t.message:String(t);i.log({message:`Rokt Kit: Preselect selectPlacements call failed: ${n}`,code:"PRESELECT_DISPATCH_FAILED"})})}function ue(i,e,t,n,r,s){const o=Fe(e,t),c=xe(o),u=!!c&&JSON.stringify(c.attributes)===JSON.stringify(r);if(c&&c.expiresAt>Date.now()&&u){i.logPlacementDiagnostic(S("skipped","active_preselection"));return}Ye(o,r),i.logPlacementDiagnostic(S("fired",s)),Je(i,{attributes:r,preselect:!0,identifier:n,omitUrl:!0})}function Be(i,e){if(!e.accountId||!e.isKitReady())return;const t=Ve(e.accountId);if(t){if(i.pending.some(n=>n.pathname===t.pathname)){v(e.accountId);return}if(!e.isPreselectionEnabled()){v(e.accountId);return}B(e.filteredUser)&&(v(e.accountId),ae(e.filteredUser)===t.mpid&&ue(e,e.accountId,t.identifier,t.identifier,t.attributes,"recovered"))}}function de(i,e,t,n=window.location.pathname){const r=He(e.accountId,n);if(!r)return;if(!e.isKitReady()){J(i,{event:t,pathname:n}),e.logPlacementDiagnostic(S("queued","not_ready"));const c=ae(e.filteredUser);if(e.accountId&&c&&B(e.filteredUser)){const{collected:u,missingKeys:l}=le(e,t,r);if(l.length===0){const p=R(u);We(e.accountId,n,r.targetPageIdentifier,p,c)||e.logPlacementDiagnostic(S("queued","persist_failed"))}}return}if(!e.isPreselectionEnabled())return;if(!B(e.filteredUser)){e.logPlacementDiagnostic(S("missed","no_valid_identity")),J(i,{event:t,pathname:n});return}const{collected:s,missingKeys:o}=le(e,t,r);if(o.length>0){for(const c of o)e.logPlacementDiagnostic(S("missed",`missing_attribute:${c}`));J(i,{event:t,pathname:n});return}ue(e,e.accountId||"",n,r.targetPageIdentifier,s,"fired")}function Qe(i,e,t=window.location.pathname){if(Be(i,e),i.pending.length===0)return;const n=i.pending;i.pending=[],n.forEach(({event:r,pathname:s})=>{s===t&&de(i,e,r,s)})}function Xe(){return{context:null,lifecycle:"idle",recreateInFlight:null}}function Ze(i,e){i.context={accountId:e.accountId,launcherOptions:{...e.launcherOptions},legacyRoktExtensions:[...e.legacyRoktExtensions]}}function et(i){i.lifecycle="attached"}function tt(i){i.lifecycle!=="idle"&&(i.lifecycle="terminated")}function it(i){i.lifecycle="terminated"}function nt(i){i.context=null,i.lifecycle="idle",i.recreateInFlight=null}function rt(i,e,t){if(i.recreateInFlight)return i.recreateInFlight;if(i.lifecycle!=="terminated"||!i.context||!e)return;i.lifecycle="recreating";const n=i.context;return i.recreateInFlight=t(n).finally(()=>{i.recreateInFlight=null}),i.recreateInFlight}const h="Rokt",K=181,st="selectPlacements",ot="apps.roktecommerce.com",ct=.1,at="ThankYouPageJourney",lt="rokt-launcher",ut="rokt-thank-you-element",dt="userIdentifiedInWorkspace",ht=3,gt=2,ft="page_events",pt="page_view_attributes",mt="mparticle_session_id",Et="mparticle_device_id",he=500,Q={UNKNOWN_ERROR:"UNKNOWN_ERROR",UNHANDLED_EXCEPTION:"UNHANDLED_EXCEPTION",IDENTITY_REQUEST:"IDENTITY_REQUEST",LOG_DELIVERY_FAILURE:"LOG_DELIVERY_FAILURE"},y={ERROR:"ERROR",INFO:"INFO",WARNING:"WARNING"},_t="apps.rokt-api.com",It="/v1/log",St="/v1/errors",yt=10;function a(){return window.mParticle}function ge(i,e){const n=[D(i),"/wsdk/integrations/launcher.js"].join("");return!e||e.length===0?n:n+"?extensions="+e.join(",")}function fe(i){return[D(i),"/rokt-elements/rokt-element-thank-you.js"].join("")}function D(i){const e=i!==void 0?i:_t;return e.includes("://")?e.replace(/\/+$/,""):["https://",e].join("")}function pe(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 D(r)+t}function me(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 M(i){if(!i)return[];try{return JSON.parse(i.replace(/"/g,'"'))}catch{console.error("Settings string contains invalid JSON")}return[]}function Ee(i){const e=i?M(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(at)):t.push(o)}return{roktExtensionsQueryParams:t,legacyRoktExtensions:n,loadThankYouElement:r}}async function At(i,e){const t=[];if(e)for(const n of i)t.push(e.use(n));return Promise.all(t)}function _e(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 Ie(i){const e={};if(!Array.isArray(i))return e;for(let t=0;t<i.length;t++){const n=i[t];if(!n||!g(n.value)||!g(n.map))continue;const r=n.value,s=n.map;e[r]||(e[r]=[]),e[r].push({eventAttributeKey:s,conditions:Array.isArray(n.conditions)?n.conditions:[]})}return e}function Se(i,e,t){return a().generateHash([i,e,t].join(""))}function Pt(i){let n="mParticle_wsdkv_"+a().getVersion()+"_kitv_"+"3.2.3";return i&&(n+="_"+i),n}function X(i){const e=document.createElement("iframe");e.style.display="none",e.setAttribute("sandbox","allow-scripts allow-same-origin"),e.src=i,e.onload=function(){e.onload=null,e.parentNode&&e.parentNode.removeChild(e)};const t=document.body||document.head;t&&t.appendChild(e)}function ye(i,e){const t=ee(window.location.origin);if(A._allowedOriginHashes.indexOf(t)===-1||Math.random()>=ct)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?D(i):"https://apps.rokt.com";X(c+"/v1/wsdk-init/index.html?"+o),X("https://"+ot+"/v1/wsdk-init/index.html?"+o+"&isControl=true")}function Rt(){return typeof window<"u"&&!!window.location?.search?.toLowerCase().includes("mp_enable_logging=true")}function bt(){return typeof window<"u"?window.location?.href:void 0}function kt(){return typeof window<"u"?window.navigator?.userAgent:void 0}class Ae{constructor(){this._logCount={}}incrementAndCheck(e){const n=(this._logCount[e]||0)+1;return this._logCount[e]=n,n>yt}}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 Ae,this._isEnabled=Rt()||o}send(e,t,n,r,s,o){if(!(!this._isEnabled||this._rateLimiter.incrementAndCheck(t)))try{const c={additionalInformation:{message:n,version:this._integrationName},severity:t,code:r||Q.UNKNOWN_ERROR,url:bt(),deviceInfo:kt(),stackTrace:s,reporter:this._reporter,integration:this._integrationName},u={Accept:"text/plain;charset=UTF-8","Content-Type":"application/json","rokt-launcher-version":this._integrationName,"rokt-wsdk-version":"joint"};this._launcherInstanceGuid&&(u["rokt-launcher-instance-guid"]=this._launcherInstanceGuid),this._accountId&&(u["rokt-account-id"]=this._accountId),fetch(e,{method:"POST",headers:u,body:JSON.stringify(c)}).then(l=>{if(!l.ok){const p=new Error("HTTP "+l.status+" from log endpoint");throw p.statusCode=l.status,p}}).catch(l=>{console.error("ReportingTransport: Failed to send log",l),o&&o(l)})}catch(c){console.error("ReportingTransport: Failed to send log",c),o&&o(c)}}}class Pe{constructor(e,t,n,r,s){this._transport=new F(e,t,n,r,s),this._errorUrl=pe(e?.errorUrl,e?.integrationDomain,St)}report(e){if(!e)return;const t=e.severity||y.ERROR;this._transport.send(this._errorUrl,t,e.message,e.code,e.stackTrace)}}class Re{constructor(e,t,n,r,s,o){this._transport=new F(e,n,r,s,o),this._placementDiagnosticTransport=new F(e,n,r,s),this._loggingUrl=pe(e?.loggingUrl,e?.integrationDomain,It),this._errorReportingService=t}log(e){e&&this._send(this._transport,e)}logPlacementDiagnostic(e){e&&this._send(this._placementDiagnosticTransport,e)}_send(e,t){e.send(this._loggingUrl,y.INFO,t.message,t.code,void 0,n=>{if(this._errorReportingService){const r=typeof n.statusCode=="number";this._errorReportingService.report({message:"LoggingService: Failed to send log: "+n.message,code:Q.LOG_DELIVERY_FAILURE,severity:r?y.ERROR:y.WARNING})}})}}function vt(i){const e=V(window.location.href),t=i.EventAttributes?.title||document.title,n=Ke(),r=i.ActiveTimeOnSite;return{pageUrl:e,sourceMessageId:i.SourceMessageId,timestamp:i.Timestamp,...t?{pageTitle:t}:{},...n!==void 0?{canonicalUrl:n}:{},...Number.isFinite(r)?{activeTimeOnSite:r}:{}}}const E=class E{constructor(){this.name=h,this.id=K,this.moduleId=K,this.isInitialized=!1,this.launcher=null,this.filters={},this.userAttributes={},this.userIdentifiedInWorkspace=!1,this.testHelpers=null,this.placementEventMappingLookup={},this.placementEventAttributeMappingLookup={},this.integrationName=null,this.errorReportingService=null,this.loggingService=null,this._thankYouElementOnLoadCallback=null,this._isThankYouElementLoaded=!1,this._workspaceSearchInFlightPromise=null,this._launcherAttachState=Xe(),this.accountId=null,this._preselectState=qe()}getEventAttributeValue(e,t){const n=e&&e.EventAttributes;return!n||n[t]===void 0?null:n[t]}doesEventAttributeConditionMatch(e,t){if(!e||!g(e.operator))return!1;const n=e.operator.toLowerCase(),r=e.attributeValue;return n==="exists"?t!==null:t==null?!1:n==="equals"?String(t)===String(r):n==="contains"?String(t).indexOf(String(r))!==-1:!1}doesEventMatchRule(e,t){if(!t||!g(t.eventAttributeKey))return!1;const n=t.conditions;if(!Array.isArray(n))return!1;const r=this.getEventAttributeValue(e,t.eventAttributeKey);if(n.length===0)return r!==null;for(let s=0;s<n.length;s++)if(!this.doesEventAttributeConditionMatch(n[s],r))return!1;return!0}applyPlacementEventAttributeMapping(e){const t=Object.keys(this.placementEventAttributeMappingLookup);for(let n=0;n<t.length;n++){const r=t[n],s=this.placementEventAttributeMappingLookup[r];if(b(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=V(window.location.href);const n=se(),r=vt(e);n.push(r);const s=Math.min(n.length,ne),o=Oe(n);if(o===0){const c=W()?"quota":"ls_unavailable";this.loggingService?.log({message:`Rokt Kit: Failed to persist page view for ${t} [reason: ${c}]`,code:"PAGE_VIEW_CAPTURE_FAILED"})}else o<s&&this.loggingService?.log({message:`Rokt Kit: Page view storage reduced from ${s} to ${o} record(s) under quota pressure [reason: quota_eviction]`,code:"PAGE_VIEW_QUOTA_EVICTION"})}catch(n){const r=W()?"exception":"ls_unavailable",s=n instanceof Error?n.message:String(n);this.loggingService?.log({message:`Rokt Kit: Failed to capture page view for ${t}: ${s} [reason: ${r}]`,code:"PAGE_VIEW_CAPTURE_FAILED"})}}isPreselectionEnabled(){return this.launcher?.enablePreselection===!0}buildCacheMatchKeys(e){if(!this.isPreselectionEnabled())return;const t=ze(this.accountId,e);if(t)return t.attributeKeys}buildPreselectHost(){return{accountId:this.accountId,filteredUser:this.filters.filteredUser,userAttributes:this.userAttributes,isKitReady:()=>this.isKitReady(),isPreselectionEnabled:()=>this.isPreselectionEnabled(),getEventAttributeValue:(e,t)=>this.getEventAttributeValue(e,t),logPlacementDiagnostic:e=>this.loggingService?.logPlacementDiagnostic(e),log:e=>this.loggingService?.log(e),selectPlacements:e=>this.selectPlacements(e)}}flushPendingPreselectDispatches(){Qe(this._preselectState,this.buildPreselectHost())}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[E.EMAIL_SHA256_KEY]=e[n]),n&&delete t[n],t}logSelectPlacementsEvent(e){if(!window.mParticle||typeof a().logEvent!="function"||!f(e))return;const t=a().EventType.Other;a().logEvent(st,t,e)}setRoktSessionId(e){if(!(!e||typeof e!="string"))try{const t=a().getInstance();t&&L(t.setIntegrationAttribute)&&t.setIntegrationAttribute(K,{roktSessionId:e})}catch{}}readMpSessionId(){const e=a()?.sessionManager,t=e?.getSessionId??e?.getSession;if(L(t))return t.call(e)||void 0}readMpDeviceId(){return a()?.getDeviceId?.()||void 0}attachLauncher(e,t,n=[]){Ze(this._launcherAttachState,{accountId:e,launcherOptions:t||{},legacyRoktExtensions:n});const r={accountId:e,...t||{}};let s;return this.isPartnerInLocalLauncherTestGroup()?s=Promise.resolve(window.Rokt.createLocalLauncher(r)):s=window.Rokt.createLauncher(r),s.then(async o=>{await At([...n],o),this.initRoktLauncher(o)}).catch(o=>{it(this._launcherAttachState),console.error("Error creating Rokt launcher:",o)})}recreateLauncherIfTerminated(){return rt(this._launcherAttachState,this.isLauncherReadyToAttach(),e=>this.attachLauncher(e.accountId,e.launcherOptions,e.legacyRoktExtensions))}initRoktLauncher(e){window.Rokt&&(window.Rokt.currentLauncher=e),this.launcher=e,et(this._launcherAttachState);const t=a().Rokt?.filters;t?(this.filters=t,t.filteredUser?this._workspaceSearchInFlightPromise=this.search(t.filteredUser):console.warn("Rokt Kit: No filtered user has been set.")):console.warn("Rokt Kit: No filters have been set."),this.isInitialized=!0,ye(this.domain,this.integrationName),a().Rokt.attachKit(this),this.flushPendingPreselectDispatches()}fetchOptimizely(){const e=a()._getActiveForwarders().filter(t=>t.name==="Optimizely");try{if(e.length>0&&window.optimizely){const t=window.optimizely.get("state");return!t||!t.getActiveExperimentIds?{}:t.getActiveExperimentIds().reduce((s,o)=>(s["rokt.custom.optimizely.experiment."+o+".variationId"]=t.getVariationMap()[o].id,s),{})}}catch(t){console.error("Error fetching Optimizely attributes:",t)}return{}}isKitReady(){return!!(this.isInitialized&&this.launcher)}isTargetingDisabled(){return a().Rokt?.launcherOptions?.noTargeting===!0}isPartnerInLocalLauncherTestGroup(){return!!(a().config&&a().config.isLocalLauncherEnabled&&this.isAssignedToSampleGroup())}isAssignedToSampleGroup(){return Math.random()>.5}captureTiming(e){window&&a()&&a().captureTiming&&e&&a().captureTiming(e)}init(e,t,n,r,s){const o=e,c=o.accountId;this.accountId=c||null,this.userAttributes=R(s),this._onboardingExpProvider=o.onboardingExpProvider;const u=M(o.placementEventMapping);this.placementEventMappingLookup=_e(u);const l=M(o.placementEventAttributeMapping);this.placementEventAttributeMappingLookup=Ie(l),o.hashedEmailUserIdentityType&&(this._mappedEmailSha256Key=o.hashedEmailUserIdentityType.toLowerCase()),this._workspaceIdSyncApiKey=g(o.workspaceIdSyncApiKey)?o.workspaceIdSyncApiKey:void 0;const p=a().Rokt?.domain,{roktExtensionsQueryParams:x,legacyRoktExtensions:Y,loadThankYouElement:G}=Ee(o.roktExtensions),_={...a().Rokt?.launcherOptions||{}};this.integrationName=Pt(_.integrationName),_.integrationName=this.integrationName,this.domain=p;const w={loggingUrl:o.loggingUrl,errorUrl:o.errorUrl,integrationDomain:p,isLoggingEnabled:a().config?.isLoggingEnabled===!0},P=new Pe(w,this.integrationName,window.__rokt_li_guid__,o.accountId),T=new Re(w,P,this.integrationName,window.__rokt_li_guid__,o.accountId);if(this.errorReportingService=P,this.loggingService=T,this.isTargetingDisabled())try{oe(),ce()}catch(m){this.errorReportingService?.report({message:"Rokt Kit: Failed to clear page views when targeting is disabled",code:"PAGE_VIEW_CAPTURE_FAILED",severity:y.INFO,stackTrace:m instanceof Error?m.stack:void 0})}return a()._registerErrorReportingService&&a()._registerErrorReportingService(P),a()._registerLoggingService&&a()._registerLoggingService(T),n?(this.testHelpers={generateLauncherScript:ge,generateThankYouElementScript:fe,extractRoktExtensionConfig:Ee,hashEventMessage:Se,parseSettingsString:M,generateMappedEventLookup:_e,generateMappedEventAttributeLookup:Ie,sendAdBlockMeasurementSignals:ye,createAutoRemovedIframe:X,djb2:ee,setAllowedOriginHashes:m=>{E._allowedOriginHashes=m},ReportingTransport:F,ErrorReportingService:Pe,LoggingService:Re,RateLimiter:Ae,ErrorCodes:Q,WSDKErrorSeverity:y,resetLauncherAttachState:()=>nt(this._launcherAttachState)},this.attachLauncher(c,_),"Successfully initialized: "+h):(G&&(a().Rokt.flushOnShoppableAdsReadyMessageQueue?.(this),me(ut,fe(p),{onLoad:()=>{this._isThankYouElementLoaded=!0,this._thankYouElementOnLoadCallback&&this._thankYouElementOnLoadCallback()},onError:m=>{console.error("Error loading Rokt Thank You Element script:",m)}})),this.isLauncherReadyToAttach()?this.attachLauncher(c,_,Y):(me(lt,ge(p,x),{onLoad:()=>{this.isLauncherReadyToAttach()?this.attachLauncher(c,_,Y):console.error("Rokt object is not available after script load.")},onError:m=>{console.error("Error loading Rokt launcher script:",m)}}),this.captureTiming(E.PERFORMANCE_MARKS.RoktScriptAppended)),"Successfully initialized: "+h)}process(e){if(this.isTargetingDisabled()||(e.EventDataType===ht&&(Ue(this.loggingService),this.capturePageView(e),de(this._preselectState,this.buildPreselectHost(),e)),e.EventDataType===gt&&(oe(),ce(),this.accountId&&v(this.accountId))),!this.isKitReady())return"Kit not ready for forwarder: "+h;if(L(a().Rokt?.setLocalSessionAttribute)&&(b(this.placementEventAttributeMappingLookup)||this.applyPlacementEventAttributeMapping(e),!b(this.placementEventMappingLookup))){const t=Se(e.EventDataType,e.EventCategory,e.EventName??"");this.placementEventMappingLookup[String(t)]&&a().Rokt.setLocalSessionAttribute?.(this.placementEventMappingLookup[String(t)],!0)}return"Successfully sent to forwarder: "+h}setExtensionData(e){if(!this.isKitReady()){console.error("Rokt Kit: Not initialized");return}window.Rokt.setExtensionData(e)}setUserAttribute(e,t){return Z(e)||(this.userAttributes[e]=t),$e(this.accountId,e)&&this.flushPendingPreselectDispatches(),"Successfully set user attribute for forwarder: "+h}removeUserAttribute(e){return delete this.userAttributes[e],"Successfully removed user attribute for forwarder: "+h}handleIdentityComplete(e,t){return this.userAttributes=R(e.getAllUserAttributes()),"Successfully called "+t+" for forwarder: "+h}onUserIdentified(e){const t=e;this.filters.filteredUser=t,this._workspaceSearchInFlightPromise=this.search(t);const n=this.handleIdentityComplete(e,"onUserIdentified");return this.flushPendingPreselectDispatches(),n}search(e){const t=this._workspaceIdSyncApiKey;if(!t)return this.userIdentifiedInWorkspace=!1,this._workspaceLastSearchedIdentitiesKey=void 0,Promise.resolve();const n=a().Identity?.search;if(typeof n!="function")return this.userIdentifiedInWorkspace=!1,this._workspaceLastSearchedIdentitiesKey=void 0,Promise.resolve();const r=e.getUserIdentities?e.getUserIdentities().userIdentities:null,s={};if(r)for(const u of Object.keys(r)){const l=r[u];g(l)&&l.length>0&&(s[u]=l)}const o=Object.keys(s);if(o.length===0)return this.userIdentifiedInWorkspace=!1,this._workspaceLastSearchedIdentitiesKey=void 0,Promise.resolve();const c=o.sort().map(u=>`${u}=${s[u]}`).join("&");return c===this._workspaceLastSearchedIdentitiesKey?this._workspaceSearchInFlightPromise||Promise.resolve():(this.userIdentifiedInWorkspace=!1,this._workspaceLastSearchedIdentitiesKey=c,new Promise(u=>{try{n(t,s,l=>{l?.httpCode===200&&(this.userIdentifiedInWorkspace=!0),u()})}catch(l){console.error("Rokt Kit: Workspace IDSync search failed",l),this._workspaceLastSearchedIdentitiesKey=void 0,u()}}))}onLoginComplete(e,t){return this.handleIdentityComplete(e,"onLoginComplete")}onLogoutComplete(e,t){return this.userIdentifiedInWorkspace=!1,this._workspaceSearchInFlightPromise=null,this._workspaceLastSearchedIdentitiesKey=void 0,this.accountId&&v(this.accountId),this.handleIdentityComplete(e,"onLogoutComplete")}onModifyComplete(e,t){return this.handleIdentityComplete(e,"onModifyComplete")}selectPlacements(e){const t=this.recreateLauncherIfTerminated();if(t){const n=this._workspaceSearchInFlightPromise,r=n?Promise.race([n,new Promise(s=>setTimeout(s,he))]):Promise.resolve();return Promise.all([t,r]).then(()=>this._dispatchPlacements(e))}if(this._workspaceSearchInFlightPromise){const n=this._workspaceSearchInFlightPromise;return Promise.race([n,new Promise(r=>setTimeout(r,he))]).then(()=>this._dispatchPlacements(e))}return this._dispatchPlacements(e)}_dispatchPlacements(e){const t=e&&e.attributes||{},r={...R(this.userAttributes),...t},s=this.filters||{},o=s.userAttributeFilters||[],c=s.filteredUser||null,u=c?c.getMPID():null;let l;s?s.filterUserAttributes?l=s.filterUserAttributes(r,o):l=r:(console.warn("Rokt Kit: No filters available, using user attributes"),l=r),this.userAttributes=R(l);const p=this._onboardingExpProvider==="Optimizely"?this.fetchOptimizely():{},x=this.returnUserIdentities(c),Y=this.returnLocalSessionAttributes(),G=Ne(se()),_=Ce(),w=this.readMpSessionId(),P=this.readMpDeviceId(),T={...x,...l,...p,...Y,...G.length?{[ft]:JSON.stringify(G)}:{},..._?{[pt]:_}:{},...this.userIdentifiedInWorkspace?{[dt]:!0}:{},...w?{[mt]:w}:{},...P?{[Et]:P}:{},mpid:u},m=this.buildCacheMatchKeys(typeof e.identifier=="string"?e.identifier:void 0),Lt={...e,attributes:T,...m!==void 0?{cacheMatchKeys:m}:{}},be=this.launcher.selectPlacements(Lt),ke=e.preselect===!0,Ot=()=>{ke||this.logSelectPlacementsEvent(T)};return Promise.resolve(be).then(Nt=>{if(!ke)return Nt?.context?.sessionId?.then(Ut=>this.setRoktSessionId(Ut))}).catch(()=>{}).finally(Ot),be}hashAttributes(e){return this.isKitReady()?this.launcher.hashAttributes(e):(console.error("Rokt Kit: Not initialized"),null)}use(e){return this.isKitReady()?!e||!g(e)?Promise.reject(new Error("Rokt Kit: Invalid extension name")):this.launcher.use(e):(console.error("Rokt Kit: Not initialized"),Promise.reject(new Error("Rokt Kit: Not initialized")))}terminate(){return this.isKitReady()?(tt(this._launcherAttachState),this.launcher.terminate()):(console.error("Rokt Kit: Not initialized"),Promise.resolve())}onShoppableAdsReady(e){this._isThankYouElementLoaded?e():this._thankYouElementOnLoadCallback=e}};E._allowedOriginHashes=[-553112570,549508659],E.PERFORMANCE_MARKS={RoktScriptAppended:"mp:RoktScriptAppended"},E.EMAIL_SHA256_KEY="emailsha256";let A=E;function wt(){return K}function Tt(i){if(!i){window.console.log("You must pass a config object to register the kit "+h);return}if(!f(i)){window.console.log("'config' must be an object. You passed in a "+typeof i);return}f(i.kits)?i.kits[h]={constructor:A}:(i.kits={},i.kits[h]={constructor:A}),window.console.log("Successfully registered "+h+" to your mParticle configuration")}return typeof window<"u"&&window.mParticle&&a().addForwarder&&a().addForwarder({name:h,constructor:A,getId:wt}),j.register=Tt,Object.defineProperty(j,Symbol.toStringTag,{value:"Module"}),j})({});
|
|
1
|
+
var RoktKit=(function(j){"use strict";const ve=["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"],we=new Set(ve);function Z(i){return we.has(i.toLowerCase())}function R(i){const e={},t=i||{},n=Object.keys(t);for(let r=0;r<n.length;r++){const s=n[r];Z(s)||(e[s]=t[s])}return e}function f(i){return typeof i=="object"&&i!==null&&!Array.isArray(i)}function g(i){return typeof i=="string"}function N(i){return typeof i=="function"}function b(i){return i==null?!0:typeof i=="string"?i.length===0:typeof i=="object"?Object.keys(i).length===0:!1}function V(i){try{const e=new URL(i);return e.search="",e.toString()}catch{return i}}function ee(i){let e=5381;for(let t=0;t<i.length;t++)e=(e<<5)+e+i.charCodeAt(t),e=e&e;return e}const d="mp-rokt-kit",te="__rokt_ls_probe__";function W(){try{return window.localStorage.setItem(te,"1"),window.localStorage.removeItem(te),!0}catch{return!1}}const I=()=>window.localStorage;function H(i,e=I){try{const t=e().getItem(i);return t===null?null:JSON.parse(t)}catch{return null}}function ie(i,e,t=I){try{return t().setItem(i,JSON.stringify(e)),!0}catch{return!1}}function Te(i,e=I){try{e().removeItem(i)}catch{}}function k(i,e,t=I){const n=H(i,t);return f(n)?n[e]:void 0}function U(i,e,t,n=I){const r=H(i,n),s=f(r)?{...r}:{};return s[e]=t,ie(i,s,n)}function C(i,e,t=I){const n=H(i,t);if(!f(n)||!(e in n))return;const r={...n};delete r[e],Object.keys(r).length===0?Te(i,t):ie(i,r,t)}const z="pageViews",K="utmParams",ne=25,Le=["utm_source","utm_medium","utm_campaign","utm_term","utm_content"];function re(i){return i.slice(-ne)}function se(){const i=k(d,z);return Array.isArray(i)?i:[]}function Oe(i){const e=re(i);for(let t=0;t<e.length;t++){const n=e.slice(t);if(U(d,z,n))return n.length}return 0}function oe(){C(d,z)}function Ne(i){const e=re(i);return e.map((t,n)=>{const r=t.activeTimeOnSite,s=r!==void 0&&Number.isFinite(r),c=e[n+1]?.activeTimeOnSite,u=c!==void 0&&Number.isFinite(c),l=s&&u?c-r:void 0;return{pageUrl:t.pageUrl,sourceMessageId:t.sourceMessageId,timestamp:t.timestamp,...t.pageTitle!==void 0?{pageTitle:t.pageTitle}:{},...t.canonicalUrl!==void 0?{canonicalUrl:t.canonicalUrl}:{},...s?{activeTimeOnSite:r}:{},...l!==void 0&&l>=0?{activeTimeOnPage:l}:{}}})}function Ue(i){if(k(d,K)!==void 0)return;const e=new URLSearchParams(window.location.search),t={};for(const r of Le){const s=e.get(r);s&&(t[r]=s)}if(Object.keys(t).length===0)return;const n=Object.keys(t).join(", ");if(!U(d,K,t)){const r=W()?"quota":"ls_unavailable";i?.log({message:`Rokt Kit: Failed to persist UTM params [reason: ${r}]`,code:"UTM_CAPTURE_FAILED"});return}i?.log({message:`Rokt Kit: Captured UTM params [${n}]`,code:"UTM_CAPTURE_SUCCESS"})}function Ce(){const i=k(d,K);return f(i)?i:null}function ce(){C(d,K)}function Ke(){const e=document.querySelector('link[rel="canonical"]')?.href;if(e)return V(e)}const $=[{accountId:"2919171670744024290",pathname:"/checkout",targetPageIdentifier:"prod.rokt.conf",attributeKeys:["email","amount","concessions_total","customertype","eventvenue","firstname","lastname","member_status","billingzipcode","currency"]}],De=6e4;function Me(i){return f(i)&&typeof i.expiresAt=="number"&&f(i.attributes)}function Fe(i,e){return`activePreselect:${i}:${e}`}function xe(i){const e=k(d,i);return Me(e)?e:null}function Ye(i,e){U(d,i,{expiresAt:Date.now()+De,attributes:e})}const Ge=2*6e4;function D(){return window.sessionStorage}function je(i){return f(i)&&typeof i.expiresAt=="number"&&g(i.pathname)&&g(i.identifier)&&f(i.attributes)&&g(i.mpid)}function q(i){return`pendingPreselect:${i}`}function Ve(i){const e=q(i),t=k(d,e,D);return je(t)?t.expiresAt<=Date.now()?(C(d,e,D),null):t:null}function We(i,e,t,n,r){return U(d,q(i),{expiresAt:Date.now()+Ge,pathname:e,identifier:t,attributes:n,mpid:r},D)}function v(i){C(d,q(i),D)}function y(i,e){const t={fired:"PRESELECT_FIRED",missed:"PRESELECT_MISSED",queued:"PRESELECT_QUEUED",skipped:"PRESELECT_SKIPPED"};return{message:`Rokt Kit: preselect ${i} [reason=${e}]`,code:t[i]}}function He(i,e){if(i)return $.find(t=>t.accountId===i&&t.pathname===e)}function ze(i,e){if(!(!i||!g(e)))return $.find(t=>t.accountId===i&&t.targetPageIdentifier===e)}function $e(i,e){return i?$.some(t=>t.accountId===i&&t.attributeKeys.includes(e)):!1}function qe(){return{pending:[]}}function J(i,e){const t=i.pending.findIndex(n=>n.pathname===e.pathname);if(t>=0){i.pending[t]=e;return}i.pending.push(e)}function B(i){if(!i?.getUserIdentities)return!1;const e=i.getUserIdentities().userIdentities;return e?Object.keys(e).some(t=>{const n=e[t];return g(n)&&n.length>0}):!1}function ae(i){const e=i?.getMPID?.();return e==null?null:String(e)}function le(i,e,t){const n=i.filteredUser?.getAllUserAttributes?.()||{},r={},s=[];for(const o of t.attributeKeys){const c=i.getEventAttributeValue(e,o),u=b(c)?i.userAttributes[o]??n[o]:c;if(b(u)){s.push(o);continue}r[o]=u}return{collected:r,missingKeys:s}}function Je(i,e){Promise.resolve(i.selectPlacements(e)).catch(t=>{const n=t instanceof Error?t.message:String(t);i.log({message:`Rokt Kit: Preselect selectPlacements call failed: ${n}`,code:"PRESELECT_DISPATCH_FAILED"})})}function ue(i,e,t,n,r,s){const o=Fe(e,t),c=xe(o),u=!!c&&JSON.stringify(c.attributes)===JSON.stringify(r);if(c&&c.expiresAt>Date.now()&&u){i.logPlacementDiagnostic(y("skipped","active_preselection"));return}Ye(o,r),i.logPlacementDiagnostic(y("fired",s)),Je(i,{attributes:r,preselect:!0,identifier:n,omitUrl:!0})}function Be(i,e){if(!e.accountId||!e.isKitReady())return;const t=Ve(e.accountId);if(t){if(i.pending.some(n=>n.pathname===t.pathname)){v(e.accountId);return}if(!e.isPreselectionEnabled()){v(e.accountId);return}B(e.filteredUser)&&(v(e.accountId),ae(e.filteredUser)===t.mpid&&ue(e,e.accountId,t.identifier,t.identifier,t.attributes,"recovered"))}}function de(i,e,t,n=window.location.pathname){const r=He(e.accountId,n);if(!r)return;if(!e.isKitReady()){const c=[y("queued","not_ready")],u=ae(e.filteredUser);if(e.accountId&&u&&B(e.filteredUser)){const{collected:l,missingKeys:p}=le(e,t,r);if(p.length===0){const w=R(l);We(e.accountId,n,r.targetPageIdentifier,w,u)||c.push(y("queued","persist_failed"))}}J(i,{event:t,pathname:n,storedDiagnostics:c});return}if(!e.isPreselectionEnabled())return;if(!B(e.filteredUser)){e.logPlacementDiagnostic(y("missed","no_valid_identity")),J(i,{event:t,pathname:n});return}const{collected:s,missingKeys:o}=le(e,t,r);if(o.length>0){for(const c of o)e.logPlacementDiagnostic(y("missed",`missing_attribute:${c}`));J(i,{event:t,pathname:n});return}ue(e,e.accountId||"",n,r.targetPageIdentifier,s,"fired")}function Qe(i,e,t=window.location.pathname){if(Be(i,e),i.pending.length===0)return;const n=i.pending;i.pending=[],n.forEach(({event:r,pathname:s,storedDiagnostics:o})=>{s===t&&(e.isKitReady()&&e.isPreselectionEnabled()&&o?.forEach(c=>e.logPlacementDiagnostic(c)),de(i,e,r,s))})}function Xe(){return{context:null,lifecycle:"idle",recreateInFlight:null}}function Ze(i,e){i.context={accountId:e.accountId,launcherOptions:{...e.launcherOptions},legacyRoktExtensions:[...e.legacyRoktExtensions]}}function et(i){i.lifecycle="attached"}function tt(i){i.lifecycle!=="idle"&&(i.lifecycle="terminated")}function it(i){i.lifecycle="terminated"}function nt(i){i.context=null,i.lifecycle="idle",i.recreateInFlight=null}function rt(i,e,t){if(i.recreateInFlight)return i.recreateInFlight;if(i.lifecycle!=="terminated"||!i.context||!e)return;i.lifecycle="recreating";const n=i.context;return i.recreateInFlight=t(n).finally(()=>{i.recreateInFlight=null}),i.recreateInFlight}const h="Rokt",M=181,st="selectPlacements",ot="apps.roktecommerce.com",ct=.1,at="ThankYouPageJourney",lt="rokt-launcher",ut="rokt-thank-you-element",dt="userIdentifiedInWorkspace",ht=3,gt=2,ft="page_events",pt="page_view_attributes",mt="mparticle_session_id",Et="mparticle_device_id",he=500,Q={UNKNOWN_ERROR:"UNKNOWN_ERROR",UNHANDLED_EXCEPTION:"UNHANDLED_EXCEPTION",IDENTITY_REQUEST:"IDENTITY_REQUEST",LOG_DELIVERY_FAILURE:"LOG_DELIVERY_FAILURE"},S={ERROR:"ERROR",INFO:"INFO",WARNING:"WARNING"},_t="apps.rokt-api.com",It="/v1/log",yt="/v1/errors",St=10;function a(){return window.mParticle}function ge(i,e){const n=[F(i),"/wsdk/integrations/launcher.js"].join("");return!e||e.length===0?n:n+"?extensions="+e.join(",")}function fe(i){return[F(i),"/rokt-elements/rokt-element-thank-you.js"].join("")}function F(i){const e=i!==void 0?i:_t;return e.includes("://")?e.replace(/\/+$/,""):["https://",e].join("")}function pe(i,e,t){if(i)return i.startsWith("http://")||i.startsWith("https://")?i:"https://"+i;const r=e?.includes("://")&&!/^https?:\/\//i.test(e)?void 0:e;return F(r)+t}function me(i,e,t){if(document.getElementById(i))return;const n=document.head||document.body,r=document.createElement("script");r.id=i,r.type="text/javascript",r.src=e,r.async=!0,r.crossOrigin="anonymous",r.fetchPriority="high",t?.onLoad&&(r.onload=t.onLoad),t?.onError&&(r.onerror=t.onError),n.appendChild(r)}function x(i){if(!i)return[];try{return JSON.parse(i.replace(/"/g,'"'))}catch{console.error("Settings string contains invalid JSON")}return[]}function Ee(i){const e=i?x(i):[],t=[],n=[];let r=!1;for(let s=0;s<e.length;s++){const o=e[s].value;o==="thank-you-journey"?(r=!0,n.push(at)):t.push(o)}return{roktExtensionsQueryParams:t,legacyRoktExtensions:n,loadThankYouElement:r}}async function At(i,e){const t=[];if(e)for(const n of i)t.push(e.use(n));return Promise.all(t)}function _e(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 Ie(i){const e={};if(!Array.isArray(i))return e;for(let t=0;t<i.length;t++){const n=i[t];if(!n||!g(n.value)||!g(n.map))continue;const r=n.value,s=n.map;e[r]||(e[r]=[]),e[r].push({eventAttributeKey:s,conditions:Array.isArray(n.conditions)?n.conditions:[]})}return e}function ye(i,e,t){return a().generateHash([i,e,t].join(""))}function Pt(i){let n="mParticle_wsdkv_"+a().getVersion()+"_kitv_"+"3.3.0";return i&&(n+="_"+i),n}function X(i){const e=document.createElement("iframe");e.style.display="none",e.setAttribute("sandbox","allow-scripts allow-same-origin"),e.src=i,e.onload=function(){e.onload=null,e.parentNode&&e.parentNode.removeChild(e)};const t=document.body||document.head;t&&t.appendChild(e)}function Se(i,e){const t=ee(window.location.origin);if(A._allowedOriginHashes.indexOf(t)===-1||Math.random()>=ct)return;const r=window.__rokt_li_guid__;if(!r||i&&i.includes("://")&&!/^https:\/\//i.test(i))return;const s=window.location.href.split("?")[0].split("#")[0],o="version="+encodeURIComponent(e??"")+"&launcherInstanceGuid="+encodeURIComponent(r)+"&pageUrl="+encodeURIComponent(s),c=i?F(i):"https://apps.rokt.com";X(c+"/v1/wsdk-init/index.html?"+o),X("https://"+ot+"/v1/wsdk-init/index.html?"+o+"&isControl=true")}function Rt(){return typeof window<"u"&&!!window.location?.search?.toLowerCase().includes("mp_enable_logging=true")}function bt(){return typeof window<"u"?window.location?.href:void 0}function kt(){return typeof window<"u"?window.navigator?.userAgent:void 0}class Ae{constructor(){this._logCount={}}incrementAndCheck(e){const n=(this._logCount[e]||0)+1;return this._logCount[e]=n,n>St}}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 Ae,this._isEnabled=Rt()||o}send(e,t,n,r,s,o){if(!(!this._isEnabled||this._rateLimiter.incrementAndCheck(t)))try{const c={additionalInformation:{message:n,version:this._integrationName},severity:t,code:r||Q.UNKNOWN_ERROR,url:bt(),deviceInfo:kt(),stackTrace:s,reporter:this._reporter,integration:this._integrationName},u={Accept:"text/plain;charset=UTF-8","Content-Type":"application/json","rokt-launcher-version":this._integrationName,"rokt-wsdk-version":"joint"};this._launcherInstanceGuid&&(u["rokt-launcher-instance-guid"]=this._launcherInstanceGuid),this._accountId&&(u["rokt-account-id"]=this._accountId),fetch(e,{method:"POST",headers:u,body:JSON.stringify(c)}).then(l=>{if(!l.ok){const p=new Error("HTTP "+l.status+" from log endpoint");throw p.statusCode=l.status,p}}).catch(l=>{console.error("ReportingTransport: Failed to send log",l),o&&o(l)})}catch(c){console.error("ReportingTransport: Failed to send log",c),o&&o(c)}}}class Pe{constructor(e,t,n,r,s){this._transport=new Y(e,t,n,r,s),this._errorUrl=pe(e?.errorUrl,e?.integrationDomain,yt)}report(e){if(!e)return;const t=e.severity||S.ERROR;this._transport.send(this._errorUrl,t,e.message,e.code,e.stackTrace)}}class Re{constructor(e,t,n,r,s,o){this._transport=new Y(e,n,r,s,o),this._placementDiagnosticTransport=new Y(e,n,r,s),this._loggingUrl=pe(e?.loggingUrl,e?.integrationDomain,It),this._errorReportingService=t}log(e){e&&this._send(this._transport,e)}logPlacementDiagnostic(e){e&&this._send(this._placementDiagnosticTransport,e)}_send(e,t){e.send(this._loggingUrl,S.INFO,t.message,t.code,void 0,n=>{if(this._errorReportingService){const r=typeof n.statusCode=="number";this._errorReportingService.report({message:"LoggingService: Failed to send log: "+n.message,code:Q.LOG_DELIVERY_FAILURE,severity:r?S.ERROR:S.WARNING})}})}}function vt(i){const e=V(window.location.href),t=i.EventAttributes?.title||document.title,n=Ke(),r=i.ActiveTimeOnSite;return{pageUrl:e,sourceMessageId:i.SourceMessageId,timestamp:i.Timestamp,...t?{pageTitle:t}:{},...n!==void 0?{canonicalUrl:n}:{},...Number.isFinite(r)?{activeTimeOnSite:r}:{}}}const E=class E{constructor(){this.name=h,this.id=M,this.moduleId=M,this.isInitialized=!1,this.launcher=null,this.filters={},this.userAttributes={},this.userIdentifiedInWorkspace=!1,this.testHelpers=null,this.placementEventMappingLookup={},this.placementEventAttributeMappingLookup={},this.integrationName=null,this.errorReportingService=null,this.loggingService=null,this._thankYouElementOnLoadCallback=null,this._isThankYouElementLoaded=!1,this._workspaceSearchInFlightPromise=null,this._launcherAttachState=Xe(),this.accountId=null,this._preselectState=qe()}getEventAttributeValue(e,t){const n=e&&e.EventAttributes;return!n||n[t]===void 0?null:n[t]}doesEventAttributeConditionMatch(e,t){if(!e||!g(e.operator))return!1;const n=e.operator.toLowerCase(),r=e.attributeValue;return n==="exists"?t!==null:t==null?!1:n==="equals"?String(t)===String(r):n==="contains"?String(t).indexOf(String(r))!==-1:!1}doesEventMatchRule(e,t){if(!t||!g(t.eventAttributeKey))return!1;const n=t.conditions;if(!Array.isArray(n))return!1;const r=this.getEventAttributeValue(e,t.eventAttributeKey);if(n.length===0)return r!==null;for(let s=0;s<n.length;s++)if(!this.doesEventAttributeConditionMatch(n[s],r))return!1;return!0}applyPlacementEventAttributeMapping(e){const t=Object.keys(this.placementEventAttributeMappingLookup);for(let n=0;n<t.length;n++){const r=t[n],s=this.placementEventAttributeMappingLookup[r];if(b(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=V(window.location.href);const n=se(),r=vt(e);n.push(r);const s=Math.min(n.length,ne),o=Oe(n);if(o===0){const c=W()?"quota":"ls_unavailable";this.loggingService?.log({message:`Rokt Kit: Failed to persist page view for ${t} [reason: ${c}]`,code:"PAGE_VIEW_CAPTURE_FAILED"})}else o<s&&this.loggingService?.log({message:`Rokt Kit: Page view storage reduced from ${s} to ${o} record(s) under quota pressure [reason: quota_eviction]`,code:"PAGE_VIEW_QUOTA_EVICTION"})}catch(n){const r=W()?"exception":"ls_unavailable",s=n instanceof Error?n.message:String(n);this.loggingService?.log({message:`Rokt Kit: Failed to capture page view for ${t}: ${s} [reason: ${r}]`,code:"PAGE_VIEW_CAPTURE_FAILED"})}}isPreselectionEnabled(){return this.launcher?.enablePreselection===!0}buildCacheMatchKeys(e){if(!this.isPreselectionEnabled())return;const t=ze(this.accountId,e);if(t)return t.attributeKeys}buildPreselectHost(){return{accountId:this.accountId,filteredUser:this.filters.filteredUser,userAttributes:this.userAttributes,isKitReady:()=>this.isKitReady(),isPreselectionEnabled:()=>this.isPreselectionEnabled(),getEventAttributeValue:(e,t)=>this.getEventAttributeValue(e,t),logPlacementDiagnostic:e=>this.loggingService?.logPlacementDiagnostic(e),log:e=>this.loggingService?.log(e),selectPlacements:e=>this.selectPlacements(e)}}flushPendingPreselectDispatches(){Qe(this._preselectState,this.buildPreselectHost())}isLauncherReadyToAttach(){return!!window.Rokt&&N(window.Rokt.createLauncher)}returnUserIdentities(e){if(!e||!e.getUserIdentities)return{};const t=e.getUserIdentities().userIdentities;return this.replaceOtherIdentityWithEmailsha256(t)}returnLocalSessionAttributes(){return!a().Rokt||typeof a().Rokt.getLocalSessionAttributes!="function"?{}:a().Rokt.getLocalSessionAttributes()}replaceOtherIdentityWithEmailsha256(e){const t={...e||{}},n=this._mappedEmailSha256Key;return n&&e[n]&&(t[E.EMAIL_SHA256_KEY]=e[n]),n&&delete t[n],t}logSelectPlacementsEvent(e){if(!window.mParticle||typeof a().logEvent!="function"||!f(e))return;const t=a().EventType.Other;a().logEvent(st,t,e)}setRoktSessionId(e){if(!(!e||typeof e!="string"))try{const t=a().getInstance();t&&N(t.setIntegrationAttribute)&&t.setIntegrationAttribute(M,{roktSessionId:e})}catch{}}readMpSessionId(){const e=a()?.sessionManager,t=e?.getSessionId??e?.getSession;if(N(t))return t.call(e)||void 0}readMpDeviceId(){return a()?.getDeviceId?.()||void 0}attachLauncher(e,t,n=[]){Ze(this._launcherAttachState,{accountId:e,launcherOptions:t||{},legacyRoktExtensions:n});const r={accountId:e,...t||{}};let s;return this.isPartnerInLocalLauncherTestGroup()?s=Promise.resolve(window.Rokt.createLocalLauncher(r)):s=window.Rokt.createLauncher(r),s.then(async o=>{await At([...n],o),this.initRoktLauncher(o)}).catch(o=>{it(this._launcherAttachState),console.error("Error creating Rokt launcher:",o)})}recreateLauncherIfTerminated(){return rt(this._launcherAttachState,this.isLauncherReadyToAttach(),e=>this.attachLauncher(e.accountId,e.launcherOptions,e.legacyRoktExtensions))}initRoktLauncher(e){window.Rokt&&(window.Rokt.currentLauncher=e),this.launcher=e,et(this._launcherAttachState);const t=a().Rokt?.filters;t?(this.filters=t,t.filteredUser?this._workspaceSearchInFlightPromise=this.search(t.filteredUser):console.warn("Rokt Kit: No filtered user has been set.")):console.warn("Rokt Kit: No filters have been set."),this.isInitialized=!0,Se(this.domain,this.integrationName),a().Rokt.attachKit(this),this.flushPendingPreselectDispatches()}fetchOptimizely(){const e=a()._getActiveForwarders().filter(t=>t.name==="Optimizely");try{if(e.length>0&&window.optimizely){const t=window.optimizely.get("state");return!t||!t.getActiveExperimentIds?{}:t.getActiveExperimentIds().reduce((s,o)=>(s["rokt.custom.optimizely.experiment."+o+".variationId"]=t.getVariationMap()[o].id,s),{})}}catch(t){console.error("Error fetching Optimizely attributes:",t)}return{}}isKitReady(){return!!(this.isInitialized&&this.launcher)}isTargetingDisabled(){return a().Rokt?.launcherOptions?.noTargeting===!0}isPartnerInLocalLauncherTestGroup(){return!!(a().config&&a().config.isLocalLauncherEnabled&&this.isAssignedToSampleGroup())}isAssignedToSampleGroup(){return Math.random()>.5}captureTiming(e){window&&a()&&a().captureTiming&&e&&a().captureTiming(e)}init(e,t,n,r,s){const o=e,c=o.accountId;this.accountId=c||null,this.userAttributes=R(s),this._onboardingExpProvider=o.onboardingExpProvider;const u=x(o.placementEventMapping);this.placementEventMappingLookup=_e(u);const l=x(o.placementEventAttributeMapping);this.placementEventAttributeMappingLookup=Ie(l),o.hashedEmailUserIdentityType&&(this._mappedEmailSha256Key=o.hashedEmailUserIdentityType.toLowerCase()),this._workspaceIdSyncApiKey=g(o.workspaceIdSyncApiKey)?o.workspaceIdSyncApiKey:void 0;const p=a().Rokt?.domain,{roktExtensionsQueryParams:w,legacyRoktExtensions:T,loadThankYouElement:G}=Ee(o.roktExtensions),_={...a().Rokt?.launcherOptions||{}};this.integrationName=Pt(_.integrationName),_.integrationName=this.integrationName,this.domain=p;const L={loggingUrl:o.loggingUrl,errorUrl:o.errorUrl,integrationDomain:p,isLoggingEnabled:a().config?.isLoggingEnabled===!0},P=new Pe(L,this.integrationName,window.__rokt_li_guid__,o.accountId),O=new Re(L,P,this.integrationName,window.__rokt_li_guid__,o.accountId);if(this.errorReportingService=P,this.loggingService=O,this.isTargetingDisabled())try{oe(),ce()}catch(m){this.errorReportingService?.report({message:"Rokt Kit: Failed to clear page views when targeting is disabled",code:"PAGE_VIEW_CAPTURE_FAILED",severity:S.INFO,stackTrace:m instanceof Error?m.stack:void 0})}return a()._registerErrorReportingService&&a()._registerErrorReportingService(P),a()._registerLoggingService&&a()._registerLoggingService(O),n?(this.testHelpers={generateLauncherScript:ge,generateThankYouElementScript:fe,extractRoktExtensionConfig:Ee,hashEventMessage:ye,parseSettingsString:x,generateMappedEventLookup:_e,generateMappedEventAttributeLookup:Ie,sendAdBlockMeasurementSignals:Se,createAutoRemovedIframe:X,djb2:ee,setAllowedOriginHashes:m=>{E._allowedOriginHashes=m},ReportingTransport:Y,ErrorReportingService:Pe,LoggingService:Re,RateLimiter:Ae,ErrorCodes:Q,WSDKErrorSeverity:S,resetLauncherAttachState:()=>nt(this._launcherAttachState)},this.attachLauncher(c,_),"Successfully initialized: "+h):(G&&(a().Rokt.flushOnShoppableAdsReadyMessageQueue?.(this),me(ut,fe(p),{onLoad:()=>{this._isThankYouElementLoaded=!0,this._thankYouElementOnLoadCallback&&this._thankYouElementOnLoadCallback()},onError:m=>{console.error("Error loading Rokt Thank You Element script:",m)}})),this.isLauncherReadyToAttach()?this.attachLauncher(c,_,T):(me(lt,ge(p,w),{onLoad:()=>{this.isLauncherReadyToAttach()?this.attachLauncher(c,_,T):console.error("Rokt object is not available after script load.")},onError:m=>{console.error("Error loading Rokt launcher script:",m)}}),this.captureTiming(E.PERFORMANCE_MARKS.RoktScriptAppended)),"Successfully initialized: "+h)}process(e){if(this.isTargetingDisabled()||(e.EventDataType===ht&&(Ue(this.loggingService),this.capturePageView(e),de(this._preselectState,this.buildPreselectHost(),e)),e.EventDataType===gt&&(oe(),ce(),this.accountId&&v(this.accountId))),!this.isKitReady())return"Kit not ready for forwarder: "+h;if(N(a().Rokt?.setLocalSessionAttribute)&&(b(this.placementEventAttributeMappingLookup)||this.applyPlacementEventAttributeMapping(e),!b(this.placementEventMappingLookup))){const t=ye(e.EventDataType,e.EventCategory,e.EventName??"");this.placementEventMappingLookup[String(t)]&&a().Rokt.setLocalSessionAttribute?.(this.placementEventMappingLookup[String(t)],!0)}return"Successfully sent to forwarder: "+h}setExtensionData(e){if(!this.isKitReady()){console.error("Rokt Kit: Not initialized");return}window.Rokt.setExtensionData(e)}setUserAttribute(e,t){return Z(e)||(this.userAttributes[e]=t),$e(this.accountId,e)&&this.flushPendingPreselectDispatches(),"Successfully set user attribute for forwarder: "+h}removeUserAttribute(e){return delete this.userAttributes[e],"Successfully removed user attribute for forwarder: "+h}handleIdentityComplete(e,t){return this.userAttributes=R(e.getAllUserAttributes()),"Successfully called "+t+" for forwarder: "+h}onUserIdentified(e){const t=e;this.filters.filteredUser=t,this._workspaceSearchInFlightPromise=this.search(t);const n=this.handleIdentityComplete(e,"onUserIdentified");return this.flushPendingPreselectDispatches(),n}search(e){const t=this._workspaceIdSyncApiKey;if(!t)return this.userIdentifiedInWorkspace=!1,this._workspaceLastSearchedIdentitiesKey=void 0,Promise.resolve();const n=a().Identity?.search;if(typeof n!="function")return this.userIdentifiedInWorkspace=!1,this._workspaceLastSearchedIdentitiesKey=void 0,Promise.resolve();const r=e.getUserIdentities?e.getUserIdentities().userIdentities:null,s={};if(r)for(const u of Object.keys(r)){const l=r[u];g(l)&&l.length>0&&(s[u]=l)}const o=Object.keys(s);if(o.length===0)return this.userIdentifiedInWorkspace=!1,this._workspaceLastSearchedIdentitiesKey=void 0,Promise.resolve();const c=o.sort().map(u=>`${u}=${s[u]}`).join("&");return c===this._workspaceLastSearchedIdentitiesKey?this._workspaceSearchInFlightPromise||Promise.resolve():(this.userIdentifiedInWorkspace=!1,this._workspaceLastSearchedIdentitiesKey=c,new Promise(u=>{try{n(t,s,l=>{l?.httpCode===200&&(this.userIdentifiedInWorkspace=!0),u()})}catch(l){console.error("Rokt Kit: Workspace IDSync search failed",l),this._workspaceLastSearchedIdentitiesKey=void 0,u()}}))}onLoginComplete(e,t){return this.handleIdentityComplete(e,"onLoginComplete")}onLogoutComplete(e,t){return this.userIdentifiedInWorkspace=!1,this._workspaceSearchInFlightPromise=null,this._workspaceLastSearchedIdentitiesKey=void 0,this.accountId&&v(this.accountId),this.handleIdentityComplete(e,"onLogoutComplete")}onModifyComplete(e,t){return this.handleIdentityComplete(e,"onModifyComplete")}selectPlacements(e){const t=this.recreateLauncherIfTerminated();if(t){const n=this._workspaceSearchInFlightPromise,r=n?Promise.race([n,new Promise(s=>setTimeout(s,he))]):Promise.resolve();return Promise.all([t,r]).then(()=>this._dispatchPlacements(e))}if(this._workspaceSearchInFlightPromise){const n=this._workspaceSearchInFlightPromise;return Promise.race([n,new Promise(r=>setTimeout(r,he))]).then(()=>this._dispatchPlacements(e))}return this._dispatchPlacements(e)}_dispatchPlacements(e){const t=e&&e.attributes||{},r={...R(this.userAttributes),...t},s=this.filters||{},o=s.userAttributeFilters||[],c=s.filteredUser||null,u=c?c.getMPID():null;let l;s?s.filterUserAttributes?l=s.filterUserAttributes(r,o):l=r:(console.warn("Rokt Kit: No filters available, using user attributes"),l=r),this.userAttributes=R(l);const p=this._onboardingExpProvider==="Optimizely"?this.fetchOptimizely():{},w=this.returnUserIdentities(c),T=this.returnLocalSessionAttributes(),G=Ne(se()),_=Ce(),L=this.readMpSessionId(),P=this.readMpDeviceId(),O={...w,...l,...p,...T,...G.length?{[ft]:JSON.stringify(G)}:{},..._?{[pt]:_}:{},...this.userIdentifiedInWorkspace?{[dt]:!0}:{},...L?{[mt]:L}:{},...P?{[Et]:P}:{},mpid:u},m=this.buildCacheMatchKeys(typeof e.identifier=="string"?e.identifier:void 0),Lt={...e,attributes:O,...m!==void 0?{cacheMatchKeys:m}:{}},be=this.launcher.selectPlacements(Lt),ke=e.preselect===!0,Ot=()=>{ke||this.logSelectPlacementsEvent(O)};return Promise.resolve(be).then(Nt=>{if(!ke)return Nt?.context?.sessionId?.then(Ut=>this.setRoktSessionId(Ut))}).catch(()=>{}).finally(Ot),be}hashAttributes(e){return this.isKitReady()?this.launcher.hashAttributes(e):(console.error("Rokt Kit: Not initialized"),null)}use(e){return this.isKitReady()?!e||!g(e)?Promise.reject(new Error("Rokt Kit: Invalid extension name")):this.launcher.use(e):(console.error("Rokt Kit: Not initialized"),Promise.reject(new Error("Rokt Kit: Not initialized")))}terminate(){return this.isKitReady()?(tt(this._launcherAttachState),this.launcher.terminate()):(console.error("Rokt Kit: Not initialized"),Promise.resolve())}onShoppableAdsReady(e){this._isThankYouElementLoaded?e():this._thankYouElementOnLoadCallback=e}};E._allowedOriginHashes=[-553112570,549508659],E.PERFORMANCE_MARKS={RoktScriptAppended:"mp:RoktScriptAppended"},E.EMAIL_SHA256_KEY="emailsha256";let A=E;function wt(){return M}function Tt(i){if(!i){window.console.log("You must pass a config object to register the kit "+h);return}if(!f(i)){window.console.log("'config' must be an object. You passed in a "+typeof i);return}f(i.kits)?i.kits[h]={constructor:A}:(i.kits={},i.kits[h]={constructor:A}),window.console.log("Successfully registered "+h+" to your mParticle configuration")}return typeof window<"u"&&window.mParticle&&a().addForwarder&&a().addForwarder({name:h,constructor:A,getId:wt}),j.register=Tt,Object.defineProperty(j,Symbol.toStringTag,{value:"Module"}),j})({});
|
|
2
2
|
//# sourceMappingURL=Rokt-Kit.iife.js.map
|