@mparticle/web-rokt-kit 1.23.0 → 1.24.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const g="Rokt",I=181,F="selectPlacements",G="apps.roktecommerce.com",z=.1,Q=14,N={UNKNOWN_ERROR:"UNKNOWN_ERROR",UNHANDLED_EXCEPTION:"UNHANDLED_EXCEPTION",IDENTITY_REQUEST:"IDENTITY_REQUEST"},w={ERROR:"ERROR",INFO:"INFO",WARNING:"WARNING"},V="apps.rokt-api.com/v1/log",W="apps.rokt-api.com/v1/errors",Y=10;function s(){return window.mParticle}function M(n,t){const o=["https://",typeof n<"u"?n:"apps.rokt.com","/wsdk/integrations/launcher.js"].join("");return!t||t.length===0?o:o+"?extensions="+t.join(",")}function S(n){return n!=null&&typeof n=="object"&&Array.isArray(n)===!1}function y(n){if(!n)return[];try{return JSON.parse(n.replace(/&quot;/g,'"'))}catch{console.error("Settings string contains invalid JSON")}return[]}function T(n){const t=n?y(n):[],e=[];for(let i=0;i<t.length;i++)e.push(t[i].value);return e}function U(n){if(!n)return{};const t={};for(let e=0;e<n.length;e++){const i=n[e];t[i.jsmap]=i.value}return t}function P(n){const t={};if(!Array.isArray(n))return t;for(let e=0;e<n.length;e++){const i=n[e];if(!i||!R(i.value)||!R(i.map))continue;const r=i.value,o=i.map;t[r]||(t[r]=[]),t[r].push({eventAttributeKey:o,conditions:Array.isArray(i.conditions)?i.conditions:[]})}return t}function C(n,t,e){return s().generateHash([n,t,e].join(""))}function A(n){return n==null?!0:typeof n=="object"?Object.keys(n).length===0:Array.isArray(n)?n.length===0:!1}function R(n){return typeof n=="string"}function q(n){let i="mParticle_wsdkv_"+s().getVersion()+"_kitv_"+"1.23.0";return n&&(i+="_"+n),i}function j(n){let t=5381;for(let e=0;e<n.length;e++)t=(t<<5)+t+n.charCodeAt(e),t=t&t;return t}function L(n){const t=document.createElement("iframe");t.style.display="none",t.setAttribute("sandbox","allow-scripts allow-same-origin"),t.src=n,t.onload=function(){t.onload=null,t.parentNode&&t.parentNode.removeChild(t)};const e=document.body||document.head;e&&e.appendChild(t)}function D(n,t){const e=j(window.location.origin);if(f._allowedOriginHashes.indexOf(e)===-1||Math.random()>=z)return;const r=window.__rokt_li_guid__;if(!r)return;const o=window.location.href.split("?")[0].split("#")[0],a="version="+encodeURIComponent(t??"")+"&launcherInstanceGuid="+encodeURIComponent(r)+"&pageUrl="+encodeURIComponent(o);L("https://"+(n||"apps.rokt.com")+"/v1/wsdk-init/index.html?"+a),L("https://"+G+"/v1/wsdk-init/index.html?"+a+"&isControl=true")}function B(){return typeof window<"u"&&!!window.ROKT_DOMAIN}function J(){return typeof window<"u"&&!!window.location?.search?.toLowerCase().includes("mp_enable_logging=true")}function X(){return typeof window<"u"?window.location?.href:void 0}function Z(){return typeof window<"u"?window.navigator?.userAgent:void 0}class H{constructor(){this._logCount={}}incrementAndCheck(t){const i=(this._logCount[t]||0)+1;return this._logCount[t]=i,i>Y}}class O{constructor(t,e,i,r,o){this._reporter="mp-wsdk";const a=t?.isLoggingEnabled===!0||t?.isLoggingEnabled==="true";this._integrationName=e||"",this._launcherInstanceGuid=i,this._accountId=r||null,this._rateLimiter=o||new H,this._isEnabled=J()||B()&&a}send(t,e,i,r,o,a){if(!(!this._isEnabled||this._rateLimiter.incrementAndCheck(e)))try{const c={additionalInformation:{message:i,version:this._integrationName},severity:e,code:r||N.UNKNOWN_ERROR,url:X(),deviceInfo:Z(),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(t,{method:"POST",headers:u,body:JSON.stringify(c)}).catch(p=>{console.error("ReportingTransport: Failed to send log",p),a&&a(p)})}catch(c){console.error("ReportingTransport: Failed to send log",c),a&&a(c)}}}class K{constructor(t,e,i,r,o){this._transport=new O(t,e,i,r,o),this._errorUrl="https://"+(t?.errorUrl||W)}report(t){if(!t)return;const e=t.severity||w.ERROR;this._transport.send(this._errorUrl,e,t.message,t.code,t.stackTrace)}}class x{constructor(t,e,i,r,o,a){this._transport=new O(t,i,r,o,a),this._loggingUrl="https://"+(t?.loggingUrl||V),this._errorReportingService=e}log(t){t&&this._transport.send(this._loggingUrl,w.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:w.ERROR})})}}const h=class h{constructor(){this.name=g,this.moduleId=I,this.isInitialized=!1,this.launcher=null,this.filters={},this.userAttributes={},this.testHelpers=null,this.placementEventMappingLookup={},this.placementEventAttributeMappingLookup={},this.eventQueue=[],this.eventStreamQueue=[],this.integrationName=null,this.errorReportingService=null,this.loggingService=null}getEventAttributeValue(t,e){const i=t&&t.EventAttributes;return!i||typeof i[e]>"u"?null:i[e]}doesEventAttributeConditionMatch(t,e){if(!t||!R(t.operator))return!1;const i=t.operator.toLowerCase(),r=t.attributeValue;return i==="exists"?e!==null:e==null?!1:i==="equals"?String(e)===String(r):i==="contains"?String(e).indexOf(String(r))!==-1:!1}doesEventMatchRule(t,e){if(!e||!R(e.eventAttributeKey))return!1;const i=e.conditions;if(!Array.isArray(i))return!1;const r=this.getEventAttributeValue(t,e.eventAttributeKey);if(i.length===0)return r!==null;for(let o=0;o<i.length;o++)if(!this.doesEventAttributeConditionMatch(i[o],r))return!1;return!0}applyPlacementEventAttributeMapping(t){const e=Object.keys(this.placementEventAttributeMappingLookup);for(let i=0;i<e.length;i++){const r=e[i],o=this.placementEventAttributeMappingLookup[r];if(A(o))continue;let a=!0;for(let c=0;c<o.length;c++)if(!this.doesEventMatchRule(t,o[c])){a=!1;break}a&&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"?{}:A(this.placementEventMappingLookup)&&A(this.placementEventAttributeMappingLookup)?{}:s().Rokt.getLocalSessionAttributes()}replaceOtherIdentityWithEmailsha256(t){const e={...t||{}},i=this._mappedEmailSha256Key;return i&&t[i]&&(e[h.EMAIL_SHA256_KEY]=t[i]),i&&delete e[i],e}logSelectPlacementsEvent(t){if(!window.mParticle||typeof s().logEvent!="function"||!S(t))return;const e=s().EventType.Other;s().logEvent(F,e,t)}processEventQueue(){this.eventQueue.forEach(t=>{this.process(t)}),this.eventQueue=[]}enrichEvent(t){return{...t,UserAttributes:this.userAttributes}}sendEventStream(t){if(window.Rokt&&typeof window.Rokt.__event_stream__=="function"){if(this.eventStreamQueue.length){const e=this.eventStreamQueue;this.eventStreamQueue=[];for(let i=0;i<e.length;i++)window.Rokt.__event_stream__(this.enrichEvent(e[i]))}window.Rokt.__event_stream__(this.enrichEvent(t))}else this.eventStreamQueue.push(t)}setRoktSessionId(t){if(!(!t||typeof t!="string"))try{const e=s().getInstance();e&&typeof e.setIntegrationAttribute=="function"&&e.setIntegrationAttribute(I,{roktSessionId:t})}catch{}}buildIdentityEvent(t,e){const i=e.getMPID&&typeof e.getMPID=="function"?e.getMPID():null,r=s()&&s().sessionManager&&typeof s().sessionManager.getSession=="function"?s().sessionManager.getSession():null,o=e.getUserIdentities&&typeof e.getUserIdentities=="function"?e.getUserIdentities().userIdentities:null;return{EventName:t,EventDataType:Q,EventCategory:0,Timestamp:Date.now(),MPID:i,SessionId:r,UserIdentities:o}}attachLauncher(t,e){const i=s()&&s().sessionManager&&typeof s().sessionManager.getSession=="function"?s().sessionManager.getSession():void 0,r={accountId:t,...e||{},...i?{mpSessionId:i}:{}};if(this.isPartnerInLocalLauncherTestGroup()){const o=window.Rokt.createLocalLauncher(r);this.initRoktLauncher(o)}else window.Rokt.createLauncher(r).then(o=>this.initRoktLauncher(o)).catch(o=>{console.error("Error creating Rokt launcher:",o)})}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,D(this.domain,this.integrationName),s().Rokt.attachKit(this),this.processEventQueue()}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((o,a)=>(o["rokt.custom.optimizely.experiment."+a+".variationId"]=e.getVariationMap()[a].id,o),{})}}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,i,r,o){const a=t.accountId,c=T(t.roktExtensions);this.userAttributes=o||{},this._onboardingExpProvider=t.onboardingExpProvider;const u=y(t.placementEventMapping);this.placementEventMappingLookup=U(u);const p=y(t.placementEventAttributeMapping);this.placementEventAttributeMappingLookup=P(p),t.hashedEmailUserIdentityType&&(this._mappedEmailSha256Key=t.hashedEmailUserIdentityType.toLowerCase());const b=s().Rokt?.domain,d={...s().Rokt?.launcherOptions||{}};this.integrationName=q(d.integrationName),d.integrationName=this.integrationName,this.domain=b;const m={loggingUrl:t.loggingUrl,errorUrl:t.errorUrl,isLoggingEnabled:t.isLoggingEnabled==="true"||t.isLoggingEnabled===!0},E=new K(m,this.integrationName,window.__rokt_li_guid__,t.accountId),_=new x(m,E,this.integrationName,window.__rokt_li_guid__,t.accountId);if(this.errorReportingService=E,this.loggingService=_,s()._registerErrorReportingService&&s()._registerErrorReportingService(E),s()._registerLoggingService&&s()._registerLoggingService(_),i){this.testHelpers={generateLauncherScript:M,extractRoktExtensions:T,hashEventMessage:C,parseSettingsString:y,generateMappedEventLookup:U,generateMappedEventAttributeLookup:P,sendAdBlockMeasurementSignals:D,createAutoRemovedIframe:L,djb2:j,setAllowedOriginHashes:v=>{h._allowedOriginHashes=v},ReportingTransport:O,ErrorReportingService:K,LoggingService:x,RateLimiter:H,ErrorCodes:N,WSDKErrorSeverity:w},this.attachLauncher(a,d);return}if(this.isLauncherReadyToAttach())this.attachLauncher(a,d);else{const v=document.head||document.body,l=document.createElement("script");l.type="text/javascript",l.src=M(b,c),l.async=!0,l.crossOrigin="anonymous",l.fetchPriority="high",l.id="rokt-launcher",l.onload=()=>{this.isLauncherReadyToAttach()?this.attachLauncher(a,d):console.error("Rokt object is not available after script load.")},l.onerror=k=>{console.error("Error loading Rokt launcher script:",k)},v.appendChild(l),this.captureTiming(h.PERFORMANCE_MARKS.RoktScriptAppended)}}process(t){if(!this.isKitReady()){this.eventQueue.push(t);return}if(this.sendEventStream(t),typeof s().Rokt?.setLocalSessionAttribute!="function"||(A(this.placementEventAttributeMappingLookup)||this.applyPlacementEventAttributeMapping(t),A(this.placementEventMappingLookup)))return;const e=C(t.EventDataType,t.EventCategory,t.EventName??"");if(this.placementEventMappingLookup[String(e)]){const i=this.placementEventMappingLookup[String(e)];s().Rokt.setLocalSessionAttribute?.(i,!0)}}setExtensionData(t){if(!this.isKitReady()){console.error("Rokt Kit: Not initialized");return}window.Rokt.setExtensionData(t)}setUserAttribute(t,e){this.userAttributes[t]=e,this.sendEventStream(this.buildIdentityEvent("set_user_attributes",this.filters.filteredUser??{}))}removeUserAttribute(t){delete this.userAttributes[t]}onUserIdentified(t){this.filters.filteredUser=t,this.userAttributes=t.getAllUserAttributes(),this.sendEventStream(this.buildIdentityEvent("identify",t))}onLoginComplete(t){this.userAttributes=t.getAllUserAttributes(),this.sendEventStream(this.buildIdentityEvent("login",t))}onLogoutComplete(t){this.userAttributes=t.getAllUserAttributes(),this.sendEventStream(this.buildIdentityEvent("logout",t))}onModifyComplete(t){this.userAttributes=t.getAllUserAttributes(),this.sendEventStream(this.buildIdentityEvent("modify_user",t))}selectPlacements(t){const e=t&&t.attributes||{},i={...this.userAttributes,...e},r=this.filters||{},o=r.userAttributeFilters||[],a=r.filteredUser||null,c=a&&a.getMPID&&typeof a.getMPID=="function"?a.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 p=this._onboardingExpProvider==="Optimizely"?this.fetchOptimizely():{},b=this.returnUserIdentities(a),d=this.returnLocalSessionAttributes(),m={...b,...u,...p,...d,mpid:c},E={...t,attributes:m},_=this.launcher.selectPlacements(E),v=()=>this.logSelectPlacementsEvent(m);return Promise.resolve(_).then(l=>l?.context?.sessionId?.then(k=>this.setRoktSessionId(k))).catch(()=>{}).finally(v),_}hashAttributes(t){return this.isKitReady()?this.launcher.hashAttributes(t):(console.error("Rokt Kit: Not initialized"),null)}use(t){return this.isKitReady()?!t||!R(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")))}};h._allowedOriginHashes=[-553112570,549508659],h.PERFORMANCE_MARKS={RoktScriptAppended:"mp:RoktScriptAppended"},h.EMAIL_SHA256_KEY="emailsha256";let f=h;function $(){return I}function tt(n){if(!n){window.console.log("You must pass a config object to register the kit "+g);return}if(!S(n)){window.console.log("'config' must be an object. You passed in a "+typeof n);return}S(n.kits)?n.kits[g]={constructor:f}:(n.kits={},n.kits[g]={constructor:f}),window.console.log("Successfully registered "+g+" to your mParticle configuration")}typeof window<"u"&&window.mParticle&&s().addForwarder&&s().addForwarder({name:g,constructor:f,getId:$});exports.register=tt;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c="Rokt",v=181,F="selectPlacements",G="apps.roktecommerce.com",Q=.1,B=14,N={UNKNOWN_ERROR:"UNKNOWN_ERROR",UNHANDLED_EXCEPTION:"UNHANDLED_EXCEPTION",IDENTITY_REQUEST:"IDENTITY_REQUEST"},I={ERROR:"ERROR",INFO:"INFO",WARNING:"WARNING"},V="apps.rokt-api.com/v1/log",W="apps.rokt-api.com/v1/errors",Y=10;function o(){return window.mParticle}function U(n,t){const s=["https://",typeof n<"u"?n:"apps.rokt.com","/wsdk/integrations/launcher.js"].join("");return!t||t.length===0?s:s+"?extensions="+t.join(",")}function k(n){return n!=null&&typeof n=="object"&&Array.isArray(n)===!1}function w(n){if(!n)return[];try{return JSON.parse(n.replace(/&quot;/g,'"'))}catch{console.error("Settings string contains invalid JSON")}return[]}function T(n){const t=n?w(n):[],e=[];for(let i=0;i<t.length;i++)e.push(t[i].value);return e}function M(n){if(!n)return{};const t={};for(let e=0;e<n.length;e++){const i=n[e];t[i.jsmap]=i.value}return t}function P(n){const t={};if(!Array.isArray(n))return t;for(let e=0;e<n.length;e++){const i=n[e];if(!i||!_(i.value)||!_(i.map))continue;const r=i.value,s=i.map;t[r]||(t[r]=[]),t[r].push({eventAttributeKey:s,conditions:Array.isArray(i.conditions)?i.conditions:[]})}return t}function C(n,t,e){return o().generateHash([n,t,e].join(""))}function y(n){return n==null?!0:typeof n=="object"?Object.keys(n).length===0:Array.isArray(n)?n.length===0:!1}function _(n){return typeof n=="string"}function q(n){let i="mParticle_wsdkv_"+o().getVersion()+"_kitv_"+"1.24.0";return n&&(i+="_"+n),i}function j(n){let t=5381;for(let e=0;e<n.length;e++)t=(t<<5)+t+n.charCodeAt(e),t=t&t;return t}function L(n){const t=document.createElement("iframe");t.style.display="none",t.setAttribute("sandbox","allow-scripts allow-same-origin"),t.src=n,t.onload=function(){t.onload=null,t.parentNode&&t.parentNode.removeChild(t)};const e=document.body||document.head;e&&e.appendChild(t)}function K(n,t){const e=j(window.location.origin);if(m._allowedOriginHashes.indexOf(e)===-1||Math.random()>=Q)return;const r=window.__rokt_li_guid__;if(!r)return;const s=window.location.href.split("?")[0].split("#")[0],a="version="+encodeURIComponent(t??"")+"&launcherInstanceGuid="+encodeURIComponent(r)+"&pageUrl="+encodeURIComponent(s);L("https://"+(n||"apps.rokt.com")+"/v1/wsdk-init/index.html?"+a),L("https://"+G+"/v1/wsdk-init/index.html?"+a+"&isControl=true")}function J(){return typeof window<"u"&&!!window.ROKT_DOMAIN}function X(){return typeof window<"u"&&!!window.location?.search?.toLowerCase().includes("mp_enable_logging=true")}function Z(){return typeof window<"u"?window.location?.href:void 0}function $(){return typeof window<"u"?window.navigator?.userAgent:void 0}class H{constructor(){this._logCount={}}incrementAndCheck(t){const i=(this._logCount[t]||0)+1;return this._logCount[t]=i,i>Y}}class O{constructor(t,e,i,r,s){this._reporter="mp-wsdk";const a=t?.isLoggingEnabled===!0||t?.isLoggingEnabled==="true";this._integrationName=e||"",this._launcherInstanceGuid=i,this._accountId=r||null,this._rateLimiter=s||new H,this._isEnabled=X()||J()&&a}send(t,e,i,r,s,a){if(!(!this._isEnabled||this._rateLimiter.incrementAndCheck(e)))try{const u={additionalInformation:{message:i,version:this._integrationName},severity:e,code:r||N.UNKNOWN_ERROR,url:Z(),deviceInfo:$(),stackTrace:s,reporter:this._reporter,integration:this._integrationName},l={Accept:"text/plain;charset=UTF-8","Content-Type":"application/json","rokt-launcher-version":this._integrationName,"rokt-wsdk-version":"joint"};this._launcherInstanceGuid&&(l["rokt-launcher-instance-guid"]=this._launcherInstanceGuid),this._accountId&&(l["rokt-account-id"]=this._accountId),fetch(t,{method:"POST",headers:l,body:JSON.stringify(u)}).catch(g=>{console.error("ReportingTransport: Failed to send log",g),a&&a(g)})}catch(u){console.error("ReportingTransport: Failed to send log",u),a&&a(u)}}}class D{constructor(t,e,i,r,s){this._transport=new O(t,e,i,r,s),this._errorUrl="https://"+(t?.errorUrl||W)}report(t){if(!t)return;const e=t.severity||I.ERROR;this._transport.send(this._errorUrl,e,t.message,t.code,t.stackTrace)}}class x{constructor(t,e,i,r,s,a){this._transport=new O(t,i,r,s,a),this._loggingUrl="https://"+(t?.loggingUrl||V),this._errorReportingService=e}log(t){t&&this._transport.send(this._loggingUrl,I.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:I.ERROR})})}}const p=class p{constructor(){this.name=c,this.id=v,this.moduleId=v,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}getEventAttributeValue(t,e){const i=t&&t.EventAttributes;return!i||typeof i[e]>"u"?null:i[e]}doesEventAttributeConditionMatch(t,e){if(!t||!_(t.operator))return!1;const i=t.operator.toLowerCase(),r=t.attributeValue;return i==="exists"?e!==null:e==null?!1:i==="equals"?String(e)===String(r):i==="contains"?String(e).indexOf(String(r))!==-1:!1}doesEventMatchRule(t,e){if(!e||!_(e.eventAttributeKey))return!1;const i=e.conditions;if(!Array.isArray(i))return!1;const r=this.getEventAttributeValue(t,e.eventAttributeKey);if(i.length===0)return r!==null;for(let s=0;s<i.length;s++)if(!this.doesEventAttributeConditionMatch(i[s],r))return!1;return!0}applyPlacementEventAttributeMapping(t){const e=Object.keys(this.placementEventAttributeMappingLookup);for(let i=0;i<e.length;i++){const r=e[i],s=this.placementEventAttributeMappingLookup[r];if(y(s))continue;let a=!0;for(let u=0;u<s.length;u++)if(!this.doesEventMatchRule(t,s[u])){a=!1;break}a&&o().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!o().Rokt||typeof o().Rokt.getLocalSessionAttributes!="function"?{}:y(this.placementEventMappingLookup)&&y(this.placementEventAttributeMappingLookup)?{}:o().Rokt.getLocalSessionAttributes()}replaceOtherIdentityWithEmailsha256(t){const e={...t||{}},i=this._mappedEmailSha256Key;return i&&t[i]&&(e[p.EMAIL_SHA256_KEY]=t[i]),i&&delete e[i],e}logSelectPlacementsEvent(t){if(!window.mParticle||typeof o().logEvent!="function"||!k(t))return;const e=o().EventType.Other;o().logEvent(F,e,t)}buildIdentityEvent(t,e){const i=e.getMPID(),r=o()&&o().sessionManager&&typeof o().sessionManager.getSession=="function"?o().sessionManager.getSession():null,s=e.getUserIdentities&&typeof e.getUserIdentities=="function"?e.getUserIdentities().userIdentities:null;return{EventName:t,EventDataType:B,EventCategory:0,Timestamp:Date.now(),MPID:i,SessionId:r,UserIdentities:s}}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: "+c):(this.batchQueue.push(t),"Batch queued for forwarder: "+c)}sendBatchStream(t){if(window.Rokt&&typeof window.Rokt.__batch_stream__=="function"){if(this.batchStreamQueue.length){const e=this.batchStreamQueue;this.batchStreamQueue=[];for(let i=0;i<e.length;i++)window.Rokt.__batch_stream__(e[i])}window.Rokt.__batch_stream__(t)}else this.batchStreamQueue.push(t)}setRoktSessionId(t){if(!(!t||typeof t!="string"))try{const e=o().getInstance();e&&typeof e.setIntegrationAttribute=="function"&&e.setIntegrationAttribute(v,{roktSessionId:t})}catch{}}attachLauncher(t,e){const i=o()&&o().sessionManager&&typeof o().sessionManager.getSession=="function"?o().sessionManager.getSession():void 0,r={accountId:t,...e||{},...i?{mpSessionId:i}:{}};if(this.isPartnerInLocalLauncherTestGroup()){const s=window.Rokt.createLocalLauncher(r);this.initRoktLauncher(s)}else window.Rokt.createLauncher(r).then(s=>this.initRoktLauncher(s)).catch(s=>{console.error("Error creating Rokt launcher:",s)})}initRoktLauncher(t){window.Rokt&&(window.Rokt.currentLauncher=t),this.launcher=t;const e=o().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,K(this.domain,this.integrationName),o().Rokt.attachKit(this),this.drainBatchQueue()}fetchOptimizely(){const t=o()._getActiveForwarders().filter(e=>e.name==="Optimizely");try{if(t.length>0&&window.optimizely){const e=window.optimizely.get("state");return!e||!e.getActiveExperimentIds?{}:e.getActiveExperimentIds().reduce((s,a)=>(s["rokt.custom.optimizely.experiment."+a+".variationId"]=e.getVariationMap()[a].id,s),{})}}catch(e){console.error("Error fetching Optimizely attributes:",e)}return{}}isKitReady(){return!!(this.isInitialized&&this.launcher)}isPartnerInLocalLauncherTestGroup(){return!!(o().config&&o().config.isLocalLauncherEnabled&&this.isAssignedToSampleGroup())}isAssignedToSampleGroup(){return Math.random()>.5}captureTiming(t){window&&o()&&o().captureTiming&&t&&o().captureTiming(t)}init(t,e,i,r,s){const a=t,u=a.accountId,l=T(a.roktExtensions);this.userAttributes=s||{},this._onboardingExpProvider=a.onboardingExpProvider;const g=w(a.placementEventMapping);this.placementEventMappingLookup=M(g);const S=w(a.placementEventAttributeMapping);this.placementEventAttributeMappingLookup=P(S),a.hashedEmailUserIdentityType&&(this._mappedEmailSha256Key=a.hashedEmailUserIdentityType.toLowerCase());const R=o().Rokt?.domain,h={...o().Rokt?.launcherOptions||{}};this.integrationName=q(h.integrationName),h.integrationName=this.integrationName,this.domain=R;const A={loggingUrl:a.loggingUrl,errorUrl:a.errorUrl,isLoggingEnabled:a.isLoggingEnabled==="true"||a.isLoggingEnabled===!0},f=new D(A,this.integrationName,window.__rokt_li_guid__,a.accountId),b=new x(A,f,this.integrationName,window.__rokt_li_guid__,a.accountId);if(this.errorReportingService=f,this.loggingService=b,o()._registerErrorReportingService&&o()._registerErrorReportingService(f),o()._registerLoggingService&&o()._registerLoggingService(b),i)return this.testHelpers={generateLauncherScript:U,extractRoktExtensions:T,hashEventMessage:C,parseSettingsString:w,generateMappedEventLookup:M,generateMappedEventAttributeLookup:P,sendAdBlockMeasurementSignals:K,createAutoRemovedIframe:L,djb2:j,setAllowedOriginHashes:E=>{p._allowedOriginHashes=E},ReportingTransport:O,ErrorReportingService:D,LoggingService:x,RateLimiter:H,ErrorCodes:N,WSDKErrorSeverity:I},this.attachLauncher(u,h),"Successfully initialized: "+c;if(this.isLauncherReadyToAttach())this.attachLauncher(u,h);else{const E=document.head||document.body,d=document.createElement("script");d.type="text/javascript",d.src=U(R,l),d.async=!0,d.crossOrigin="anonymous",d.fetchPriority="high",d.id="rokt-launcher",d.onload=()=>{this.isLauncherReadyToAttach()?this.attachLauncher(u,h):console.error("Rokt object is not available after script load.")},d.onerror=z=>{console.error("Error loading Rokt launcher script:",z)},E.appendChild(d),this.captureTiming(p.PERFORMANCE_MARKS.RoktScriptAppended)}return"Successfully initialized: "+c}process(t){if(!this.isKitReady())return"Kit not ready for forwarder: "+c;if(typeof o().Rokt?.setLocalSessionAttribute=="function"&&(y(this.placementEventAttributeMappingLookup)||this.applyPlacementEventAttributeMapping(t),!y(this.placementEventMappingLookup))){const e=C(t.EventDataType,t.EventCategory,t.EventName??"");this.placementEventMappingLookup[String(e)]&&o().Rokt.setLocalSessionAttribute?.(this.placementEventMappingLookup[String(e)],!0)}return"Successfully sent to forwarder: "+c}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: "+c}removeUserAttribute(t){return delete this.userAttributes[t],"Successfully removed user attribute for forwarder: "+c}onUserIdentified(t){const e=t;return this.filters.filteredUser=e,this.userAttributes=t.getAllUserAttributes(),this.pendingIdentityEvents.push(this.buildIdentityEvent("identify",e)),"Successfully called onUserIdentified for forwarder: "+c}onLoginComplete(t,e){const i=t;return this.userAttributes=t.getAllUserAttributes(),this.pendingIdentityEvents.push(this.buildIdentityEvent("login",i)),"Successfully called onLoginComplete for forwarder: "+c}onLogoutComplete(t,e){const i=t;return this.userAttributes=t.getAllUserAttributes(),this.pendingIdentityEvents.push(this.buildIdentityEvent("logout",i)),"Successfully called onLogoutComplete for forwarder: "+c}onModifyComplete(t,e){const i=t;return this.userAttributes=t.getAllUserAttributes(),this.pendingIdentityEvents.push(this.buildIdentityEvent("modify",i)),"Successfully called onModifyComplete for forwarder: "+c}selectPlacements(t){const e=t&&t.attributes||{},i={...this.userAttributes,...e},r=this.filters||{},s=r.userAttributeFilters||[],a=r.filteredUser||null,u=a?a.getMPID():null;let l;r?r.filterUserAttributes?l=r.filterUserAttributes(i,s):l=i:(console.warn("Rokt Kit: No filters available, using user attributes"),l=i),this.userAttributes=l;const g=this._onboardingExpProvider==="Optimizely"?this.fetchOptimizely():{},S=this.returnUserIdentities(a),R=this.returnLocalSessionAttributes(),h={...S,...l,...g,...R,mpid:u},A={...t,attributes:h},f=this.launcher.selectPlacements(A),b=()=>this.logSelectPlacementsEvent(h);return Promise.resolve(f).then(E=>E?.context?.sessionId?.then(d=>this.setRoktSessionId(d))).catch(()=>{}).finally(b),f}hashAttributes(t){return this.isKitReady()?this.launcher.hashAttributes(t):(console.error("Rokt Kit: Not initialized"),null)}use(t){return this.isKitReady()?!t||!_(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")))}};p._allowedOriginHashes=[-553112570,549508659],p.PERFORMANCE_MARKS={RoktScriptAppended:"mp:RoktScriptAppended"},p.EMAIL_SHA256_KEY="emailsha256";let m=p;function tt(){return v}function et(n){if(!n){window.console.log("You must pass a config object to register the kit "+c);return}if(!k(n)){window.console.log("'config' must be an object. You passed in a "+typeof n);return}k(n.kits)?n.kits[c]={constructor:m}:(n.kits={},n.kits[c]={constructor:m}),window.console.log("Successfully registered "+c+" to your mParticle configuration")}typeof window<"u"&&window.mParticle&&o().addForwarder&&o().addForwarder({name:c,constructor:m,getId:tt});exports.register=et;
2
2
  //# sourceMappingURL=Rokt-Kit.common.js.map
@@ -1,25 +1,25 @@
1
- const g = "Rokt";
2
- const H = "selectPlacements", j = "apps.roktecommerce.com";
1
+ const c = "Rokt";
2
+ const j = "selectPlacements", F = "apps.roktecommerce.com";
3
3
  const L = {
4
4
  UNKNOWN_ERROR: "UNKNOWN_ERROR",
5
5
  UNHANDLED_EXCEPTION: "UNHANDLED_EXCEPTION",
6
6
  IDENTITY_REQUEST: "IDENTITY_REQUEST"
7
- }, w = {
7
+ }, v = {
8
8
  ERROR: "ERROR",
9
9
  INFO: "INFO",
10
10
  WARNING: "WARNING"
11
- }, F = "apps.rokt-api.com/v1/log", z = "apps.rokt-api.com/v1/errors", Q = 10;
12
- function s() {
11
+ }, z = "apps.rokt-api.com/v1/log", Q = "apps.rokt-api.com/v1/errors", B = 10;
12
+ function o() {
13
13
  return window.mParticle;
14
14
  }
15
15
  function O(n, t) {
16
- const o = ["https://", typeof n < "u" ? n : "apps.rokt.com", "/wsdk/integrations/launcher.js"].join("");
17
- return !t || t.length === 0 ? o : o + "?extensions=" + t.join(",");
16
+ const s = ["https://", typeof n < "u" ? n : "apps.rokt.com", "/wsdk/integrations/launcher.js"].join("");
17
+ return !t || t.length === 0 ? s : s + "?extensions=" + t.join(",");
18
18
  }
19
- function k(n) {
19
+ function S(n) {
20
20
  return n != null && typeof n == "object" && Array.isArray(n) === !1;
21
21
  }
22
- function y(n) {
22
+ function w(n) {
23
23
  if (!n)
24
24
  return [];
25
25
  try {
@@ -29,8 +29,8 @@ function y(n) {
29
29
  }
30
30
  return [];
31
31
  }
32
- function M(n) {
33
- const t = n ? y(n) : [], e = [];
32
+ function U(n) {
33
+ const t = n ? w(n) : [], e = [];
34
34
  for (let i = 0; i < t.length; i++)
35
35
  e.push(t[i].value);
36
36
  return e;
@@ -45,33 +45,33 @@ function T(n) {
45
45
  }
46
46
  return t;
47
47
  }
48
- function U(n) {
48
+ function M(n) {
49
49
  const t = {};
50
50
  if (!Array.isArray(n))
51
51
  return t;
52
52
  for (let e = 0; e < n.length; e++) {
53
53
  const i = n[e];
54
- if (!i || !v(i.value) || !v(i.map))
54
+ if (!i || !y(i.value) || !y(i.map))
55
55
  continue;
56
- const r = i.value, o = i.map;
56
+ const r = i.value, s = i.map;
57
57
  t[r] || (t[r] = []), t[r].push({
58
- eventAttributeKey: o,
58
+ eventAttributeKey: s,
59
59
  conditions: Array.isArray(i.conditions) ? i.conditions : []
60
60
  });
61
61
  }
62
62
  return t;
63
63
  }
64
64
  function P(n, t, e) {
65
- return s().generateHash([n, t, e].join(""));
65
+ return o().generateHash([n, t, e].join(""));
66
66
  }
67
- function R(n) {
67
+ function _(n) {
68
68
  return n == null ? !0 : typeof n == "object" ? Object.keys(n).length === 0 : Array.isArray(n) ? n.length === 0 : !1;
69
69
  }
70
- function v(n) {
70
+ function y(n) {
71
71
  return typeof n == "string";
72
72
  }
73
73
  function V(n) {
74
- let i = "mParticle_wsdkv_" + s().getVersion() + "_kitv_" + "1.23.0";
74
+ let i = "mParticle_wsdkv_" + o().getVersion() + "_kitv_" + "1.24.0";
75
75
  return n && (i += "_" + n), i;
76
76
  }
77
77
  function x(n) {
@@ -80,7 +80,7 @@ function x(n) {
80
80
  t = (t << 5) + t + n.charCodeAt(e), t = t & t;
81
81
  return t;
82
82
  }
83
- function S(n) {
83
+ function k(n) {
84
84
  const t = document.createElement("iframe");
85
85
  t.style.display = "none", t.setAttribute("sandbox", "allow-scripts allow-same-origin"), t.src = n, t.onload = function() {
86
86
  t.onload = null, t.parentNode && t.parentNode.removeChild(t);
@@ -90,14 +90,14 @@ function S(n) {
90
90
  }
91
91
  function C(n, t) {
92
92
  const e = x(window.location.origin);
93
- if (f._allowedOriginHashes.indexOf(e) === -1 || Math.random() >= 0.1)
93
+ if (m._allowedOriginHashes.indexOf(e) === -1 || Math.random() >= 0.1)
94
94
  return;
95
95
  const r = window.__rokt_li_guid__;
96
96
  if (!r)
97
97
  return;
98
- const o = window.location.href.split("?")[0].split("#")[0], a = "version=" + encodeURIComponent(t ?? "") + "&launcherInstanceGuid=" + encodeURIComponent(r) + "&pageUrl=" + encodeURIComponent(o);
99
- S("https://" + (n || "apps.rokt.com") + "/v1/wsdk-init/index.html?" + a), S(
100
- "https://" + j + "/v1/wsdk-init/index.html?" + a + "&isControl=true"
98
+ const s = window.location.href.split("?")[0].split("#")[0], a = "version=" + encodeURIComponent(t ?? "") + "&launcherInstanceGuid=" + encodeURIComponent(r) + "&pageUrl=" + encodeURIComponent(s);
99
+ k("https://" + (n || "apps.rokt.com") + "/v1/wsdk-init/index.html?" + a), k(
100
+ "https://" + F + "/v1/wsdk-init/index.html?" + a + "&isControl=true"
101
101
  );
102
102
  }
103
103
  function Y() {
@@ -109,7 +109,7 @@ function W() {
109
109
  function q() {
110
110
  return typeof window < "u" ? window.location?.href : void 0;
111
111
  }
112
- function B() {
112
+ function J() {
113
113
  return typeof window < "u" ? window.navigator?.userAgent : void 0;
114
114
  }
115
115
  class G {
@@ -118,19 +118,19 @@ class G {
118
118
  }
119
119
  incrementAndCheck(t) {
120
120
  const i = (this._logCount[t] || 0) + 1;
121
- return this._logCount[t] = i, i > Q;
121
+ return this._logCount[t] = i, i > B;
122
122
  }
123
123
  }
124
124
  class N {
125
- constructor(t, e, i, r, o) {
125
+ constructor(t, e, i, r, s) {
126
126
  this._reporter = "mp-wsdk";
127
127
  const a = t?.isLoggingEnabled === !0 || t?.isLoggingEnabled === "true";
128
- this._integrationName = e || "", this._launcherInstanceGuid = i, this._accountId = r || null, this._rateLimiter = o || new G(), this._isEnabled = W() || Y() && a;
128
+ this._integrationName = e || "", this._launcherInstanceGuid = i, this._accountId = r || null, this._rateLimiter = s || new G(), this._isEnabled = W() || Y() && a;
129
129
  }
130
- send(t, e, i, r, o, a) {
130
+ send(t, e, i, r, s, a) {
131
131
  if (!(!this._isEnabled || this._rateLimiter.incrementAndCheck(e)))
132
132
  try {
133
- const c = {
133
+ const u = {
134
134
  additionalInformation: {
135
135
  message: i,
136
136
  version: this._integrationName
@@ -138,46 +138,46 @@ class N {
138
138
  severity: e,
139
139
  code: r || L.UNKNOWN_ERROR,
140
140
  url: q(),
141
- deviceInfo: B(),
142
- stackTrace: o,
141
+ deviceInfo: J(),
142
+ stackTrace: s,
143
143
  reporter: this._reporter,
144
144
  integration: this._integrationName
145
- }, u = {
145
+ }, l = {
146
146
  Accept: "text/plain;charset=UTF-8",
147
147
  "Content-Type": "application/json",
148
148
  "rokt-launcher-version": this._integrationName,
149
149
  "rokt-wsdk-version": "joint"
150
150
  };
151
- this._launcherInstanceGuid && (u["rokt-launcher-instance-guid"] = this._launcherInstanceGuid), this._accountId && (u["rokt-account-id"] = this._accountId), fetch(t, {
151
+ this._launcherInstanceGuid && (l["rokt-launcher-instance-guid"] = this._launcherInstanceGuid), this._accountId && (l["rokt-account-id"] = this._accountId), fetch(t, {
152
152
  method: "POST",
153
- headers: u,
154
- body: JSON.stringify(c)
155
- }).catch((p) => {
156
- console.error("ReportingTransport: Failed to send log", p), a && a(p);
153
+ headers: l,
154
+ body: JSON.stringify(u)
155
+ }).catch((g) => {
156
+ console.error("ReportingTransport: Failed to send log", g), a && a(g);
157
157
  });
158
- } catch (c) {
159
- console.error("ReportingTransport: Failed to send log", c), a && a(c);
158
+ } catch (u) {
159
+ console.error("ReportingTransport: Failed to send log", u), a && a(u);
160
160
  }
161
161
  }
162
162
  }
163
- class D {
164
- constructor(t, e, i, r, o) {
165
- this._transport = new N(t, e, i, r, o), this._errorUrl = "https://" + (t?.errorUrl || z);
163
+ class K {
164
+ constructor(t, e, i, r, s) {
165
+ this._transport = new N(t, e, i, r, s), this._errorUrl = "https://" + (t?.errorUrl || Q);
166
166
  }
167
167
  report(t) {
168
168
  if (!t) return;
169
- const e = t.severity || w.ERROR;
169
+ const e = t.severity || v.ERROR;
170
170
  this._transport.send(this._errorUrl, e, t.message, t.code, t.stackTrace);
171
171
  }
172
172
  }
173
- class K {
174
- constructor(t, e, i, r, o, a) {
175
- this._transport = new N(t, i, r, o, a), this._loggingUrl = "https://" + (t?.loggingUrl || F), this._errorReportingService = e;
173
+ class D {
174
+ constructor(t, e, i, r, s, a) {
175
+ this._transport = new N(t, i, r, s, a), this._loggingUrl = "https://" + (t?.loggingUrl || z), this._errorReportingService = e;
176
176
  }
177
177
  log(t) {
178
178
  t && this._transport.send(
179
179
  this._loggingUrl,
180
- w.INFO,
180
+ v.INFO,
181
181
  t.message,
182
182
  t.code,
183
183
  void 0,
@@ -185,15 +185,15 @@ class K {
185
185
  this._errorReportingService && this._errorReportingService.report({
186
186
  message: "LoggingService: Failed to send log: " + e.message,
187
187
  code: L.UNKNOWN_ERROR,
188
- severity: w.ERROR
188
+ severity: v.ERROR
189
189
  });
190
190
  }
191
191
  );
192
192
  }
193
193
  }
194
- const d = class d {
194
+ const p = class p {
195
195
  constructor() {
196
- this.name = g, this.moduleId = 181, this.isInitialized = !1, this.launcher = null, this.filters = {}, this.userAttributes = {}, this.testHelpers = null, this.placementEventMappingLookup = {}, this.placementEventAttributeMappingLookup = {}, this.eventQueue = [], this.eventStreamQueue = [], this.integrationName = null, this.errorReportingService = null, this.loggingService = null;
196
+ this.name = c, 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;
197
197
  }
198
198
  // ---- Private helpers ----
199
199
  getEventAttributeValue(t, e) {
@@ -201,13 +201,13 @@ const d = class d {
201
201
  return !i || typeof i[e] > "u" ? null : i[e];
202
202
  }
203
203
  doesEventAttributeConditionMatch(t, e) {
204
- if (!t || !v(t.operator))
204
+ if (!t || !y(t.operator))
205
205
  return !1;
206
206
  const i = t.operator.toLowerCase(), r = t.attributeValue;
207
207
  return i === "exists" ? e !== null : e == null ? !1 : i === "equals" ? String(e) === String(r) : i === "contains" ? String(e).indexOf(String(r)) !== -1 : !1;
208
208
  }
209
209
  doesEventMatchRule(t, e) {
210
- if (!e || !v(e.eventAttributeKey))
210
+ if (!e || !y(e.eventAttributeKey))
211
211
  return !1;
212
212
  const i = e.conditions;
213
213
  if (!Array.isArray(i))
@@ -215,24 +215,24 @@ const d = class d {
215
215
  const r = this.getEventAttributeValue(t, e.eventAttributeKey);
216
216
  if (i.length === 0)
217
217
  return r !== null;
218
- for (let o = 0; o < i.length; o++)
219
- if (!this.doesEventAttributeConditionMatch(i[o], r))
218
+ for (let s = 0; s < i.length; s++)
219
+ if (!this.doesEventAttributeConditionMatch(i[s], r))
220
220
  return !1;
221
221
  return !0;
222
222
  }
223
223
  applyPlacementEventAttributeMapping(t) {
224
224
  const e = Object.keys(this.placementEventAttributeMappingLookup);
225
225
  for (let i = 0; i < e.length; i++) {
226
- const r = e[i], o = this.placementEventAttributeMappingLookup[r];
227
- if (R(o))
226
+ const r = e[i], s = this.placementEventAttributeMappingLookup[r];
227
+ if (_(s))
228
228
  continue;
229
229
  let a = !0;
230
- for (let c = 0; c < o.length; c++)
231
- if (!this.doesEventMatchRule(t, o[c])) {
230
+ for (let u = 0; u < s.length; u++)
231
+ if (!this.doesEventMatchRule(t, s[u])) {
232
232
  a = !1;
233
233
  break;
234
234
  }
235
- a && s().Rokt.setLocalSessionAttribute?.(r, !0);
235
+ a && o().Rokt.setLocalSessionAttribute?.(r, !0);
236
236
  }
237
237
  }
238
238
  isLauncherReadyToAttach() {
@@ -248,85 +248,94 @@ const d = class d {
248
248
  return this.replaceOtherIdentityWithEmailsha256(e);
249
249
  }
250
250
  returnLocalSessionAttributes() {
251
- return !s().Rokt || typeof s().Rokt.getLocalSessionAttributes != "function" ? {} : R(this.placementEventMappingLookup) && R(this.placementEventAttributeMappingLookup) ? {} : s().Rokt.getLocalSessionAttributes();
251
+ return !o().Rokt || typeof o().Rokt.getLocalSessionAttributes != "function" ? {} : _(this.placementEventMappingLookup) && _(this.placementEventAttributeMappingLookup) ? {} : o().Rokt.getLocalSessionAttributes();
252
252
  }
253
253
  replaceOtherIdentityWithEmailsha256(t) {
254
254
  const e = { ...t || {} }, i = this._mappedEmailSha256Key;
255
- return i && t[i] && (e[d.EMAIL_SHA256_KEY] = t[i]), i && delete e[i], e;
255
+ return i && t[i] && (e[p.EMAIL_SHA256_KEY] = t[i]), i && delete e[i], e;
256
256
  }
257
257
  logSelectPlacementsEvent(t) {
258
- if (!window.mParticle || typeof s().logEvent != "function" || !k(t))
258
+ if (!window.mParticle || typeof o().logEvent != "function" || !S(t))
259
259
  return;
260
- const e = s().EventType.Other;
261
- s().logEvent(H, e, t);
262
- }
263
- processEventQueue() {
264
- this.eventQueue.forEach((t) => {
265
- this.process(t);
266
- }), this.eventQueue = [];
267
- }
268
- enrichEvent(t) {
269
- return { ...t, UserAttributes: this.userAttributes };
270
- }
271
- sendEventStream(t) {
272
- if (window.Rokt && typeof window.Rokt.__event_stream__ == "function") {
273
- if (this.eventStreamQueue.length) {
274
- const e = this.eventStreamQueue;
275
- this.eventStreamQueue = [];
260
+ const e = o().EventType.Other;
261
+ o().logEvent(j, e, t);
262
+ }
263
+ buildIdentityEvent(t, e) {
264
+ const i = e.getMPID(), r = o() && o().sessionManager && typeof o().sessionManager.getSession == "function" ? o().sessionManager.getSession() : null, s = e.getUserIdentities && typeof e.getUserIdentities == "function" ? e.getUserIdentities().userIdentities : null;
265
+ return {
266
+ EventName: t,
267
+ EventDataType: 14,
268
+ EventCategory: 0,
269
+ Timestamp: Date.now(),
270
+ MPID: i,
271
+ SessionId: r,
272
+ UserIdentities: s
273
+ };
274
+ }
275
+ mergePendingIdentityEvents(t) {
276
+ if (this.pendingIdentityEvents.length === 0)
277
+ return t;
278
+ const e = {
279
+ ...t,
280
+ events: [...t.events ?? [], ...this.pendingIdentityEvents]
281
+ };
282
+ return this.pendingIdentityEvents = [], e;
283
+ }
284
+ drainBatchQueue() {
285
+ this.batchQueue.forEach((t) => {
286
+ this.processBatch(t);
287
+ }), this.batchQueue = [];
288
+ }
289
+ processBatch(t) {
290
+ return this.isKitReady() ? (this.sendBatchStream(this.mergePendingIdentityEvents(t)), "Successfully sent batch to forwarder: " + c) : (this.batchQueue.push(t), "Batch queued for forwarder: " + c);
291
+ }
292
+ sendBatchStream(t) {
293
+ if (window.Rokt && typeof window.Rokt.__batch_stream__ == "function") {
294
+ if (this.batchStreamQueue.length) {
295
+ const e = this.batchStreamQueue;
296
+ this.batchStreamQueue = [];
276
297
  for (let i = 0; i < e.length; i++)
277
- window.Rokt.__event_stream__(this.enrichEvent(e[i]));
298
+ window.Rokt.__batch_stream__(e[i]);
278
299
  }
279
- window.Rokt.__event_stream__(this.enrichEvent(t));
300
+ window.Rokt.__batch_stream__(t);
280
301
  } else
281
- this.eventStreamQueue.push(t);
302
+ this.batchStreamQueue.push(t);
282
303
  }
283
304
  setRoktSessionId(t) {
284
305
  if (!(!t || typeof t != "string"))
285
306
  try {
286
- const e = s().getInstance();
307
+ const e = o().getInstance();
287
308
  e && typeof e.setIntegrationAttribute == "function" && e.setIntegrationAttribute(181, {
288
309
  roktSessionId: t
289
310
  });
290
311
  } catch {
291
312
  }
292
313
  }
293
- buildIdentityEvent(t, e) {
294
- const i = e.getMPID && typeof e.getMPID == "function" ? e.getMPID() : null, r = s() && s().sessionManager && typeof s().sessionManager.getSession == "function" ? s().sessionManager.getSession() : null, o = e.getUserIdentities && typeof e.getUserIdentities == "function" ? e.getUserIdentities().userIdentities : null;
295
- return {
296
- EventName: t,
297
- EventDataType: 14,
298
- EventCategory: 0,
299
- Timestamp: Date.now(),
300
- MPID: i,
301
- SessionId: r,
302
- UserIdentities: o
303
- };
304
- }
305
314
  attachLauncher(t, e) {
306
- const i = s() && s().sessionManager && typeof s().sessionManager.getSession == "function" ? s().sessionManager.getSession() : void 0, r = {
315
+ const i = o() && o().sessionManager && typeof o().sessionManager.getSession == "function" ? o().sessionManager.getSession() : void 0, r = {
307
316
  accountId: t,
308
317
  ...e || {},
309
318
  ...i ? { mpSessionId: i } : {}
310
319
  };
311
320
  if (this.isPartnerInLocalLauncherTestGroup()) {
312
- const o = window.Rokt.createLocalLauncher(r);
313
- this.initRoktLauncher(o);
321
+ const s = window.Rokt.createLocalLauncher(r);
322
+ this.initRoktLauncher(s);
314
323
  } else
315
- window.Rokt.createLauncher(r).then((o) => this.initRoktLauncher(o)).catch((o) => {
316
- console.error("Error creating Rokt launcher:", o);
324
+ window.Rokt.createLauncher(r).then((s) => this.initRoktLauncher(s)).catch((s) => {
325
+ console.error("Error creating Rokt launcher:", s);
317
326
  });
318
327
  }
319
328
  initRoktLauncher(t) {
320
329
  window.Rokt && (window.Rokt.currentLauncher = t), this.launcher = t;
321
- const e = s().Rokt?.filters;
322
- 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, C(this.domain, this.integrationName), s().Rokt.attachKit(this), this.processEventQueue();
330
+ const e = o().Rokt?.filters;
331
+ 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, C(this.domain, this.integrationName), o().Rokt.attachKit(this), this.drainBatchQueue();
323
332
  }
324
333
  fetchOptimizely() {
325
- const t = s()._getActiveForwarders().filter((e) => e.name === "Optimizely");
334
+ const t = o()._getActiveForwarders().filter((e) => e.name === "Optimizely");
326
335
  try {
327
336
  if (t.length > 0 && window.optimizely) {
328
337
  const e = window.optimizely.get("state");
329
- return !e || !e.getActiveExperimentIds ? {} : e.getActiveExperimentIds().reduce((o, a) => (o["rokt.custom.optimizely.experiment." + a + ".variationId"] = e.getVariationMap()[a].id, o), {});
338
+ return !e || !e.getActiveExperimentIds ? {} : e.getActiveExperimentIds().reduce((s, a) => (s["rokt.custom.optimizely.experiment." + a + ".variationId"] = e.getVariationMap()[a].id, s), {});
330
339
  }
331
340
  } catch (e) {
332
341
  console.error("Error fetching Optimizely attributes:", e);
@@ -337,93 +346,88 @@ const d = class d {
337
346
  return !!(this.isInitialized && this.launcher);
338
347
  }
339
348
  isPartnerInLocalLauncherTestGroup() {
340
- return !!(s().config && s().config.isLocalLauncherEnabled && this.isAssignedToSampleGroup());
349
+ return !!(o().config && o().config.isLocalLauncherEnabled && this.isAssignedToSampleGroup());
341
350
  }
342
351
  isAssignedToSampleGroup() {
343
352
  return Math.random() > 0.5;
344
353
  }
345
354
  captureTiming(t) {
346
- window && s() && s().captureTiming && t && s().captureTiming(t);
355
+ window && o() && o().captureTiming && t && o().captureTiming(t);
347
356
  }
348
357
  // ---- Public methods (mParticle Kit Callbacks) ----
349
358
  /**
350
359
  * Initializes the Rokt forwarder with settings from the mParticle server.
351
360
  */
352
- init(t, e, i, r, o) {
353
- const a = t.accountId, c = M(t.roktExtensions);
354
- this.userAttributes = o || {}, this._onboardingExpProvider = t.onboardingExpProvider;
355
- const u = y(t.placementEventMapping);
356
- this.placementEventMappingLookup = T(u);
357
- const p = y(
358
- t.placementEventAttributeMapping
361
+ init(t, e, i, r, s) {
362
+ const a = t, u = a.accountId, l = U(a.roktExtensions);
363
+ this.userAttributes = s || {}, this._onboardingExpProvider = a.onboardingExpProvider;
364
+ const g = w(a.placementEventMapping);
365
+ this.placementEventMappingLookup = T(g);
366
+ const I = w(
367
+ a.placementEventAttributeMapping
359
368
  );
360
- this.placementEventAttributeMappingLookup = U(p), t.hashedEmailUserIdentityType && (this._mappedEmailSha256Key = t.hashedEmailUserIdentityType.toLowerCase());
361
- const b = s().Rokt?.domain, h = {
362
- ...s().Rokt?.launcherOptions || {}
369
+ this.placementEventAttributeMappingLookup = M(I), a.hashedEmailUserIdentityType && (this._mappedEmailSha256Key = a.hashedEmailUserIdentityType.toLowerCase());
370
+ const R = o().Rokt?.domain, h = {
371
+ ...o().Rokt?.launcherOptions || {}
363
372
  };
364
- this.integrationName = V(h.integrationName), h.integrationName = this.integrationName, this.domain = b;
365
- const m = {
366
- loggingUrl: t.loggingUrl,
367
- errorUrl: t.errorUrl,
368
- isLoggingEnabled: t.isLoggingEnabled === "true" || t.isLoggingEnabled === !0
369
- }, E = new D(
370
- m,
373
+ this.integrationName = V(h.integrationName), h.integrationName = this.integrationName, this.domain = R;
374
+ const A = {
375
+ loggingUrl: a.loggingUrl,
376
+ errorUrl: a.errorUrl,
377
+ isLoggingEnabled: a.isLoggingEnabled === "true" || a.isLoggingEnabled === !0
378
+ }, f = new K(
379
+ A,
371
380
  this.integrationName,
372
381
  window.__rokt_li_guid__,
373
- t.accountId
374
- ), _ = new K(
375
- m,
376
- E,
382
+ a.accountId
383
+ ), b = new D(
384
+ A,
385
+ f,
377
386
  this.integrationName,
378
387
  window.__rokt_li_guid__,
379
- t.accountId
388
+ a.accountId
380
389
  );
381
- if (this.errorReportingService = E, this.loggingService = _, s()._registerErrorReportingService && s()._registerErrorReportingService(E), s()._registerLoggingService && s()._registerLoggingService(_), i) {
382
- this.testHelpers = {
390
+ if (this.errorReportingService = f, this.loggingService = b, o()._registerErrorReportingService && o()._registerErrorReportingService(f), o()._registerLoggingService && o()._registerLoggingService(b), i)
391
+ return this.testHelpers = {
383
392
  generateLauncherScript: O,
384
- extractRoktExtensions: M,
393
+ extractRoktExtensions: U,
385
394
  hashEventMessage: P,
386
- parseSettingsString: y,
395
+ parseSettingsString: w,
387
396
  generateMappedEventLookup: T,
388
- generateMappedEventAttributeLookup: U,
397
+ generateMappedEventAttributeLookup: M,
389
398
  sendAdBlockMeasurementSignals: C,
390
- createAutoRemovedIframe: S,
399
+ createAutoRemovedIframe: k,
391
400
  djb2: x,
392
- setAllowedOriginHashes: (A) => {
393
- d._allowedOriginHashes = A;
401
+ setAllowedOriginHashes: (E) => {
402
+ p._allowedOriginHashes = E;
394
403
  },
395
404
  ReportingTransport: N,
396
- ErrorReportingService: D,
397
- LoggingService: K,
405
+ ErrorReportingService: K,
406
+ LoggingService: D,
398
407
  RateLimiter: G,
399
408
  ErrorCodes: L,
400
- WSDKErrorSeverity: w
401
- }, this.attachLauncher(a, h);
402
- return;
403
- }
409
+ WSDKErrorSeverity: v
410
+ }, this.attachLauncher(u, h), "Successfully initialized: " + c;
404
411
  if (this.isLauncherReadyToAttach())
405
- this.attachLauncher(a, h);
412
+ this.attachLauncher(u, h);
406
413
  else {
407
- const A = document.head || document.body, l = document.createElement("script");
408
- l.type = "text/javascript", l.src = O(b, c), l.async = !0, l.crossOrigin = "anonymous", l.fetchPriority = "high", l.id = "rokt-launcher", l.onload = () => {
409
- this.isLauncherReadyToAttach() ? this.attachLauncher(a, h) : console.error("Rokt object is not available after script load.");
410
- }, l.onerror = (I) => {
411
- console.error("Error loading Rokt launcher script:", I);
412
- }, A.appendChild(l), this.captureTiming(d.PERFORMANCE_MARKS.RoktScriptAppended);
414
+ const E = document.head || document.body, d = document.createElement("script");
415
+ d.type = "text/javascript", d.src = O(R, l), d.async = !0, d.crossOrigin = "anonymous", d.fetchPriority = "high", d.id = "rokt-launcher", d.onload = () => {
416
+ this.isLauncherReadyToAttach() ? this.attachLauncher(u, h) : console.error("Rokt object is not available after script load.");
417
+ }, d.onerror = (H) => {
418
+ console.error("Error loading Rokt launcher script:", H);
419
+ }, E.appendChild(d), this.captureTiming(p.PERFORMANCE_MARKS.RoktScriptAppended);
413
420
  }
421
+ return "Successfully initialized: " + c;
414
422
  }
415
423
  process(t) {
416
- if (!this.isKitReady()) {
417
- this.eventQueue.push(t);
418
- return;
419
- }
420
- if (this.sendEventStream(t), typeof s().Rokt?.setLocalSessionAttribute != "function" || (R(this.placementEventAttributeMappingLookup) || this.applyPlacementEventAttributeMapping(t), R(this.placementEventMappingLookup)))
421
- return;
422
- const e = P(t.EventDataType, t.EventCategory, t.EventName ?? "");
423
- if (this.placementEventMappingLookup[String(e)]) {
424
- const i = this.placementEventMappingLookup[String(e)];
425
- s().Rokt.setLocalSessionAttribute?.(i, !0);
424
+ if (!this.isKitReady())
425
+ return "Kit not ready for forwarder: " + c;
426
+ if (typeof o().Rokt?.setLocalSessionAttribute == "function" && (_(this.placementEventAttributeMappingLookup) || this.applyPlacementEventAttributeMapping(t), !_(this.placementEventMappingLookup))) {
427
+ const e = P(t.EventDataType, t.EventCategory, t.EventName ?? "");
428
+ this.placementEventMappingLookup[String(e)] && o().Rokt.setLocalSessionAttribute?.(this.placementEventMappingLookup[String(e)], !0);
426
429
  }
430
+ return "Successfully sent to forwarder: " + c;
427
431
  }
428
432
  setExtensionData(t) {
429
433
  if (!this.isKitReady()) {
@@ -433,41 +437,43 @@ const d = class d {
433
437
  window.Rokt.setExtensionData(t);
434
438
  }
435
439
  setUserAttribute(t, e) {
436
- this.userAttributes[t] = e, this.sendEventStream(
437
- this.buildIdentityEvent("set_user_attributes", this.filters.filteredUser ?? {})
438
- );
440
+ return this.userAttributes[t] = e, "Successfully set user attribute for forwarder: " + c;
439
441
  }
440
442
  removeUserAttribute(t) {
441
- delete this.userAttributes[t];
443
+ return delete this.userAttributes[t], "Successfully removed user attribute for forwarder: " + c;
442
444
  }
443
445
  onUserIdentified(t) {
444
- this.filters.filteredUser = t, this.userAttributes = t.getAllUserAttributes(), this.sendEventStream(this.buildIdentityEvent("identify", t));
446
+ const e = t;
447
+ return this.filters.filteredUser = e, this.userAttributes = t.getAllUserAttributes(), this.pendingIdentityEvents.push(this.buildIdentityEvent("identify", e)), "Successfully called onUserIdentified for forwarder: " + c;
445
448
  }
446
- onLoginComplete(t) {
447
- this.userAttributes = t.getAllUserAttributes(), this.sendEventStream(this.buildIdentityEvent("login", t));
449
+ onLoginComplete(t, e) {
450
+ const i = t;
451
+ return this.userAttributes = t.getAllUserAttributes(), this.pendingIdentityEvents.push(this.buildIdentityEvent("login", i)), "Successfully called onLoginComplete for forwarder: " + c;
448
452
  }
449
- onLogoutComplete(t) {
450
- this.userAttributes = t.getAllUserAttributes(), this.sendEventStream(this.buildIdentityEvent("logout", t));
453
+ onLogoutComplete(t, e) {
454
+ const i = t;
455
+ return this.userAttributes = t.getAllUserAttributes(), this.pendingIdentityEvents.push(this.buildIdentityEvent("logout", i)), "Successfully called onLogoutComplete for forwarder: " + c;
451
456
  }
452
- onModifyComplete(t) {
453
- this.userAttributes = t.getAllUserAttributes(), this.sendEventStream(this.buildIdentityEvent("modify_user", t));
457
+ onModifyComplete(t, e) {
458
+ const i = t;
459
+ return this.userAttributes = t.getAllUserAttributes(), this.pendingIdentityEvents.push(this.buildIdentityEvent("modify", i)), "Successfully called onModifyComplete for forwarder: " + c;
454
460
  }
455
461
  /**
456
462
  * Selects placements for Rokt Web SDK with merged attributes, filters, and experimentation options.
457
463
  */
458
464
  selectPlacements(t) {
459
- const e = t && t.attributes || {}, i = { ...this.userAttributes, ...e }, r = this.filters || {}, o = r.userAttributeFilters || [], a = r.filteredUser || null, c = a && a.getMPID && typeof a.getMPID == "function" ? a.getMPID() : null;
460
- let u;
461
- 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;
462
- const p = this._onboardingExpProvider === "Optimizely" ? this.fetchOptimizely() : {}, b = this.returnUserIdentities(a), h = this.returnLocalSessionAttributes(), m = {
463
- ...b,
464
- ...u,
465
- ...p,
466
- ...h,
467
- mpid: c
468
- }, E = { ...t, attributes: m }, _ = this.launcher.selectPlacements(E), A = () => this.logSelectPlacementsEvent(m);
469
- return Promise.resolve(_).then((l) => l?.context?.sessionId?.then((I) => this.setRoktSessionId(I))).catch(() => {
470
- }).finally(A), _;
465
+ const e = t && t.attributes || {}, i = { ...this.userAttributes, ...e }, r = this.filters || {}, s = r.userAttributeFilters || [], a = r.filteredUser || null, u = a ? a.getMPID() : null;
466
+ let l;
467
+ r ? r.filterUserAttributes ? l = r.filterUserAttributes(i, s) : l = i : (console.warn("Rokt Kit: No filters available, using user attributes"), l = i), this.userAttributes = l;
468
+ const g = this._onboardingExpProvider === "Optimizely" ? this.fetchOptimizely() : {}, I = this.returnUserIdentities(a), R = this.returnLocalSessionAttributes(), h = {
469
+ ...I,
470
+ ...l,
471
+ ...g,
472
+ ...R,
473
+ mpid: u
474
+ }, A = { ...t, attributes: h }, f = this.launcher.selectPlacements(A), b = () => this.logSelectPlacementsEvent(h);
475
+ return Promise.resolve(f).then((E) => E?.context?.sessionId?.then((d) => this.setRoktSessionId(d))).catch(() => {
476
+ }).finally(b), f;
471
477
  }
472
478
  /**
473
479
  * Passes attributes to the Rokt Web SDK for client-side hashing.
@@ -479,37 +485,37 @@ const d = class d {
479
485
  * Enables optional Integration Launcher extensions before selecting placements.
480
486
  */
481
487
  use(t) {
482
- return this.isKitReady() ? !t || !v(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")));
488
+ 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")));
483
489
  }
484
490
  };
485
- d._allowedOriginHashes = [-553112570, 549508659], d.PERFORMANCE_MARKS = {
491
+ p._allowedOriginHashes = [-553112570, 549508659], p.PERFORMANCE_MARKS = {
486
492
  RoktScriptAppended: "mp:RoktScriptAppended"
487
- }, d.EMAIL_SHA256_KEY = "emailsha256";
488
- let f = d;
489
- function J() {
493
+ }, p.EMAIL_SHA256_KEY = "emailsha256";
494
+ let m = p;
495
+ function X() {
490
496
  return 181;
491
497
  }
492
- function X(n) {
498
+ function Z(n) {
493
499
  if (!n) {
494
- window.console.log("You must pass a config object to register the kit " + g);
500
+ window.console.log("You must pass a config object to register the kit " + c);
495
501
  return;
496
502
  }
497
- if (!k(n)) {
503
+ if (!S(n)) {
498
504
  window.console.log("'config' must be an object. You passed in a " + typeof n);
499
505
  return;
500
506
  }
501
- k(n.kits) ? n.kits[g] = {
502
- constructor: f
503
- } : (n.kits = {}, n.kits[g] = {
504
- constructor: f
505
- }), window.console.log("Successfully registered " + g + " to your mParticle configuration");
507
+ S(n.kits) ? n.kits[c] = {
508
+ constructor: m
509
+ } : (n.kits = {}, n.kits[c] = {
510
+ constructor: m
511
+ }), window.console.log("Successfully registered " + c + " to your mParticle configuration");
506
512
  }
507
- typeof window < "u" && window.mParticle && s().addForwarder && s().addForwarder({
508
- name: g,
509
- constructor: f,
510
- getId: J
513
+ typeof window < "u" && window.mParticle && o().addForwarder && o().addForwarder({
514
+ name: c,
515
+ constructor: m,
516
+ getId: X
511
517
  });
512
518
  export {
513
- X as register
519
+ Z as register
514
520
  };
515
521
  //# sourceMappingURL=Rokt-Kit.esm.js.map
@@ -1,2 +1,2 @@
1
- var RoktKit=(function(I){"use strict";const p="Rokt",H="selectPlacements",F="apps.roktecommerce.com",k={UNKNOWN_ERROR:"UNKNOWN_ERROR",UNHANDLED_EXCEPTION:"UNHANDLED_EXCEPTION",IDENTITY_REQUEST:"IDENTITY_REQUEST"},b={ERROR:"ERROR",INFO:"INFO",WARNING:"WARNING"},z="apps.rokt-api.com/v1/log",Q="apps.rokt-api.com/v1/errors",V=10;function s(){return window.mParticle}function M(n,t){const o=["https://",typeof n<"u"?n:"apps.rokt.com","/wsdk/integrations/launcher.js"].join("");return!t||t.length===0?o:o+"?extensions="+t.join(",")}function S(n){return n!=null&&typeof n=="object"&&Array.isArray(n)===!1}function y(n){if(!n)return[];try{return JSON.parse(n.replace(/&quot;/g,'"'))}catch{console.error("Settings string contains invalid JSON")}return[]}function T(n){const t=n?y(n):[],e=[];for(let i=0;i<t.length;i++)e.push(t[i].value);return e}function P(n){if(!n)return{};const t={};for(let e=0;e<n.length;e++){const i=n[e];t[i.jsmap]=i.value}return t}function U(n){const t={};if(!Array.isArray(n))return t;for(let e=0;e<n.length;e++){const i=n[e];if(!i||!E(i.value)||!E(i.map))continue;const r=i.value,o=i.map;t[r]||(t[r]=[]),t[r].push({eventAttributeKey:o,conditions:Array.isArray(i.conditions)?i.conditions:[]})}return t}function C(n,t,e){return s().generateHash([n,t,e].join(""))}function m(n){return n==null?!0:typeof n=="object"?Object.keys(n).length===0:Array.isArray(n)?n.length===0:!1}function E(n){return typeof n=="string"}function Y(n){let i="mParticle_wsdkv_"+s().getVersion()+"_kitv_"+"1.23.0";return n&&(i+="_"+n),i}function D(n){let t=5381;for(let e=0;e<n.length;e++)t=(t<<5)+t+n.charCodeAt(e),t=t&t;return t}function L(n){const t=document.createElement("iframe");t.style.display="none",t.setAttribute("sandbox","allow-scripts allow-same-origin"),t.src=n,t.onload=function(){t.onload=null,t.parentNode&&t.parentNode.removeChild(t)};const e=document.body||document.head;e&&e.appendChild(t)}function K(n,t){const e=D(window.location.origin);if(g._allowedOriginHashes.indexOf(e)===-1||Math.random()>=.1)return;const r=window.__rokt_li_guid__;if(!r)return;const o=window.location.href.split("?")[0].split("#")[0],a="version="+encodeURIComponent(t??"")+"&launcherInstanceGuid="+encodeURIComponent(r)+"&pageUrl="+encodeURIComponent(o);L("https://"+(n||"apps.rokt.com")+"/v1/wsdk-init/index.html?"+a),L("https://"+F+"/v1/wsdk-init/index.html?"+a+"&isControl=true")}function W(){return typeof window<"u"&&!!window.ROKT_DOMAIN}function q(){return typeof window<"u"&&!!window.location?.search?.toLowerCase().includes("mp_enable_logging=true")}function B(){return typeof window<"u"?window.location?.href:void 0}function J(){return typeof window<"u"?window.navigator?.userAgent:void 0}class x{constructor(){this._logCount={}}incrementAndCheck(t){const i=(this._logCount[t]||0)+1;return this._logCount[t]=i,i>V}}class N{constructor(t,e,i,r,o){this._reporter="mp-wsdk";const a=t?.isLoggingEnabled===!0||t?.isLoggingEnabled==="true";this._integrationName=e||"",this._launcherInstanceGuid=i,this._accountId=r||null,this._rateLimiter=o||new x,this._isEnabled=q()||W()&&a}send(t,e,i,r,o,a){if(!(!this._isEnabled||this._rateLimiter.incrementAndCheck(e)))try{const c={additionalInformation:{message:i,version:this._integrationName},severity:e,code:r||k.UNKNOWN_ERROR,url:B(),deviceInfo:J(),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(t,{method:"POST",headers:u,body:JSON.stringify(c)}).catch(f=>{console.error("ReportingTransport: Failed to send log",f),a&&a(f)})}catch(c){console.error("ReportingTransport: Failed to send log",c),a&&a(c)}}}class j{constructor(t,e,i,r,o){this._transport=new N(t,e,i,r,o),this._errorUrl="https://"+(t?.errorUrl||Q)}report(t){if(!t)return;const e=t.severity||b.ERROR;this._transport.send(this._errorUrl,e,t.message,t.code,t.stackTrace)}}class G{constructor(t,e,i,r,o,a){this._transport=new N(t,i,r,o,a),this._loggingUrl="https://"+(t?.loggingUrl||z),this._errorReportingService=e}log(t){t&&this._transport.send(this._loggingUrl,b.INFO,t.message,t.code,void 0,e=>{this._errorReportingService&&this._errorReportingService.report({message:"LoggingService: Failed to send log: "+e.message,code:k.UNKNOWN_ERROR,severity:b.ERROR})})}}const d=class d{constructor(){this.name=p,this.moduleId=181,this.isInitialized=!1,this.launcher=null,this.filters={},this.userAttributes={},this.testHelpers=null,this.placementEventMappingLookup={},this.placementEventAttributeMappingLookup={},this.eventQueue=[],this.eventStreamQueue=[],this.integrationName=null,this.errorReportingService=null,this.loggingService=null}getEventAttributeValue(t,e){const i=t&&t.EventAttributes;return!i||typeof i[e]>"u"?null:i[e]}doesEventAttributeConditionMatch(t,e){if(!t||!E(t.operator))return!1;const i=t.operator.toLowerCase(),r=t.attributeValue;return i==="exists"?e!==null:e==null?!1:i==="equals"?String(e)===String(r):i==="contains"?String(e).indexOf(String(r))!==-1:!1}doesEventMatchRule(t,e){if(!e||!E(e.eventAttributeKey))return!1;const i=e.conditions;if(!Array.isArray(i))return!1;const r=this.getEventAttributeValue(t,e.eventAttributeKey);if(i.length===0)return r!==null;for(let o=0;o<i.length;o++)if(!this.doesEventAttributeConditionMatch(i[o],r))return!1;return!0}applyPlacementEventAttributeMapping(t){const e=Object.keys(this.placementEventAttributeMappingLookup);for(let i=0;i<e.length;i++){const r=e[i],o=this.placementEventAttributeMappingLookup[r];if(m(o))continue;let a=!0;for(let c=0;c<o.length;c++)if(!this.doesEventMatchRule(t,o[c])){a=!1;break}a&&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"?{}:m(this.placementEventMappingLookup)&&m(this.placementEventAttributeMappingLookup)?{}:s().Rokt.getLocalSessionAttributes()}replaceOtherIdentityWithEmailsha256(t){const e={...t||{}},i=this._mappedEmailSha256Key;return i&&t[i]&&(e[d.EMAIL_SHA256_KEY]=t[i]),i&&delete e[i],e}logSelectPlacementsEvent(t){if(!window.mParticle||typeof s().logEvent!="function"||!S(t))return;const e=s().EventType.Other;s().logEvent(H,e,t)}processEventQueue(){this.eventQueue.forEach(t=>{this.process(t)}),this.eventQueue=[]}enrichEvent(t){return{...t,UserAttributes:this.userAttributes}}sendEventStream(t){if(window.Rokt&&typeof window.Rokt.__event_stream__=="function"){if(this.eventStreamQueue.length){const e=this.eventStreamQueue;this.eventStreamQueue=[];for(let i=0;i<e.length;i++)window.Rokt.__event_stream__(this.enrichEvent(e[i]))}window.Rokt.__event_stream__(this.enrichEvent(t))}else this.eventStreamQueue.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{}}buildIdentityEvent(t,e){const i=e.getMPID&&typeof e.getMPID=="function"?e.getMPID():null,r=s()&&s().sessionManager&&typeof s().sessionManager.getSession=="function"?s().sessionManager.getSession():null,o=e.getUserIdentities&&typeof e.getUserIdentities=="function"?e.getUserIdentities().userIdentities:null;return{EventName:t,EventDataType:14,EventCategory:0,Timestamp:Date.now(),MPID:i,SessionId:r,UserIdentities:o}}attachLauncher(t,e){const i=s()&&s().sessionManager&&typeof s().sessionManager.getSession=="function"?s().sessionManager.getSession():void 0,r={accountId:t,...e||{},...i?{mpSessionId:i}:{}};if(this.isPartnerInLocalLauncherTestGroup()){const o=window.Rokt.createLocalLauncher(r);this.initRoktLauncher(o)}else window.Rokt.createLauncher(r).then(o=>this.initRoktLauncher(o)).catch(o=>{console.error("Error creating Rokt launcher:",o)})}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,K(this.domain,this.integrationName),s().Rokt.attachKit(this),this.processEventQueue()}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((o,a)=>(o["rokt.custom.optimizely.experiment."+a+".variationId"]=e.getVariationMap()[a].id,o),{})}}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,i,r,o){const a=t.accountId,c=T(t.roktExtensions);this.userAttributes=o||{},this._onboardingExpProvider=t.onboardingExpProvider;const u=y(t.placementEventMapping);this.placementEventMappingLookup=P(u);const f=y(t.placementEventAttributeMapping);this.placementEventAttributeMappingLookup=U(f),t.hashedEmailUserIdentityType&&(this._mappedEmailSha256Key=t.hashedEmailUserIdentityType.toLowerCase());const w=s().Rokt?.domain,h={...s().Rokt?.launcherOptions||{}};this.integrationName=Y(h.integrationName),h.integrationName=this.integrationName,this.domain=w;const _={loggingUrl:t.loggingUrl,errorUrl:t.errorUrl,isLoggingEnabled:t.isLoggingEnabled==="true"||t.isLoggingEnabled===!0},A=new j(_,this.integrationName,window.__rokt_li_guid__,t.accountId),R=new G(_,A,this.integrationName,window.__rokt_li_guid__,t.accountId);if(this.errorReportingService=A,this.loggingService=R,s()._registerErrorReportingService&&s()._registerErrorReportingService(A),s()._registerLoggingService&&s()._registerLoggingService(R),i){this.testHelpers={generateLauncherScript:M,extractRoktExtensions:T,hashEventMessage:C,parseSettingsString:y,generateMappedEventLookup:P,generateMappedEventAttributeLookup:U,sendAdBlockMeasurementSignals:K,createAutoRemovedIframe:L,djb2:D,setAllowedOriginHashes:v=>{d._allowedOriginHashes=v},ReportingTransport:N,ErrorReportingService:j,LoggingService:G,RateLimiter:x,ErrorCodes:k,WSDKErrorSeverity:b},this.attachLauncher(a,h);return}if(this.isLauncherReadyToAttach())this.attachLauncher(a,h);else{const v=document.head||document.body,l=document.createElement("script");l.type="text/javascript",l.src=M(w,c),l.async=!0,l.crossOrigin="anonymous",l.fetchPriority="high",l.id="rokt-launcher",l.onload=()=>{this.isLauncherReadyToAttach()?this.attachLauncher(a,h):console.error("Rokt object is not available after script load.")},l.onerror=O=>{console.error("Error loading Rokt launcher script:",O)},v.appendChild(l),this.captureTiming(d.PERFORMANCE_MARKS.RoktScriptAppended)}}process(t){if(!this.isKitReady()){this.eventQueue.push(t);return}if(this.sendEventStream(t),typeof s().Rokt?.setLocalSessionAttribute!="function"||(m(this.placementEventAttributeMappingLookup)||this.applyPlacementEventAttributeMapping(t),m(this.placementEventMappingLookup)))return;const e=C(t.EventDataType,t.EventCategory,t.EventName??"");if(this.placementEventMappingLookup[String(e)]){const i=this.placementEventMappingLookup[String(e)];s().Rokt.setLocalSessionAttribute?.(i,!0)}}setExtensionData(t){if(!this.isKitReady()){console.error("Rokt Kit: Not initialized");return}window.Rokt.setExtensionData(t)}setUserAttribute(t,e){this.userAttributes[t]=e,this.sendEventStream(this.buildIdentityEvent("set_user_attributes",this.filters.filteredUser??{}))}removeUserAttribute(t){delete this.userAttributes[t]}onUserIdentified(t){this.filters.filteredUser=t,this.userAttributes=t.getAllUserAttributes(),this.sendEventStream(this.buildIdentityEvent("identify",t))}onLoginComplete(t){this.userAttributes=t.getAllUserAttributes(),this.sendEventStream(this.buildIdentityEvent("login",t))}onLogoutComplete(t){this.userAttributes=t.getAllUserAttributes(),this.sendEventStream(this.buildIdentityEvent("logout",t))}onModifyComplete(t){this.userAttributes=t.getAllUserAttributes(),this.sendEventStream(this.buildIdentityEvent("modify_user",t))}selectPlacements(t){const e=t&&t.attributes||{},i={...this.userAttributes,...e},r=this.filters||{},o=r.userAttributeFilters||[],a=r.filteredUser||null,c=a&&a.getMPID&&typeof a.getMPID=="function"?a.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 f=this._onboardingExpProvider==="Optimizely"?this.fetchOptimizely():{},w=this.returnUserIdentities(a),h=this.returnLocalSessionAttributes(),_={...w,...u,...f,...h,mpid:c},A={...t,attributes:_},R=this.launcher.selectPlacements(A),v=()=>this.logSelectPlacementsEvent(_);return Promise.resolve(R).then(l=>l?.context?.sessionId?.then(O=>this.setRoktSessionId(O))).catch(()=>{}).finally(v),R}hashAttributes(t){return this.isKitReady()?this.launcher.hashAttributes(t):(console.error("Rokt Kit: Not initialized"),null)}use(t){return this.isKitReady()?!t||!E(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")))}};d._allowedOriginHashes=[-553112570,549508659],d.PERFORMANCE_MARKS={RoktScriptAppended:"mp:RoktScriptAppended"},d.EMAIL_SHA256_KEY="emailsha256";let g=d;function X(){return 181}function Z(n){if(!n){window.console.log("You must pass a config object to register the kit "+p);return}if(!S(n)){window.console.log("'config' must be an object. You passed in a "+typeof n);return}S(n.kits)?n.kits[p]={constructor:g}:(n.kits={},n.kits[p]={constructor:g}),window.console.log("Successfully registered "+p+" to your mParticle configuration")}return typeof window<"u"&&window.mParticle&&s().addForwarder&&s().addForwarder({name:p,constructor:g,getId:X}),I.register=Z,Object.defineProperty(I,Symbol.toStringTag,{value:"Module"}),I})({});
1
+ var RoktKit=(function(I){"use strict";const c="Rokt",H="selectPlacements",F="apps.roktecommerce.com",S={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",Q="apps.rokt-api.com/v1/errors",B=10;function o(){return window.mParticle}function U(n,t){const s=["https://",typeof n<"u"?n:"apps.rokt.com","/wsdk/integrations/launcher.js"].join("");return!t||t.length===0?s:s+"?extensions="+t.join(",")}function k(n){return n!=null&&typeof n=="object"&&Array.isArray(n)===!1}function A(n){if(!n)return[];try{return JSON.parse(n.replace(/&quot;/g,'"'))}catch{console.error("Settings string contains invalid JSON")}return[]}function T(n){const t=n?A(n):[],e=[];for(let i=0;i<t.length;i++)e.push(t[i].value);return e}function M(n){if(!n)return{};const t={};for(let e=0;e<n.length;e++){const i=n[e];t[i.jsmap]=i.value}return t}function P(n){const t={};if(!Array.isArray(n))return t;for(let e=0;e<n.length;e++){const i=n[e];if(!i||!_(i.value)||!_(i.map))continue;const r=i.value,s=i.map;t[r]||(t[r]=[]),t[r].push({eventAttributeKey:s,conditions:Array.isArray(i.conditions)?i.conditions:[]})}return t}function C(n,t,e){return o().generateHash([n,t,e].join(""))}function E(n){return n==null?!0:typeof n=="object"?Object.keys(n).length===0:Array.isArray(n)?n.length===0:!1}function _(n){return typeof n=="string"}function V(n){let i="mParticle_wsdkv_"+o().getVersion()+"_kitv_"+"1.24.0";return n&&(i+="_"+n),i}function K(n){let t=5381;for(let e=0;e<n.length;e++)t=(t<<5)+t+n.charCodeAt(e),t=t&t;return t}function L(n){const t=document.createElement("iframe");t.style.display="none",t.setAttribute("sandbox","allow-scripts allow-same-origin"),t.src=n,t.onload=function(){t.onload=null,t.parentNode&&t.parentNode.removeChild(t)};const e=document.body||document.head;e&&e.appendChild(t)}function D(n,t){const e=K(window.location.origin);if(g._allowedOriginHashes.indexOf(e)===-1||Math.random()>=.1)return;const r=window.__rokt_li_guid__;if(!r)return;const s=window.location.href.split("?")[0].split("#")[0],a="version="+encodeURIComponent(t??"")+"&launcherInstanceGuid="+encodeURIComponent(r)+"&pageUrl="+encodeURIComponent(s);L("https://"+(n||"apps.rokt.com")+"/v1/wsdk-init/index.html?"+a),L("https://"+F+"/v1/wsdk-init/index.html?"+a+"&isControl=true")}function Y(){return typeof window<"u"&&!!window.ROKT_DOMAIN}function W(){return typeof window<"u"&&!!window.location?.search?.toLowerCase().includes("mp_enable_logging=true")}function q(){return typeof window<"u"?window.location?.href:void 0}function J(){return typeof window<"u"?window.navigator?.userAgent:void 0}class x{constructor(){this._logCount={}}incrementAndCheck(t){const i=(this._logCount[t]||0)+1;return this._logCount[t]=i,i>B}}class N{constructor(t,e,i,r,s){this._reporter="mp-wsdk";const a=t?.isLoggingEnabled===!0||t?.isLoggingEnabled==="true";this._integrationName=e||"",this._launcherInstanceGuid=i,this._accountId=r||null,this._rateLimiter=s||new x,this._isEnabled=W()||Y()&&a}send(t,e,i,r,s,a){if(!(!this._isEnabled||this._rateLimiter.incrementAndCheck(e)))try{const u={additionalInformation:{message:i,version:this._integrationName},severity:e,code:r||S.UNKNOWN_ERROR,url:q(),deviceInfo:J(),stackTrace:s,reporter:this._reporter,integration:this._integrationName},l={Accept:"text/plain;charset=UTF-8","Content-Type":"application/json","rokt-launcher-version":this._integrationName,"rokt-wsdk-version":"joint"};this._launcherInstanceGuid&&(l["rokt-launcher-instance-guid"]=this._launcherInstanceGuid),this._accountId&&(l["rokt-account-id"]=this._accountId),fetch(t,{method:"POST",headers:l,body:JSON.stringify(u)}).catch(f=>{console.error("ReportingTransport: Failed to send log",f),a&&a(f)})}catch(u){console.error("ReportingTransport: Failed to send log",u),a&&a(u)}}}class j{constructor(t,e,i,r,s){this._transport=new N(t,e,i,r,s),this._errorUrl="https://"+(t?.errorUrl||Q)}report(t){if(!t)return;const e=t.severity||R.ERROR;this._transport.send(this._errorUrl,e,t.message,t.code,t.stackTrace)}}class G{constructor(t,e,i,r,s,a){this._transport=new N(t,i,r,s,a),this._loggingUrl="https://"+(t?.loggingUrl||z),this._errorReportingService=e}log(t){t&&this._transport.send(this._loggingUrl,R.INFO,t.message,t.code,void 0,e=>{this._errorReportingService&&this._errorReportingService.report({message:"LoggingService: Failed to send log: "+e.message,code:S.UNKNOWN_ERROR,severity:R.ERROR})})}}const h=class h{constructor(){this.name=c,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}getEventAttributeValue(t,e){const i=t&&t.EventAttributes;return!i||typeof i[e]>"u"?null:i[e]}doesEventAttributeConditionMatch(t,e){if(!t||!_(t.operator))return!1;const i=t.operator.toLowerCase(),r=t.attributeValue;return i==="exists"?e!==null:e==null?!1:i==="equals"?String(e)===String(r):i==="contains"?String(e).indexOf(String(r))!==-1:!1}doesEventMatchRule(t,e){if(!e||!_(e.eventAttributeKey))return!1;const i=e.conditions;if(!Array.isArray(i))return!1;const r=this.getEventAttributeValue(t,e.eventAttributeKey);if(i.length===0)return r!==null;for(let s=0;s<i.length;s++)if(!this.doesEventAttributeConditionMatch(i[s],r))return!1;return!0}applyPlacementEventAttributeMapping(t){const e=Object.keys(this.placementEventAttributeMappingLookup);for(let i=0;i<e.length;i++){const r=e[i],s=this.placementEventAttributeMappingLookup[r];if(E(s))continue;let a=!0;for(let u=0;u<s.length;u++)if(!this.doesEventMatchRule(t,s[u])){a=!1;break}a&&o().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!o().Rokt||typeof o().Rokt.getLocalSessionAttributes!="function"?{}:E(this.placementEventMappingLookup)&&E(this.placementEventAttributeMappingLookup)?{}:o().Rokt.getLocalSessionAttributes()}replaceOtherIdentityWithEmailsha256(t){const e={...t||{}},i=this._mappedEmailSha256Key;return i&&t[i]&&(e[h.EMAIL_SHA256_KEY]=t[i]),i&&delete e[i],e}logSelectPlacementsEvent(t){if(!window.mParticle||typeof o().logEvent!="function"||!k(t))return;const e=o().EventType.Other;o().logEvent(H,e,t)}buildIdentityEvent(t,e){const i=e.getMPID(),r=o()&&o().sessionManager&&typeof o().sessionManager.getSession=="function"?o().sessionManager.getSession():null,s=e.getUserIdentities&&typeof e.getUserIdentities=="function"?e.getUserIdentities().userIdentities:null;return{EventName:t,EventDataType:14,EventCategory:0,Timestamp:Date.now(),MPID:i,SessionId:r,UserIdentities:s}}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: "+c):(this.batchQueue.push(t),"Batch queued for forwarder: "+c)}sendBatchStream(t){if(window.Rokt&&typeof window.Rokt.__batch_stream__=="function"){if(this.batchStreamQueue.length){const e=this.batchStreamQueue;this.batchStreamQueue=[];for(let i=0;i<e.length;i++)window.Rokt.__batch_stream__(e[i])}window.Rokt.__batch_stream__(t)}else this.batchStreamQueue.push(t)}setRoktSessionId(t){if(!(!t||typeof t!="string"))try{const e=o().getInstance();e&&typeof e.setIntegrationAttribute=="function"&&e.setIntegrationAttribute(181,{roktSessionId:t})}catch{}}attachLauncher(t,e){const i=o()&&o().sessionManager&&typeof o().sessionManager.getSession=="function"?o().sessionManager.getSession():void 0,r={accountId:t,...e||{},...i?{mpSessionId:i}:{}};if(this.isPartnerInLocalLauncherTestGroup()){const s=window.Rokt.createLocalLauncher(r);this.initRoktLauncher(s)}else window.Rokt.createLauncher(r).then(s=>this.initRoktLauncher(s)).catch(s=>{console.error("Error creating Rokt launcher:",s)})}initRoktLauncher(t){window.Rokt&&(window.Rokt.currentLauncher=t),this.launcher=t;const e=o().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,D(this.domain,this.integrationName),o().Rokt.attachKit(this),this.drainBatchQueue()}fetchOptimizely(){const t=o()._getActiveForwarders().filter(e=>e.name==="Optimizely");try{if(t.length>0&&window.optimizely){const e=window.optimizely.get("state");return!e||!e.getActiveExperimentIds?{}:e.getActiveExperimentIds().reduce((s,a)=>(s["rokt.custom.optimizely.experiment."+a+".variationId"]=e.getVariationMap()[a].id,s),{})}}catch(e){console.error("Error fetching Optimizely attributes:",e)}return{}}isKitReady(){return!!(this.isInitialized&&this.launcher)}isPartnerInLocalLauncherTestGroup(){return!!(o().config&&o().config.isLocalLauncherEnabled&&this.isAssignedToSampleGroup())}isAssignedToSampleGroup(){return Math.random()>.5}captureTiming(t){window&&o()&&o().captureTiming&&t&&o().captureTiming(t)}init(t,e,i,r,s){const a=t,u=a.accountId,l=T(a.roktExtensions);this.userAttributes=s||{},this._onboardingExpProvider=a.onboardingExpProvider;const f=A(a.placementEventMapping);this.placementEventMappingLookup=M(f);const O=A(a.placementEventAttributeMapping);this.placementEventAttributeMappingLookup=P(O),a.hashedEmailUserIdentityType&&(this._mappedEmailSha256Key=a.hashedEmailUserIdentityType.toLowerCase());const b=o().Rokt?.domain,p={...o().Rokt?.launcherOptions||{}};this.integrationName=V(p.integrationName),p.integrationName=this.integrationName,this.domain=b;const v={loggingUrl:a.loggingUrl,errorUrl:a.errorUrl,isLoggingEnabled:a.isLoggingEnabled==="true"||a.isLoggingEnabled===!0},m=new j(v,this.integrationName,window.__rokt_li_guid__,a.accountId),w=new G(v,m,this.integrationName,window.__rokt_li_guid__,a.accountId);if(this.errorReportingService=m,this.loggingService=w,o()._registerErrorReportingService&&o()._registerErrorReportingService(m),o()._registerLoggingService&&o()._registerLoggingService(w),i)return this.testHelpers={generateLauncherScript:U,extractRoktExtensions:T,hashEventMessage:C,parseSettingsString:A,generateMappedEventLookup:M,generateMappedEventAttributeLookup:P,sendAdBlockMeasurementSignals:D,createAutoRemovedIframe:L,djb2:K,setAllowedOriginHashes:y=>{h._allowedOriginHashes=y},ReportingTransport:N,ErrorReportingService:j,LoggingService:G,RateLimiter:x,ErrorCodes:S,WSDKErrorSeverity:R},this.attachLauncher(u,p),"Successfully initialized: "+c;if(this.isLauncherReadyToAttach())this.attachLauncher(u,p);else{const y=document.head||document.body,d=document.createElement("script");d.type="text/javascript",d.src=U(b,l),d.async=!0,d.crossOrigin="anonymous",d.fetchPriority="high",d.id="rokt-launcher",d.onload=()=>{this.isLauncherReadyToAttach()?this.attachLauncher(u,p):console.error("Rokt object is not available after script load.")},d.onerror=$=>{console.error("Error loading Rokt launcher script:",$)},y.appendChild(d),this.captureTiming(h.PERFORMANCE_MARKS.RoktScriptAppended)}return"Successfully initialized: "+c}process(t){if(!this.isKitReady())return"Kit not ready for forwarder: "+c;if(typeof o().Rokt?.setLocalSessionAttribute=="function"&&(E(this.placementEventAttributeMappingLookup)||this.applyPlacementEventAttributeMapping(t),!E(this.placementEventMappingLookup))){const e=C(t.EventDataType,t.EventCategory,t.EventName??"");this.placementEventMappingLookup[String(e)]&&o().Rokt.setLocalSessionAttribute?.(this.placementEventMappingLookup[String(e)],!0)}return"Successfully sent to forwarder: "+c}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: "+c}removeUserAttribute(t){return delete this.userAttributes[t],"Successfully removed user attribute for forwarder: "+c}onUserIdentified(t){const e=t;return this.filters.filteredUser=e,this.userAttributes=t.getAllUserAttributes(),this.pendingIdentityEvents.push(this.buildIdentityEvent("identify",e)),"Successfully called onUserIdentified for forwarder: "+c}onLoginComplete(t,e){const i=t;return this.userAttributes=t.getAllUserAttributes(),this.pendingIdentityEvents.push(this.buildIdentityEvent("login",i)),"Successfully called onLoginComplete for forwarder: "+c}onLogoutComplete(t,e){const i=t;return this.userAttributes=t.getAllUserAttributes(),this.pendingIdentityEvents.push(this.buildIdentityEvent("logout",i)),"Successfully called onLogoutComplete for forwarder: "+c}onModifyComplete(t,e){const i=t;return this.userAttributes=t.getAllUserAttributes(),this.pendingIdentityEvents.push(this.buildIdentityEvent("modify",i)),"Successfully called onModifyComplete for forwarder: "+c}selectPlacements(t){const e=t&&t.attributes||{},i={...this.userAttributes,...e},r=this.filters||{},s=r.userAttributeFilters||[],a=r.filteredUser||null,u=a?a.getMPID():null;let l;r?r.filterUserAttributes?l=r.filterUserAttributes(i,s):l=i:(console.warn("Rokt Kit: No filters available, using user attributes"),l=i),this.userAttributes=l;const f=this._onboardingExpProvider==="Optimizely"?this.fetchOptimizely():{},O=this.returnUserIdentities(a),b=this.returnLocalSessionAttributes(),p={...O,...l,...f,...b,mpid:u},v={...t,attributes:p},m=this.launcher.selectPlacements(v),w=()=>this.logSelectPlacementsEvent(p);return Promise.resolve(m).then(y=>y?.context?.sessionId?.then(d=>this.setRoktSessionId(d))).catch(()=>{}).finally(w),m}hashAttributes(t){return this.isKitReady()?this.launcher.hashAttributes(t):(console.error("Rokt Kit: Not initialized"),null)}use(t){return this.isKitReady()?!t||!_(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")))}};h._allowedOriginHashes=[-553112570,549508659],h.PERFORMANCE_MARKS={RoktScriptAppended:"mp:RoktScriptAppended"},h.EMAIL_SHA256_KEY="emailsha256";let g=h;function X(){return 181}function Z(n){if(!n){window.console.log("You must pass a config object to register the kit "+c);return}if(!k(n)){window.console.log("'config' must be an object. You passed in a "+typeof n);return}k(n.kits)?n.kits[c]={constructor:g}:(n.kits={},n.kits[c]={constructor:g}),window.console.log("Successfully registered "+c+" to your mParticle configuration")}return typeof window<"u"&&window.mParticle&&o().addForwarder&&o().addForwarder({name:c,constructor:g,getId:X}),I.register=Z,Object.defineProperty(I,Symbol.toStringTag,{value:"Module"}),I})({});
2
2
  //# sourceMappingURL=Rokt-Kit.iife.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mparticle/web-rokt-kit",
3
- "version": "1.23.0",
3
+ "version": "1.24.0",
4
4
  "description": "mParticle integration kit for Rokt",
5
5
  "main": "dist/Rokt-Kit.common.js",
6
6
  "module": "dist/Rokt-Kit.esm.js",
@@ -36,6 +36,7 @@
36
36
  "devDependencies": {
37
37
  "@eslint/js": "^9.23.0",
38
38
  "@eslint/eslintrc": "^3.3.1",
39
+ "@mparticle/event-models": "^1.1.9",
39
40
  "@semantic-release/changelog": "^6.0.3",
40
41
  "@semantic-release/exec": "^6.0.3",
41
42
  "@semantic-release/git": "^10.0.1",
@@ -56,7 +57,7 @@
56
57
  "vitest": "^4.0.0"
57
58
  },
58
59
  "dependencies": {
59
- "@mparticle/web-sdk": "^2.56.0"
60
+ "@mparticle/web-sdk": "^2.62.0"
60
61
  },
61
62
  "license": "Apache-2.0"
62
63
  }