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