@mparticle/web-rokt-kit 1.26.3 → 1.27.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Rokt-Kit.common.js +1 -1
- package/dist/Rokt-Kit.esm.js +257 -208
- 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 l="Rokt",S=181,Q="selectPlacements",B="apps.roktecommerce.com",V=.1,w={LOGIN:"login",LOGOUT:"logout",MODIFY_USER:"modify_user",IDENTIFY:"identify"},q="ThankYouPageJourney",J="rokt-launcher",X="rokt-thank-you-element",$="userIdentifiedInWorkspace",Z=500,N={UNKNOWN_ERROR:"UNKNOWN_ERROR",UNHANDLED_EXCEPTION:"UNHANDLED_EXCEPTION",IDENTITY_REQUEST:"IDENTITY_REQUEST"},v={ERROR:"ERROR",INFO:"INFO",WARNING:"WARNING"},ee="apps.rokt-api.com/v1/log",te="apps.rokt-api.com/v1/errors",ie=10;function o(){return window.mParticle}function U(n,e){const i=[G(n),"/wsdk/integrations/launcher.js"].join("");return!e||e.length===0?i:i+"?extensions="+e.join(",")}function C(n){return[G(n),"/rokt-elements/rokt-element-thank-you.js"].join("")}function G(n){return["https://",typeof n<"u"?n:"apps.rokt-api.com"].join("")}function M(n,e,t){if(document.getElementById(n))return;const i=document.head||document.body,r=document.createElement("script");r.id=n,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),i.appendChild(r)}function O(n){return n!=null&&typeof n=="object"&&Array.isArray(n)===!1}function A(n){if(!n)return[];try{return JSON.parse(n.replace(/"/g,'"'))}catch{console.error("Settings string contains invalid JSON")}return[]}function K(n){const e=n?A(n):[],t=[],i=[];let r=!1;for(let a=0;a<e.length;a++){const s=e[a].value;s==="thank-you-journey"?(r=!0,i.push(q)):t.push(s)}return{roktExtensionsQueryParams:t,legacyRoktExtensions:i,loadThankYouElement:r}}async function ne(n,e){const t=[];if(e)for(const i of n)t.push(e.use(i));return Promise.all(t)}function D(n){if(!n)return{};const e={};for(let t=0;t<n.length;t++){const i=n[t];e[i.jsmap]=i.value}return e}function x(n){const e={};if(!Array.isArray(n))return e;for(let t=0;t<n.length;t++){const i=n[t];if(!i||!g(i.value)||!g(i.map))continue;const r=i.value,a=i.map;e[r]||(e[r]=[]),e[r].push({eventAttributeKey:a,conditions:Array.isArray(i.conditions)?i.conditions:[]})}return e}function Y(n,e,t){return o().generateHash([n,e,t].join(""))}function k(n){return n==null?!0:typeof n=="object"?Object.keys(n).length===0:Array.isArray(n)?n.length===0:!1}function g(n){return typeof n=="string"}function re(n){let i="mParticle_wsdkv_"+o().getVersion()+"_kitv_"+"1.26.3";return n&&(i+="_"+n),i}function W(n){let e=5381;for(let t=0;t<n.length;t++)e=(e<<5)+e+n.charCodeAt(t),e=e&e;return e}function T(n){const e=document.createElement("iframe");e.style.display="none",e.setAttribute("sandbox","allow-scripts allow-same-origin"),e.src=n,e.onload=function(){e.onload=null,e.parentNode&&e.parentNode.removeChild(e)};const t=document.body||document.head;t&&t.appendChild(e)}function F(n,e){const t=W(window.location.origin);if(f._allowedOriginHashes.indexOf(t)===-1||Math.random()>=V)return;const r=window.__rokt_li_guid__;if(!r)return;const a=window.location.href.split("?")[0].split("#")[0],s="version="+encodeURIComponent(e??"")+"&launcherInstanceGuid="+encodeURIComponent(r)+"&pageUrl="+encodeURIComponent(a);T("https://"+(n||"apps.rokt.com")+"/v1/wsdk-init/index.html?"+s),T("https://"+B+"/v1/wsdk-init/index.html?"+s+"&isControl=true")}function se(){return typeof window<"u"&&!!window.location?.search?.toLowerCase().includes("mp_enable_logging=true")}function oe(){return typeof window<"u"?window.location?.href:void 0}function ae(){return typeof window<"u"?window.navigator?.userAgent:void 0}class z{constructor(){this._logCount={}}incrementAndCheck(e){const i=(this._logCount[e]||0)+1;return this._logCount[e]=i,i>ie}}class P{constructor(e,t,i,r,a){this._reporter="mp-wsdk";const s=e.isLoggingEnabled;this._integrationName=t||"",this._launcherInstanceGuid=i,this._accountId=r||null,this._rateLimiter=a||new z,this._isEnabled=se()||s}send(e,t,i,r,a,s){if(!(!this._isEnabled||this._rateLimiter.incrementAndCheck(t)))try{const c={additionalInformation:{message:i,version:this._integrationName},severity:t,code:r||N.UNKNOWN_ERROR,url:oe(),deviceInfo:ae(),stackTrace:a,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)}).catch(d=>{console.error("ReportingTransport: Failed to send log",d),s&&s(d)})}catch(c){console.error("ReportingTransport: Failed to send log",c),s&&s(c)}}}class j{constructor(e,t,i,r,a){this._transport=new P(e,t,i,r,a),this._errorUrl="https://"+(e?.errorUrl||te)}report(e){if(!e)return;const t=e.severity||v.ERROR;this._transport.send(this._errorUrl,t,e.message,e.code,e.stackTrace)}}class H{constructor(e,t,i,r,a,s){this._transport=new P(e,i,r,a,s),this._loggingUrl="https://"+(e?.loggingUrl||ee),this._errorReportingService=t}log(e){e&&this._transport.send(this._loggingUrl,v.INFO,e.message,e.code,void 0,t=>{this._errorReportingService&&this._errorReportingService.report({message:"LoggingService: Failed to send log: "+t.message,code:N.UNKNOWN_ERROR,severity:v.ERROR})})}}const p=class p{constructor(){this.name=l,this.id=S,this.moduleId=S,this.isInitialized=!1,this.launcher=null,this.filters={},this.userAttributes={},this.userIdentifiedInWorkspace=!1,this.testHelpers=null,this.placementEventMappingLookup={},this.placementEventAttributeMappingLookup={},this.batchQueue=[],this.batchStreamQueue=[],this.pendingIdentityEvents=[],this.integrationName=null,this.errorReportingService=null,this.loggingService=null,this._thankYouElementOnLoadCallback=null,this._isThankYouElementLoaded=!1,this._workspaceSearchInFlightPromise=null}getEventAttributeValue(e,t){const i=e&&e.EventAttributes;return!i||typeof i[t]>"u"?null:i[t]}doesEventAttributeConditionMatch(e,t){if(!e||!g(e.operator))return!1;const i=e.operator.toLowerCase(),r=e.attributeValue;return i==="exists"?t!==null:t==null?!1:i==="equals"?String(t)===String(r):i==="contains"?String(t).indexOf(String(r))!==-1:!1}doesEventMatchRule(e,t){if(!t||!g(t.eventAttributeKey))return!1;const i=t.conditions;if(!Array.isArray(i))return!1;const r=this.getEventAttributeValue(e,t.eventAttributeKey);if(i.length===0)return r!==null;for(let a=0;a<i.length;a++)if(!this.doesEventAttributeConditionMatch(i[a],r))return!1;return!0}applyPlacementEventAttributeMapping(e){const t=Object.keys(this.placementEventAttributeMappingLookup);for(let i=0;i<t.length;i++){const r=t[i],a=this.placementEventAttributeMappingLookup[r];if(k(a))continue;let s=!0;for(let c=0;c<a.length;c++)if(!this.doesEventMatchRule(e,a[c])){s=!1;break}s&&o().Rokt.setLocalSessionAttribute?.(r,!0)}}isLauncherReadyToAttach(){return!!window.Rokt&&typeof window.Rokt.createLauncher=="function"}returnUserIdentities(e){if(!e||!e.getUserIdentities)return{};const t=e.getUserIdentities().userIdentities;return this.replaceOtherIdentityWithEmailsha256(t)}returnLocalSessionAttributes(){return!o().Rokt||typeof o().Rokt.getLocalSessionAttributes!="function"?{}:k(this.placementEventMappingLookup)&&k(this.placementEventAttributeMappingLookup)?{}:o().Rokt.getLocalSessionAttributes()}replaceOtherIdentityWithEmailsha256(e){const t={...e||{}},i=this._mappedEmailSha256Key;return i&&e[i]&&(t[p.EMAIL_SHA256_KEY]=e[i]),i&&delete t[i],t}logSelectPlacementsEvent(e){if(!window.mParticle||typeof o().logEvent!="function"||!O(e))return;const t=o().EventType.Other;o().logEvent(Q,t,e)}buildIdentityEvent(e,t){const i=t.getMPID(),r=o()&&o().sessionManager&&typeof o().sessionManager.getSession=="function"?o().sessionManager.getSession():void 0;return{event_type:e,data:{timestamp_unixtime_ms:Date.now(),session_uuid:r??void 0,mpid:i}}}mergePendingIdentityEvents(e){if(this.pendingIdentityEvents.length===0)return e;const t={...e,events:[...e.events??[],...this.pendingIdentityEvents]};return this.pendingIdentityEvents=[],t}drainBatchQueue(){this.batchQueue.forEach(e=>{this.processBatch(e)}),this.batchQueue=[]}processBatch(e){return this.isKitReady()?(this.sendBatchStream(this.mergePendingIdentityEvents(e)),"Successfully sent batch to forwarder: "+l):(this.batchQueue.push(e),"Batch queued for forwarder: "+l)}sendBatchStream(e){if(window.Rokt&&typeof window.Rokt.__batch_stream__=="function"){if(this.batchStreamQueue.length){const t=this.batchStreamQueue;this.batchStreamQueue=[];for(let i=0;i<t.length;i++)window.Rokt.__batch_stream__(t[i])}window.Rokt.__batch_stream__(e)}else this.batchStreamQueue.push(e)}setRoktSessionId(e){if(!(!e||typeof e!="string"))try{const t=o().getInstance();t&&typeof t.setIntegrationAttribute=="function"&&t.setIntegrationAttribute(S,{roktSessionId:e})}catch{}}attachLauncher(e,t,i=[]){const r=o()&&o().sessionManager&&typeof o().sessionManager.getSession=="function"?o().sessionManager.getSession():void 0,a={accountId:e,...t||{},...r?{mpSessionId:r}:{}};let s;this.isPartnerInLocalLauncherTestGroup()?s=Promise.resolve(window.Rokt.createLocalLauncher(a)):s=window.Rokt.createLauncher(a),s.then(async c=>{await ne(i,c),this.initRoktLauncher(c)}).catch(c=>{console.error("Error creating Rokt launcher:",c)})}initRoktLauncher(e){window.Rokt&&(window.Rokt.currentLauncher=e),this.launcher=e;const t=o().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,F(this.domain,this.integrationName),o().Rokt.attachKit(this),this.drainBatchQueue()}fetchOptimizely(){const e=o()._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((a,s)=>(a["rokt.custom.optimizely.experiment."+s+".variationId"]=t.getVariationMap()[s].id,a),{})}}catch(t){console.error("Error fetching Optimizely attributes:",t)}return{}}isKitReady(){return!!(this.isInitialized&&this.launcher)}isPartnerInLocalLauncherTestGroup(){return!!(o().config&&o().config.isLocalLauncherEnabled&&this.isAssignedToSampleGroup())}isAssignedToSampleGroup(){return Math.random()>.5}captureTiming(e){window&&o()&&o().captureTiming&&e&&o().captureTiming(e)}init(e,t,i,r,a){const s=e,c=s.accountId;this.userAttributes=a||{},this._onboardingExpProvider=s.onboardingExpProvider;const u=A(s.placementEventMapping);this.placementEventMappingLookup=D(u);const d=A(s.placementEventAttributeMapping);this.placementEventAttributeMappingLookup=x(d),s.hashedEmailUserIdentityType&&(this._mappedEmailSha256Key=s.hashedEmailUserIdentityType.toLowerCase()),this._workspaceIdSyncApiKey=g(s.workspaceIdSyncApiKey)?s.workspaceIdSyncApiKey:void 0;const m=o().Rokt?.domain,{roktExtensionsQueryParams:b,legacyRoktExtensions:E,loadThankYouElement:L}=K(s.roktExtensions),h={...o().Rokt?.launcherOptions||{}};this.integrationName=re(h.integrationName),h.integrationName=this.integrationName,this.domain=m;const I={loggingUrl:s.loggingUrl,errorUrl:s.errorUrl,isLoggingEnabled:o().config?.isLoggingEnabled===!0},_=new j(I,this.integrationName,window.__rokt_li_guid__,s.accountId),R=new H(I,_,this.integrationName,window.__rokt_li_guid__,s.accountId);return this.errorReportingService=_,this.loggingService=R,o()._registerErrorReportingService&&o()._registerErrorReportingService(_),o()._registerLoggingService&&o()._registerLoggingService(R),i?(this.testHelpers={generateLauncherScript:U,generateThankYouElementScript:C,extractRoktExtensionConfig:K,hashEventMessage:Y,parseSettingsString:A,generateMappedEventLookup:D,generateMappedEventAttributeLookup:x,sendAdBlockMeasurementSignals:F,createAutoRemovedIframe:T,djb2:W,setAllowedOriginHashes:y=>{p._allowedOriginHashes=y},ReportingTransport:P,ErrorReportingService:j,LoggingService:H,RateLimiter:z,ErrorCodes:N,WSDKErrorSeverity:v},this.attachLauncher(c,h),"Successfully initialized: "+l):(L&&(o().Rokt.flushOnShoppableAdsReadyMessageQueue?.(this),M(X,C(m),{onLoad:()=>{this._isThankYouElementLoaded=!0,this._thankYouElementOnLoadCallback&&this._thankYouElementOnLoadCallback()},onError:y=>{console.error("Error loading Rokt Thank You Element script:",y)}})),this.isLauncherReadyToAttach()?this.attachLauncher(c,h,E):(M(J,U(m,b),{onLoad:()=>{this.isLauncherReadyToAttach()?this.attachLauncher(c,h,E):console.error("Rokt object is not available after script load.")},onError:y=>{console.error("Error loading Rokt launcher script:",y)}}),this.captureTiming(p.PERFORMANCE_MARKS.RoktScriptAppended)),"Successfully initialized: "+l)}process(e){if(!this.isKitReady())return"Kit not ready for forwarder: "+l;if(typeof o().Rokt?.setLocalSessionAttribute=="function"&&(k(this.placementEventAttributeMappingLookup)||this.applyPlacementEventAttributeMapping(e),!k(this.placementEventMappingLookup))){const t=Y(e.EventDataType,e.EventCategory,e.EventName??"");this.placementEventMappingLookup[String(t)]&&o().Rokt.setLocalSessionAttribute?.(this.placementEventMappingLookup[String(t)],!0)}return"Successfully sent to forwarder: "+l}setExtensionData(e){if(!this.isKitReady()){console.error("Rokt Kit: Not initialized");return}window.Rokt.setExtensionData(e)}setUserAttribute(e,t){return this.userAttributes[e]=t,"Successfully set user attribute for forwarder: "+l}removeUserAttribute(e){return delete this.userAttributes[e],"Successfully removed user attribute for forwarder: "+l}handleIdentityComplete(e,t,i){const r=e;return this.userAttributes=e.getAllUserAttributes(),this.pendingIdentityEvents.push(this.buildIdentityEvent(t,r)),"Successfully called "+i+" for forwarder: "+l}onUserIdentified(e){const t=e;return this.filters.filteredUser=t,this._workspaceSearchInFlightPromise=this.search(t),this.handleIdentityComplete(e,w.IDENTIFY,"onUserIdentified")}search(e){const t=this._workspaceIdSyncApiKey;if(!t)return this.userIdentifiedInWorkspace=!1,this._workspaceLastSearchedIdentitiesKey=void 0,Promise.resolve();const i=o().Identity?.search;if(typeof i!="function")return this.userIdentifiedInWorkspace=!1,this._workspaceLastSearchedIdentitiesKey=void 0,Promise.resolve();const r=e.getUserIdentities?e.getUserIdentities().userIdentities:null,a={};if(r)for(const u of Object.keys(r)){const d=r[u];g(d)&&d.length>0&&(a[u]=d)}const s=Object.keys(a);if(s.length===0)return this.userIdentifiedInWorkspace=!1,this._workspaceLastSearchedIdentitiesKey=void 0,Promise.resolve();const c=s.sort().map(u=>`${u}=${a[u]}`).join("&");return c===this._workspaceLastSearchedIdentitiesKey?this._workspaceSearchInFlightPromise||Promise.resolve():(this.userIdentifiedInWorkspace=!1,this._workspaceLastSearchedIdentitiesKey=c,new Promise(u=>{try{i(t,a,d=>{d?.httpCode===200&&(this.userIdentifiedInWorkspace=!0),u()})}catch(d){console.error("Rokt Kit: Workspace IDSync search failed",d),this._workspaceLastSearchedIdentitiesKey=void 0,u()}}))}onLoginComplete(e,t){return this.handleIdentityComplete(e,w.LOGIN,"onLoginComplete")}onLogoutComplete(e,t){return this.userIdentifiedInWorkspace=!1,this._workspaceSearchInFlightPromise=null,this._workspaceLastSearchedIdentitiesKey=void 0,this.handleIdentityComplete(e,w.LOGOUT,"onLogoutComplete")}onModifyComplete(e,t){return this.handleIdentityComplete(e,w.MODIFY_USER,"onModifyComplete")}selectPlacements(e){if(this._workspaceSearchInFlightPromise){const t=this._workspaceSearchInFlightPromise;return Promise.race([t,new Promise(i=>setTimeout(i,Z))]).then(()=>this._dispatchPlacements(e))}return this._dispatchPlacements(e)}_dispatchPlacements(e){const t=e&&e.attributes||{},i={...this.userAttributes,...t},r=this.filters||{},a=r.userAttributeFilters||[],s=r.filteredUser||null,c=s?s.getMPID():null;let u;r?r.filterUserAttributes?u=r.filterUserAttributes(i,a):u=i:(console.warn("Rokt Kit: No filters available, using user attributes"),u=i),this.userAttributes=u;const d=this._onboardingExpProvider==="Optimizely"?this.fetchOptimizely():{},m=this.returnUserIdentities(s),b=this.returnLocalSessionAttributes(),E={...m,...u,...d,...b,...this.userIdentifiedInWorkspace?{[$]:!0}:{},mpid:c},L={...e,attributes:E},h=this.launcher.selectPlacements(L),I=()=>this.logSelectPlacementsEvent(E);return Promise.resolve(h).then(_=>_?.context?.sessionId?.then(R=>this.setRoktSessionId(R))).catch(()=>{}).finally(I),h}hashAttributes(e){return this.isKitReady()?this.launcher.hashAttributes(e):(console.error("Rokt Kit: Not initialized"),null)}use(e){return this.isKitReady()?!e||!g(e)?Promise.reject(new Error("Rokt Kit: Invalid extension name")):this.launcher.use(e):(console.error("Rokt Kit: Not initialized"),Promise.reject(new Error("Rokt Kit: Not initialized")))}onShoppableAdsReady(e){this._isThankYouElementLoaded?e():this._thankYouElementOnLoadCallback=e}};p._allowedOriginHashes=[-553112570,549508659],p.PERFORMANCE_MARKS={RoktScriptAppended:"mp:RoktScriptAppended"},p.EMAIL_SHA256_KEY="emailsha256";let f=p;function ce(){return S}function ue(n){if(!n){window.console.log("You must pass a config object to register the kit "+l);return}if(!O(n)){window.console.log("'config' must be an object. You passed in a "+typeof n);return}O(n.kits)?n.kits[l]={constructor:f}:(n.kits={},n.kits[l]={constructor:f}),window.console.log("Successfully registered "+l+" to your mParticle configuration")}typeof window<"u"&&window.mParticle&&o().addForwarder&&o().addForwarder({name:l,constructor:f,getId:ce});exports.register=ue;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const V=["billingaddress1","billingaddress2","billingcity","billingstate","billingzipcode","cartitems","ccbin","confirmationref","conversiontype","country","couponcode","currency","language","paymentserviceprovider","paymentserviceproviderattribute","paymenttype","shippingaddress1","shippingcity","shippingcountry","shippingmethod","shippingstate","shippingzipcode","totalprice"],q=new Set(V);function z(n){return q.has(n.toLowerCase())}function v(n){const e={},t=n||{},i=Object.keys(t);for(let r=0;r<i.length;r++){const s=i[r];z(s)||(e[s]=t[s])}return e}const d="Rokt",w=181,J="selectPlacements",X="apps.roktecommerce.com",$=.1,A={LOGIN:"login",LOGOUT:"logout",MODIFY_USER:"modify_user",IDENTIFY:"identify"},Z="ThankYouPageJourney",ee="rokt-launcher",te="rokt-thank-you-element",ie="userIdentifiedInWorkspace",ne=500,P={UNKNOWN_ERROR:"UNKNOWN_ERROR",UNHANDLED_EXCEPTION:"UNHANDLED_EXCEPTION",IDENTITY_REQUEST:"IDENTITY_REQUEST"},L={ERROR:"ERROR",INFO:"INFO",WARNING:"WARNING"},re="apps.rokt-api.com/v1/log",se="apps.rokt-api.com/v1/errors",oe=10;function a(){return window.mParticle}function C(n,e){const i=[W(n),"/wsdk/integrations/launcher.js"].join("");return!e||e.length===0?i:i+"?extensions="+e.join(",")}function M(n){return[W(n),"/rokt-elements/rokt-element-thank-you.js"].join("")}function W(n){return["https://",typeof n<"u"?n:"apps.rokt-api.com"].join("")}function K(n,e,t){if(document.getElementById(n))return;const i=document.head||document.body,r=document.createElement("script");r.id=n,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),i.appendChild(r)}function T(n){return n!=null&&typeof n=="object"&&Array.isArray(n)===!1}function b(n){if(!n)return[];try{return JSON.parse(n.replace(/"/g,'"'))}catch{console.error("Settings string contains invalid JSON")}return[]}function D(n){const e=n?b(n):[],t=[],i=[];let r=!1;for(let s=0;s<e.length;s++){const o=e[s].value;o==="thank-you-journey"?(r=!0,i.push(Z)):t.push(o)}return{roktExtensionsQueryParams:t,legacyRoktExtensions:i,loadThankYouElement:r}}async function ae(n,e){const t=[];if(e)for(const i of n)t.push(e.use(i));return Promise.all(t)}function Y(n){if(!n)return{};const e={};for(let t=0;t<n.length;t++){const i=n[t];e[i.jsmap]=i.value}return e}function x(n){const e={};if(!Array.isArray(n))return e;for(let t=0;t<n.length;t++){const i=n[t];if(!i||!f(i.value)||!f(i.map))continue;const r=i.value,s=i.map;e[r]||(e[r]=[]),e[r].push({eventAttributeKey:s,conditions:Array.isArray(i.conditions)?i.conditions:[]})}return e}function F(n,e,t){return a().generateHash([n,e,t].join(""))}function I(n){return n==null?!0:typeof n=="object"?Object.keys(n).length===0:Array.isArray(n)?n.length===0:!1}function f(n){return typeof n=="string"}function ce(n){let i="mParticle_wsdkv_"+a().getVersion()+"_kitv_"+"1.27.0";return n&&(i+="_"+n),i}function Q(n){let e=5381;for(let t=0;t<n.length;t++)e=(e<<5)+e+n.charCodeAt(t),e=e&e;return e}function N(n){const e=document.createElement("iframe");e.style.display="none",e.setAttribute("sandbox","allow-scripts allow-same-origin"),e.src=n,e.onload=function(){e.onload=null,e.parentNode&&e.parentNode.removeChild(e)};const t=document.body||document.head;t&&t.appendChild(e)}function j(n,e){const t=Q(window.location.origin);if(m._allowedOriginHashes.indexOf(t)===-1||Math.random()>=$)return;const r=window.__rokt_li_guid__;if(!r)return;const s=window.location.href.split("?")[0].split("#")[0],o="version="+encodeURIComponent(e??"")+"&launcherInstanceGuid="+encodeURIComponent(r)+"&pageUrl="+encodeURIComponent(s);N("https://"+(n||"apps.rokt.com")+"/v1/wsdk-init/index.html?"+o),N("https://"+X+"/v1/wsdk-init/index.html?"+o+"&isControl=true")}function ue(){return typeof window<"u"&&!!window.location?.search?.toLowerCase().includes("mp_enable_logging=true")}function le(){return typeof window<"u"?window.location?.href:void 0}function de(){return typeof window<"u"?window.navigator?.userAgent:void 0}class B{constructor(){this._logCount={}}incrementAndCheck(e){const i=(this._logCount[e]||0)+1;return this._logCount[e]=i,i>oe}}class U{constructor(e,t,i,r,s){this._reporter="mp-wsdk";const o=e.isLoggingEnabled;this._integrationName=t||"",this._launcherInstanceGuid=i,this._accountId=r||null,this._rateLimiter=s||new B,this._isEnabled=ue()||o}send(e,t,i,r,s,o){if(!(!this._isEnabled||this._rateLimiter.incrementAndCheck(t)))try{const c={additionalInformation:{message:i,version:this._integrationName},severity:t,code:r||P.UNKNOWN_ERROR,url:le(),deviceInfo:de(),stackTrace:s,reporter:this._reporter,integration:this._integrationName},l={Accept:"text/plain;charset=UTF-8","Content-Type":"application/json","rokt-launcher-version":this._integrationName,"rokt-wsdk-version":"joint"};this._launcherInstanceGuid&&(l["rokt-launcher-instance-guid"]=this._launcherInstanceGuid),this._accountId&&(l["rokt-account-id"]=this._accountId),fetch(e,{method:"POST",headers:l,body:JSON.stringify(c)}).catch(u=>{console.error("ReportingTransport: Failed to send log",u),o&&o(u)})}catch(c){console.error("ReportingTransport: Failed to send log",c),o&&o(c)}}}class H{constructor(e,t,i,r,s){this._transport=new U(e,t,i,r,s),this._errorUrl="https://"+(e?.errorUrl||se)}report(e){if(!e)return;const t=e.severity||L.ERROR;this._transport.send(this._errorUrl,t,e.message,e.code,e.stackTrace)}}class G{constructor(e,t,i,r,s,o){this._transport=new U(e,i,r,s,o),this._loggingUrl="https://"+(e?.loggingUrl||re),this._errorReportingService=t}log(e){e&&this._transport.send(this._loggingUrl,L.INFO,e.message,e.code,void 0,t=>{this._errorReportingService&&this._errorReportingService.report({message:"LoggingService: Failed to send log: "+t.message,code:P.UNKNOWN_ERROR,severity:L.ERROR})})}}const h=class h{constructor(){this.name=d,this.id=w,this.moduleId=w,this.isInitialized=!1,this.launcher=null,this.filters={},this.userAttributes={},this.userIdentifiedInWorkspace=!1,this.testHelpers=null,this.placementEventMappingLookup={},this.placementEventAttributeMappingLookup={},this.batchQueue=[],this.batchStreamQueue=[],this.pendingIdentityEvents=[],this.integrationName=null,this.errorReportingService=null,this.loggingService=null,this._thankYouElementOnLoadCallback=null,this._isThankYouElementLoaded=!1,this._workspaceSearchInFlightPromise=null}getEventAttributeValue(e,t){const i=e&&e.EventAttributes;return!i||typeof i[t]>"u"?null:i[t]}doesEventAttributeConditionMatch(e,t){if(!e||!f(e.operator))return!1;const i=e.operator.toLowerCase(),r=e.attributeValue;return i==="exists"?t!==null:t==null?!1:i==="equals"?String(t)===String(r):i==="contains"?String(t).indexOf(String(r))!==-1:!1}doesEventMatchRule(e,t){if(!t||!f(t.eventAttributeKey))return!1;const i=t.conditions;if(!Array.isArray(i))return!1;const r=this.getEventAttributeValue(e,t.eventAttributeKey);if(i.length===0)return r!==null;for(let s=0;s<i.length;s++)if(!this.doesEventAttributeConditionMatch(i[s],r))return!1;return!0}applyPlacementEventAttributeMapping(e){const t=Object.keys(this.placementEventAttributeMappingLookup);for(let i=0;i<t.length;i++){const r=t[i],s=this.placementEventAttributeMappingLookup[r];if(I(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)}}isLauncherReadyToAttach(){return!!window.Rokt&&typeof window.Rokt.createLauncher=="function"}returnUserIdentities(e){if(!e||!e.getUserIdentities)return{};const t=e.getUserIdentities().userIdentities;return this.replaceOtherIdentityWithEmailsha256(t)}returnLocalSessionAttributes(){return!a().Rokt||typeof a().Rokt.getLocalSessionAttributes!="function"?{}:I(this.placementEventMappingLookup)&&I(this.placementEventAttributeMappingLookup)?{}:a().Rokt.getLocalSessionAttributes()}replaceOtherIdentityWithEmailsha256(e){const t={...e||{}},i=this._mappedEmailSha256Key;return i&&e[i]&&(t[h.EMAIL_SHA256_KEY]=e[i]),i&&delete t[i],t}logSelectPlacementsEvent(e){if(!window.mParticle||typeof a().logEvent!="function"||!T(e))return;const t=a().EventType.Other;a().logEvent(J,t,e)}buildIdentityEvent(e,t){const i=t.getMPID(),r=a()&&a().sessionManager&&typeof a().sessionManager.getSession=="function"?a().sessionManager.getSession():void 0;return{event_type:e,data:{timestamp_unixtime_ms:Date.now(),session_uuid:r??void 0,mpid:i}}}mergePendingIdentityEvents(e){if(this.pendingIdentityEvents.length===0)return e;const t={...e,events:[...e.events??[],...this.pendingIdentityEvents]};return this.pendingIdentityEvents=[],t}drainBatchQueue(){this.batchQueue.forEach(e=>{this.processBatch(e)}),this.batchQueue=[]}processBatch(e){if(!this.isKitReady())return this.batchQueue.push(e),"Batch queued for forwarder: "+d;const t=this.enrichCommerceEventTypes(this.mergePendingIdentityEvents(e));return this.sendBatchStream(t),"Successfully sent batch to forwarder: "+d}enrichCommerceEventTypes(e){if(!e.events)return e;for(const t of e.events){if(t.event_type!=="commerce_event")continue;const{data:i}=t;if(!i)continue;const r=i.custom_flags?.["Rokt.CommerceEventType"];r&&T(i.product_action)&&(i.product_action.action=r)}return e}sendBatchStream(e){if(window.Rokt&&typeof window.Rokt.__batch_stream__=="function"){if(this.batchStreamQueue.length){const t=this.batchStreamQueue;this.batchStreamQueue=[];for(let i=0;i<t.length;i++)window.Rokt.__batch_stream__(t[i])}window.Rokt.__batch_stream__(e)}else this.batchStreamQueue.push(e)}setRoktSessionId(e){if(!(!e||typeof e!="string"))try{const t=a().getInstance();t&&typeof t.setIntegrationAttribute=="function"&&t.setIntegrationAttribute(w,{roktSessionId:e})}catch{}}attachLauncher(e,t,i=[]){const r=a()&&a().sessionManager&&typeof a().sessionManager.getSession=="function"?a().sessionManager.getSession():void 0,s={accountId:e,...t||{},...r?{mpSessionId:r}:{}};let o;this.isPartnerInLocalLauncherTestGroup()?o=Promise.resolve(window.Rokt.createLocalLauncher(s)):o=window.Rokt.createLauncher(s),o.then(async c=>{await ae(i,c),this.initRoktLauncher(c)}).catch(c=>{console.error("Error creating Rokt launcher:",c)})}initRoktLauncher(e){window.Rokt&&(window.Rokt.currentLauncher=e),this.launcher=e;const t=a().Rokt?.filters;t?(this.filters=t,t.filteredUser?this._workspaceSearchInFlightPromise=this.search(t.filteredUser):console.warn("Rokt Kit: No filtered user has been set.")):console.warn("Rokt Kit: No filters have been set."),this.isInitialized=!0,j(this.domain,this.integrationName),a().Rokt.attachKit(this),this.drainBatchQueue()}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)}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,i,r,s){const o=e,c=o.accountId;this.userAttributes=v(s),this._onboardingExpProvider=o.onboardingExpProvider;const l=b(o.placementEventMapping);this.placementEventMappingLookup=Y(l);const u=b(o.placementEventAttributeMapping);this.placementEventAttributeMappingLookup=x(u),o.hashedEmailUserIdentityType&&(this._mappedEmailSha256Key=o.hashedEmailUserIdentityType.toLowerCase()),this._workspaceIdSyncApiKey=f(o.workspaceIdSyncApiKey)?o.workspaceIdSyncApiKey:void 0;const E=a().Rokt?.domain,{roktExtensionsQueryParams:O,legacyRoktExtensions:k,loadThankYouElement:R}=D(o.roktExtensions),p={...a().Rokt?.launcherOptions||{}};this.integrationName=ce(p.integrationName),p.integrationName=this.integrationName,this.domain=E;const _={loggingUrl:o.loggingUrl,errorUrl:o.errorUrl,isLoggingEnabled:a().config?.isLoggingEnabled===!0},y=new H(_,this.integrationName,window.__rokt_li_guid__,o.accountId),S=new G(_,y,this.integrationName,window.__rokt_li_guid__,o.accountId);return this.errorReportingService=y,this.loggingService=S,a()._registerErrorReportingService&&a()._registerErrorReportingService(y),a()._registerLoggingService&&a()._registerLoggingService(S),i?(this.testHelpers={generateLauncherScript:C,generateThankYouElementScript:M,extractRoktExtensionConfig:D,hashEventMessage:F,parseSettingsString:b,generateMappedEventLookup:Y,generateMappedEventAttributeLookup:x,sendAdBlockMeasurementSignals:j,createAutoRemovedIframe:N,djb2:Q,setAllowedOriginHashes:g=>{h._allowedOriginHashes=g},ReportingTransport:U,ErrorReportingService:H,LoggingService:G,RateLimiter:B,ErrorCodes:P,WSDKErrorSeverity:L},this.attachLauncher(c,p),"Successfully initialized: "+d):(R&&(a().Rokt.flushOnShoppableAdsReadyMessageQueue?.(this),K(te,M(E),{onLoad:()=>{this._isThankYouElementLoaded=!0,this._thankYouElementOnLoadCallback&&this._thankYouElementOnLoadCallback()},onError:g=>{console.error("Error loading Rokt Thank You Element script:",g)}})),this.isLauncherReadyToAttach()?this.attachLauncher(c,p,k):(K(ee,C(E,O),{onLoad:()=>{this.isLauncherReadyToAttach()?this.attachLauncher(c,p,k):console.error("Rokt object is not available after script load.")},onError:g=>{console.error("Error loading Rokt launcher script:",g)}}),this.captureTiming(h.PERFORMANCE_MARKS.RoktScriptAppended)),"Successfully initialized: "+d)}process(e){if(!this.isKitReady())return"Kit not ready for forwarder: "+d;if(typeof a().Rokt?.setLocalSessionAttribute=="function"&&(I(this.placementEventAttributeMappingLookup)||this.applyPlacementEventAttributeMapping(e),!I(this.placementEventMappingLookup))){const t=F(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,i){const r=e;return this.userAttributes=v(e.getAllUserAttributes()),this.pendingIdentityEvents.push(this.buildIdentityEvent(t,r)),"Successfully called "+i+" for forwarder: "+d}onUserIdentified(e){const t=e;return this.filters.filteredUser=t,this._workspaceSearchInFlightPromise=this.search(t),this.handleIdentityComplete(e,A.IDENTIFY,"onUserIdentified")}search(e){const t=this._workspaceIdSyncApiKey;if(!t)return this.userIdentifiedInWorkspace=!1,this._workspaceLastSearchedIdentitiesKey=void 0,Promise.resolve();const i=a().Identity?.search;if(typeof i!="function")return this.userIdentifiedInWorkspace=!1,this._workspaceLastSearchedIdentitiesKey=void 0,Promise.resolve();const r=e.getUserIdentities?e.getUserIdentities().userIdentities:null,s={};if(r)for(const l of Object.keys(r)){const u=r[l];f(u)&&u.length>0&&(s[l]=u)}const o=Object.keys(s);if(o.length===0)return this.userIdentifiedInWorkspace=!1,this._workspaceLastSearchedIdentitiesKey=void 0,Promise.resolve();const c=o.sort().map(l=>`${l}=${s[l]}`).join("&");return c===this._workspaceLastSearchedIdentitiesKey?this._workspaceSearchInFlightPromise||Promise.resolve():(this.userIdentifiedInWorkspace=!1,this._workspaceLastSearchedIdentitiesKey=c,new Promise(l=>{try{i(t,s,u=>{u?.httpCode===200&&(this.userIdentifiedInWorkspace=!0),l()})}catch(u){console.error("Rokt Kit: Workspace IDSync search failed",u),this._workspaceLastSearchedIdentitiesKey=void 0,l()}}))}onLoginComplete(e,t){return this.handleIdentityComplete(e,A.LOGIN,"onLoginComplete")}onLogoutComplete(e,t){return this.userIdentifiedInWorkspace=!1,this._workspaceSearchInFlightPromise=null,this._workspaceLastSearchedIdentitiesKey=void 0,this.handleIdentityComplete(e,A.LOGOUT,"onLogoutComplete")}onModifyComplete(e,t){return this.handleIdentityComplete(e,A.MODIFY_USER,"onModifyComplete")}selectPlacements(e){if(this._workspaceSearchInFlightPromise){const t=this._workspaceSearchInFlightPromise;return Promise.race([t,new Promise(i=>setTimeout(i,ne))]).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,l=c?c.getMPID():null;let u;s?s.filterUserAttributes?u=s.filterUserAttributes(r,o):u=r:(console.warn("Rokt Kit: No filters available, using user attributes"),u=r),this.userAttributes=v(u);const E=this._onboardingExpProvider==="Optimizely"?this.fetchOptimizely():{},O=this.returnUserIdentities(c),k=this.returnLocalSessionAttributes(),R={...O,...u,...E,...k,...this.userIdentifiedInWorkspace?{[ie]:!0}:{},mpid:l},p={...e,attributes:R},_=this.launcher.selectPlacements(p),y=()=>this.logSelectPlacementsEvent(R);return Promise.resolve(_).then(S=>S?.context?.sessionId?.then(g=>this.setRoktSessionId(g))).catch(()=>{}).finally(y),_}hashAttributes(e){return this.isKitReady()?this.launcher.hashAttributes(e):(console.error("Rokt Kit: Not initialized"),null)}use(e){return this.isKitReady()?!e||!f(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}};h._allowedOriginHashes=[-553112570,549508659],h.PERFORMANCE_MARKS={RoktScriptAppended:"mp:RoktScriptAppended"},h.EMAIL_SHA256_KEY="emailsha256";let m=h;function he(){return w}function pe(n){if(!n){window.console.log("You must pass a config object to register the kit "+d);return}if(!T(n)){window.console.log("'config' must be an object. You passed in a "+typeof n);return}T(n.kits)?n.kits[d]={constructor:m}:(n.kits={},n.kits[d]={constructor:m}),window.console.log("Successfully registered "+d+" to your mParticle configuration")}typeof window<"u"&&window.mParticle&&a().addForwarder&&a().addForwarder({name:d,constructor:m,getId:he});exports.register=pe;
|
|
2
2
|
//# sourceMappingURL=Rokt-Kit.common.js.map
|
package/dist/Rokt-Kit.esm.js
CHANGED
|
@@ -1,41 +1,75 @@
|
|
|
1
|
-
const
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
const V = [
|
|
2
|
+
"billingaddress1",
|
|
3
|
+
"billingaddress2",
|
|
4
|
+
"billingcity",
|
|
5
|
+
"billingstate",
|
|
6
|
+
"billingzipcode",
|
|
7
|
+
"cartitems",
|
|
8
|
+
"ccbin",
|
|
9
|
+
"confirmationref",
|
|
10
|
+
"conversiontype",
|
|
11
|
+
"country",
|
|
12
|
+
"couponcode",
|
|
13
|
+
"currency",
|
|
14
|
+
"language",
|
|
15
|
+
"paymentserviceprovider",
|
|
16
|
+
"paymentserviceproviderattribute",
|
|
17
|
+
"paymenttype",
|
|
18
|
+
"shippingaddress1",
|
|
19
|
+
"shippingcity",
|
|
20
|
+
"shippingcountry",
|
|
21
|
+
"shippingmethod",
|
|
22
|
+
"shippingstate",
|
|
23
|
+
"shippingzipcode",
|
|
24
|
+
"totalprice"
|
|
25
|
+
], q = new Set(V);
|
|
26
|
+
function z(n) {
|
|
27
|
+
return q.has(n.toLowerCase());
|
|
28
|
+
}
|
|
29
|
+
function A(n) {
|
|
30
|
+
const e = {}, t = n || {}, i = Object.keys(t);
|
|
31
|
+
for (let r = 0; r < i.length; r++) {
|
|
32
|
+
const s = i[r];
|
|
33
|
+
z(s) || (e[s] = t[s]);
|
|
34
|
+
}
|
|
35
|
+
return e;
|
|
36
|
+
}
|
|
37
|
+
const d = "Rokt", w = 181, J = "selectPlacements", X = "apps.roktecommerce.com", $ = 0.1, v = {
|
|
4
38
|
LOGIN: "login",
|
|
5
39
|
LOGOUT: "logout",
|
|
6
40
|
MODIFY_USER: "modify_user",
|
|
7
41
|
IDENTIFY: "identify"
|
|
8
|
-
},
|
|
42
|
+
}, Z = "ThankYouPageJourney", ee = "rokt-launcher", te = "rokt-thank-you-element", ie = "userIdentifiedInWorkspace", ne = 500, P = {
|
|
9
43
|
UNKNOWN_ERROR: "UNKNOWN_ERROR",
|
|
10
44
|
UNHANDLED_EXCEPTION: "UNHANDLED_EXCEPTION",
|
|
11
45
|
IDENTITY_REQUEST: "IDENTITY_REQUEST"
|
|
12
|
-
},
|
|
46
|
+
}, L = {
|
|
13
47
|
ERROR: "ERROR",
|
|
14
48
|
INFO: "INFO",
|
|
15
49
|
WARNING: "WARNING"
|
|
16
|
-
},
|
|
17
|
-
function
|
|
50
|
+
}, re = "apps.rokt-api.com/v1/log", se = "apps.rokt-api.com/v1/errors", oe = 10;
|
|
51
|
+
function a() {
|
|
18
52
|
return window.mParticle;
|
|
19
53
|
}
|
|
20
|
-
function
|
|
21
|
-
const i = [
|
|
54
|
+
function C(n, e) {
|
|
55
|
+
const i = [W(n), "/wsdk/integrations/launcher.js"].join("");
|
|
22
56
|
return !e || e.length === 0 ? i : i + "?extensions=" + e.join(",");
|
|
23
57
|
}
|
|
24
|
-
function
|
|
25
|
-
return [
|
|
58
|
+
function M(n) {
|
|
59
|
+
return [W(n), "/rokt-elements/rokt-element-thank-you.js"].join("");
|
|
26
60
|
}
|
|
27
|
-
function
|
|
61
|
+
function W(n) {
|
|
28
62
|
return ["https://", typeof n < "u" ? n : "apps.rokt-api.com"].join("");
|
|
29
63
|
}
|
|
30
|
-
function
|
|
64
|
+
function K(n, e, t) {
|
|
31
65
|
if (document.getElementById(n)) return;
|
|
32
66
|
const i = document.head || document.body, r = document.createElement("script");
|
|
33
67
|
r.id = n, 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), i.appendChild(r);
|
|
34
68
|
}
|
|
35
|
-
function
|
|
69
|
+
function T(n) {
|
|
36
70
|
return n != null && typeof n == "object" && Array.isArray(n) === !1;
|
|
37
71
|
}
|
|
38
|
-
function
|
|
72
|
+
function b(n) {
|
|
39
73
|
if (!n)
|
|
40
74
|
return [];
|
|
41
75
|
try {
|
|
@@ -45,12 +79,12 @@ function S(n) {
|
|
|
45
79
|
}
|
|
46
80
|
return [];
|
|
47
81
|
}
|
|
48
|
-
function
|
|
49
|
-
const e = n ?
|
|
82
|
+
function D(n) {
|
|
83
|
+
const e = n ? b(n) : [], t = [], i = [];
|
|
50
84
|
let r = !1;
|
|
51
|
-
for (let
|
|
52
|
-
const
|
|
53
|
-
|
|
85
|
+
for (let s = 0; s < e.length; s++) {
|
|
86
|
+
const o = e[s].value;
|
|
87
|
+
o === "thank-you-journey" ? (r = !0, i.push(Z)) : t.push(o);
|
|
54
88
|
}
|
|
55
89
|
return {
|
|
56
90
|
roktExtensionsQueryParams: t,
|
|
@@ -58,14 +92,14 @@ function M(n) {
|
|
|
58
92
|
loadThankYouElement: r
|
|
59
93
|
};
|
|
60
94
|
}
|
|
61
|
-
async function
|
|
95
|
+
async function ae(n, e) {
|
|
62
96
|
const t = [];
|
|
63
97
|
if (e)
|
|
64
98
|
for (const i of n)
|
|
65
99
|
t.push(e.use(i));
|
|
66
100
|
return Promise.all(t);
|
|
67
101
|
}
|
|
68
|
-
function
|
|
102
|
+
function x(n) {
|
|
69
103
|
if (!n)
|
|
70
104
|
return {};
|
|
71
105
|
const e = {};
|
|
@@ -75,42 +109,42 @@ function K(n) {
|
|
|
75
109
|
}
|
|
76
110
|
return e;
|
|
77
111
|
}
|
|
78
|
-
function
|
|
112
|
+
function Y(n) {
|
|
79
113
|
const e = {};
|
|
80
114
|
if (!Array.isArray(n))
|
|
81
115
|
return e;
|
|
82
116
|
for (let t = 0; t < n.length; t++) {
|
|
83
117
|
const i = n[t];
|
|
84
|
-
if (!i || !
|
|
118
|
+
if (!i || !f(i.value) || !f(i.map))
|
|
85
119
|
continue;
|
|
86
|
-
const r = i.value,
|
|
120
|
+
const r = i.value, s = i.map;
|
|
87
121
|
e[r] || (e[r] = []), e[r].push({
|
|
88
|
-
eventAttributeKey:
|
|
122
|
+
eventAttributeKey: s,
|
|
89
123
|
conditions: Array.isArray(i.conditions) ? i.conditions : []
|
|
90
124
|
});
|
|
91
125
|
}
|
|
92
126
|
return e;
|
|
93
127
|
}
|
|
94
|
-
function
|
|
95
|
-
return
|
|
128
|
+
function F(n, e, t) {
|
|
129
|
+
return a().generateHash([n, e, t].join(""));
|
|
96
130
|
}
|
|
97
|
-
function
|
|
131
|
+
function I(n) {
|
|
98
132
|
return n == null ? !0 : typeof n == "object" ? Object.keys(n).length === 0 : Array.isArray(n) ? n.length === 0 : !1;
|
|
99
133
|
}
|
|
100
|
-
function
|
|
134
|
+
function f(n) {
|
|
101
135
|
return typeof n == "string";
|
|
102
136
|
}
|
|
103
|
-
function
|
|
104
|
-
let i = "mParticle_wsdkv_" +
|
|
137
|
+
function ce(n) {
|
|
138
|
+
let i = "mParticle_wsdkv_" + a().getVersion() + "_kitv_" + "1.27.0";
|
|
105
139
|
return n && (i += "_" + n), i;
|
|
106
140
|
}
|
|
107
|
-
function
|
|
141
|
+
function Q(n) {
|
|
108
142
|
let e = 5381;
|
|
109
143
|
for (let t = 0; t < n.length; t++)
|
|
110
144
|
e = (e << 5) + e + n.charCodeAt(t), e = e & e;
|
|
111
145
|
return e;
|
|
112
146
|
}
|
|
113
|
-
function
|
|
147
|
+
function N(n) {
|
|
114
148
|
const e = document.createElement("iframe");
|
|
115
149
|
e.style.display = "none", e.setAttribute("sandbox", "allow-scripts allow-same-origin"), e.src = n, e.onload = function() {
|
|
116
150
|
e.onload = null, e.parentNode && e.parentNode.removeChild(e);
|
|
@@ -118,43 +152,43 @@ function O(n) {
|
|
|
118
152
|
const t = document.body || document.head;
|
|
119
153
|
t && t.appendChild(e);
|
|
120
154
|
}
|
|
121
|
-
function
|
|
122
|
-
const t =
|
|
123
|
-
if (
|
|
155
|
+
function j(n, e) {
|
|
156
|
+
const t = Q(window.location.origin);
|
|
157
|
+
if (m._allowedOriginHashes.indexOf(t) === -1 || Math.random() >= $)
|
|
124
158
|
return;
|
|
125
159
|
const r = window.__rokt_li_guid__;
|
|
126
160
|
if (!r)
|
|
127
161
|
return;
|
|
128
|
-
const
|
|
129
|
-
|
|
130
|
-
"https://" +
|
|
162
|
+
const s = window.location.href.split("?")[0].split("#")[0], o = "version=" + encodeURIComponent(e ?? "") + "&launcherInstanceGuid=" + encodeURIComponent(r) + "&pageUrl=" + encodeURIComponent(s);
|
|
163
|
+
N("https://" + (n || "apps.rokt.com") + "/v1/wsdk-init/index.html?" + o), N(
|
|
164
|
+
"https://" + X + "/v1/wsdk-init/index.html?" + o + "&isControl=true"
|
|
131
165
|
);
|
|
132
166
|
}
|
|
133
|
-
function
|
|
167
|
+
function ue() {
|
|
134
168
|
return typeof window < "u" && !!window.location?.search?.toLowerCase().includes("mp_enable_logging=true");
|
|
135
169
|
}
|
|
136
|
-
function
|
|
170
|
+
function le() {
|
|
137
171
|
return typeof window < "u" ? window.location?.href : void 0;
|
|
138
172
|
}
|
|
139
|
-
function
|
|
173
|
+
function de() {
|
|
140
174
|
return typeof window < "u" ? window.navigator?.userAgent : void 0;
|
|
141
175
|
}
|
|
142
|
-
class
|
|
176
|
+
class B {
|
|
143
177
|
constructor() {
|
|
144
178
|
this._logCount = {};
|
|
145
179
|
}
|
|
146
180
|
incrementAndCheck(e) {
|
|
147
181
|
const i = (this._logCount[e] || 0) + 1;
|
|
148
|
-
return this._logCount[e] = i, i >
|
|
182
|
+
return this._logCount[e] = i, i > oe;
|
|
149
183
|
}
|
|
150
184
|
}
|
|
151
|
-
class
|
|
152
|
-
constructor(e, t, i, r,
|
|
185
|
+
class U {
|
|
186
|
+
constructor(e, t, i, r, s) {
|
|
153
187
|
this._reporter = "mp-wsdk";
|
|
154
|
-
const
|
|
155
|
-
this._integrationName = t || "", this._launcherInstanceGuid = i, this._accountId = r || null, this._rateLimiter =
|
|
188
|
+
const o = e.isLoggingEnabled;
|
|
189
|
+
this._integrationName = t || "", this._launcherInstanceGuid = i, this._accountId = r || null, this._rateLimiter = s || new B(), this._isEnabled = ue() || o;
|
|
156
190
|
}
|
|
157
|
-
send(e, t, i, r,
|
|
191
|
+
send(e, t, i, r, s, o) {
|
|
158
192
|
if (!(!this._isEnabled || this._rateLimiter.incrementAndCheck(t)))
|
|
159
193
|
try {
|
|
160
194
|
const c = {
|
|
@@ -163,64 +197,64 @@ class N {
|
|
|
163
197
|
version: this._integrationName
|
|
164
198
|
},
|
|
165
199
|
severity: t,
|
|
166
|
-
code: r ||
|
|
167
|
-
url:
|
|
168
|
-
deviceInfo:
|
|
169
|
-
stackTrace:
|
|
200
|
+
code: r || P.UNKNOWN_ERROR,
|
|
201
|
+
url: le(),
|
|
202
|
+
deviceInfo: de(),
|
|
203
|
+
stackTrace: s,
|
|
170
204
|
reporter: this._reporter,
|
|
171
205
|
integration: this._integrationName
|
|
172
|
-
},
|
|
206
|
+
}, l = {
|
|
173
207
|
Accept: "text/plain;charset=UTF-8",
|
|
174
208
|
"Content-Type": "application/json",
|
|
175
209
|
"rokt-launcher-version": this._integrationName,
|
|
176
210
|
"rokt-wsdk-version": "joint"
|
|
177
211
|
};
|
|
178
|
-
this._launcherInstanceGuid && (
|
|
212
|
+
this._launcherInstanceGuid && (l["rokt-launcher-instance-guid"] = this._launcherInstanceGuid), this._accountId && (l["rokt-account-id"] = this._accountId), fetch(e, {
|
|
179
213
|
method: "POST",
|
|
180
|
-
headers:
|
|
214
|
+
headers: l,
|
|
181
215
|
body: JSON.stringify(c)
|
|
182
|
-
}).catch((
|
|
183
|
-
console.error("ReportingTransport: Failed to send log",
|
|
216
|
+
}).catch((u) => {
|
|
217
|
+
console.error("ReportingTransport: Failed to send log", u), o && o(u);
|
|
184
218
|
});
|
|
185
219
|
} catch (c) {
|
|
186
|
-
console.error("ReportingTransport: Failed to send log", c),
|
|
220
|
+
console.error("ReportingTransport: Failed to send log", c), o && o(c);
|
|
187
221
|
}
|
|
188
222
|
}
|
|
189
223
|
}
|
|
190
|
-
class
|
|
191
|
-
constructor(e, t, i, r,
|
|
192
|
-
this._transport = new
|
|
224
|
+
class H {
|
|
225
|
+
constructor(e, t, i, r, s) {
|
|
226
|
+
this._transport = new U(e, t, i, r, s), this._errorUrl = "https://" + (e?.errorUrl || se);
|
|
193
227
|
}
|
|
194
228
|
report(e) {
|
|
195
229
|
if (!e) return;
|
|
196
|
-
const t = e.severity ||
|
|
230
|
+
const t = e.severity || L.ERROR;
|
|
197
231
|
this._transport.send(this._errorUrl, t, e.message, e.code, e.stackTrace);
|
|
198
232
|
}
|
|
199
233
|
}
|
|
200
|
-
class
|
|
201
|
-
constructor(e, t, i, r,
|
|
202
|
-
this._transport = new
|
|
234
|
+
class G {
|
|
235
|
+
constructor(e, t, i, r, s, o) {
|
|
236
|
+
this._transport = new U(e, i, r, s, o), this._loggingUrl = "https://" + (e?.loggingUrl || re), this._errorReportingService = t;
|
|
203
237
|
}
|
|
204
238
|
log(e) {
|
|
205
239
|
e && this._transport.send(
|
|
206
240
|
this._loggingUrl,
|
|
207
|
-
|
|
241
|
+
L.INFO,
|
|
208
242
|
e.message,
|
|
209
243
|
e.code,
|
|
210
244
|
void 0,
|
|
211
245
|
(t) => {
|
|
212
246
|
this._errorReportingService && this._errorReportingService.report({
|
|
213
247
|
message: "LoggingService: Failed to send log: " + t.message,
|
|
214
|
-
code:
|
|
215
|
-
severity:
|
|
248
|
+
code: P.UNKNOWN_ERROR,
|
|
249
|
+
severity: L.ERROR
|
|
216
250
|
});
|
|
217
251
|
}
|
|
218
252
|
);
|
|
219
253
|
}
|
|
220
254
|
}
|
|
221
|
-
const
|
|
255
|
+
const h = class h {
|
|
222
256
|
constructor() {
|
|
223
|
-
this.name =
|
|
257
|
+
this.name = d, this.id = w, this.moduleId = w, this.isInitialized = !1, this.launcher = null, this.filters = {}, this.userAttributes = {}, this.userIdentifiedInWorkspace = !1, this.testHelpers = null, this.placementEventMappingLookup = {}, this.placementEventAttributeMappingLookup = {}, this.batchQueue = [], this.batchStreamQueue = [], this.pendingIdentityEvents = [], this.integrationName = null, this.errorReportingService = null, this.loggingService = null, this._thankYouElementOnLoadCallback = null, this._isThankYouElementLoaded = !1, this._workspaceSearchInFlightPromise = null;
|
|
224
258
|
}
|
|
225
259
|
// ---- Private helpers ----
|
|
226
260
|
getEventAttributeValue(e, t) {
|
|
@@ -228,13 +262,13 @@ const p = class p {
|
|
|
228
262
|
return !i || typeof i[t] > "u" ? null : i[t];
|
|
229
263
|
}
|
|
230
264
|
doesEventAttributeConditionMatch(e, t) {
|
|
231
|
-
if (!e || !
|
|
265
|
+
if (!e || !f(e.operator))
|
|
232
266
|
return !1;
|
|
233
267
|
const i = e.operator.toLowerCase(), r = e.attributeValue;
|
|
234
268
|
return i === "exists" ? t !== null : t == null ? !1 : i === "equals" ? String(t) === String(r) : i === "contains" ? String(t).indexOf(String(r)) !== -1 : !1;
|
|
235
269
|
}
|
|
236
270
|
doesEventMatchRule(e, t) {
|
|
237
|
-
if (!t || !
|
|
271
|
+
if (!t || !f(t.eventAttributeKey))
|
|
238
272
|
return !1;
|
|
239
273
|
const i = t.conditions;
|
|
240
274
|
if (!Array.isArray(i))
|
|
@@ -242,24 +276,24 @@ const p = class p {
|
|
|
242
276
|
const r = this.getEventAttributeValue(e, t.eventAttributeKey);
|
|
243
277
|
if (i.length === 0)
|
|
244
278
|
return r !== null;
|
|
245
|
-
for (let
|
|
246
|
-
if (!this.doesEventAttributeConditionMatch(i[
|
|
279
|
+
for (let s = 0; s < i.length; s++)
|
|
280
|
+
if (!this.doesEventAttributeConditionMatch(i[s], r))
|
|
247
281
|
return !1;
|
|
248
282
|
return !0;
|
|
249
283
|
}
|
|
250
284
|
applyPlacementEventAttributeMapping(e) {
|
|
251
285
|
const t = Object.keys(this.placementEventAttributeMappingLookup);
|
|
252
286
|
for (let i = 0; i < t.length; i++) {
|
|
253
|
-
const r = t[i],
|
|
254
|
-
if (
|
|
287
|
+
const r = t[i], s = this.placementEventAttributeMappingLookup[r];
|
|
288
|
+
if (I(s))
|
|
255
289
|
continue;
|
|
256
|
-
let
|
|
257
|
-
for (let c = 0; c <
|
|
258
|
-
if (!this.doesEventMatchRule(e,
|
|
259
|
-
|
|
290
|
+
let o = !0;
|
|
291
|
+
for (let c = 0; c < s.length; c++)
|
|
292
|
+
if (!this.doesEventMatchRule(e, s[c])) {
|
|
293
|
+
o = !1;
|
|
260
294
|
break;
|
|
261
295
|
}
|
|
262
|
-
|
|
296
|
+
o && a().Rokt.setLocalSessionAttribute?.(r, !0);
|
|
263
297
|
}
|
|
264
298
|
}
|
|
265
299
|
isLauncherReadyToAttach() {
|
|
@@ -275,20 +309,20 @@ const p = class p {
|
|
|
275
309
|
return this.replaceOtherIdentityWithEmailsha256(t);
|
|
276
310
|
}
|
|
277
311
|
returnLocalSessionAttributes() {
|
|
278
|
-
return !
|
|
312
|
+
return !a().Rokt || typeof a().Rokt.getLocalSessionAttributes != "function" ? {} : I(this.placementEventMappingLookup) && I(this.placementEventAttributeMappingLookup) ? {} : a().Rokt.getLocalSessionAttributes();
|
|
279
313
|
}
|
|
280
314
|
replaceOtherIdentityWithEmailsha256(e) {
|
|
281
315
|
const t = { ...e || {} }, i = this._mappedEmailSha256Key;
|
|
282
|
-
return i && e[i] && (t[
|
|
316
|
+
return i && e[i] && (t[h.EMAIL_SHA256_KEY] = e[i]), i && delete t[i], t;
|
|
283
317
|
}
|
|
284
318
|
logSelectPlacementsEvent(e) {
|
|
285
|
-
if (!window.mParticle || typeof
|
|
319
|
+
if (!window.mParticle || typeof a().logEvent != "function" || !T(e))
|
|
286
320
|
return;
|
|
287
|
-
const t =
|
|
288
|
-
|
|
321
|
+
const t = a().EventType.Other;
|
|
322
|
+
a().logEvent(J, t, e);
|
|
289
323
|
}
|
|
290
324
|
buildIdentityEvent(e, t) {
|
|
291
|
-
const i = t.getMPID(), r =
|
|
325
|
+
const i = t.getMPID(), r = a() && a().sessionManager && typeof a().sessionManager.getSession == "function" ? a().sessionManager.getSession() : void 0;
|
|
292
326
|
return {
|
|
293
327
|
event_type: e,
|
|
294
328
|
data: {
|
|
@@ -313,7 +347,22 @@ const p = class p {
|
|
|
313
347
|
}), this.batchQueue = [];
|
|
314
348
|
}
|
|
315
349
|
processBatch(e) {
|
|
316
|
-
|
|
350
|
+
if (!this.isKitReady())
|
|
351
|
+
return this.batchQueue.push(e), "Batch queued for forwarder: " + d;
|
|
352
|
+
const t = this.enrichCommerceEventTypes(this.mergePendingIdentityEvents(e));
|
|
353
|
+
return this.sendBatchStream(t), "Successfully sent batch to forwarder: " + d;
|
|
354
|
+
}
|
|
355
|
+
enrichCommerceEventTypes(e) {
|
|
356
|
+
if (!e.events)
|
|
357
|
+
return e;
|
|
358
|
+
for (const t of e.events) {
|
|
359
|
+
if (t.event_type !== "commerce_event") continue;
|
|
360
|
+
const { data: i } = t;
|
|
361
|
+
if (!i) continue;
|
|
362
|
+
const r = i.custom_flags?.["Rokt.CommerceEventType"];
|
|
363
|
+
r && T(i.product_action) && (i.product_action.action = r);
|
|
364
|
+
}
|
|
365
|
+
return e;
|
|
317
366
|
}
|
|
318
367
|
sendBatchStream(e) {
|
|
319
368
|
if (window.Rokt && typeof window.Rokt.__batch_stream__ == "function") {
|
|
@@ -330,37 +379,37 @@ const p = class p {
|
|
|
330
379
|
setRoktSessionId(e) {
|
|
331
380
|
if (!(!e || typeof e != "string"))
|
|
332
381
|
try {
|
|
333
|
-
const t =
|
|
334
|
-
t && typeof t.setIntegrationAttribute == "function" && t.setIntegrationAttribute(
|
|
382
|
+
const t = a().getInstance();
|
|
383
|
+
t && typeof t.setIntegrationAttribute == "function" && t.setIntegrationAttribute(w, {
|
|
335
384
|
roktSessionId: e
|
|
336
385
|
});
|
|
337
386
|
} catch {
|
|
338
387
|
}
|
|
339
388
|
}
|
|
340
389
|
attachLauncher(e, t, i = []) {
|
|
341
|
-
const r =
|
|
390
|
+
const r = a() && a().sessionManager && typeof a().sessionManager.getSession == "function" ? a().sessionManager.getSession() : void 0, s = {
|
|
342
391
|
accountId: e,
|
|
343
392
|
...t || {},
|
|
344
393
|
...r ? { mpSessionId: r } : {}
|
|
345
394
|
};
|
|
346
|
-
let
|
|
347
|
-
this.isPartnerInLocalLauncherTestGroup() ?
|
|
348
|
-
await
|
|
395
|
+
let o;
|
|
396
|
+
this.isPartnerInLocalLauncherTestGroup() ? o = Promise.resolve(window.Rokt.createLocalLauncher(s)) : o = window.Rokt.createLauncher(s), o.then(async (c) => {
|
|
397
|
+
await ae(i, c), this.initRoktLauncher(c);
|
|
349
398
|
}).catch((c) => {
|
|
350
399
|
console.error("Error creating Rokt launcher:", c);
|
|
351
400
|
});
|
|
352
401
|
}
|
|
353
402
|
initRoktLauncher(e) {
|
|
354
403
|
window.Rokt && (window.Rokt.currentLauncher = e), this.launcher = e;
|
|
355
|
-
const t =
|
|
356
|
-
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,
|
|
404
|
+
const t = a().Rokt?.filters;
|
|
405
|
+
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, j(this.domain, this.integrationName), a().Rokt.attachKit(this), this.drainBatchQueue();
|
|
357
406
|
}
|
|
358
407
|
fetchOptimizely() {
|
|
359
|
-
const e =
|
|
408
|
+
const e = a()._getActiveForwarders().filter((t) => t.name === "Optimizely");
|
|
360
409
|
try {
|
|
361
410
|
if (e.length > 0 && window.optimizely) {
|
|
362
411
|
const t = window.optimizely.get("state");
|
|
363
|
-
return !t || !t.getActiveExperimentIds ? {} : t.getActiveExperimentIds().reduce((
|
|
412
|
+
return !t || !t.getActiveExperimentIds ? {} : t.getActiveExperimentIds().reduce((s, o) => (s["rokt.custom.optimizely.experiment." + o + ".variationId"] = t.getVariationMap()[o].id, s), {});
|
|
364
413
|
}
|
|
365
414
|
} catch (t) {
|
|
366
415
|
console.error("Error fetching Optimizely attributes:", t);
|
|
@@ -371,93 +420,93 @@ const p = class p {
|
|
|
371
420
|
return !!(this.isInitialized && this.launcher);
|
|
372
421
|
}
|
|
373
422
|
isPartnerInLocalLauncherTestGroup() {
|
|
374
|
-
return !!(
|
|
423
|
+
return !!(a().config && a().config.isLocalLauncherEnabled && this.isAssignedToSampleGroup());
|
|
375
424
|
}
|
|
376
425
|
isAssignedToSampleGroup() {
|
|
377
426
|
return Math.random() > 0.5;
|
|
378
427
|
}
|
|
379
428
|
captureTiming(e) {
|
|
380
|
-
window &&
|
|
429
|
+
window && a() && a().captureTiming && e && a().captureTiming(e);
|
|
381
430
|
}
|
|
382
431
|
// ---- Public methods (mParticle Kit Callbacks) ----
|
|
383
432
|
/**
|
|
384
433
|
* Initializes the Rokt forwarder with settings from the mParticle server.
|
|
385
434
|
*/
|
|
386
|
-
init(e, t, i, r,
|
|
387
|
-
const
|
|
388
|
-
this.userAttributes =
|
|
389
|
-
const
|
|
390
|
-
this.placementEventMappingLookup =
|
|
391
|
-
const
|
|
392
|
-
|
|
435
|
+
init(e, t, i, r, s) {
|
|
436
|
+
const o = e, c = o.accountId;
|
|
437
|
+
this.userAttributes = A(s), this._onboardingExpProvider = o.onboardingExpProvider;
|
|
438
|
+
const l = b(o.placementEventMapping);
|
|
439
|
+
this.placementEventMappingLookup = x(l);
|
|
440
|
+
const u = b(
|
|
441
|
+
o.placementEventAttributeMapping
|
|
393
442
|
);
|
|
394
|
-
this.placementEventAttributeMappingLookup =
|
|
395
|
-
const
|
|
396
|
-
|
|
397
|
-
),
|
|
398
|
-
...
|
|
443
|
+
this.placementEventAttributeMappingLookup = Y(u), o.hashedEmailUserIdentityType && (this._mappedEmailSha256Key = o.hashedEmailUserIdentityType.toLowerCase()), this._workspaceIdSyncApiKey = f(o.workspaceIdSyncApiKey) ? o.workspaceIdSyncApiKey : void 0;
|
|
444
|
+
const E = a().Rokt?.domain, { roktExtensionsQueryParams: O, legacyRoktExtensions: k, loadThankYouElement: R } = D(
|
|
445
|
+
o.roktExtensions
|
|
446
|
+
), p = {
|
|
447
|
+
...a().Rokt?.launcherOptions || {}
|
|
399
448
|
};
|
|
400
|
-
this.integrationName =
|
|
401
|
-
const
|
|
402
|
-
loggingUrl:
|
|
403
|
-
errorUrl:
|
|
404
|
-
isLoggingEnabled:
|
|
405
|
-
},
|
|
406
|
-
|
|
449
|
+
this.integrationName = ce(p.integrationName), p.integrationName = this.integrationName, this.domain = E;
|
|
450
|
+
const _ = {
|
|
451
|
+
loggingUrl: o.loggingUrl,
|
|
452
|
+
errorUrl: o.errorUrl,
|
|
453
|
+
isLoggingEnabled: a().config?.isLoggingEnabled === !0
|
|
454
|
+
}, y = new H(
|
|
455
|
+
_,
|
|
407
456
|
this.integrationName,
|
|
408
457
|
window.__rokt_li_guid__,
|
|
409
|
-
|
|
410
|
-
),
|
|
411
|
-
k,
|
|
458
|
+
o.accountId
|
|
459
|
+
), S = new G(
|
|
412
460
|
_,
|
|
461
|
+
y,
|
|
413
462
|
this.integrationName,
|
|
414
463
|
window.__rokt_li_guid__,
|
|
415
|
-
|
|
464
|
+
o.accountId
|
|
416
465
|
);
|
|
417
|
-
return this.errorReportingService =
|
|
418
|
-
generateLauncherScript:
|
|
419
|
-
generateThankYouElementScript:
|
|
420
|
-
extractRoktExtensionConfig:
|
|
421
|
-
hashEventMessage:
|
|
422
|
-
parseSettingsString:
|
|
423
|
-
generateMappedEventLookup:
|
|
424
|
-
generateMappedEventAttributeLookup:
|
|
425
|
-
sendAdBlockMeasurementSignals:
|
|
426
|
-
createAutoRemovedIframe:
|
|
427
|
-
djb2:
|
|
428
|
-
setAllowedOriginHashes: (
|
|
429
|
-
|
|
466
|
+
return this.errorReportingService = y, this.loggingService = S, a()._registerErrorReportingService && a()._registerErrorReportingService(y), a()._registerLoggingService && a()._registerLoggingService(S), i ? (this.testHelpers = {
|
|
467
|
+
generateLauncherScript: C,
|
|
468
|
+
generateThankYouElementScript: M,
|
|
469
|
+
extractRoktExtensionConfig: D,
|
|
470
|
+
hashEventMessage: F,
|
|
471
|
+
parseSettingsString: b,
|
|
472
|
+
generateMappedEventLookup: x,
|
|
473
|
+
generateMappedEventAttributeLookup: Y,
|
|
474
|
+
sendAdBlockMeasurementSignals: j,
|
|
475
|
+
createAutoRemovedIframe: N,
|
|
476
|
+
djb2: Q,
|
|
477
|
+
setAllowedOriginHashes: (g) => {
|
|
478
|
+
h._allowedOriginHashes = g;
|
|
430
479
|
},
|
|
431
|
-
ReportingTransport:
|
|
432
|
-
ErrorReportingService:
|
|
433
|
-
LoggingService:
|
|
434
|
-
RateLimiter:
|
|
435
|
-
ErrorCodes:
|
|
436
|
-
WSDKErrorSeverity:
|
|
437
|
-
}, this.attachLauncher(c,
|
|
480
|
+
ReportingTransport: U,
|
|
481
|
+
ErrorReportingService: H,
|
|
482
|
+
LoggingService: G,
|
|
483
|
+
RateLimiter: B,
|
|
484
|
+
ErrorCodes: P,
|
|
485
|
+
WSDKErrorSeverity: L
|
|
486
|
+
}, this.attachLauncher(c, p), "Successfully initialized: " + d) : (R && (a().Rokt.flushOnShoppableAdsReadyMessageQueue?.(this), K(te, M(E), {
|
|
438
487
|
onLoad: () => {
|
|
439
488
|
this._isThankYouElementLoaded = !0, this._thankYouElementOnLoadCallback && this._thankYouElementOnLoadCallback();
|
|
440
489
|
},
|
|
441
|
-
onError: (
|
|
442
|
-
console.error("Error loading Rokt Thank You Element script:",
|
|
490
|
+
onError: (g) => {
|
|
491
|
+
console.error("Error loading Rokt Thank You Element script:", g);
|
|
443
492
|
}
|
|
444
|
-
})), this.isLauncherReadyToAttach() ? this.attachLauncher(c,
|
|
493
|
+
})), this.isLauncherReadyToAttach() ? this.attachLauncher(c, p, k) : (K(ee, C(E, O), {
|
|
445
494
|
onLoad: () => {
|
|
446
|
-
this.isLauncherReadyToAttach() ? this.attachLauncher(c,
|
|
495
|
+
this.isLauncherReadyToAttach() ? this.attachLauncher(c, p, k) : console.error("Rokt object is not available after script load.");
|
|
447
496
|
},
|
|
448
|
-
onError: (
|
|
449
|
-
console.error("Error loading Rokt launcher script:",
|
|
497
|
+
onError: (g) => {
|
|
498
|
+
console.error("Error loading Rokt launcher script:", g);
|
|
450
499
|
}
|
|
451
|
-
}), this.captureTiming(
|
|
500
|
+
}), this.captureTiming(h.PERFORMANCE_MARKS.RoktScriptAppended)), "Successfully initialized: " + d);
|
|
452
501
|
}
|
|
453
502
|
process(e) {
|
|
454
503
|
if (!this.isKitReady())
|
|
455
|
-
return "Kit not ready for forwarder: " +
|
|
456
|
-
if (typeof
|
|
457
|
-
const t =
|
|
458
|
-
this.placementEventMappingLookup[String(t)] &&
|
|
504
|
+
return "Kit not ready for forwarder: " + d;
|
|
505
|
+
if (typeof a().Rokt?.setLocalSessionAttribute == "function" && (I(this.placementEventAttributeMappingLookup) || this.applyPlacementEventAttributeMapping(e), !I(this.placementEventMappingLookup))) {
|
|
506
|
+
const t = F(e.EventDataType, e.EventCategory, e.EventName ?? "");
|
|
507
|
+
this.placementEventMappingLookup[String(t)] && a().Rokt.setLocalSessionAttribute?.(this.placementEventMappingLookup[String(t)], !0);
|
|
459
508
|
}
|
|
460
|
-
return "Successfully sent to forwarder: " +
|
|
509
|
+
return "Successfully sent to forwarder: " + d;
|
|
461
510
|
}
|
|
462
511
|
setExtensionData(e) {
|
|
463
512
|
if (!this.isKitReady()) {
|
|
@@ -467,54 +516,54 @@ const p = class p {
|
|
|
467
516
|
window.Rokt.setExtensionData(e);
|
|
468
517
|
}
|
|
469
518
|
setUserAttribute(e, t) {
|
|
470
|
-
return this.userAttributes[e] = t, "Successfully set user attribute for forwarder: " +
|
|
519
|
+
return z(e) || (this.userAttributes[e] = t), "Successfully set user attribute for forwarder: " + d;
|
|
471
520
|
}
|
|
472
521
|
removeUserAttribute(e) {
|
|
473
|
-
return delete this.userAttributes[e], "Successfully removed user attribute for forwarder: " +
|
|
522
|
+
return delete this.userAttributes[e], "Successfully removed user attribute for forwarder: " + d;
|
|
474
523
|
}
|
|
475
524
|
handleIdentityComplete(e, t, i) {
|
|
476
525
|
const r = e;
|
|
477
|
-
return this.userAttributes = e.getAllUserAttributes(), this.pendingIdentityEvents.push(this.buildIdentityEvent(t, r)), "Successfully called " + i + " for forwarder: " +
|
|
526
|
+
return this.userAttributes = A(e.getAllUserAttributes()), this.pendingIdentityEvents.push(this.buildIdentityEvent(t, r)), "Successfully called " + i + " for forwarder: " + d;
|
|
478
527
|
}
|
|
479
528
|
onUserIdentified(e) {
|
|
480
529
|
const t = e;
|
|
481
|
-
return this.filters.filteredUser = t, this._workspaceSearchInFlightPromise = this.search(t), this.handleIdentityComplete(e,
|
|
530
|
+
return this.filters.filteredUser = t, this._workspaceSearchInFlightPromise = this.search(t), this.handleIdentityComplete(e, v.IDENTIFY, "onUserIdentified");
|
|
482
531
|
}
|
|
483
532
|
search(e) {
|
|
484
533
|
const t = this._workspaceIdSyncApiKey;
|
|
485
534
|
if (!t)
|
|
486
535
|
return this.userIdentifiedInWorkspace = !1, this._workspaceLastSearchedIdentitiesKey = void 0, Promise.resolve();
|
|
487
|
-
const i =
|
|
536
|
+
const i = a().Identity?.search;
|
|
488
537
|
if (typeof i != "function")
|
|
489
538
|
return this.userIdentifiedInWorkspace = !1, this._workspaceLastSearchedIdentitiesKey = void 0, Promise.resolve();
|
|
490
|
-
const r = e.getUserIdentities ? e.getUserIdentities().userIdentities : null,
|
|
539
|
+
const r = e.getUserIdentities ? e.getUserIdentities().userIdentities : null, s = {};
|
|
491
540
|
if (r)
|
|
492
|
-
for (const
|
|
493
|
-
const
|
|
494
|
-
|
|
541
|
+
for (const l of Object.keys(r)) {
|
|
542
|
+
const u = r[l];
|
|
543
|
+
f(u) && u.length > 0 && (s[l] = u);
|
|
495
544
|
}
|
|
496
|
-
const
|
|
497
|
-
if (
|
|
545
|
+
const o = Object.keys(s);
|
|
546
|
+
if (o.length === 0)
|
|
498
547
|
return this.userIdentifiedInWorkspace = !1, this._workspaceLastSearchedIdentitiesKey = void 0, Promise.resolve();
|
|
499
|
-
const c =
|
|
500
|
-
return c === this._workspaceLastSearchedIdentitiesKey ? this._workspaceSearchInFlightPromise || Promise.resolve() : (this.userIdentifiedInWorkspace = !1, this._workspaceLastSearchedIdentitiesKey = c, new Promise((
|
|
548
|
+
const c = o.sort().map((l) => `${l}=${s[l]}`).join("&");
|
|
549
|
+
return c === this._workspaceLastSearchedIdentitiesKey ? this._workspaceSearchInFlightPromise || Promise.resolve() : (this.userIdentifiedInWorkspace = !1, this._workspaceLastSearchedIdentitiesKey = c, new Promise((l) => {
|
|
501
550
|
try {
|
|
502
|
-
i(t,
|
|
503
|
-
|
|
551
|
+
i(t, s, (u) => {
|
|
552
|
+
u?.httpCode === 200 && (this.userIdentifiedInWorkspace = !0), l();
|
|
504
553
|
});
|
|
505
|
-
} catch (
|
|
506
|
-
console.error("Rokt Kit: Workspace IDSync search failed",
|
|
554
|
+
} catch (u) {
|
|
555
|
+
console.error("Rokt Kit: Workspace IDSync search failed", u), this._workspaceLastSearchedIdentitiesKey = void 0, l();
|
|
507
556
|
}
|
|
508
557
|
}));
|
|
509
558
|
}
|
|
510
559
|
onLoginComplete(e, t) {
|
|
511
|
-
return this.handleIdentityComplete(e,
|
|
560
|
+
return this.handleIdentityComplete(e, v.LOGIN, "onLoginComplete");
|
|
512
561
|
}
|
|
513
562
|
onLogoutComplete(e, t) {
|
|
514
|
-
return this.userIdentifiedInWorkspace = !1, this._workspaceSearchInFlightPromise = null, this._workspaceLastSearchedIdentitiesKey = void 0, this.handleIdentityComplete(e,
|
|
563
|
+
return this.userIdentifiedInWorkspace = !1, this._workspaceSearchInFlightPromise = null, this._workspaceLastSearchedIdentitiesKey = void 0, this.handleIdentityComplete(e, v.LOGOUT, "onLogoutComplete");
|
|
515
564
|
}
|
|
516
565
|
onModifyComplete(e, t) {
|
|
517
|
-
return this.handleIdentityComplete(e,
|
|
566
|
+
return this.handleIdentityComplete(e, v.MODIFY_USER, "onModifyComplete");
|
|
518
567
|
}
|
|
519
568
|
/**
|
|
520
569
|
* Selects placements for Rokt Web SDK with merged attributes, filters, and experimentation options.
|
|
@@ -544,25 +593,25 @@ const p = class p {
|
|
|
544
593
|
const t = this._workspaceSearchInFlightPromise;
|
|
545
594
|
return Promise.race([
|
|
546
595
|
t,
|
|
547
|
-
new Promise((i) => setTimeout(i,
|
|
596
|
+
new Promise((i) => setTimeout(i, ne))
|
|
548
597
|
]).then(() => this._dispatchPlacements(e));
|
|
549
598
|
}
|
|
550
599
|
return this._dispatchPlacements(e);
|
|
551
600
|
}
|
|
552
601
|
_dispatchPlacements(e) {
|
|
553
|
-
const t = e && e.attributes || {},
|
|
602
|
+
const t = e && e.attributes || {}, r = { ...A(this.userAttributes), ...t }, s = this.filters || {}, o = s.userAttributeFilters || [], c = s.filteredUser || null, l = c ? c.getMPID() : null;
|
|
554
603
|
let u;
|
|
555
|
-
|
|
556
|
-
const
|
|
557
|
-
...
|
|
604
|
+
s ? s.filterUserAttributes ? u = s.filterUserAttributes(r, o) : u = r : (console.warn("Rokt Kit: No filters available, using user attributes"), u = r), this.userAttributes = A(u);
|
|
605
|
+
const E = this._onboardingExpProvider === "Optimizely" ? this.fetchOptimizely() : {}, O = this.returnUserIdentities(c), k = this.returnLocalSessionAttributes(), R = {
|
|
606
|
+
...O,
|
|
558
607
|
...u,
|
|
559
|
-
...
|
|
560
|
-
...
|
|
561
|
-
...this.userIdentifiedInWorkspace ? { [
|
|
562
|
-
mpid:
|
|
563
|
-
},
|
|
564
|
-
return Promise.resolve(
|
|
565
|
-
}).finally(
|
|
608
|
+
...E,
|
|
609
|
+
...k,
|
|
610
|
+
...this.userIdentifiedInWorkspace ? { [ie]: !0 } : {},
|
|
611
|
+
mpid: l
|
|
612
|
+
}, p = { ...e, attributes: R }, _ = this.launcher.selectPlacements(p), y = () => this.logSelectPlacementsEvent(R);
|
|
613
|
+
return Promise.resolve(_).then((S) => S?.context?.sessionId?.then((g) => this.setRoktSessionId(g))).catch(() => {
|
|
614
|
+
}).finally(y), _;
|
|
566
615
|
}
|
|
567
616
|
/**
|
|
568
617
|
* Passes attributes to the Rokt Web SDK for client-side hashing.
|
|
@@ -576,7 +625,7 @@ const p = class p {
|
|
|
576
625
|
* @deprecated This functionality has been internalized and will be removed in a future release.
|
|
577
626
|
*/
|
|
578
627
|
use(e) {
|
|
579
|
-
return this.isKitReady() ? !e || !
|
|
628
|
+
return this.isKitReady() ? !e || !f(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")));
|
|
580
629
|
}
|
|
581
630
|
/**
|
|
582
631
|
* Registers a callback to be invoked once rokt-thank-you-element.js becomes available.
|
|
@@ -585,34 +634,34 @@ const p = class p {
|
|
|
585
634
|
this._isThankYouElementLoaded ? e() : this._thankYouElementOnLoadCallback = e;
|
|
586
635
|
}
|
|
587
636
|
};
|
|
588
|
-
|
|
637
|
+
h._allowedOriginHashes = [-553112570, 549508659], h.PERFORMANCE_MARKS = {
|
|
589
638
|
RoktScriptAppended: "mp:RoktScriptAppended"
|
|
590
|
-
},
|
|
591
|
-
let
|
|
592
|
-
function
|
|
593
|
-
return
|
|
639
|
+
}, h.EMAIL_SHA256_KEY = "emailsha256";
|
|
640
|
+
let m = h;
|
|
641
|
+
function he() {
|
|
642
|
+
return w;
|
|
594
643
|
}
|
|
595
|
-
function
|
|
644
|
+
function pe(n) {
|
|
596
645
|
if (!n) {
|
|
597
|
-
window.console.log("You must pass a config object to register the kit " +
|
|
646
|
+
window.console.log("You must pass a config object to register the kit " + d);
|
|
598
647
|
return;
|
|
599
648
|
}
|
|
600
|
-
if (!
|
|
649
|
+
if (!T(n)) {
|
|
601
650
|
window.console.log("'config' must be an object. You passed in a " + typeof n);
|
|
602
651
|
return;
|
|
603
652
|
}
|
|
604
|
-
|
|
605
|
-
constructor:
|
|
606
|
-
} : (n.kits = {}, n.kits[
|
|
607
|
-
constructor:
|
|
608
|
-
}), window.console.log("Successfully registered " +
|
|
653
|
+
T(n.kits) ? n.kits[d] = {
|
|
654
|
+
constructor: m
|
|
655
|
+
} : (n.kits = {}, n.kits[d] = {
|
|
656
|
+
constructor: m
|
|
657
|
+
}), window.console.log("Successfully registered " + d + " to your mParticle configuration");
|
|
609
658
|
}
|
|
610
|
-
typeof window < "u" && window.mParticle &&
|
|
611
|
-
name:
|
|
612
|
-
constructor:
|
|
613
|
-
getId:
|
|
659
|
+
typeof window < "u" && window.mParticle && a().addForwarder && a().addForwarder({
|
|
660
|
+
name: d,
|
|
661
|
+
constructor: m,
|
|
662
|
+
getId: he
|
|
614
663
|
});
|
|
615
664
|
export {
|
|
616
|
-
|
|
665
|
+
pe as register
|
|
617
666
|
};
|
|
618
667
|
//# sourceMappingURL=Rokt-Kit.esm.js.map
|
package/dist/Rokt-Kit.iife.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var RoktKit=(function(v){"use strict";const l="Rokt",Q="selectPlacements",B="apps.roktecommerce.com",k={LOGIN:"login",LOGOUT:"logout",MODIFY_USER:"modify_user",IDENTIFY:"identify"},V="ThankYouPageJourney",q="rokt-launcher",J="rokt-thank-you-element",X="userIdentifiedInWorkspace",$=500,b={UNKNOWN_ERROR:"UNKNOWN_ERROR",UNHANDLED_EXCEPTION:"UNHANDLED_EXCEPTION",IDENTITY_REQUEST:"IDENTITY_REQUEST"},R={ERROR:"ERROR",INFO:"INFO",WARNING:"WARNING"},Z="apps.rokt-api.com/v1/log",ee="apps.rokt-api.com/v1/errors",te=10;function o(){return window.mParticle}function U(n,e){const i=[M(n),"/wsdk/integrations/launcher.js"].join("");return!e||e.length===0?i:i+"?extensions="+e.join(",")}function C(n){return[M(n),"/rokt-elements/rokt-element-thank-you.js"].join("")}function M(n){return["https://",typeof n<"u"?n:"apps.rokt-api.com"].join("")}function K(n,e,t){if(document.getElementById(n))return;const i=document.head||document.body,r=document.createElement("script");r.id=n,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),i.appendChild(r)}function L(n){return n!=null&&typeof n=="object"&&Array.isArray(n)===!1}function S(n){if(!n)return[];try{return JSON.parse(n.replace(/"/g,'"'))}catch{console.error("Settings string contains invalid JSON")}return[]}function D(n){const e=n?S(n):[],t=[],i=[];let r=!1;for(let a=0;a<e.length;a++){const s=e[a].value;s==="thank-you-journey"?(r=!0,i.push(V)):t.push(s)}return{roktExtensionsQueryParams:t,legacyRoktExtensions:i,loadThankYouElement:r}}async function ie(n,e){const t=[];if(e)for(const i of n)t.push(e.use(i));return Promise.all(t)}function Y(n){if(!n)return{};const e={};for(let t=0;t<n.length;t++){const i=n[t];e[i.jsmap]=i.value}return e}function x(n){const e={};if(!Array.isArray(n))return e;for(let t=0;t<n.length;t++){const i=n[t];if(!i||!g(i.value)||!g(i.map))continue;const r=i.value,a=i.map;e[r]||(e[r]=[]),e[r].push({eventAttributeKey:a,conditions:Array.isArray(i.conditions)?i.conditions:[]})}return e}function F(n,e,t){return o().generateHash([n,e,t].join(""))}function m(n){return n==null?!0:typeof n=="object"?Object.keys(n).length===0:Array.isArray(n)?n.length===0:!1}function g(n){return typeof n=="string"}function ne(n){let i="mParticle_wsdkv_"+o().getVersion()+"_kitv_"+"1.26.3";return n&&(i+="_"+n),i}function j(n){let e=5381;for(let t=0;t<n.length;t++)e=(e<<5)+e+n.charCodeAt(t),e=e&e;return e}function O(n){const e=document.createElement("iframe");e.style.display="none",e.setAttribute("sandbox","allow-scripts allow-same-origin"),e.src=n,e.onload=function(){e.onload=null,e.parentNode&&e.parentNode.removeChild(e)};const t=document.body||document.head;t&&t.appendChild(e)}function G(n,e){const t=j(window.location.origin);if(f._allowedOriginHashes.indexOf(t)===-1||Math.random()>=.1)return;const r=window.__rokt_li_guid__;if(!r)return;const a=window.location.href.split("?")[0].split("#")[0],s="version="+encodeURIComponent(e??"")+"&launcherInstanceGuid="+encodeURIComponent(r)+"&pageUrl="+encodeURIComponent(a);O("https://"+(n||"apps.rokt.com")+"/v1/wsdk-init/index.html?"+s),O("https://"+B+"/v1/wsdk-init/index.html?"+s+"&isControl=true")}function re(){return typeof window<"u"&&!!window.location?.search?.toLowerCase().includes("mp_enable_logging=true")}function se(){return typeof window<"u"?window.location?.href:void 0}function oe(){return typeof window<"u"?window.navigator?.userAgent:void 0}class H{constructor(){this._logCount={}}incrementAndCheck(e){const i=(this._logCount[e]||0)+1;return this._logCount[e]=i,i>te}}class T{constructor(e,t,i,r,a){this._reporter="mp-wsdk";const s=e.isLoggingEnabled;this._integrationName=t||"",this._launcherInstanceGuid=i,this._accountId=r||null,this._rateLimiter=a||new H,this._isEnabled=re()||s}send(e,t,i,r,a,s){if(!(!this._isEnabled||this._rateLimiter.incrementAndCheck(t)))try{const c={additionalInformation:{message:i,version:this._integrationName},severity:t,code:r||b.UNKNOWN_ERROR,url:se(),deviceInfo:oe(),stackTrace:a,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)}).catch(d=>{console.error("ReportingTransport: Failed to send log",d),s&&s(d)})}catch(c){console.error("ReportingTransport: Failed to send log",c),s&&s(c)}}}class W{constructor(e,t,i,r,a){this._transport=new T(e,t,i,r,a),this._errorUrl="https://"+(e?.errorUrl||ee)}report(e){if(!e)return;const t=e.severity||R.ERROR;this._transport.send(this._errorUrl,t,e.message,e.code,e.stackTrace)}}class z{constructor(e,t,i,r,a,s){this._transport=new T(e,i,r,a,s),this._loggingUrl="https://"+(e?.loggingUrl||Z),this._errorReportingService=t}log(e){e&&this._transport.send(this._loggingUrl,R.INFO,e.message,e.code,void 0,t=>{this._errorReportingService&&this._errorReportingService.report({message:"LoggingService: Failed to send log: "+t.message,code:b.UNKNOWN_ERROR,severity:R.ERROR})})}}const h=class h{constructor(){this.name=l,this.id=181,this.moduleId=181,this.isInitialized=!1,this.launcher=null,this.filters={},this.userAttributes={},this.userIdentifiedInWorkspace=!1,this.testHelpers=null,this.placementEventMappingLookup={},this.placementEventAttributeMappingLookup={},this.batchQueue=[],this.batchStreamQueue=[],this.pendingIdentityEvents=[],this.integrationName=null,this.errorReportingService=null,this.loggingService=null,this._thankYouElementOnLoadCallback=null,this._isThankYouElementLoaded=!1,this._workspaceSearchInFlightPromise=null}getEventAttributeValue(e,t){const i=e&&e.EventAttributes;return!i||typeof i[t]>"u"?null:i[t]}doesEventAttributeConditionMatch(e,t){if(!e||!g(e.operator))return!1;const i=e.operator.toLowerCase(),r=e.attributeValue;return i==="exists"?t!==null:t==null?!1:i==="equals"?String(t)===String(r):i==="contains"?String(t).indexOf(String(r))!==-1:!1}doesEventMatchRule(e,t){if(!t||!g(t.eventAttributeKey))return!1;const i=t.conditions;if(!Array.isArray(i))return!1;const r=this.getEventAttributeValue(e,t.eventAttributeKey);if(i.length===0)return r!==null;for(let a=0;a<i.length;a++)if(!this.doesEventAttributeConditionMatch(i[a],r))return!1;return!0}applyPlacementEventAttributeMapping(e){const t=Object.keys(this.placementEventAttributeMappingLookup);for(let i=0;i<t.length;i++){const r=t[i],a=this.placementEventAttributeMappingLookup[r];if(m(a))continue;let s=!0;for(let c=0;c<a.length;c++)if(!this.doesEventMatchRule(e,a[c])){s=!1;break}s&&o().Rokt.setLocalSessionAttribute?.(r,!0)}}isLauncherReadyToAttach(){return!!window.Rokt&&typeof window.Rokt.createLauncher=="function"}returnUserIdentities(e){if(!e||!e.getUserIdentities)return{};const t=e.getUserIdentities().userIdentities;return this.replaceOtherIdentityWithEmailsha256(t)}returnLocalSessionAttributes(){return!o().Rokt||typeof o().Rokt.getLocalSessionAttributes!="function"?{}:m(this.placementEventMappingLookup)&&m(this.placementEventAttributeMappingLookup)?{}:o().Rokt.getLocalSessionAttributes()}replaceOtherIdentityWithEmailsha256(e){const t={...e||{}},i=this._mappedEmailSha256Key;return i&&e[i]&&(t[h.EMAIL_SHA256_KEY]=e[i]),i&&delete t[i],t}logSelectPlacementsEvent(e){if(!window.mParticle||typeof o().logEvent!="function"||!L(e))return;const t=o().EventType.Other;o().logEvent(Q,t,e)}buildIdentityEvent(e,t){const i=t.getMPID(),r=o()&&o().sessionManager&&typeof o().sessionManager.getSession=="function"?o().sessionManager.getSession():void 0;return{event_type:e,data:{timestamp_unixtime_ms:Date.now(),session_uuid:r??void 0,mpid:i}}}mergePendingIdentityEvents(e){if(this.pendingIdentityEvents.length===0)return e;const t={...e,events:[...e.events??[],...this.pendingIdentityEvents]};return this.pendingIdentityEvents=[],t}drainBatchQueue(){this.batchQueue.forEach(e=>{this.processBatch(e)}),this.batchQueue=[]}processBatch(e){return this.isKitReady()?(this.sendBatchStream(this.mergePendingIdentityEvents(e)),"Successfully sent batch to forwarder: "+l):(this.batchQueue.push(e),"Batch queued for forwarder: "+l)}sendBatchStream(e){if(window.Rokt&&typeof window.Rokt.__batch_stream__=="function"){if(this.batchStreamQueue.length){const t=this.batchStreamQueue;this.batchStreamQueue=[];for(let i=0;i<t.length;i++)window.Rokt.__batch_stream__(t[i])}window.Rokt.__batch_stream__(e)}else this.batchStreamQueue.push(e)}setRoktSessionId(e){if(!(!e||typeof e!="string"))try{const t=o().getInstance();t&&typeof t.setIntegrationAttribute=="function"&&t.setIntegrationAttribute(181,{roktSessionId:e})}catch{}}attachLauncher(e,t,i=[]){const r=o()&&o().sessionManager&&typeof o().sessionManager.getSession=="function"?o().sessionManager.getSession():void 0,a={accountId:e,...t||{},...r?{mpSessionId:r}:{}};let s;this.isPartnerInLocalLauncherTestGroup()?s=Promise.resolve(window.Rokt.createLocalLauncher(a)):s=window.Rokt.createLauncher(a),s.then(async c=>{await ie(i,c),this.initRoktLauncher(c)}).catch(c=>{console.error("Error creating Rokt launcher:",c)})}initRoktLauncher(e){window.Rokt&&(window.Rokt.currentLauncher=e),this.launcher=e;const t=o().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,G(this.domain,this.integrationName),o().Rokt.attachKit(this),this.drainBatchQueue()}fetchOptimizely(){const e=o()._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((a,s)=>(a["rokt.custom.optimizely.experiment."+s+".variationId"]=t.getVariationMap()[s].id,a),{})}}catch(t){console.error("Error fetching Optimizely attributes:",t)}return{}}isKitReady(){return!!(this.isInitialized&&this.launcher)}isPartnerInLocalLauncherTestGroup(){return!!(o().config&&o().config.isLocalLauncherEnabled&&this.isAssignedToSampleGroup())}isAssignedToSampleGroup(){return Math.random()>.5}captureTiming(e){window&&o()&&o().captureTiming&&e&&o().captureTiming(e)}init(e,t,i,r,a){const s=e,c=s.accountId;this.userAttributes=a||{},this._onboardingExpProvider=s.onboardingExpProvider;const u=S(s.placementEventMapping);this.placementEventMappingLookup=Y(u);const d=S(s.placementEventAttributeMapping);this.placementEventAttributeMappingLookup=x(d),s.hashedEmailUserIdentityType&&(this._mappedEmailSha256Key=s.hashedEmailUserIdentityType.toLowerCase()),this._workspaceIdSyncApiKey=g(s.workspaceIdSyncApiKey)?s.workspaceIdSyncApiKey:void 0;const E=o().Rokt?.domain,{roktExtensionsQueryParams:N,legacyRoktExtensions:_,loadThankYouElement:P}=D(s.roktExtensions),p={...o().Rokt?.launcherOptions||{}};this.integrationName=ne(p.integrationName),p.integrationName=this.integrationName,this.domain=E;const w={loggingUrl:s.loggingUrl,errorUrl:s.errorUrl,isLoggingEnabled:o().config?.isLoggingEnabled===!0},y=new W(w,this.integrationName,window.__rokt_li_guid__,s.accountId),A=new z(w,y,this.integrationName,window.__rokt_li_guid__,s.accountId);return this.errorReportingService=y,this.loggingService=A,o()._registerErrorReportingService&&o()._registerErrorReportingService(y),o()._registerLoggingService&&o()._registerLoggingService(A),i?(this.testHelpers={generateLauncherScript:U,generateThankYouElementScript:C,extractRoktExtensionConfig:D,hashEventMessage:F,parseSettingsString:S,generateMappedEventLookup:Y,generateMappedEventAttributeLookup:x,sendAdBlockMeasurementSignals:G,createAutoRemovedIframe:O,djb2:j,setAllowedOriginHashes:I=>{h._allowedOriginHashes=I},ReportingTransport:T,ErrorReportingService:W,LoggingService:z,RateLimiter:H,ErrorCodes:b,WSDKErrorSeverity:R},this.attachLauncher(c,p),"Successfully initialized: "+l):(P&&(o().Rokt.flushOnShoppableAdsReadyMessageQueue?.(this),K(J,C(E),{onLoad:()=>{this._isThankYouElementLoaded=!0,this._thankYouElementOnLoadCallback&&this._thankYouElementOnLoadCallback()},onError:I=>{console.error("Error loading Rokt Thank You Element script:",I)}})),this.isLauncherReadyToAttach()?this.attachLauncher(c,p,_):(K(q,U(E,N),{onLoad:()=>{this.isLauncherReadyToAttach()?this.attachLauncher(c,p,_):console.error("Rokt object is not available after script load.")},onError:I=>{console.error("Error loading Rokt launcher script:",I)}}),this.captureTiming(h.PERFORMANCE_MARKS.RoktScriptAppended)),"Successfully initialized: "+l)}process(e){if(!this.isKitReady())return"Kit not ready for forwarder: "+l;if(typeof o().Rokt?.setLocalSessionAttribute=="function"&&(m(this.placementEventAttributeMappingLookup)||this.applyPlacementEventAttributeMapping(e),!m(this.placementEventMappingLookup))){const t=F(e.EventDataType,e.EventCategory,e.EventName??"");this.placementEventMappingLookup[String(t)]&&o().Rokt.setLocalSessionAttribute?.(this.placementEventMappingLookup[String(t)],!0)}return"Successfully sent to forwarder: "+l}setExtensionData(e){if(!this.isKitReady()){console.error("Rokt Kit: Not initialized");return}window.Rokt.setExtensionData(e)}setUserAttribute(e,t){return this.userAttributes[e]=t,"Successfully set user attribute for forwarder: "+l}removeUserAttribute(e){return delete this.userAttributes[e],"Successfully removed user attribute for forwarder: "+l}handleIdentityComplete(e,t,i){const r=e;return this.userAttributes=e.getAllUserAttributes(),this.pendingIdentityEvents.push(this.buildIdentityEvent(t,r)),"Successfully called "+i+" for forwarder: "+l}onUserIdentified(e){const t=e;return this.filters.filteredUser=t,this._workspaceSearchInFlightPromise=this.search(t),this.handleIdentityComplete(e,k.IDENTIFY,"onUserIdentified")}search(e){const t=this._workspaceIdSyncApiKey;if(!t)return this.userIdentifiedInWorkspace=!1,this._workspaceLastSearchedIdentitiesKey=void 0,Promise.resolve();const i=o().Identity?.search;if(typeof i!="function")return this.userIdentifiedInWorkspace=!1,this._workspaceLastSearchedIdentitiesKey=void 0,Promise.resolve();const r=e.getUserIdentities?e.getUserIdentities().userIdentities:null,a={};if(r)for(const u of Object.keys(r)){const d=r[u];g(d)&&d.length>0&&(a[u]=d)}const s=Object.keys(a);if(s.length===0)return this.userIdentifiedInWorkspace=!1,this._workspaceLastSearchedIdentitiesKey=void 0,Promise.resolve();const c=s.sort().map(u=>`${u}=${a[u]}`).join("&");return c===this._workspaceLastSearchedIdentitiesKey?this._workspaceSearchInFlightPromise||Promise.resolve():(this.userIdentifiedInWorkspace=!1,this._workspaceLastSearchedIdentitiesKey=c,new Promise(u=>{try{i(t,a,d=>{d?.httpCode===200&&(this.userIdentifiedInWorkspace=!0),u()})}catch(d){console.error("Rokt Kit: Workspace IDSync search failed",d),this._workspaceLastSearchedIdentitiesKey=void 0,u()}}))}onLoginComplete(e,t){return this.handleIdentityComplete(e,k.LOGIN,"onLoginComplete")}onLogoutComplete(e,t){return this.userIdentifiedInWorkspace=!1,this._workspaceSearchInFlightPromise=null,this._workspaceLastSearchedIdentitiesKey=void 0,this.handleIdentityComplete(e,k.LOGOUT,"onLogoutComplete")}onModifyComplete(e,t){return this.handleIdentityComplete(e,k.MODIFY_USER,"onModifyComplete")}selectPlacements(e){if(this._workspaceSearchInFlightPromise){const t=this._workspaceSearchInFlightPromise;return Promise.race([t,new Promise(i=>setTimeout(i,$))]).then(()=>this._dispatchPlacements(e))}return this._dispatchPlacements(e)}_dispatchPlacements(e){const t=e&&e.attributes||{},i={...this.userAttributes,...t},r=this.filters||{},a=r.userAttributeFilters||[],s=r.filteredUser||null,c=s?s.getMPID():null;let u;r?r.filterUserAttributes?u=r.filterUserAttributes(i,a):u=i:(console.warn("Rokt Kit: No filters available, using user attributes"),u=i),this.userAttributes=u;const d=this._onboardingExpProvider==="Optimizely"?this.fetchOptimizely():{},E=this.returnUserIdentities(s),N=this.returnLocalSessionAttributes(),_={...E,...u,...d,...N,...this.userIdentifiedInWorkspace?{[X]:!0}:{},mpid:c},P={...e,attributes:_},p=this.launcher.selectPlacements(P),w=()=>this.logSelectPlacementsEvent(_);return Promise.resolve(p).then(y=>y?.context?.sessionId?.then(A=>this.setRoktSessionId(A))).catch(()=>{}).finally(w),p}hashAttributes(e){return this.isKitReady()?this.launcher.hashAttributes(e):(console.error("Rokt Kit: Not initialized"),null)}use(e){return this.isKitReady()?!e||!g(e)?Promise.reject(new Error("Rokt Kit: Invalid extension name")):this.launcher.use(e):(console.error("Rokt Kit: Not initialized"),Promise.reject(new Error("Rokt Kit: Not initialized")))}onShoppableAdsReady(e){this._isThankYouElementLoaded?e():this._thankYouElementOnLoadCallback=e}};h._allowedOriginHashes=[-553112570,549508659],h.PERFORMANCE_MARKS={RoktScriptAppended:"mp:RoktScriptAppended"},h.EMAIL_SHA256_KEY="emailsha256";let f=h;function ae(){return 181}function ce(n){if(!n){window.console.log("You must pass a config object to register the kit "+l);return}if(!L(n)){window.console.log("'config' must be an object. You passed in a "+typeof n);return}L(n.kits)?n.kits[l]={constructor:f}:(n.kits={},n.kits[l]={constructor:f}),window.console.log("Successfully registered "+l+" to your mParticle configuration")}return typeof window<"u"&&window.mParticle&&o().addForwarder&&o().addForwarder({name:l,constructor:f,getId:ae}),v.register=ce,Object.defineProperty(v,Symbol.toStringTag,{value:"Module"}),v})({});
|
|
1
|
+
var RoktKit=(function(O){"use strict";const q=["billingaddress1","billingaddress2","billingcity","billingstate","billingzipcode","cartitems","ccbin","confirmationref","conversiontype","country","couponcode","currency","language","paymentserviceprovider","paymentserviceproviderattribute","paymenttype","shippingaddress1","shippingcity","shippingcountry","shippingmethod","shippingstate","shippingzipcode","totalprice"],J=new Set(q);function M(n){return J.has(n.toLowerCase())}function k(n){const e={},t=n||{},i=Object.keys(t);for(let r=0;r<i.length;r++){const s=i[r];M(s)||(e[s]=t[s])}return e}const d="Rokt",R=181,X="selectPlacements",$="apps.roktecommerce.com",Z=.1,S={LOGIN:"login",LOGOUT:"logout",MODIFY_USER:"modify_user",IDENTIFY:"identify"},ee="ThankYouPageJourney",te="rokt-launcher",ie="rokt-thank-you-element",ne="userIdentifiedInWorkspace",re=500,N={UNKNOWN_ERROR:"UNKNOWN_ERROR",UNHANDLED_EXCEPTION:"UNHANDLED_EXCEPTION",IDENTITY_REQUEST:"IDENTITY_REQUEST"},v={ERROR:"ERROR",INFO:"INFO",WARNING:"WARNING"},se="apps.rokt-api.com/v1/log",oe="apps.rokt-api.com/v1/errors",ae=10;function a(){return window.mParticle}function K(n,e){const i=[Y(n),"/wsdk/integrations/launcher.js"].join("");return!e||e.length===0?i:i+"?extensions="+e.join(",")}function D(n){return[Y(n),"/rokt-elements/rokt-element-thank-you.js"].join("")}function Y(n){return["https://",typeof n<"u"?n:"apps.rokt-api.com"].join("")}function x(n,e,t){if(document.getElementById(n))return;const i=document.head||document.body,r=document.createElement("script");r.id=n,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),i.appendChild(r)}function A(n){return n!=null&&typeof n=="object"&&Array.isArray(n)===!1}function w(n){if(!n)return[];try{return JSON.parse(n.replace(/"/g,'"'))}catch{console.error("Settings string contains invalid JSON")}return[]}function F(n){const e=n?w(n):[],t=[],i=[];let r=!1;for(let s=0;s<e.length;s++){const o=e[s].value;o==="thank-you-journey"?(r=!0,i.push(ee)):t.push(o)}return{roktExtensionsQueryParams:t,legacyRoktExtensions:i,loadThankYouElement:r}}async function ce(n,e){const t=[];if(e)for(const i of n)t.push(e.use(i));return Promise.all(t)}function j(n){if(!n)return{};const e={};for(let t=0;t<n.length;t++){const i=n[t];e[i.jsmap]=i.value}return e}function H(n){const e={};if(!Array.isArray(n))return e;for(let t=0;t<n.length;t++){const i=n[t];if(!i||!p(i.value)||!p(i.map))continue;const r=i.value,s=i.map;e[r]||(e[r]=[]),e[r].push({eventAttributeKey:s,conditions:Array.isArray(i.conditions)?i.conditions:[]})}return e}function G(n,e,t){return a().generateHash([n,e,t].join(""))}function E(n){return n==null?!0:typeof n=="object"?Object.keys(n).length===0:Array.isArray(n)?n.length===0:!1}function p(n){return typeof n=="string"}function ue(n){let i="mParticle_wsdkv_"+a().getVersion()+"_kitv_"+"1.27.0";return n&&(i+="_"+n),i}function z(n){let e=5381;for(let t=0;t<n.length;t++)e=(e<<5)+e+n.charCodeAt(t),e=e&e;return e}function P(n){const e=document.createElement("iframe");e.style.display="none",e.setAttribute("sandbox","allow-scripts allow-same-origin"),e.src=n,e.onload=function(){e.onload=null,e.parentNode&&e.parentNode.removeChild(e)};const t=document.body||document.head;t&&t.appendChild(e)}function W(n,e){const t=z(window.location.origin);if(m._allowedOriginHashes.indexOf(t)===-1||Math.random()>=Z)return;const r=window.__rokt_li_guid__;if(!r)return;const s=window.location.href.split("?")[0].split("#")[0],o="version="+encodeURIComponent(e??"")+"&launcherInstanceGuid="+encodeURIComponent(r)+"&pageUrl="+encodeURIComponent(s);P("https://"+(n||"apps.rokt.com")+"/v1/wsdk-init/index.html?"+o),P("https://"+$+"/v1/wsdk-init/index.html?"+o+"&isControl=true")}function le(){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 he(){return typeof window<"u"?window.navigator?.userAgent:void 0}class Q{constructor(){this._logCount={}}incrementAndCheck(e){const i=(this._logCount[e]||0)+1;return this._logCount[e]=i,i>ae}}class U{constructor(e,t,i,r,s){this._reporter="mp-wsdk";const o=e.isLoggingEnabled;this._integrationName=t||"",this._launcherInstanceGuid=i,this._accountId=r||null,this._rateLimiter=s||new Q,this._isEnabled=le()||o}send(e,t,i,r,s,o){if(!(!this._isEnabled||this._rateLimiter.incrementAndCheck(t)))try{const c={additionalInformation:{message:i,version:this._integrationName},severity:t,code:r||N.UNKNOWN_ERROR,url:de(),deviceInfo:he(),stackTrace:s,reporter:this._reporter,integration:this._integrationName},l={Accept:"text/plain;charset=UTF-8","Content-Type":"application/json","rokt-launcher-version":this._integrationName,"rokt-wsdk-version":"joint"};this._launcherInstanceGuid&&(l["rokt-launcher-instance-guid"]=this._launcherInstanceGuid),this._accountId&&(l["rokt-account-id"]=this._accountId),fetch(e,{method:"POST",headers:l,body:JSON.stringify(c)}).catch(u=>{console.error("ReportingTransport: Failed to send log",u),o&&o(u)})}catch(c){console.error("ReportingTransport: Failed to send log",c),o&&o(c)}}}class B{constructor(e,t,i,r,s){this._transport=new U(e,t,i,r,s),this._errorUrl="https://"+(e?.errorUrl||oe)}report(e){if(!e)return;const t=e.severity||v.ERROR;this._transport.send(this._errorUrl,t,e.message,e.code,e.stackTrace)}}class V{constructor(e,t,i,r,s,o){this._transport=new U(e,i,r,s,o),this._loggingUrl="https://"+(e?.loggingUrl||se),this._errorReportingService=t}log(e){e&&this._transport.send(this._loggingUrl,v.INFO,e.message,e.code,void 0,t=>{this._errorReportingService&&this._errorReportingService.report({message:"LoggingService: Failed to send log: "+t.message,code:N.UNKNOWN_ERROR,severity:v.ERROR})})}}const h=class h{constructor(){this.name=d,this.id=R,this.moduleId=R,this.isInitialized=!1,this.launcher=null,this.filters={},this.userAttributes={},this.userIdentifiedInWorkspace=!1,this.testHelpers=null,this.placementEventMappingLookup={},this.placementEventAttributeMappingLookup={},this.batchQueue=[],this.batchStreamQueue=[],this.pendingIdentityEvents=[],this.integrationName=null,this.errorReportingService=null,this.loggingService=null,this._thankYouElementOnLoadCallback=null,this._isThankYouElementLoaded=!1,this._workspaceSearchInFlightPromise=null}getEventAttributeValue(e,t){const i=e&&e.EventAttributes;return!i||typeof i[t]>"u"?null:i[t]}doesEventAttributeConditionMatch(e,t){if(!e||!p(e.operator))return!1;const i=e.operator.toLowerCase(),r=e.attributeValue;return i==="exists"?t!==null:t==null?!1:i==="equals"?String(t)===String(r):i==="contains"?String(t).indexOf(String(r))!==-1:!1}doesEventMatchRule(e,t){if(!t||!p(t.eventAttributeKey))return!1;const i=t.conditions;if(!Array.isArray(i))return!1;const r=this.getEventAttributeValue(e,t.eventAttributeKey);if(i.length===0)return r!==null;for(let s=0;s<i.length;s++)if(!this.doesEventAttributeConditionMatch(i[s],r))return!1;return!0}applyPlacementEventAttributeMapping(e){const t=Object.keys(this.placementEventAttributeMappingLookup);for(let i=0;i<t.length;i++){const r=t[i],s=this.placementEventAttributeMappingLookup[r];if(E(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)}}isLauncherReadyToAttach(){return!!window.Rokt&&typeof window.Rokt.createLauncher=="function"}returnUserIdentities(e){if(!e||!e.getUserIdentities)return{};const t=e.getUserIdentities().userIdentities;return this.replaceOtherIdentityWithEmailsha256(t)}returnLocalSessionAttributes(){return!a().Rokt||typeof a().Rokt.getLocalSessionAttributes!="function"?{}:E(this.placementEventMappingLookup)&&E(this.placementEventAttributeMappingLookup)?{}:a().Rokt.getLocalSessionAttributes()}replaceOtherIdentityWithEmailsha256(e){const t={...e||{}},i=this._mappedEmailSha256Key;return i&&e[i]&&(t[h.EMAIL_SHA256_KEY]=e[i]),i&&delete t[i],t}logSelectPlacementsEvent(e){if(!window.mParticle||typeof a().logEvent!="function"||!A(e))return;const t=a().EventType.Other;a().logEvent(X,t,e)}buildIdentityEvent(e,t){const i=t.getMPID(),r=a()&&a().sessionManager&&typeof a().sessionManager.getSession=="function"?a().sessionManager.getSession():void 0;return{event_type:e,data:{timestamp_unixtime_ms:Date.now(),session_uuid:r??void 0,mpid:i}}}mergePendingIdentityEvents(e){if(this.pendingIdentityEvents.length===0)return e;const t={...e,events:[...e.events??[],...this.pendingIdentityEvents]};return this.pendingIdentityEvents=[],t}drainBatchQueue(){this.batchQueue.forEach(e=>{this.processBatch(e)}),this.batchQueue=[]}processBatch(e){if(!this.isKitReady())return this.batchQueue.push(e),"Batch queued for forwarder: "+d;const t=this.enrichCommerceEventTypes(this.mergePendingIdentityEvents(e));return this.sendBatchStream(t),"Successfully sent batch to forwarder: "+d}enrichCommerceEventTypes(e){if(!e.events)return e;for(const t of e.events){if(t.event_type!=="commerce_event")continue;const{data:i}=t;if(!i)continue;const r=i.custom_flags?.["Rokt.CommerceEventType"];r&&A(i.product_action)&&(i.product_action.action=r)}return e}sendBatchStream(e){if(window.Rokt&&typeof window.Rokt.__batch_stream__=="function"){if(this.batchStreamQueue.length){const t=this.batchStreamQueue;this.batchStreamQueue=[];for(let i=0;i<t.length;i++)window.Rokt.__batch_stream__(t[i])}window.Rokt.__batch_stream__(e)}else this.batchStreamQueue.push(e)}setRoktSessionId(e){if(!(!e||typeof e!="string"))try{const t=a().getInstance();t&&typeof t.setIntegrationAttribute=="function"&&t.setIntegrationAttribute(R,{roktSessionId:e})}catch{}}attachLauncher(e,t,i=[]){const r=a()&&a().sessionManager&&typeof a().sessionManager.getSession=="function"?a().sessionManager.getSession():void 0,s={accountId:e,...t||{},...r?{mpSessionId:r}:{}};let o;this.isPartnerInLocalLauncherTestGroup()?o=Promise.resolve(window.Rokt.createLocalLauncher(s)):o=window.Rokt.createLauncher(s),o.then(async c=>{await ce(i,c),this.initRoktLauncher(c)}).catch(c=>{console.error("Error creating Rokt launcher:",c)})}initRoktLauncher(e){window.Rokt&&(window.Rokt.currentLauncher=e),this.launcher=e;const t=a().Rokt?.filters;t?(this.filters=t,t.filteredUser?this._workspaceSearchInFlightPromise=this.search(t.filteredUser):console.warn("Rokt Kit: No filtered user has been set.")):console.warn("Rokt Kit: No filters have been set."),this.isInitialized=!0,W(this.domain,this.integrationName),a().Rokt.attachKit(this),this.drainBatchQueue()}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)}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,i,r,s){const o=e,c=o.accountId;this.userAttributes=k(s),this._onboardingExpProvider=o.onboardingExpProvider;const l=w(o.placementEventMapping);this.placementEventMappingLookup=j(l);const u=w(o.placementEventAttributeMapping);this.placementEventAttributeMappingLookup=H(u),o.hashedEmailUserIdentityType&&(this._mappedEmailSha256Key=o.hashedEmailUserIdentityType.toLowerCase()),this._workspaceIdSyncApiKey=p(o.workspaceIdSyncApiKey)?o.workspaceIdSyncApiKey:void 0;const _=a().Rokt?.domain,{roktExtensionsQueryParams:C,legacyRoktExtensions:b,loadThankYouElement:L}=F(o.roktExtensions),g={...a().Rokt?.launcherOptions||{}};this.integrationName=ue(g.integrationName),g.integrationName=this.integrationName,this.domain=_;const y={loggingUrl:o.loggingUrl,errorUrl:o.errorUrl,isLoggingEnabled:a().config?.isLoggingEnabled===!0},I=new B(y,this.integrationName,window.__rokt_li_guid__,o.accountId),T=new V(y,I,this.integrationName,window.__rokt_li_guid__,o.accountId);return this.errorReportingService=I,this.loggingService=T,a()._registerErrorReportingService&&a()._registerErrorReportingService(I),a()._registerLoggingService&&a()._registerLoggingService(T),i?(this.testHelpers={generateLauncherScript:K,generateThankYouElementScript:D,extractRoktExtensionConfig:F,hashEventMessage:G,parseSettingsString:w,generateMappedEventLookup:j,generateMappedEventAttributeLookup:H,sendAdBlockMeasurementSignals:W,createAutoRemovedIframe:P,djb2:z,setAllowedOriginHashes:f=>{h._allowedOriginHashes=f},ReportingTransport:U,ErrorReportingService:B,LoggingService:V,RateLimiter:Q,ErrorCodes:N,WSDKErrorSeverity:v},this.attachLauncher(c,g),"Successfully initialized: "+d):(L&&(a().Rokt.flushOnShoppableAdsReadyMessageQueue?.(this),x(ie,D(_),{onLoad:()=>{this._isThankYouElementLoaded=!0,this._thankYouElementOnLoadCallback&&this._thankYouElementOnLoadCallback()},onError:f=>{console.error("Error loading Rokt Thank You Element script:",f)}})),this.isLauncherReadyToAttach()?this.attachLauncher(c,g,b):(x(te,K(_,C),{onLoad:()=>{this.isLauncherReadyToAttach()?this.attachLauncher(c,g,b):console.error("Rokt object is not available after script load.")},onError:f=>{console.error("Error loading Rokt launcher script:",f)}}),this.captureTiming(h.PERFORMANCE_MARKS.RoktScriptAppended)),"Successfully initialized: "+d)}process(e){if(!this.isKitReady())return"Kit not ready for forwarder: "+d;if(typeof a().Rokt?.setLocalSessionAttribute=="function"&&(E(this.placementEventAttributeMappingLookup)||this.applyPlacementEventAttributeMapping(e),!E(this.placementEventMappingLookup))){const t=G(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 M(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,i){const r=e;return this.userAttributes=k(e.getAllUserAttributes()),this.pendingIdentityEvents.push(this.buildIdentityEvent(t,r)),"Successfully called "+i+" for forwarder: "+d}onUserIdentified(e){const t=e;return this.filters.filteredUser=t,this._workspaceSearchInFlightPromise=this.search(t),this.handleIdentityComplete(e,S.IDENTIFY,"onUserIdentified")}search(e){const t=this._workspaceIdSyncApiKey;if(!t)return this.userIdentifiedInWorkspace=!1,this._workspaceLastSearchedIdentitiesKey=void 0,Promise.resolve();const i=a().Identity?.search;if(typeof i!="function")return this.userIdentifiedInWorkspace=!1,this._workspaceLastSearchedIdentitiesKey=void 0,Promise.resolve();const r=e.getUserIdentities?e.getUserIdentities().userIdentities:null,s={};if(r)for(const l of Object.keys(r)){const u=r[l];p(u)&&u.length>0&&(s[l]=u)}const o=Object.keys(s);if(o.length===0)return this.userIdentifiedInWorkspace=!1,this._workspaceLastSearchedIdentitiesKey=void 0,Promise.resolve();const c=o.sort().map(l=>`${l}=${s[l]}`).join("&");return c===this._workspaceLastSearchedIdentitiesKey?this._workspaceSearchInFlightPromise||Promise.resolve():(this.userIdentifiedInWorkspace=!1,this._workspaceLastSearchedIdentitiesKey=c,new Promise(l=>{try{i(t,s,u=>{u?.httpCode===200&&(this.userIdentifiedInWorkspace=!0),l()})}catch(u){console.error("Rokt Kit: Workspace IDSync search failed",u),this._workspaceLastSearchedIdentitiesKey=void 0,l()}}))}onLoginComplete(e,t){return this.handleIdentityComplete(e,S.LOGIN,"onLoginComplete")}onLogoutComplete(e,t){return this.userIdentifiedInWorkspace=!1,this._workspaceSearchInFlightPromise=null,this._workspaceLastSearchedIdentitiesKey=void 0,this.handleIdentityComplete(e,S.LOGOUT,"onLogoutComplete")}onModifyComplete(e,t){return this.handleIdentityComplete(e,S.MODIFY_USER,"onModifyComplete")}selectPlacements(e){if(this._workspaceSearchInFlightPromise){const t=this._workspaceSearchInFlightPromise;return Promise.race([t,new Promise(i=>setTimeout(i,re))]).then(()=>this._dispatchPlacements(e))}return this._dispatchPlacements(e)}_dispatchPlacements(e){const t=e&&e.attributes||{},r={...k(this.userAttributes),...t},s=this.filters||{},o=s.userAttributeFilters||[],c=s.filteredUser||null,l=c?c.getMPID():null;let u;s?s.filterUserAttributes?u=s.filterUserAttributes(r,o):u=r:(console.warn("Rokt Kit: No filters available, using user attributes"),u=r),this.userAttributes=k(u);const _=this._onboardingExpProvider==="Optimizely"?this.fetchOptimizely():{},C=this.returnUserIdentities(c),b=this.returnLocalSessionAttributes(),L={...C,...u,..._,...b,...this.userIdentifiedInWorkspace?{[ne]:!0}:{},mpid:l},g={...e,attributes:L},y=this.launcher.selectPlacements(g),I=()=>this.logSelectPlacementsEvent(L);return Promise.resolve(y).then(T=>T?.context?.sessionId?.then(f=>this.setRoktSessionId(f))).catch(()=>{}).finally(I),y}hashAttributes(e){return this.isKitReady()?this.launcher.hashAttributes(e):(console.error("Rokt Kit: Not initialized"),null)}use(e){return this.isKitReady()?!e||!p(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}};h._allowedOriginHashes=[-553112570,549508659],h.PERFORMANCE_MARKS={RoktScriptAppended:"mp:RoktScriptAppended"},h.EMAIL_SHA256_KEY="emailsha256";let m=h;function pe(){return R}function ge(n){if(!n){window.console.log("You must pass a config object to register the kit "+d);return}if(!A(n)){window.console.log("'config' must be an object. You passed in a "+typeof n);return}A(n.kits)?n.kits[d]={constructor:m}:(n.kits={},n.kits[d]={constructor:m}),window.console.log("Successfully registered "+d+" to your mParticle configuration")}return typeof window<"u"&&window.mParticle&&a().addForwarder&&a().addForwarder({name:d,constructor:m,getId:pe}),O.register=ge,Object.defineProperty(O,Symbol.toStringTag,{value:"Module"}),O})({});
|
|
2
2
|
//# sourceMappingURL=Rokt-Kit.iife.js.map
|