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