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