@mparticle/web-rokt-kit 1.33.1 → 1.33.2
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 +127 -115
- package/dist/Rokt-Kit.iife.js +1 -1
- package/package.json +1 -1
package/dist/Rokt-Kit.common.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const le=["active_time_on_site_ms","billingaddress1","billingaddress2","billingcity","billingstate","billingzipcode","cartitems","ccbin","confirmationref","conversiontype","country","couponcode","currency","language","paymentserviceprovider","paymentserviceproviderattribute","paymenttype","shippingaddress1","shippingcity","shippingcountry","shippingmethod","shippingstate","shippingzipcode","totalprice"],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.1";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,t=e?.getSessionId??e?.getSession;if(L(t))return t.call(e)||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;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const de=["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"],he=new Set(de);function te(i){return he.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];te(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}}const x="__rokt_ls_probe__";function G(){try{return window.localStorage.setItem(x,"1"),window.localStorage.removeItem(x),!0}catch{return!1}}function O(i){try{const e=window.localStorage.getItem(i);return e===null?null:JSON.parse(e)}catch{return null}}function ie(i,e){try{return window.localStorage.setItem(i,JSON.stringify(e)),!0}catch{return!1}}function ne(i){try{window.localStorage.removeItem(i)}catch{}}function re(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,ie(i,r)}function ge(i,e){const t=O(i);if(!_(t)||!(e in t))return;const n={...t};delete n[e],Object.keys(n).length===0?ne(i):ie(i,n)}function pe(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",W="mpPageViews",fe=100*1024;function se(i){const e=O(W);if(e===null)return;if(!(re(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 [reason: migration_retry]",code:"PAGE_VIEW_CAPTURE_FAILED"});return}ne(W)}function j(i){se(i);const e=re(k,R);return Array.isArray(e)?e:[]}function me(i){return pe(k,R,i,fe)}function H(){ge(k,R)}function Ee(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 _e(){const e=document.querySelector('link[rel="canonical"]')?.href;if(e)return D(e)}const d="Rokt",T=181,Se="selectPlacements",ye="apps.roktecommerce.com",Ie=.1,Ae="ThankYouPageJourney",ke="rokt-launcher",Re="rokt-thank-you-element",ve="userIdentifiedInWorkspace",we=3,be=2,Le="page_events",Te="mparticle_session_id",Ne=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"},Oe="apps.rokt-api.com",Pe="/v1/log",Ue="/v1/errors",Ce=10;function a(){return window.mParticle}function V(i,e){const n=[P(i),"/wsdk/integrations/launcher.js"].join("");return!e||e.length===0?n:n+"?extensions="+e.join(",")}function z(i){return[P(i),"/rokt-elements/rokt-element-thank-you.js"].join("")}function P(i){const e=typeof i<"u"?i:Oe;return e.includes("://")?e.replace(/\/+$/,""):["https://",e].join("")}function oe(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 J(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 B(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(Ae)):t.push(o)}return{roktExtensionsQueryParams:t,legacyRoktExtensions:n,loadThankYouElement:r}}async function Me(i,e){const t=[];if(e)for(const n of i)t.push(e.use(n));return Promise.all(t)}function q(i){if(!i)return{};const e={};for(let t=0;t<i.length;t++){const n=i[t];e[n.jsmap]=n.value}return e}function $(i){const e={};if(!Array.isArray(i))return e;for(let t=0;t<i.length;t++){const n=i[t];if(!n||!m(n.value)||!m(n.map))continue;const r=n.value,s=n.map;e[r]||(e[r]=[]),e[r].push({eventAttributeKey:s,conditions:Array.isArray(n.conditions)?n.conditions:[]})}return e}function Q(i,e,t){return a().generateHash([i,e,t].join(""))}function Ke(i){let n="mParticle_wsdkv_"+a().getVersion()+"_kitv_"+"1.33.2";return i&&(n+="_"+i),n}function ae(i){let e=5381;for(let t=0;t<i.length;t++)e=(e<<5)+e+i.charCodeAt(t),e=e&e;return e}function 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 X(i,e){const t=ae(window.location.origin);if(S._allowedOriginHashes.indexOf(t)===-1||Math.random()>=Ie)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://"+ye+"/v1/wsdk-init/index.html?"+o+"&isControl=true")}function De(){return typeof window<"u"&&!!window.location?.search?.toLowerCase().includes("mp_enable_logging=true")}function Fe(){return typeof window<"u"?window.location?.href:void 0}function Ye(){return typeof window<"u"?window.navigator?.userAgent:void 0}class ce{constructor(){this._logCount={}}incrementAndCheck(e){const n=(this._logCount[e]||0)+1;return this._logCount[e]=n,n>Ce}}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 ce,this._isEnabled=De()||o}send(e,t,n,r,s,o){if(!(!this._isEnabled||this._rateLimiter.incrementAndCheck(t)))try{const c={additionalInformation:{message:n,version:this._integrationName},severity:t,code:r||F.UNKNOWN_ERROR,url:Fe(),deviceInfo:Ye(),stackTrace:s,reporter:this._reporter,integration:this._integrationName},u={Accept:"text/plain;charset=UTF-8","Content-Type":"application/json","rokt-launcher-version":this._integrationName,"rokt-wsdk-version":"joint"};this._launcherInstanceGuid&&(u["rokt-launcher-instance-guid"]=this._launcherInstanceGuid),this._accountId&&(u["rokt-account-id"]=this._accountId),fetch(e,{method:"POST",headers:u,body:JSON.stringify(c)}).then(l=>{if(!l.ok){const g=new Error("HTTP "+l.status+" from log endpoint");throw g.statusCode=l.status,g}}).catch(l=>{console.error("ReportingTransport: Failed to send log",l),o&&o(l)})}catch(c){console.error("ReportingTransport: Failed to send log",c),o&&o(c)}}}class Z{constructor(e,t,n,r,s){this._transport=new Y(e,t,n,r,s),this._errorUrl=oe(e?.errorUrl,e?.integrationDomain,Ue)}report(e){if(!e)return;const t=e.severity||E.ERROR;this._transport.send(this._errorUrl,t,e.message,e.code,e.stackTrace)}}class ee{constructor(e,t,n,r,s,o){this._transport=new Y(e,n,r,s,o),this._loggingUrl=oe(e?.loggingUrl,e?.integrationDomain,Pe),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 xe(i){const e=D(window.location.href),t=i.EventAttributes?.title||document.title,n=_e(),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=j(this.loggingService),r=xe(e);if(n.push(r),!me(n)){const s=G()?"quota":"ls_unavailable";this.loggingService?.log({message:`Rokt Kit: Failed to persist page view for ${t} [reason: ${s}]`,code:"PAGE_VIEW_CAPTURE_FAILED"})}}catch(n){const r=G()?"exception":"ls_unavailable",s=n instanceof Error?n.message:String(n);this.loggingService?.log({message:`Rokt Kit: Failed to capture page view for ${t}: ${s} [reason: ${r}]`,code:"PAGE_VIEW_CAPTURE_FAILED"})}}isLauncherReadyToAttach(){return!!window.Rokt&&L(window.Rokt.createLauncher)}returnUserIdentities(e){if(!e||!e.getUserIdentities)return{};const t=e.getUserIdentities().userIdentities;return this.replaceOtherIdentityWithEmailsha256(t)}returnLocalSessionAttributes(){return!a().Rokt||typeof a().Rokt.getLocalSessionAttributes!="function"?{}:a().Rokt.getLocalSessionAttributes()}replaceOtherIdentityWithEmailsha256(e){const t={...e||{}},n=this._mappedEmailSha256Key;return n&&e[n]&&(t[f.EMAIL_SHA256_KEY]=e[n]),n&&delete t[n],t}logSelectPlacementsEvent(e){if(!window.mParticle||typeof a().logEvent!="function"||!_(e))return;const t=a().EventType.Other;a().logEvent(Se,t,e)}setRoktSessionId(e){if(!(!e||typeof e!="string"))try{const t=a().getInstance();t&&L(t.setIntegrationAttribute)&&t.setIntegrationAttribute(T,{roktSessionId:e})}catch{}}readMpSessionId(){const e=a()?.sessionManager,t=e?.getSessionId??e?.getSession;if(L(t))return t.call(e)||void 0}attachLauncher(e,t,n=[]){const r={accountId:e,...t||{}};let s;this.isPartnerInLocalLauncherTestGroup()?s=Promise.resolve(window.Rokt.createLocalLauncher(r)):s=window.Rokt.createLauncher(r),s.then(async o=>{await Me(n,o),this.initRoktLauncher(o)}).catch(o=>{console.error("Error creating Rokt launcher:",o)})}initRoktLauncher(e){window.Rokt&&(window.Rokt.currentLauncher=e),this.launcher=e;const t=a().Rokt?.filters;t?(this.filters=t,t.filteredUser?this._workspaceSearchInFlightPromise=this.search(t.filteredUser):console.warn("Rokt Kit: No filtered user has been set.")):console.warn("Rokt Kit: No filters have been set."),this.isInitialized=!0,X(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=q(u);const l=N(o.placementEventAttributeMapping);this.placementEventAttributeMappingLookup=$(l),o.hashedEmailUserIdentityType&&(this._mappedEmailSha256Key=o.hashedEmailUserIdentityType.toLowerCase()),this._workspaceIdSyncApiKey=m(o.workspaceIdSyncApiKey)?o.workspaceIdSyncApiKey:void 0;const g=a().Rokt?.domain,{roktExtensionsQueryParams:U,legacyRoktExtensions:v,loadThankYouElement:w}=B(o.roktExtensions),p={...a().Rokt?.launcherOptions||{}};this.integrationName=Ke(p.integrationName),p.integrationName=this.integrationName,this.domain=g;const y={loggingUrl:o.loggingUrl,errorUrl:o.errorUrl,integrationDomain:g,isLoggingEnabled:a().config?.isLoggingEnabled===!0},I=new Z(y,this.integrationName,window.__rokt_li_guid__,o.accountId),A=new ee(y,I,this.integrationName,window.__rokt_li_guid__,o.accountId);if(this.errorReportingService=I,this.loggingService=A,this.isTargetingDisabled())try{H()}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(I),a()._registerLoggingService&&a()._registerLoggingService(A),n?(this.testHelpers={generateLauncherScript:V,generateThankYouElementScript:z,extractRoktExtensionConfig:B,hashEventMessage:Q,parseSettingsString:N,generateMappedEventLookup:q,generateMappedEventAttributeLookup:$,sendAdBlockMeasurementSignals:X,createAutoRemovedIframe:K,djb2:ae,setAllowedOriginHashes:h=>{f._allowedOriginHashes=h},ReportingTransport:Y,ErrorReportingService:Z,LoggingService:ee,RateLimiter:ce,ErrorCodes:F,WSDKErrorSeverity:E},this.attachLauncher(c,p),"Successfully initialized: "+d):(w&&(a().Rokt.flushOnShoppableAdsReadyMessageQueue?.(this),J(Re,z(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):(J(ke,V(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===we&&this.capturePageView(e),e.EventDataType===be&&(se(this.loggingService),H())),!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 te(e)||(this.userAttributes[e]=t),"Successfully set user attribute for forwarder: "+d}removeUserAttribute(e){return delete this.userAttributes[e],"Successfully removed user attribute for forwarder: "+d}handleIdentityComplete(e,t){return this.userAttributes=b(e.getAllUserAttributes()),"Successfully called "+t+" for forwarder: "+d}onUserIdentified(e){const t=e;return this.filters.filteredUser=t,this._workspaceSearchInFlightPromise=this.search(t),this.handleIdentityComplete(e,"onUserIdentified")}search(e){const t=this._workspaceIdSyncApiKey;if(!t)return this.userIdentifiedInWorkspace=!1,this._workspaceLastSearchedIdentitiesKey=void 0,Promise.resolve();const n=a().Identity?.search;if(typeof n!="function")return this.userIdentifiedInWorkspace=!1,this._workspaceLastSearchedIdentitiesKey=void 0,Promise.resolve();const r=e.getUserIdentities?e.getUserIdentities().userIdentities:null,s={};if(r)for(const u of Object.keys(r)){const l=r[u];m(l)&&l.length>0&&(s[u]=l)}const o=Object.keys(s);if(o.length===0)return this.userIdentifiedInWorkspace=!1,this._workspaceLastSearchedIdentitiesKey=void 0,Promise.resolve();const c=o.sort().map(u=>`${u}=${s[u]}`).join("&");return c===this._workspaceLastSearchedIdentitiesKey?this._workspaceSearchInFlightPromise||Promise.resolve():(this.userIdentifiedInWorkspace=!1,this._workspaceLastSearchedIdentitiesKey=c,new Promise(u=>{try{n(t,s,l=>{l?.httpCode===200&&(this.userIdentifiedInWorkspace=!0),u()})}catch(l){console.error("Rokt Kit: Workspace IDSync search failed",l),this._workspaceLastSearchedIdentitiesKey=void 0,u()}}))}onLoginComplete(e,t){return this.handleIdentityComplete(e,"onLoginComplete")}onLogoutComplete(e,t){return this.userIdentifiedInWorkspace=!1,this._workspaceSearchInFlightPromise=null,this._workspaceLastSearchedIdentitiesKey=void 0,this.handleIdentityComplete(e,"onLogoutComplete")}onModifyComplete(e,t){return this.handleIdentityComplete(e,"onModifyComplete")}selectPlacements(e){if(this._workspaceSearchInFlightPromise){const t=this._workspaceSearchInFlightPromise;return Promise.race([t,new Promise(n=>setTimeout(n,Ne))]).then(()=>this._dispatchPlacements(e))}return this._dispatchPlacements(e)}_dispatchPlacements(e){const t=e&&e.attributes||{},r={...b(this.userAttributes),...t},s=this.filters||{},o=s.userAttributeFilters||[],c=s.filteredUser||null,u=c?c.getMPID():null;let l;s?s.filterUserAttributes?l=s.filterUserAttributes(r,o):l=r:(console.warn("Rokt Kit: No filters available, using user attributes"),l=r),this.userAttributes=b(l);const g=this._onboardingExpProvider==="Optimizely"?this.fetchOptimizely():{},U=this.returnUserIdentities(c),v=this.returnLocalSessionAttributes(),w=Ee(j(this.loggingService)),p=this.readMpSessionId(),y={...U,...l,...g,...v,...w.length?{[Le]:JSON.stringify(w)}:{},...this.userIdentifiedInWorkspace?{[ve]:!0}:{},...p?{[Te]:p}:{},mpid:u},I={...e,attributes:y},A=this.launcher.selectPlacements(I),h=()=>this.logSelectPlacementsEvent(y);return Promise.resolve(A).then(le=>le?.context?.sessionId?.then(ue=>this.setRoktSessionId(ue))).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 S=f;function Ge(){return T}function We(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:S}:(i.kits={},i.kits[d]={constructor:S}),window.console.log("Successfully registered "+d+" to your mParticle configuration")}typeof window<"u"&&window.mParticle&&a().addForwarder&&a().addForwarder({name:d,constructor:S,getId:Ge});exports.register=We;
|
|
2
2
|
//# sourceMappingURL=Rokt-Kit.common.js.map
|
package/dist/Rokt-Kit.esm.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const
|
|
1
|
+
const de = [
|
|
2
2
|
"active_time_on_site_ms",
|
|
3
3
|
"billingaddress1",
|
|
4
4
|
"billingaddress2",
|
|
@@ -23,15 +23,15 @@ const le = [
|
|
|
23
23
|
"shippingstate",
|
|
24
24
|
"shippingzipcode",
|
|
25
25
|
"totalprice"
|
|
26
|
-
],
|
|
27
|
-
function
|
|
28
|
-
return
|
|
26
|
+
], he = new Set(de);
|
|
27
|
+
function te(i) {
|
|
28
|
+
return he.has(i.toLowerCase());
|
|
29
29
|
}
|
|
30
30
|
function b(i) {
|
|
31
31
|
const e = {}, t = i || {}, n = Object.keys(t);
|
|
32
32
|
for (let r = 0; r < n.length; r++) {
|
|
33
33
|
const s = n[r];
|
|
34
|
-
|
|
34
|
+
te(s) || (e[s] = t[s]);
|
|
35
35
|
}
|
|
36
36
|
return e;
|
|
37
37
|
}
|
|
@@ -55,6 +55,14 @@ function D(i) {
|
|
|
55
55
|
return i;
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
|
+
const x = "__rokt_ls_probe__";
|
|
59
|
+
function G() {
|
|
60
|
+
try {
|
|
61
|
+
return window.localStorage.setItem(x, "1"), window.localStorage.removeItem(x), !0;
|
|
62
|
+
} catch {
|
|
63
|
+
return !1;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
58
66
|
function O(i) {
|
|
59
67
|
try {
|
|
60
68
|
const e = window.localStorage.getItem(i);
|
|
@@ -63,35 +71,35 @@ function O(i) {
|
|
|
63
71
|
return null;
|
|
64
72
|
}
|
|
65
73
|
}
|
|
66
|
-
function
|
|
74
|
+
function ie(i, e) {
|
|
67
75
|
try {
|
|
68
76
|
return window.localStorage.setItem(i, JSON.stringify(e)), !0;
|
|
69
77
|
} catch {
|
|
70
78
|
return !1;
|
|
71
79
|
}
|
|
72
80
|
}
|
|
73
|
-
function
|
|
81
|
+
function ne(i) {
|
|
74
82
|
try {
|
|
75
83
|
window.localStorage.removeItem(i);
|
|
76
84
|
} catch {
|
|
77
85
|
}
|
|
78
86
|
}
|
|
79
|
-
function
|
|
87
|
+
function re(i, e) {
|
|
80
88
|
const t = O(i);
|
|
81
89
|
return _(t) ? t[e] : void 0;
|
|
82
90
|
}
|
|
83
91
|
function M(i, e, t) {
|
|
84
92
|
const n = O(i), r = _(n) ? { ...n } : {};
|
|
85
|
-
return r[e] = t,
|
|
93
|
+
return r[e] = t, ie(i, r);
|
|
86
94
|
}
|
|
87
|
-
function
|
|
95
|
+
function ge(i, e) {
|
|
88
96
|
const t = O(i);
|
|
89
97
|
if (!_(t) || !(e in t))
|
|
90
98
|
return;
|
|
91
99
|
const n = { ...t };
|
|
92
|
-
delete n[e], Object.keys(n).length === 0 ?
|
|
100
|
+
delete n[e], Object.keys(n).length === 0 ? ne(i) : ie(i, n);
|
|
93
101
|
}
|
|
94
|
-
function
|
|
102
|
+
function pe(i, e, t, n) {
|
|
95
103
|
const r = t.slice(), s = () => r.length <= 1 ? !1 : (r.shift(), !0);
|
|
96
104
|
let o = JSON.stringify(r).length > n;
|
|
97
105
|
for (; o && s(); )
|
|
@@ -101,32 +109,32 @@ function he(i, e, t, n) {
|
|
|
101
109
|
c = M(i, e, r);
|
|
102
110
|
return c;
|
|
103
111
|
}
|
|
104
|
-
const k = "mp-rokt-kit", R = "pageViews",
|
|
105
|
-
function
|
|
106
|
-
const e = O(
|
|
112
|
+
const k = "mp-rokt-kit", R = "pageViews", W = "mpPageViews", fe = 100 * 1024;
|
|
113
|
+
function se(i) {
|
|
114
|
+
const e = O(W);
|
|
107
115
|
if (e === null)
|
|
108
116
|
return;
|
|
109
|
-
if (!(
|
|
117
|
+
if (!(re(k, R) !== void 0) && Array.isArray(e) && !M(k, R, e)) {
|
|
110
118
|
i?.log({
|
|
111
|
-
message: "Rokt Kit: Failed to migrate legacy page-view storage; retaining legacy key for retry",
|
|
119
|
+
message: "Rokt Kit: Failed to migrate legacy page-view storage; retaining legacy key for retry [reason: migration_retry]",
|
|
112
120
|
code: "PAGE_VIEW_CAPTURE_FAILED"
|
|
113
121
|
});
|
|
114
122
|
return;
|
|
115
123
|
}
|
|
116
|
-
|
|
124
|
+
ne(W);
|
|
117
125
|
}
|
|
118
|
-
function
|
|
119
|
-
|
|
120
|
-
const e =
|
|
126
|
+
function j(i) {
|
|
127
|
+
se(i);
|
|
128
|
+
const e = re(k, R);
|
|
121
129
|
return Array.isArray(e) ? e : [];
|
|
122
130
|
}
|
|
123
|
-
function
|
|
124
|
-
return
|
|
131
|
+
function me(i) {
|
|
132
|
+
return pe(k, R, i, fe);
|
|
125
133
|
}
|
|
126
|
-
function
|
|
127
|
-
|
|
134
|
+
function H() {
|
|
135
|
+
ge(k, R);
|
|
128
136
|
}
|
|
129
|
-
function
|
|
137
|
+
function Ee(i) {
|
|
130
138
|
return i.map((e, t) => {
|
|
131
139
|
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;
|
|
132
140
|
return {
|
|
@@ -140,12 +148,12 @@ function fe(i) {
|
|
|
140
148
|
};
|
|
141
149
|
});
|
|
142
150
|
}
|
|
143
|
-
function
|
|
151
|
+
function _e() {
|
|
144
152
|
const e = document.querySelector('link[rel="canonical"]')?.href;
|
|
145
153
|
if (e)
|
|
146
154
|
return D(e);
|
|
147
155
|
}
|
|
148
|
-
const d = "Rokt", T = 181,
|
|
156
|
+
const d = "Rokt", T = 181, Ie = "selectPlacements", Se = "apps.roktecommerce.com", ye = 0.1, Ae = "ThankYouPageJourney", ke = "rokt-launcher", Re = "rokt-thank-you-element", ve = "userIdentifiedInWorkspace", we = 3, be = 2, Le = "page_events", Te = "mparticle_session_id", Ne = 500, F = {
|
|
149
157
|
UNKNOWN_ERROR: "UNKNOWN_ERROR",
|
|
150
158
|
UNHANDLED_EXCEPTION: "UNHANDLED_EXCEPTION",
|
|
151
159
|
IDENTITY_REQUEST: "IDENTITY_REQUEST",
|
|
@@ -154,28 +162,28 @@ const d = "Rokt", T = 181, Ee = "selectPlacements", _e = "apps.roktecommerce.com
|
|
|
154
162
|
ERROR: "ERROR",
|
|
155
163
|
INFO: "INFO",
|
|
156
164
|
WARNING: "WARNING"
|
|
157
|
-
},
|
|
165
|
+
}, Oe = "apps.rokt-api.com", Pe = "/v1/log", Ue = "/v1/errors", Ce = 10;
|
|
158
166
|
function a() {
|
|
159
167
|
return window.mParticle;
|
|
160
168
|
}
|
|
161
|
-
function
|
|
169
|
+
function V(i, e) {
|
|
162
170
|
const n = [P(i), "/wsdk/integrations/launcher.js"].join("");
|
|
163
171
|
return !e || e.length === 0 ? n : n + "?extensions=" + e.join(",");
|
|
164
172
|
}
|
|
165
|
-
function
|
|
173
|
+
function z(i) {
|
|
166
174
|
return [P(i), "/rokt-elements/rokt-element-thank-you.js"].join("");
|
|
167
175
|
}
|
|
168
176
|
function P(i) {
|
|
169
|
-
const e = typeof i < "u" ? i :
|
|
177
|
+
const e = typeof i < "u" ? i : Oe;
|
|
170
178
|
return e.includes("://") ? e.replace(/\/+$/, "") : ["https://", e].join("");
|
|
171
179
|
}
|
|
172
|
-
function
|
|
180
|
+
function oe(i, e, t) {
|
|
173
181
|
if (i)
|
|
174
182
|
return i.startsWith("http://") || i.startsWith("https://") ? i : "https://" + i;
|
|
175
183
|
const r = e?.includes("://") && !/^https?:\/\//i.test(e) ? void 0 : e;
|
|
176
184
|
return P(r) + t;
|
|
177
185
|
}
|
|
178
|
-
function
|
|
186
|
+
function J(i, e, t) {
|
|
179
187
|
if (document.getElementById(i)) return;
|
|
180
188
|
const n = document.head || document.body, r = document.createElement("script");
|
|
181
189
|
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);
|
|
@@ -190,12 +198,12 @@ function N(i) {
|
|
|
190
198
|
}
|
|
191
199
|
return [];
|
|
192
200
|
}
|
|
193
|
-
function
|
|
201
|
+
function B(i) {
|
|
194
202
|
const e = i ? N(i) : [], t = [], n = [];
|
|
195
203
|
let r = !1;
|
|
196
204
|
for (let s = 0; s < e.length; s++) {
|
|
197
205
|
const o = e[s].value;
|
|
198
|
-
o === "thank-you-journey" ? (r = !0, n.push(
|
|
206
|
+
o === "thank-you-journey" ? (r = !0, n.push(Ae)) : t.push(o);
|
|
199
207
|
}
|
|
200
208
|
return {
|
|
201
209
|
roktExtensionsQueryParams: t,
|
|
@@ -203,14 +211,14 @@ function z(i) {
|
|
|
203
211
|
loadThankYouElement: r
|
|
204
212
|
};
|
|
205
213
|
}
|
|
206
|
-
async function
|
|
214
|
+
async function Me(i, e) {
|
|
207
215
|
const t = [];
|
|
208
216
|
if (e)
|
|
209
217
|
for (const n of i)
|
|
210
218
|
t.push(e.use(n));
|
|
211
219
|
return Promise.all(t);
|
|
212
220
|
}
|
|
213
|
-
function
|
|
221
|
+
function q(i) {
|
|
214
222
|
if (!i)
|
|
215
223
|
return {};
|
|
216
224
|
const e = {};
|
|
@@ -220,7 +228,7 @@ function J(i) {
|
|
|
220
228
|
}
|
|
221
229
|
return e;
|
|
222
230
|
}
|
|
223
|
-
function
|
|
231
|
+
function $(i) {
|
|
224
232
|
const e = {};
|
|
225
233
|
if (!Array.isArray(i))
|
|
226
234
|
return e;
|
|
@@ -236,14 +244,14 @@ function B(i) {
|
|
|
236
244
|
}
|
|
237
245
|
return e;
|
|
238
246
|
}
|
|
239
|
-
function
|
|
247
|
+
function Q(i, e, t) {
|
|
240
248
|
return a().generateHash([i, e, t].join(""));
|
|
241
249
|
}
|
|
242
|
-
function
|
|
243
|
-
let n = "mParticle_wsdkv_" + a().getVersion() + "_kitv_" + "1.33.
|
|
250
|
+
function Ke(i) {
|
|
251
|
+
let n = "mParticle_wsdkv_" + a().getVersion() + "_kitv_" + "1.33.2";
|
|
244
252
|
return i && (n += "_" + i), n;
|
|
245
253
|
}
|
|
246
|
-
function
|
|
254
|
+
function ae(i) {
|
|
247
255
|
let e = 5381;
|
|
248
256
|
for (let t = 0; t < i.length; t++)
|
|
249
257
|
e = (e << 5) + e + i.charCodeAt(t), e = e & e;
|
|
@@ -257,41 +265,41 @@ function K(i) {
|
|
|
257
265
|
const t = document.body || document.head;
|
|
258
266
|
t && t.appendChild(e);
|
|
259
267
|
}
|
|
260
|
-
function
|
|
261
|
-
const t =
|
|
262
|
-
if (I._allowedOriginHashes.indexOf(t) === -1 || Math.random() >=
|
|
268
|
+
function X(i, e) {
|
|
269
|
+
const t = ae(window.location.origin);
|
|
270
|
+
if (I._allowedOriginHashes.indexOf(t) === -1 || Math.random() >= ye)
|
|
263
271
|
return;
|
|
264
272
|
const r = window.__rokt_li_guid__;
|
|
265
273
|
if (!r || i && i.includes("://") && !/^https:\/\//i.test(i))
|
|
266
274
|
return;
|
|
267
275
|
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
276
|
K(c + "/v1/wsdk-init/index.html?" + o), K(
|
|
269
|
-
"https://" +
|
|
277
|
+
"https://" + Se + "/v1/wsdk-init/index.html?" + o + "&isControl=true"
|
|
270
278
|
);
|
|
271
279
|
}
|
|
272
|
-
function
|
|
280
|
+
function De() {
|
|
273
281
|
return typeof window < "u" && !!window.location?.search?.toLowerCase().includes("mp_enable_logging=true");
|
|
274
282
|
}
|
|
275
|
-
function
|
|
283
|
+
function Fe() {
|
|
276
284
|
return typeof window < "u" ? window.location?.href : void 0;
|
|
277
285
|
}
|
|
278
|
-
function
|
|
286
|
+
function Ye() {
|
|
279
287
|
return typeof window < "u" ? window.navigator?.userAgent : void 0;
|
|
280
288
|
}
|
|
281
|
-
class
|
|
289
|
+
class ce {
|
|
282
290
|
constructor() {
|
|
283
291
|
this._logCount = {};
|
|
284
292
|
}
|
|
285
293
|
incrementAndCheck(e) {
|
|
286
294
|
const n = (this._logCount[e] || 0) + 1;
|
|
287
|
-
return this._logCount[e] = n, n >
|
|
295
|
+
return this._logCount[e] = n, n > Ce;
|
|
288
296
|
}
|
|
289
297
|
}
|
|
290
298
|
class Y {
|
|
291
299
|
constructor(e, t, n, r, s) {
|
|
292
300
|
this._reporter = "mp-wsdk";
|
|
293
301
|
const o = e.isLoggingEnabled;
|
|
294
|
-
this._integrationName = t || "", this._launcherInstanceGuid = n, this._accountId = r || null, this._rateLimiter = s || new
|
|
302
|
+
this._integrationName = t || "", this._launcherInstanceGuid = n, this._accountId = r || null, this._rateLimiter = s || new ce(), this._isEnabled = De() || o;
|
|
295
303
|
}
|
|
296
304
|
send(e, t, n, r, s, o) {
|
|
297
305
|
if (!(!this._isEnabled || this._rateLimiter.incrementAndCheck(t)))
|
|
@@ -303,8 +311,8 @@ class Y {
|
|
|
303
311
|
},
|
|
304
312
|
severity: t,
|
|
305
313
|
code: r || F.UNKNOWN_ERROR,
|
|
306
|
-
url:
|
|
307
|
-
deviceInfo:
|
|
314
|
+
url: Fe(),
|
|
315
|
+
deviceInfo: Ye(),
|
|
308
316
|
stackTrace: s,
|
|
309
317
|
reporter: this._reporter,
|
|
310
318
|
integration: this._integrationName
|
|
@@ -320,8 +328,8 @@ class Y {
|
|
|
320
328
|
body: JSON.stringify(c)
|
|
321
329
|
}).then((l) => {
|
|
322
330
|
if (!l.ok) {
|
|
323
|
-
const
|
|
324
|
-
throw
|
|
331
|
+
const g = new Error("HTTP " + l.status + " from log endpoint");
|
|
332
|
+
throw g.statusCode = l.status, g;
|
|
325
333
|
}
|
|
326
334
|
}).catch((l) => {
|
|
327
335
|
console.error("ReportingTransport: Failed to send log", l), o && o(l);
|
|
@@ -331,9 +339,9 @@ class Y {
|
|
|
331
339
|
}
|
|
332
340
|
}
|
|
333
341
|
}
|
|
334
|
-
class
|
|
342
|
+
class Z {
|
|
335
343
|
constructor(e, t, n, r, s) {
|
|
336
|
-
this._transport = new Y(e, t, n, r, s), this._errorUrl =
|
|
344
|
+
this._transport = new Y(e, t, n, r, s), this._errorUrl = oe(e?.errorUrl, e?.integrationDomain, Ue);
|
|
337
345
|
}
|
|
338
346
|
report(e) {
|
|
339
347
|
if (!e) return;
|
|
@@ -341,9 +349,9 @@ class Q {
|
|
|
341
349
|
this._transport.send(this._errorUrl, t, e.message, e.code, e.stackTrace);
|
|
342
350
|
}
|
|
343
351
|
}
|
|
344
|
-
class
|
|
352
|
+
class ee {
|
|
345
353
|
constructor(e, t, n, r, s, o) {
|
|
346
|
-
this._transport = new Y(e, n, r, s, o), this._loggingUrl =
|
|
354
|
+
this._transport = new Y(e, n, r, s, o), this._loggingUrl = oe(e?.loggingUrl, e?.integrationDomain, Pe), this._errorReportingService = t;
|
|
347
355
|
}
|
|
348
356
|
log(e) {
|
|
349
357
|
e && this._transport.send(
|
|
@@ -365,8 +373,8 @@ class X {
|
|
|
365
373
|
);
|
|
366
374
|
}
|
|
367
375
|
}
|
|
368
|
-
function
|
|
369
|
-
const e = D(window.location.href), t = i.EventAttributes?.title || document.title, n =
|
|
376
|
+
function xe(i) {
|
|
377
|
+
const e = D(window.location.href), t = i.EventAttributes?.title || document.title, n = _e(), r = i.ActiveTimeOnSite;
|
|
370
378
|
return {
|
|
371
379
|
pageUrl: e,
|
|
372
380
|
sourceMessageId: i.SourceMessageId,
|
|
@@ -424,14 +432,18 @@ const f = class f {
|
|
|
424
432
|
let t;
|
|
425
433
|
try {
|
|
426
434
|
t = D(window.location.href);
|
|
427
|
-
const n =
|
|
428
|
-
n.push(r),
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
435
|
+
const n = j(this.loggingService), r = xe(e);
|
|
436
|
+
if (n.push(r), !me(n)) {
|
|
437
|
+
const s = G() ? "quota" : "ls_unavailable";
|
|
438
|
+
this.loggingService?.log({
|
|
439
|
+
message: `Rokt Kit: Failed to persist page view for ${t} [reason: ${s}]`,
|
|
440
|
+
code: "PAGE_VIEW_CAPTURE_FAILED"
|
|
441
|
+
});
|
|
442
|
+
}
|
|
432
443
|
} catch (n) {
|
|
444
|
+
const r = G() ? "exception" : "ls_unavailable", s = n instanceof Error ? n.message : String(n);
|
|
433
445
|
this.loggingService?.log({
|
|
434
|
-
message: `Rokt Kit: Failed to capture page view for ${t}: ${
|
|
446
|
+
message: `Rokt Kit: Failed to capture page view for ${t}: ${s} [reason: ${r}]`,
|
|
435
447
|
code: "PAGE_VIEW_CAPTURE_FAILED"
|
|
436
448
|
});
|
|
437
449
|
}
|
|
@@ -459,7 +471,7 @@ const f = class f {
|
|
|
459
471
|
if (!window.mParticle || typeof a().logEvent != "function" || !_(e))
|
|
460
472
|
return;
|
|
461
473
|
const t = a().EventType.Other;
|
|
462
|
-
a().logEvent(
|
|
474
|
+
a().logEvent(Ie, t, e);
|
|
463
475
|
}
|
|
464
476
|
setRoktSessionId(e) {
|
|
465
477
|
if (!(!e || typeof e != "string"))
|
|
@@ -483,7 +495,7 @@ const f = class f {
|
|
|
483
495
|
};
|
|
484
496
|
let s;
|
|
485
497
|
this.isPartnerInLocalLauncherTestGroup() ? s = Promise.resolve(window.Rokt.createLocalLauncher(r)) : s = window.Rokt.createLauncher(r), s.then(async (o) => {
|
|
486
|
-
await
|
|
498
|
+
await Me(n, o), this.initRoktLauncher(o);
|
|
487
499
|
}).catch((o) => {
|
|
488
500
|
console.error("Error creating Rokt launcher:", o);
|
|
489
501
|
});
|
|
@@ -491,7 +503,7 @@ const f = class f {
|
|
|
491
503
|
initRoktLauncher(e) {
|
|
492
504
|
window.Rokt && (window.Rokt.currentLauncher = e), this.launcher = e;
|
|
493
505
|
const t = a().Rokt?.filters;
|
|
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,
|
|
506
|
+
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, X(this.domain, this.integrationName), a().Rokt.attachKit(this);
|
|
495
507
|
}
|
|
496
508
|
fetchOptimizely() {
|
|
497
509
|
const e = a()._getActiveForwarders().filter((t) => t.name === "Optimizely");
|
|
@@ -530,37 +542,37 @@ const f = class f {
|
|
|
530
542
|
const o = e, c = o.accountId;
|
|
531
543
|
this.userAttributes = b(s), this._onboardingExpProvider = o.onboardingExpProvider;
|
|
532
544
|
const u = N(o.placementEventMapping);
|
|
533
|
-
this.placementEventMappingLookup =
|
|
545
|
+
this.placementEventMappingLookup = q(u);
|
|
534
546
|
const l = N(
|
|
535
547
|
o.placementEventAttributeMapping
|
|
536
548
|
);
|
|
537
|
-
this.placementEventAttributeMappingLookup =
|
|
538
|
-
const
|
|
549
|
+
this.placementEventAttributeMappingLookup = $(l), o.hashedEmailUserIdentityType && (this._mappedEmailSha256Key = o.hashedEmailUserIdentityType.toLowerCase()), this._workspaceIdSyncApiKey = m(o.workspaceIdSyncApiKey) ? o.workspaceIdSyncApiKey : void 0;
|
|
550
|
+
const g = a().Rokt?.domain, { roktExtensionsQueryParams: U, legacyRoktExtensions: v, loadThankYouElement: w } = B(
|
|
539
551
|
o.roktExtensions
|
|
540
|
-
),
|
|
552
|
+
), p = {
|
|
541
553
|
...a().Rokt?.launcherOptions || {}
|
|
542
554
|
};
|
|
543
|
-
this.integrationName =
|
|
544
|
-
const
|
|
555
|
+
this.integrationName = Ke(p.integrationName), p.integrationName = this.integrationName, this.domain = g;
|
|
556
|
+
const S = {
|
|
545
557
|
loggingUrl: o.loggingUrl,
|
|
546
558
|
errorUrl: o.errorUrl,
|
|
547
|
-
integrationDomain:
|
|
559
|
+
integrationDomain: g,
|
|
548
560
|
isLoggingEnabled: a().config?.isLoggingEnabled === !0
|
|
549
|
-
},
|
|
550
|
-
|
|
561
|
+
}, y = new Z(
|
|
562
|
+
S,
|
|
551
563
|
this.integrationName,
|
|
552
564
|
window.__rokt_li_guid__,
|
|
553
565
|
o.accountId
|
|
554
|
-
), A = new
|
|
555
|
-
y,
|
|
566
|
+
), A = new ee(
|
|
556
567
|
S,
|
|
568
|
+
y,
|
|
557
569
|
this.integrationName,
|
|
558
570
|
window.__rokt_li_guid__,
|
|
559
571
|
o.accountId
|
|
560
572
|
);
|
|
561
|
-
if (this.errorReportingService =
|
|
573
|
+
if (this.errorReportingService = y, this.loggingService = A, this.isTargetingDisabled())
|
|
562
574
|
try {
|
|
563
|
-
|
|
575
|
+
H();
|
|
564
576
|
} catch (h) {
|
|
565
577
|
this.errorReportingService?.report({
|
|
566
578
|
message: "Rokt Kit: Failed to clear page views when targeting is disabled",
|
|
@@ -569,36 +581,36 @@ const f = class f {
|
|
|
569
581
|
stackTrace: h instanceof Error ? h.stack : void 0
|
|
570
582
|
});
|
|
571
583
|
}
|
|
572
|
-
return a()._registerErrorReportingService && a()._registerErrorReportingService(
|
|
573
|
-
generateLauncherScript:
|
|
574
|
-
generateThankYouElementScript:
|
|
575
|
-
extractRoktExtensionConfig:
|
|
576
|
-
hashEventMessage:
|
|
584
|
+
return a()._registerErrorReportingService && a()._registerErrorReportingService(y), a()._registerLoggingService && a()._registerLoggingService(A), n ? (this.testHelpers = {
|
|
585
|
+
generateLauncherScript: V,
|
|
586
|
+
generateThankYouElementScript: z,
|
|
587
|
+
extractRoktExtensionConfig: B,
|
|
588
|
+
hashEventMessage: Q,
|
|
577
589
|
parseSettingsString: N,
|
|
578
|
-
generateMappedEventLookup:
|
|
579
|
-
generateMappedEventAttributeLookup:
|
|
580
|
-
sendAdBlockMeasurementSignals:
|
|
590
|
+
generateMappedEventLookup: q,
|
|
591
|
+
generateMappedEventAttributeLookup: $,
|
|
592
|
+
sendAdBlockMeasurementSignals: X,
|
|
581
593
|
createAutoRemovedIframe: K,
|
|
582
|
-
djb2:
|
|
594
|
+
djb2: ae,
|
|
583
595
|
setAllowedOriginHashes: (h) => {
|
|
584
596
|
f._allowedOriginHashes = h;
|
|
585
597
|
},
|
|
586
598
|
ReportingTransport: Y,
|
|
587
|
-
ErrorReportingService:
|
|
588
|
-
LoggingService:
|
|
589
|
-
RateLimiter:
|
|
599
|
+
ErrorReportingService: Z,
|
|
600
|
+
LoggingService: ee,
|
|
601
|
+
RateLimiter: ce,
|
|
590
602
|
ErrorCodes: F,
|
|
591
603
|
WSDKErrorSeverity: E
|
|
592
|
-
}, this.attachLauncher(c,
|
|
604
|
+
}, this.attachLauncher(c, p), "Successfully initialized: " + d) : (w && (a().Rokt.flushOnShoppableAdsReadyMessageQueue?.(this), J(Re, z(g), {
|
|
593
605
|
onLoad: () => {
|
|
594
606
|
this._isThankYouElementLoaded = !0, this._thankYouElementOnLoadCallback && this._thankYouElementOnLoadCallback();
|
|
595
607
|
},
|
|
596
608
|
onError: (h) => {
|
|
597
609
|
console.error("Error loading Rokt Thank You Element script:", h);
|
|
598
610
|
}
|
|
599
|
-
})), this.isLauncherReadyToAttach() ? this.attachLauncher(c,
|
|
611
|
+
})), this.isLauncherReadyToAttach() ? this.attachLauncher(c, p, v) : (J(ke, V(g, U), {
|
|
600
612
|
onLoad: () => {
|
|
601
|
-
this.isLauncherReadyToAttach() ? this.attachLauncher(c,
|
|
613
|
+
this.isLauncherReadyToAttach() ? this.attachLauncher(c, p, v) : console.error("Rokt object is not available after script load.");
|
|
602
614
|
},
|
|
603
615
|
onError: (h) => {
|
|
604
616
|
console.error("Error loading Rokt launcher script:", h);
|
|
@@ -606,10 +618,10 @@ const f = class f {
|
|
|
606
618
|
}), this.captureTiming(f.PERFORMANCE_MARKS.RoktScriptAppended)), "Successfully initialized: " + d);
|
|
607
619
|
}
|
|
608
620
|
process(e) {
|
|
609
|
-
if (this.isTargetingDisabled() || (e.EventDataType ===
|
|
621
|
+
if (this.isTargetingDisabled() || (e.EventDataType === we && this.capturePageView(e), e.EventDataType === be && (se(this.loggingService), H())), !this.isKitReady())
|
|
610
622
|
return "Kit not ready for forwarder: " + d;
|
|
611
623
|
if (L(a().Rokt?.setLocalSessionAttribute) && (C(this.placementEventAttributeMappingLookup) || this.applyPlacementEventAttributeMapping(e), !C(this.placementEventMappingLookup))) {
|
|
612
|
-
const t =
|
|
624
|
+
const t = Q(e.EventDataType, e.EventCategory, e.EventName ?? "");
|
|
613
625
|
this.placementEventMappingLookup[String(t)] && a().Rokt.setLocalSessionAttribute?.(this.placementEventMappingLookup[String(t)], !0);
|
|
614
626
|
}
|
|
615
627
|
return "Successfully sent to forwarder: " + d;
|
|
@@ -622,7 +634,7 @@ const f = class f {
|
|
|
622
634
|
window.Rokt.setExtensionData(e);
|
|
623
635
|
}
|
|
624
636
|
setUserAttribute(e, t) {
|
|
625
|
-
return
|
|
637
|
+
return te(e) || (this.userAttributes[e] = t), "Successfully set user attribute for forwarder: " + d;
|
|
626
638
|
}
|
|
627
639
|
removeUserAttribute(e) {
|
|
628
640
|
return delete this.userAttributes[e], "Successfully removed user attribute for forwarder: " + d;
|
|
@@ -698,7 +710,7 @@ const f = class f {
|
|
|
698
710
|
const t = this._workspaceSearchInFlightPromise;
|
|
699
711
|
return Promise.race([
|
|
700
712
|
t,
|
|
701
|
-
new Promise((n) => setTimeout(n,
|
|
713
|
+
new Promise((n) => setTimeout(n, Ne))
|
|
702
714
|
]).then(() => this._dispatchPlacements(e));
|
|
703
715
|
}
|
|
704
716
|
return this._dispatchPlacements(e);
|
|
@@ -707,17 +719,17 @@ const f = class f {
|
|
|
707
719
|
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;
|
|
708
720
|
let l;
|
|
709
721
|
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
|
|
722
|
+
const g = this._onboardingExpProvider === "Optimizely" ? this.fetchOptimizely() : {}, U = this.returnUserIdentities(c), v = this.returnLocalSessionAttributes(), w = Ee(j(this.loggingService)), p = this.readMpSessionId(), S = {
|
|
711
723
|
...U,
|
|
712
724
|
...l,
|
|
713
|
-
...
|
|
725
|
+
...g,
|
|
714
726
|
...v,
|
|
715
|
-
...w.length ? { [
|
|
716
|
-
...this.userIdentifiedInWorkspace ? { [
|
|
717
|
-
...
|
|
727
|
+
...w.length ? { [Le]: JSON.stringify(w) } : {},
|
|
728
|
+
...this.userIdentifiedInWorkspace ? { [ve]: !0 } : {},
|
|
729
|
+
...p ? { [Te]: p } : {},
|
|
718
730
|
mpid: u
|
|
719
|
-
},
|
|
720
|
-
return Promise.resolve(A).then((
|
|
731
|
+
}, y = { ...e, attributes: S }, A = this.launcher.selectPlacements(y), h = () => this.logSelectPlacementsEvent(S);
|
|
732
|
+
return Promise.resolve(A).then((le) => le?.context?.sessionId?.then((ue) => this.setRoktSessionId(ue))).catch(() => {
|
|
721
733
|
}).finally(h), A;
|
|
722
734
|
}
|
|
723
735
|
/**
|
|
@@ -745,10 +757,10 @@ f._allowedOriginHashes = [-553112570, 549508659], f.PERFORMANCE_MARKS = {
|
|
|
745
757
|
RoktScriptAppended: "mp:RoktScriptAppended"
|
|
746
758
|
}, f.EMAIL_SHA256_KEY = "emailsha256";
|
|
747
759
|
let I = f;
|
|
748
|
-
function
|
|
760
|
+
function Ge() {
|
|
749
761
|
return T;
|
|
750
762
|
}
|
|
751
|
-
function
|
|
763
|
+
function We(i) {
|
|
752
764
|
if (!i) {
|
|
753
765
|
window.console.log("You must pass a config object to register the kit " + d);
|
|
754
766
|
return;
|
|
@@ -766,9 +778,9 @@ function xe(i) {
|
|
|
766
778
|
typeof window < "u" && window.mParticle && a().addForwarder && a().addForwarder({
|
|
767
779
|
name: d,
|
|
768
780
|
constructor: I,
|
|
769
|
-
getId:
|
|
781
|
+
getId: Ge
|
|
770
782
|
});
|
|
771
783
|
export {
|
|
772
|
-
|
|
784
|
+
We as register
|
|
773
785
|
};
|
|
774
786
|
//# sourceMappingURL=Rokt-Kit.esm.js.map
|
package/dist/Rokt-Kit.iife.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
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.1";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,t=e?.getSessionId??e?.getSession;if(w(t))return t.call(e)||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})({});
|
|
1
|
+
var RoktKit=(function(U){"use strict";const ue=["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"],de=new Set(ue);function G(i){return de.has(i.toLowerCase())}function v(i){const e={},t=i||{},n=Object.keys(t);for(let r=0;r<n.length;r++){const s=n[r];G(s)||(e[s]=t[s])}return e}function E(i){return typeof i=="object"&&i!==null&&!Array.isArray(i)}function m(i){return typeof i=="string"}function 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}}const W="__rokt_ls_probe__";function j(){try{return window.localStorage.setItem(W,"1"),window.localStorage.removeItem(W),!0}catch{return!1}}function b(i){try{const e=window.localStorage.getItem(i);return e===null?null:JSON.parse(e)}catch{return null}}function H(i,e){try{return window.localStorage.setItem(i,JSON.stringify(e)),!0}catch{return!1}}function V(i){try{window.localStorage.removeItem(i)}catch{}}function z(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,H(i,r)}function he(i,e){const t=b(i);if(!E(t)||!(e in t))return;const n={...t};delete n[e],Object.keys(n).length===0?V(i):H(i,n)}function ge(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 y="mp-rokt-kit",I="pageViews",J="mpPageViews",pe=100*1024;function B(i){const e=b(J);if(e===null)return;if(!(z(y,I)!==void 0)&&Array.isArray(e)&&!K(y,I,e)){i?.log({message:"Rokt Kit: Failed to migrate legacy page-view storage; retaining legacy key for retry [reason: migration_retry]",code:"PAGE_VIEW_CAPTURE_FAILED"});return}V(J)}function q(i){B(i);const e=z(y,I);return Array.isArray(e)?e:[]}function fe(i){return ge(y,I,i,pe)}function $(){he(y,I)}function me(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 Ee(){const e=document.querySelector('link[rel="canonical"]')?.href;if(e)return M(e)}const d="Rokt",L=181,_e="selectPlacements",Se="apps.roktecommerce.com",ye=.1,Ie="ThankYouPageJourney",ke="rokt-launcher",Ae="rokt-thank-you-element",Re="userIdentifiedInWorkspace",ve=3,we=2,be="page_events",Le="mparticle_session_id",Te=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"},Ne="apps.rokt-api.com",Oe="/v1/log",Pe="/v1/errors",Ue=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 X(i){return[T(i),"/rokt-elements/rokt-element-thank-you.js"].join("")}function T(i){const e=typeof i<"u"?i:Ne;return e.includes("://")?e.replace(/\/+$/,""):["https://",e].join("")}function Z(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 ee(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 te(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 Ce(i,e){const t=[];if(e)for(const n of i)t.push(e.use(n));return Promise.all(t)}function ie(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 ne(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 re(i,e,t){return a().generateHash([i,e,t].join(""))}function Me(i){let n="mParticle_wsdkv_"+a().getVersion()+"_kitv_"+"1.33.2";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 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 oe(i,e){const t=se(window.location.origin);if(S._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?T(i):"https://apps.rokt.com";F(c+"/v1/wsdk-init/index.html?"+o),F("https://"+Se+"/v1/wsdk-init/index.html?"+o+"&isControl=true")}function Ke(){return typeof window<"u"&&!!window.location?.search?.toLowerCase().includes("mp_enable_logging=true")}function De(){return typeof window<"u"?window.location?.href:void 0}function Fe(){return typeof window<"u"?window.navigator?.userAgent:void 0}class ae{constructor(){this._logCount={}}incrementAndCheck(e){const n=(this._logCount[e]||0)+1;return this._logCount[e]=n,n>Ue}}class Y{constructor(e,t,n,r,s){this._reporter="mp-wsdk";const o=e.isLoggingEnabled;this._integrationName=t||"",this._launcherInstanceGuid=n,this._accountId=r||null,this._rateLimiter=s||new ae,this._isEnabled=Ke()||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:De(),deviceInfo:Fe(),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 ce{constructor(e,t,n,r,s){this._transport=new Y(e,t,n,r,s),this._errorUrl=Z(e?.errorUrl,e?.integrationDomain,Pe)}report(e){if(!e)return;const t=e.severity||_.ERROR;this._transport.send(this._errorUrl,t,e.message,e.code,e.stackTrace)}}class le{constructor(e,t,n,r,s,o){this._transport=new Y(e,n,r,s,o),this._loggingUrl=Z(e?.loggingUrl,e?.integrationDomain,Oe),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 Ye(i){const e=M(window.location.href),t=i.EventAttributes?.title||document.title,n=Ee(),r=i.ActiveTimeOnSite;return{pageUrl:e,sourceMessageId:i.SourceMessageId,timestamp:i.Timestamp,...t?{pageTitle:t}:{},...n!==void 0?{canonicalUrl:n}:{},...Number.isFinite(r)?{activeTimeOnSite:r}:{}}}const p=class p{constructor(){this.name=d,this.id=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=q(this.loggingService),r=Ye(e);if(n.push(r),!fe(n)){const s=j()?"quota":"ls_unavailable";this.loggingService?.log({message:`Rokt Kit: Failed to persist page view for ${t} [reason: ${s}]`,code:"PAGE_VIEW_CAPTURE_FAILED"})}}catch(n){const r=j()?"exception":"ls_unavailable",s=n instanceof Error?n.message:String(n);this.loggingService?.log({message:`Rokt Kit: Failed to capture page view for ${t}: ${s} [reason: ${r}]`,code:"PAGE_VIEW_CAPTURE_FAILED"})}}isLauncherReadyToAttach(){return!!window.Rokt&&w(window.Rokt.createLauncher)}returnUserIdentities(e){if(!e||!e.getUserIdentities)return{};const t=e.getUserIdentities().userIdentities;return this.replaceOtherIdentityWithEmailsha256(t)}returnLocalSessionAttributes(){return!a().Rokt||typeof a().Rokt.getLocalSessionAttributes!="function"?{}:a().Rokt.getLocalSessionAttributes()}replaceOtherIdentityWithEmailsha256(e){const t={...e||{}},n=this._mappedEmailSha256Key;return n&&e[n]&&(t[p.EMAIL_SHA256_KEY]=e[n]),n&&delete t[n],t}logSelectPlacementsEvent(e){if(!window.mParticle||typeof a().logEvent!="function"||!E(e))return;const t=a().EventType.Other;a().logEvent(_e,t,e)}setRoktSessionId(e){if(!(!e||typeof e!="string"))try{const t=a().getInstance();t&&w(t.setIntegrationAttribute)&&t.setIntegrationAttribute(L,{roktSessionId:e})}catch{}}readMpSessionId(){const e=a()?.sessionManager,t=e?.getSessionId??e?.getSession;if(w(t))return t.call(e)||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 Ce(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,oe(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=ie(u);const l=N(o.placementEventAttributeMapping);this.placementEventAttributeMappingLookup=ne(l),o.hashedEmailUserIdentityType&&(this._mappedEmailSha256Key=o.hashedEmailUserIdentityType.toLowerCase()),this._workspaceIdSyncApiKey=m(o.workspaceIdSyncApiKey)?o.workspaceIdSyncApiKey:void 0;const g=a().Rokt?.domain,{roktExtensionsQueryParams:x,legacyRoktExtensions:O,loadThankYouElement:P}=te(o.roktExtensions),f={...a().Rokt?.launcherOptions||{}};this.integrationName=Me(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 ce(k,this.integrationName,window.__rokt_li_guid__,o.accountId),R=new le(k,A,this.integrationName,window.__rokt_li_guid__,o.accountId);if(this.errorReportingService=A,this.loggingService=R,this.isTargetingDisabled())try{$()}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:X,extractRoktExtensionConfig:te,hashEventMessage:re,parseSettingsString:N,generateMappedEventLookup:ie,generateMappedEventAttributeLookup:ne,sendAdBlockMeasurementSignals:oe,createAutoRemovedIframe:F,djb2:se,setAllowedOriginHashes:h=>{p._allowedOriginHashes=h},ReportingTransport:Y,ErrorReportingService:ce,LoggingService:le,RateLimiter:ae,ErrorCodes:D,WSDKErrorSeverity:_},this.attachLauncher(c,f),"Successfully initialized: "+d):(P&&(a().Rokt.flushOnShoppableAdsReadyMessageQueue?.(this),ee(Ae,X(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):(ee(ke,Q(g,x),{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===ve&&this.capturePageView(e),e.EventDataType===we&&(B(this.loggingService),$())),!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=re(e.EventDataType,e.EventCategory,e.EventName??"");this.placementEventMappingLookup[String(t)]&&a().Rokt.setLocalSessionAttribute?.(this.placementEventMappingLookup[String(t)],!0)}return"Successfully sent to forwarder: "+d}setExtensionData(e){if(!this.isKitReady()){console.error("Rokt Kit: Not initialized");return}window.Rokt.setExtensionData(e)}setUserAttribute(e,t){return G(e)||(this.userAttributes[e]=t),"Successfully set user attribute for forwarder: "+d}removeUserAttribute(e){return delete this.userAttributes[e],"Successfully removed user attribute for forwarder: "+d}handleIdentityComplete(e,t){return this.userAttributes=v(e.getAllUserAttributes()),"Successfully called "+t+" for forwarder: "+d}onUserIdentified(e){const t=e;return this.filters.filteredUser=t,this._workspaceSearchInFlightPromise=this.search(t),this.handleIdentityComplete(e,"onUserIdentified")}search(e){const t=this._workspaceIdSyncApiKey;if(!t)return this.userIdentifiedInWorkspace=!1,this._workspaceLastSearchedIdentitiesKey=void 0,Promise.resolve();const n=a().Identity?.search;if(typeof n!="function")return this.userIdentifiedInWorkspace=!1,this._workspaceLastSearchedIdentitiesKey=void 0,Promise.resolve();const r=e.getUserIdentities?e.getUserIdentities().userIdentities:null,s={};if(r)for(const u of Object.keys(r)){const l=r[u];m(l)&&l.length>0&&(s[u]=l)}const o=Object.keys(s);if(o.length===0)return this.userIdentifiedInWorkspace=!1,this._workspaceLastSearchedIdentitiesKey=void 0,Promise.resolve();const c=o.sort().map(u=>`${u}=${s[u]}`).join("&");return c===this._workspaceLastSearchedIdentitiesKey?this._workspaceSearchInFlightPromise||Promise.resolve():(this.userIdentifiedInWorkspace=!1,this._workspaceLastSearchedIdentitiesKey=c,new Promise(u=>{try{n(t,s,l=>{l?.httpCode===200&&(this.userIdentifiedInWorkspace=!0),u()})}catch(l){console.error("Rokt Kit: Workspace IDSync search failed",l),this._workspaceLastSearchedIdentitiesKey=void 0,u()}}))}onLoginComplete(e,t){return this.handleIdentityComplete(e,"onLoginComplete")}onLogoutComplete(e,t){return this.userIdentifiedInWorkspace=!1,this._workspaceSearchInFlightPromise=null,this._workspaceLastSearchedIdentitiesKey=void 0,this.handleIdentityComplete(e,"onLogoutComplete")}onModifyComplete(e,t){return this.handleIdentityComplete(e,"onModifyComplete")}selectPlacements(e){if(this._workspaceSearchInFlightPromise){const t=this._workspaceSearchInFlightPromise;return Promise.race([t,new Promise(n=>setTimeout(n,Te))]).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():{},x=this.returnUserIdentities(c),O=this.returnLocalSessionAttributes(),P=me(q(this.loggingService)),f=this.readMpSessionId(),k={...x,...l,...g,...O,...P.length?{[be]:JSON.stringify(P)}:{},...this.userIdentifiedInWorkspace?{[Re]:!0}:{},...f?{[Le]:f}:{},mpid:u},A={...e,attributes:k},R=this.launcher.selectPlacements(A),h=()=>this.logSelectPlacementsEvent(k);return Promise.resolve(R).then(We=>We?.context?.sessionId?.then(je=>this.setRoktSessionId(je))).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 S=p;function xe(){return L}function Ge(i){if(!i){window.console.log("You must pass a config object to register the kit "+d);return}if(!E(i)){window.console.log("'config' must be an object. You passed in a "+typeof i);return}E(i.kits)?i.kits[d]={constructor:S}:(i.kits={},i.kits[d]={constructor:S}),window.console.log("Successfully registered "+d+" to your mParticle configuration")}return typeof window<"u"&&window.mParticle&&a().addForwarder&&a().addForwarder({name:d,constructor:S,getId:xe}),U.register=Ge,Object.defineProperty(U,Symbol.toStringTag,{value:"Module"}),U})({});
|
|
2
2
|
//# sourceMappingURL=Rokt-Kit.iife.js.map
|