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