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