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