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