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