@mparticle/web-rokt-kit 1.26.0 → 1.26.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Rokt-Kit.common.js +1 -1
- package/dist/Rokt-Kit.esm.js +13 -13
- 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 l="Rokt",S=181,Q="selectPlacements",B="apps.roktecommerce.com",V=.1,w={LOGIN:"login",LOGOUT:"logout",MODIFY_USER:"modify_user",IDENTIFY:"identify"},q="ThankYouPageJourney",J="rokt-launcher",X="rokt-thank-you-element",$="userIdentifiedInWorkspace",Z=500,N={UNKNOWN_ERROR:"UNKNOWN_ERROR",UNHANDLED_EXCEPTION:"UNHANDLED_EXCEPTION",IDENTITY_REQUEST:"IDENTITY_REQUEST"},v={ERROR:"ERROR",INFO:"INFO",WARNING:"WARNING"},ee="apps.rokt-api.com/v1/log",te="apps.rokt-api.com/v1/errors",ie=10;function a(){return window.mParticle}function U(n,e){const i=[G(n),"/wsdk/integrations/launcher.js"].join("");return!e||e.length===0?i:i+"?extensions="+e.join(",")}function C(n){return[G(n),"/rokt-elements/rokt-element-thank-you.js"].join("")}function G(n){return["https://",typeof n<"u"?n:"apps.rokt-api.com"].join("")}function M(n,e,t){if(document.getElementById(n))return;const i=document.head||document.body,r=document.createElement("script");r.id=n,r.type="text/javascript",r.src=e,r.async=!0,r.crossOrigin="anonymous",r.fetchPriority="high",t?.onLoad&&(r.onload=t.onLoad),t?.onError&&(r.onerror=t.onError),i.appendChild(r)}function O(n){return n!=null&&typeof n=="object"&&Array.isArray(n)===!1}function A(n){if(!n)return[];try{return JSON.parse(n.replace(/"/g,'"'))}catch{console.error("Settings string contains invalid JSON")}return[]}function K(n){const e=n?A(n):[],t=[],i=[];let r=!1;for(let o=0;o<e.length;o++){const s=e[o].value;s==="thank-you-journey"?(r=!0,i.push(q)):t.push(s)}return{roktExtensionsQueryParams:t,legacyRoktExtensions:i,loadThankYouElement:r}}async function ne(n,e){const t=[];if(e)for(const i of n)t.push(e.use(i));return Promise.all(t)}function D(n){if(!n)return{};const e={};for(let t=0;t<n.length;t++){const i=n[t];e[i.jsmap]=i.value}return e}function x(n){const e={};if(!Array.isArray(n))return e;for(let t=0;t<n.length;t++){const i=n[t];if(!i||!g(i.value)||!g(i.map))continue;const r=i.value,o=i.map;e[r]||(e[r]=[]),e[r].push({eventAttributeKey:o,conditions:Array.isArray(i.conditions)?i.conditions:[]})}return e}function Y(n,e,t){return a().generateHash([n,e,t].join(""))}function k(n){return n==null?!0:typeof n=="object"?Object.keys(n).length===0:Array.isArray(n)?n.length===0:!1}function g(n){return typeof n=="string"}function re(n){let i="mParticle_wsdkv_"+a().getVersion()+"_kitv_"+"1.26.0";return n&&(i+="_"+n),i}function W(n){let e=5381;for(let t=0;t<n.length;t++)e=(e<<5)+e+n.charCodeAt(t),e=e&e;return e}function T(n){const e=document.createElement("iframe");e.style.display="none",e.setAttribute("sandbox","allow-scripts allow-same-origin"),e.src=n,e.onload=function(){e.onload=null,e.parentNode&&e.parentNode.removeChild(e)};const t=document.body||document.head;t&&t.appendChild(e)}function F(n,e){const t=W(window.location.origin);if(f._allowedOriginHashes.indexOf(t)===-1||Math.random()>=V)return;const r=window.__rokt_li_guid__;if(!r)return;const o=window.location.href.split("?")[0].split("#")[0],s="version="+encodeURIComponent(e??"")+"&launcherInstanceGuid="+encodeURIComponent(r)+"&pageUrl="+encodeURIComponent(o);T("https://"+(n||"apps.rokt.com")+"/v1/wsdk-init/index.html?"+s),T("https://"+B+"/v1/wsdk-init/index.html?"+s+"&isControl=true")}function se(){return typeof window<"u"&&!!window.ROKT_DOMAIN}function oe(){return typeof window<"u"&&!!window.location?.search?.toLowerCase().includes("mp_enable_logging=true")}function ae(){return typeof window<"u"?window.location?.href:void 0}function ce(){return typeof window<"u"?window.navigator?.userAgent:void 0}class z{constructor(){this._logCount={}}incrementAndCheck(e){const i=(this._logCount[e]||0)+1;return this._logCount[e]=i,i>ie}}class P{constructor(e,t,i,r,o){this._reporter="mp-wsdk";const s=e?.isLoggingEnabled===!0||e?.isLoggingEnabled==="true";this._integrationName=t||"",this._launcherInstanceGuid=i,this._accountId=r||null,this._rateLimiter=o||new z,this._isEnabled=oe()||se()&&s}send(e,t,i,r,o,s){if(!(!this._isEnabled||this._rateLimiter.incrementAndCheck(t)))try{const c={additionalInformation:{message:i,version:this._integrationName},severity:t,code:r||N.UNKNOWN_ERROR,url:ae(),deviceInfo:ce(),stackTrace:o,reporter:this._reporter,integration:this._integrationName},u={Accept:"text/plain;charset=UTF-8","Content-Type":"application/json","rokt-launcher-version":this._integrationName,"rokt-wsdk-version":"joint"};this._launcherInstanceGuid&&(u["rokt-launcher-instance-guid"]=this._launcherInstanceGuid),this._accountId&&(u["rokt-account-id"]=this._accountId),fetch(e,{method:"POST",headers:u,body:JSON.stringify(c)}).catch(d=>{console.error("ReportingTransport: Failed to send log",d),s&&s(d)})}catch(c){console.error("ReportingTransport: Failed to send log",c),s&&s(c)}}}class j{constructor(e,t,i,r,o){this._transport=new P(e,t,i,r,o),this._errorUrl="https://"+(e?.errorUrl||te)}report(e){if(!e)return;const t=e.severity||v.ERROR;this._transport.send(this._errorUrl,t,e.message,e.code,e.stackTrace)}}class H{constructor(e,t,i,r,o,s){this._transport=new P(e,i,r,o,s),this._loggingUrl="https://"+(e?.loggingUrl||ee),this._errorReportingService=t}log(e){e&&this._transport.send(this._loggingUrl,v.INFO,e.message,e.code,void 0,t=>{this._errorReportingService&&this._errorReportingService.report({message:"LoggingService: Failed to send log: "+t.message,code:N.UNKNOWN_ERROR,severity:v.ERROR})})}}const p=class p{constructor(){this.name=l,this.id=S,this.moduleId=S,this.isInitialized=!1,this.launcher=null,this.filters={},this.userAttributes={},this.userIdentifiedInWorkspace=!1,this.testHelpers=null,this.placementEventMappingLookup={},this.placementEventAttributeMappingLookup={},this.batchQueue=[],this.batchStreamQueue=[],this.pendingIdentityEvents=[],this.integrationName=null,this.errorReportingService=null,this.loggingService=null,this._thankYouElementOnLoadCallback=null,this._isThankYouElementLoaded=!1,this._workspaceSearchInFlightPromise=null}getEventAttributeValue(e,t){const i=e&&e.EventAttributes;return!i||typeof i[t]>"u"?null:i[t]}doesEventAttributeConditionMatch(e,t){if(!e||!g(e.operator))return!1;const i=e.operator.toLowerCase(),r=e.attributeValue;return i==="exists"?t!==null:t==null?!1:i==="equals"?String(t)===String(r):i==="contains"?String(t).indexOf(String(r))!==-1:!1}doesEventMatchRule(e,t){if(!t||!g(t.eventAttributeKey))return!1;const i=t.conditions;if(!Array.isArray(i))return!1;const r=this.getEventAttributeValue(e,t.eventAttributeKey);if(i.length===0)return r!==null;for(let o=0;o<i.length;o++)if(!this.doesEventAttributeConditionMatch(i[o],r))return!1;return!0}applyPlacementEventAttributeMapping(e){const t=Object.keys(this.placementEventAttributeMappingLookup);for(let i=0;i<t.length;i++){const r=t[i],o=this.placementEventAttributeMappingLookup[r];if(k(o))continue;let s=!0;for(let c=0;c<o.length;c++)if(!this.doesEventMatchRule(e,o[c])){s=!1;break}s&&a().Rokt.setLocalSessionAttribute?.(r,!0)}}isLauncherReadyToAttach(){return!!window.Rokt&&typeof window.Rokt.createLauncher=="function"}returnUserIdentities(e){if(!e||!e.getUserIdentities)return{};const t=e.getUserIdentities().userIdentities;return this.replaceOtherIdentityWithEmailsha256(t)}returnLocalSessionAttributes(){return!a().Rokt||typeof a().Rokt.getLocalSessionAttributes!="function"?{}:k(this.placementEventMappingLookup)&&k(this.placementEventAttributeMappingLookup)?{}:a().Rokt.getLocalSessionAttributes()}replaceOtherIdentityWithEmailsha256(e){const t={...e||{}},i=this._mappedEmailSha256Key;return i&&e[i]&&(t[p.EMAIL_SHA256_KEY]=e[i]),i&&delete t[i],t}logSelectPlacementsEvent(e){if(!window.mParticle||typeof a().logEvent!="function"||!O(e))return;const t=a().EventType.Other;a().logEvent(Q,t,e)}buildIdentityEvent(e,t){const i=t.getMPID(),r=a()&&a().sessionManager&&typeof a().sessionManager.getSession=="function"?a().sessionManager.getSession():void 0;return{event_type:e,data:{timestamp_unixtime_ms:Date.now(),session_uuid:r??void 0,mpid:i}}}mergePendingIdentityEvents(e){if(this.pendingIdentityEvents.length===0)return e;const t={...e,events:[...e.events??[],...this.pendingIdentityEvents]};return this.pendingIdentityEvents=[],t}drainBatchQueue(){this.batchQueue.forEach(e=>{this.processBatch(e)}),this.batchQueue=[]}processBatch(e){return this.isKitReady()?(this.sendBatchStream(this.mergePendingIdentityEvents(e)),"Successfully sent batch to forwarder: "+l):(this.batchQueue.push(e),"Batch queued for forwarder: "+l)}sendBatchStream(e){if(window.Rokt&&typeof window.Rokt.__batch_stream__=="function"){if(this.batchStreamQueue.length){const t=this.batchStreamQueue;this.batchStreamQueue=[];for(let i=0;i<t.length;i++)window.Rokt.__batch_stream__(t[i])}window.Rokt.__batch_stream__(e)}else this.batchStreamQueue.push(e)}setRoktSessionId(e){if(!(!e||typeof e!="string"))try{const t=a().getInstance();t&&typeof t.setIntegrationAttribute=="function"&&t.setIntegrationAttribute(S,{roktSessionId:e})}catch{}}attachLauncher(e,t,i=[]){const r=a()&&a().sessionManager&&typeof a().sessionManager.getSession=="function"?a().sessionManager.getSession():void 0,o={accountId:e,...t||{},...r?{mpSessionId:r}:{}};let s;this.isPartnerInLocalLauncherTestGroup()?s=Promise.resolve(window.Rokt.createLocalLauncher(o)):s=window.Rokt.createLauncher(o),s.then(async c=>{await ne(i,c),this.initRoktLauncher(c)}).catch(c=>{console.error("Error creating Rokt launcher:",c)})}initRoktLauncher(e){window.Rokt&&(window.Rokt.currentLauncher=e),this.launcher=e;const t=a().Rokt?.filters;t?(this.filters=t,t.filteredUser||console.warn("Rokt Kit: No filtered user has been set.")):console.warn("Rokt Kit: No filters have been set."),this.isInitialized=!0,F(this.domain,this.integrationName),a().Rokt.attachKit(this),this.drainBatchQueue()}fetchOptimizely(){const e=a()._getActiveForwarders().filter(t=>t.name==="Optimizely");try{if(e.length>0&&window.optimizely){const t=window.optimizely.get("state");return!t||!t.getActiveExperimentIds?{}:t.getActiveExperimentIds().reduce((o,s)=>(o["rokt.custom.optimizely.experiment."+s+".variationId"]=t.getVariationMap()[s].id,o),{})}}catch(t){console.error("Error fetching Optimizely attributes:",t)}return{}}isKitReady(){return!!(this.isInitialized&&this.launcher)}isPartnerInLocalLauncherTestGroup(){return!!(a().config&&a().config.isLocalLauncherEnabled&&this.isAssignedToSampleGroup())}isAssignedToSampleGroup(){return Math.random()>.5}captureTiming(e){window&&a()&&a().captureTiming&&e&&a().captureTiming(e)}init(e,t,i,r,o){const s=e,c=s.accountId;this.userAttributes=o||{},this._onboardingExpProvider=s.onboardingExpProvider;const u=A(s.placementEventMapping);this.placementEventMappingLookup=D(u);const d=A(s.placementEventAttributeMapping);this.placementEventAttributeMappingLookup=x(d),s.hashedEmailUserIdentityType&&(this._mappedEmailSha256Key=s.hashedEmailUserIdentityType.toLowerCase()),this._workspaceIdSyncApiKey=g(s.workspaceIdSyncApiKey)?s.workspaceIdSyncApiKey:void 0;const m=a().Rokt?.domain,{roktExtensionsQueryParams:b,legacyRoktExtensions:E,loadThankYouElement:L}=K(s.roktExtensions),h={...a().Rokt?.launcherOptions||{}};this.integrationName=re(h.integrationName),h.integrationName=this.integrationName,this.domain=m;const I={loggingUrl:s.loggingUrl,errorUrl:s.errorUrl,isLoggingEnabled:s.isLoggingEnabled==="true"||s.isLoggingEnabled===!0},_=new j(I,this.integrationName,window.__rokt_li_guid__,s.accountId),R=new H(I,_,this.integrationName,window.__rokt_li_guid__,s.accountId);return this.errorReportingService=_,this.loggingService=R,a()._registerErrorReportingService&&a()._registerErrorReportingService(_),a()._registerLoggingService&&a()._registerLoggingService(R),i?(this.testHelpers={generateLauncherScript:U,generateThankYouElementScript:C,extractRoktExtensionConfig:K,hashEventMessage:Y,parseSettingsString:A,generateMappedEventLookup:D,generateMappedEventAttributeLookup:x,sendAdBlockMeasurementSignals:F,createAutoRemovedIframe:T,djb2:W,setAllowedOriginHashes:y=>{p._allowedOriginHashes=y},ReportingTransport:P,ErrorReportingService:j,LoggingService:H,RateLimiter:z,ErrorCodes:N,WSDKErrorSeverity:v},this.attachLauncher(c,h),"Successfully initialized: "+l):(L&&(a().Rokt.flushOnShoppableAdsReadyMessageQueue?.(this),M(X,C(m),{onLoad:()=>{this._isThankYouElementLoaded=!0,this._thankYouElementOnLoadCallback&&this._thankYouElementOnLoadCallback()},onError:y=>{console.error("Error loading Rokt Thank You Element script:",y)}})),this.isLauncherReadyToAttach()?this.attachLauncher(c,h,E):(M(J,U(m,b),{onLoad:()=>{this.isLauncherReadyToAttach()?this.attachLauncher(c,h,E):console.error("Rokt object is not available after script load.")},onError:y=>{console.error("Error loading Rokt launcher script:",y)}}),this.captureTiming(p.PERFORMANCE_MARKS.RoktScriptAppended)),"Successfully initialized: "+l)}process(e){if(!this.isKitReady())return"Kit not ready for forwarder: "+l;if(typeof a().Rokt?.setLocalSessionAttribute=="function"&&(k(this.placementEventAttributeMappingLookup)||this.applyPlacementEventAttributeMapping(e),!k(this.placementEventMappingLookup))){const t=Y(e.EventDataType,e.EventCategory,e.EventName??"");this.placementEventMappingLookup[String(t)]&&a().Rokt.setLocalSessionAttribute?.(this.placementEventMappingLookup[String(t)],!0)}return"Successfully sent to forwarder: "+l}setExtensionData(e){if(!this.isKitReady()){console.error("Rokt Kit: Not initialized");return}window.Rokt.setExtensionData(e)}setUserAttribute(e,t){return this.userAttributes[e]=t,"Successfully set user attribute for forwarder: "+l}removeUserAttribute(e){return delete this.userAttributes[e],"Successfully removed user attribute for forwarder: "+l}handleIdentityComplete(e,t,i){const r=e;return this.userAttributes=e.getAllUserAttributes(),this.pendingIdentityEvents.push(this.buildIdentityEvent(t,r)),"Successfully called "+i+" for forwarder: "+l}onUserIdentified(e){const t=e;return this.filters.filteredUser=t,this._workspaceSearchInFlightPromise=this.search(t),this.handleIdentityComplete(e,w.IDENTIFY,"onUserIdentified")}search(e){const t=this._workspaceIdSyncApiKey;if(!t)return this.userIdentifiedInWorkspace=!1,this._workspaceLastSearchedIdentitiesKey=void 0,Promise.resolve();const i=a().Identity?.search;if(typeof i!="function")return this.userIdentifiedInWorkspace=!1,this._workspaceLastSearchedIdentitiesKey=void 0,Promise.resolve();const r=e.getUserIdentities?e.getUserIdentities().userIdentities:null,o={};if(r)for(const u of Object.keys(r)){const d=r[u];g(d)&&d.length>0&&(o[u]=d)}const s=Object.keys(o);if(s.length===0)return this.userIdentifiedInWorkspace=!1,this._workspaceLastSearchedIdentitiesKey=void 0,Promise.resolve();const c=s.sort().map(u=>`${u}=${o[u]}`).join("&");return c===this._workspaceLastSearchedIdentitiesKey?Promise.resolve():(this.userIdentifiedInWorkspace=!1,this._workspaceLastSearchedIdentitiesKey=c,new Promise(u=>{try{i(t,o,d=>{d?.httpCode===200&&(this.userIdentifiedInWorkspace=!0),u()})}catch(d){console.error("Rokt Kit: Workspace IDSync search failed",d),this._workspaceLastSearchedIdentitiesKey=void 0,u()}}))}onLoginComplete(e,t){return this.handleIdentityComplete(e,w.LOGIN,"onLoginComplete")}onLogoutComplete(e,t){return this.userIdentifiedInWorkspace=!1,this._workspaceSearchInFlightPromise=null,this._workspaceLastSearchedIdentitiesKey=void 0,this.handleIdentityComplete(e,w.LOGOUT,"onLogoutComplete")}onModifyComplete(e,t){return this.handleIdentityComplete(e,w.MODIFY_USER,"onModifyComplete")}selectPlacements(e){if(this._workspaceSearchInFlightPromise){const t=this._workspaceSearchInFlightPromise;return Promise.race([t,new Promise(i=>setTimeout(i,Z))]).then(()=>this._dispatchPlacements(e))}return this._dispatchPlacements(e)}_dispatchPlacements(e){const t=e&&e.attributes||{},i={...this.userAttributes,...t},r=this.filters||{},o=r.userAttributeFilters||[],s=r.filteredUser||null,c=s?s.getMPID():null;let u;r?r.filterUserAttributes?u=r.filterUserAttributes(i,o):u=i:(console.warn("Rokt Kit: No filters available, using user attributes"),u=i),this.userAttributes=u;const d=this._onboardingExpProvider==="Optimizely"?this.fetchOptimizely():{},m=this.returnUserIdentities(s),b=this.returnLocalSessionAttributes(),E={...m,...u,...d,...b,...this.userIdentifiedInWorkspace?{[$]:!0}:{},mpid:c},L={...e,attributes:E},h=this.launcher.selectPlacements(L),I=()=>this.logSelectPlacementsEvent(E);return Promise.resolve(h).then(_=>_?.context?.sessionId?.then(R=>this.setRoktSessionId(R))).catch(()=>{}).finally(I),h}hashAttributes(e){return this.isKitReady()?this.launcher.hashAttributes(e):(console.error("Rokt Kit: Not initialized"),null)}use(e){return this.isKitReady()?!e||!g(e)?Promise.reject(new Error("Rokt Kit: Invalid extension name")):this.launcher.use(e):(console.error("Rokt Kit: Not initialized"),Promise.reject(new Error("Rokt Kit: Not initialized")))}onShoppableAdsReady(e){this._isThankYouElementLoaded?e():this._thankYouElementOnLoadCallback=e}};p._allowedOriginHashes=[-553112570,549508659],p.PERFORMANCE_MARKS={RoktScriptAppended:"mp:RoktScriptAppended"},p.EMAIL_SHA256_KEY="emailsha256";let f=p;function ue(){return S}function le(n){if(!n){window.console.log("You must pass a config object to register the kit "+l);return}if(!O(n)){window.console.log("'config' must be an object. You passed in a "+typeof n);return}O(n.kits)?n.kits[l]={constructor:f}:(n.kits={},n.kits[l]={constructor:f}),window.console.log("Successfully registered "+l+" to your mParticle configuration")}typeof window<"u"&&window.mParticle&&a().addForwarder&&a().addForwarder({name:l,constructor:f,getId:ue});exports.register=le;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l="Rokt",S=181,Q="selectPlacements",B="apps.roktecommerce.com",V=.1,w={LOGIN:"login",LOGOUT:"logout",MODIFY_USER:"modify_user",IDENTIFY:"identify"},q="ThankYouPageJourney",J="rokt-launcher",X="rokt-thank-you-element",$="userIdentifiedInWorkspace",Z=500,N={UNKNOWN_ERROR:"UNKNOWN_ERROR",UNHANDLED_EXCEPTION:"UNHANDLED_EXCEPTION",IDENTITY_REQUEST:"IDENTITY_REQUEST"},v={ERROR:"ERROR",INFO:"INFO",WARNING:"WARNING"},ee="apps.rokt-api.com/v1/log",te="apps.rokt-api.com/v1/errors",ie=10;function a(){return window.mParticle}function U(n,e){const i=[G(n),"/wsdk/integrations/launcher.js"].join("");return!e||e.length===0?i:i+"?extensions="+e.join(",")}function C(n){return[G(n),"/rokt-elements/rokt-element-thank-you.js"].join("")}function G(n){return["https://",typeof n<"u"?n:"apps.rokt-api.com"].join("")}function M(n,e,t){if(document.getElementById(n))return;const i=document.head||document.body,r=document.createElement("script");r.id=n,r.type="text/javascript",r.src=e,r.async=!0,r.crossOrigin="anonymous",r.fetchPriority="high",t?.onLoad&&(r.onload=t.onLoad),t?.onError&&(r.onerror=t.onError),i.appendChild(r)}function O(n){return n!=null&&typeof n=="object"&&Array.isArray(n)===!1}function A(n){if(!n)return[];try{return JSON.parse(n.replace(/"/g,'"'))}catch{console.error("Settings string contains invalid JSON")}return[]}function K(n){const e=n?A(n):[],t=[],i=[];let r=!1;for(let o=0;o<e.length;o++){const s=e[o].value;s==="thank-you-journey"?(r=!0,i.push(q)):t.push(s)}return{roktExtensionsQueryParams:t,legacyRoktExtensions:i,loadThankYouElement:r}}async function ne(n,e){const t=[];if(e)for(const i of n)t.push(e.use(i));return Promise.all(t)}function D(n){if(!n)return{};const e={};for(let t=0;t<n.length;t++){const i=n[t];e[i.jsmap]=i.value}return e}function x(n){const e={};if(!Array.isArray(n))return e;for(let t=0;t<n.length;t++){const i=n[t];if(!i||!g(i.value)||!g(i.map))continue;const r=i.value,o=i.map;e[r]||(e[r]=[]),e[r].push({eventAttributeKey:o,conditions:Array.isArray(i.conditions)?i.conditions:[]})}return e}function Y(n,e,t){return a().generateHash([n,e,t].join(""))}function k(n){return n==null?!0:typeof n=="object"?Object.keys(n).length===0:Array.isArray(n)?n.length===0:!1}function g(n){return typeof n=="string"}function re(n){let i="mParticle_wsdkv_"+a().getVersion()+"_kitv_"+"1.26.1";return n&&(i+="_"+n),i}function W(n){let e=5381;for(let t=0;t<n.length;t++)e=(e<<5)+e+n.charCodeAt(t),e=e&e;return e}function T(n){const e=document.createElement("iframe");e.style.display="none",e.setAttribute("sandbox","allow-scripts allow-same-origin"),e.src=n,e.onload=function(){e.onload=null,e.parentNode&&e.parentNode.removeChild(e)};const t=document.body||document.head;t&&t.appendChild(e)}function F(n,e){const t=W(window.location.origin);if(f._allowedOriginHashes.indexOf(t)===-1||Math.random()>=V)return;const r=window.__rokt_li_guid__;if(!r)return;const o=window.location.href.split("?")[0].split("#")[0],s="version="+encodeURIComponent(e??"")+"&launcherInstanceGuid="+encodeURIComponent(r)+"&pageUrl="+encodeURIComponent(o);T("https://"+(n||"apps.rokt.com")+"/v1/wsdk-init/index.html?"+s),T("https://"+B+"/v1/wsdk-init/index.html?"+s+"&isControl=true")}function se(){return typeof window<"u"&&!!window.ROKT_DOMAIN}function oe(){return typeof window<"u"&&!!window.location?.search?.toLowerCase().includes("mp_enable_logging=true")}function ae(){return typeof window<"u"?window.location?.href:void 0}function ce(){return typeof window<"u"?window.navigator?.userAgent:void 0}class z{constructor(){this._logCount={}}incrementAndCheck(e){const i=(this._logCount[e]||0)+1;return this._logCount[e]=i,i>ie}}class P{constructor(e,t,i,r,o){this._reporter="mp-wsdk";const s=e?.isLoggingEnabled===!0||e?.isLoggingEnabled==="true";this._integrationName=t||"",this._launcherInstanceGuid=i,this._accountId=r||null,this._rateLimiter=o||new z,this._isEnabled=oe()||se()&&s}send(e,t,i,r,o,s){if(!(!this._isEnabled||this._rateLimiter.incrementAndCheck(t)))try{const c={additionalInformation:{message:i,version:this._integrationName},severity:t,code:r||N.UNKNOWN_ERROR,url:ae(),deviceInfo:ce(),stackTrace:o,reporter:this._reporter,integration:this._integrationName},u={Accept:"text/plain;charset=UTF-8","Content-Type":"application/json","rokt-launcher-version":this._integrationName,"rokt-wsdk-version":"joint"};this._launcherInstanceGuid&&(u["rokt-launcher-instance-guid"]=this._launcherInstanceGuid),this._accountId&&(u["rokt-account-id"]=this._accountId),fetch(e,{method:"POST",headers:u,body:JSON.stringify(c)}).catch(d=>{console.error("ReportingTransport: Failed to send log",d),s&&s(d)})}catch(c){console.error("ReportingTransport: Failed to send log",c),s&&s(c)}}}class j{constructor(e,t,i,r,o){this._transport=new P(e,t,i,r,o),this._errorUrl="https://"+(e?.errorUrl||te)}report(e){if(!e)return;const t=e.severity||v.ERROR;this._transport.send(this._errorUrl,t,e.message,e.code,e.stackTrace)}}class H{constructor(e,t,i,r,o,s){this._transport=new P(e,i,r,o,s),this._loggingUrl="https://"+(e?.loggingUrl||ee),this._errorReportingService=t}log(e){e&&this._transport.send(this._loggingUrl,v.INFO,e.message,e.code,void 0,t=>{this._errorReportingService&&this._errorReportingService.report({message:"LoggingService: Failed to send log: "+t.message,code:N.UNKNOWN_ERROR,severity:v.ERROR})})}}const p=class p{constructor(){this.name=l,this.id=S,this.moduleId=S,this.isInitialized=!1,this.launcher=null,this.filters={},this.userAttributes={},this.userIdentifiedInWorkspace=!1,this.testHelpers=null,this.placementEventMappingLookup={},this.placementEventAttributeMappingLookup={},this.batchQueue=[],this.batchStreamQueue=[],this.pendingIdentityEvents=[],this.integrationName=null,this.errorReportingService=null,this.loggingService=null,this._thankYouElementOnLoadCallback=null,this._isThankYouElementLoaded=!1,this._workspaceSearchInFlightPromise=null}getEventAttributeValue(e,t){const i=e&&e.EventAttributes;return!i||typeof i[t]>"u"?null:i[t]}doesEventAttributeConditionMatch(e,t){if(!e||!g(e.operator))return!1;const i=e.operator.toLowerCase(),r=e.attributeValue;return i==="exists"?t!==null:t==null?!1:i==="equals"?String(t)===String(r):i==="contains"?String(t).indexOf(String(r))!==-1:!1}doesEventMatchRule(e,t){if(!t||!g(t.eventAttributeKey))return!1;const i=t.conditions;if(!Array.isArray(i))return!1;const r=this.getEventAttributeValue(e,t.eventAttributeKey);if(i.length===0)return r!==null;for(let o=0;o<i.length;o++)if(!this.doesEventAttributeConditionMatch(i[o],r))return!1;return!0}applyPlacementEventAttributeMapping(e){const t=Object.keys(this.placementEventAttributeMappingLookup);for(let i=0;i<t.length;i++){const r=t[i],o=this.placementEventAttributeMappingLookup[r];if(k(o))continue;let s=!0;for(let c=0;c<o.length;c++)if(!this.doesEventMatchRule(e,o[c])){s=!1;break}s&&a().Rokt.setLocalSessionAttribute?.(r,!0)}}isLauncherReadyToAttach(){return!!window.Rokt&&typeof window.Rokt.createLauncher=="function"}returnUserIdentities(e){if(!e||!e.getUserIdentities)return{};const t=e.getUserIdentities().userIdentities;return this.replaceOtherIdentityWithEmailsha256(t)}returnLocalSessionAttributes(){return!a().Rokt||typeof a().Rokt.getLocalSessionAttributes!="function"?{}:k(this.placementEventMappingLookup)&&k(this.placementEventAttributeMappingLookup)?{}:a().Rokt.getLocalSessionAttributes()}replaceOtherIdentityWithEmailsha256(e){const t={...e||{}},i=this._mappedEmailSha256Key;return i&&e[i]&&(t[p.EMAIL_SHA256_KEY]=e[i]),i&&delete t[i],t}logSelectPlacementsEvent(e){if(!window.mParticle||typeof a().logEvent!="function"||!O(e))return;const t=a().EventType.Other;a().logEvent(Q,t,e)}buildIdentityEvent(e,t){const i=t.getMPID(),r=a()&&a().sessionManager&&typeof a().sessionManager.getSession=="function"?a().sessionManager.getSession():void 0;return{event_type:e,data:{timestamp_unixtime_ms:Date.now(),session_uuid:r??void 0,mpid:i}}}mergePendingIdentityEvents(e){if(this.pendingIdentityEvents.length===0)return e;const t={...e,events:[...e.events??[],...this.pendingIdentityEvents]};return this.pendingIdentityEvents=[],t}drainBatchQueue(){this.batchQueue.forEach(e=>{this.processBatch(e)}),this.batchQueue=[]}processBatch(e){return this.isKitReady()?(this.sendBatchStream(this.mergePendingIdentityEvents(e)),"Successfully sent batch to forwarder: "+l):(this.batchQueue.push(e),"Batch queued for forwarder: "+l)}sendBatchStream(e){if(window.Rokt&&typeof window.Rokt.__batch_stream__=="function"){if(this.batchStreamQueue.length){const t=this.batchStreamQueue;this.batchStreamQueue=[];for(let i=0;i<t.length;i++)window.Rokt.__batch_stream__(t[i])}window.Rokt.__batch_stream__(e)}else this.batchStreamQueue.push(e)}setRoktSessionId(e){if(!(!e||typeof e!="string"))try{const t=a().getInstance();t&&typeof t.setIntegrationAttribute=="function"&&t.setIntegrationAttribute(S,{roktSessionId:e})}catch{}}attachLauncher(e,t,i=[]){const r=a()&&a().sessionManager&&typeof a().sessionManager.getSession=="function"?a().sessionManager.getSession():void 0,o={accountId:e,...t||{},...r?{mpSessionId:r}:{}};let s;this.isPartnerInLocalLauncherTestGroup()?s=Promise.resolve(window.Rokt.createLocalLauncher(o)):s=window.Rokt.createLauncher(o),s.then(async c=>{await ne(i,c),this.initRoktLauncher(c)}).catch(c=>{console.error("Error creating Rokt launcher:",c)})}initRoktLauncher(e){window.Rokt&&(window.Rokt.currentLauncher=e),this.launcher=e;const t=a().Rokt?.filters;t?(this.filters=t,t.filteredUser?this._workspaceSearchInFlightPromise=this.search(t.filteredUser):console.warn("Rokt Kit: No filtered user has been set.")):console.warn("Rokt Kit: No filters have been set."),this.isInitialized=!0,F(this.domain,this.integrationName),a().Rokt.attachKit(this),this.drainBatchQueue()}fetchOptimizely(){const e=a()._getActiveForwarders().filter(t=>t.name==="Optimizely");try{if(e.length>0&&window.optimizely){const t=window.optimizely.get("state");return!t||!t.getActiveExperimentIds?{}:t.getActiveExperimentIds().reduce((o,s)=>(o["rokt.custom.optimizely.experiment."+s+".variationId"]=t.getVariationMap()[s].id,o),{})}}catch(t){console.error("Error fetching Optimizely attributes:",t)}return{}}isKitReady(){return!!(this.isInitialized&&this.launcher)}isPartnerInLocalLauncherTestGroup(){return!!(a().config&&a().config.isLocalLauncherEnabled&&this.isAssignedToSampleGroup())}isAssignedToSampleGroup(){return Math.random()>.5}captureTiming(e){window&&a()&&a().captureTiming&&e&&a().captureTiming(e)}init(e,t,i,r,o){const s=e,c=s.accountId;this.userAttributes=o||{},this._onboardingExpProvider=s.onboardingExpProvider;const u=A(s.placementEventMapping);this.placementEventMappingLookup=D(u);const d=A(s.placementEventAttributeMapping);this.placementEventAttributeMappingLookup=x(d),s.hashedEmailUserIdentityType&&(this._mappedEmailSha256Key=s.hashedEmailUserIdentityType.toLowerCase()),this._workspaceIdSyncApiKey=g(s.workspaceIdSyncApiKey)?s.workspaceIdSyncApiKey:void 0;const m=a().Rokt?.domain,{roktExtensionsQueryParams:b,legacyRoktExtensions:E,loadThankYouElement:L}=K(s.roktExtensions),h={...a().Rokt?.launcherOptions||{}};this.integrationName=re(h.integrationName),h.integrationName=this.integrationName,this.domain=m;const I={loggingUrl:s.loggingUrl,errorUrl:s.errorUrl,isLoggingEnabled:s.isLoggingEnabled==="true"||s.isLoggingEnabled===!0},_=new j(I,this.integrationName,window.__rokt_li_guid__,s.accountId),R=new H(I,_,this.integrationName,window.__rokt_li_guid__,s.accountId);return this.errorReportingService=_,this.loggingService=R,a()._registerErrorReportingService&&a()._registerErrorReportingService(_),a()._registerLoggingService&&a()._registerLoggingService(R),i?(this.testHelpers={generateLauncherScript:U,generateThankYouElementScript:C,extractRoktExtensionConfig:K,hashEventMessage:Y,parseSettingsString:A,generateMappedEventLookup:D,generateMappedEventAttributeLookup:x,sendAdBlockMeasurementSignals:F,createAutoRemovedIframe:T,djb2:W,setAllowedOriginHashes:y=>{p._allowedOriginHashes=y},ReportingTransport:P,ErrorReportingService:j,LoggingService:H,RateLimiter:z,ErrorCodes:N,WSDKErrorSeverity:v},this.attachLauncher(c,h),"Successfully initialized: "+l):(L&&(a().Rokt.flushOnShoppableAdsReadyMessageQueue?.(this),M(X,C(m),{onLoad:()=>{this._isThankYouElementLoaded=!0,this._thankYouElementOnLoadCallback&&this._thankYouElementOnLoadCallback()},onError:y=>{console.error("Error loading Rokt Thank You Element script:",y)}})),this.isLauncherReadyToAttach()?this.attachLauncher(c,h,E):(M(J,U(m,b),{onLoad:()=>{this.isLauncherReadyToAttach()?this.attachLauncher(c,h,E):console.error("Rokt object is not available after script load.")},onError:y=>{console.error("Error loading Rokt launcher script:",y)}}),this.captureTiming(p.PERFORMANCE_MARKS.RoktScriptAppended)),"Successfully initialized: "+l)}process(e){if(!this.isKitReady())return"Kit not ready for forwarder: "+l;if(typeof a().Rokt?.setLocalSessionAttribute=="function"&&(k(this.placementEventAttributeMappingLookup)||this.applyPlacementEventAttributeMapping(e),!k(this.placementEventMappingLookup))){const t=Y(e.EventDataType,e.EventCategory,e.EventName??"");this.placementEventMappingLookup[String(t)]&&a().Rokt.setLocalSessionAttribute?.(this.placementEventMappingLookup[String(t)],!0)}return"Successfully sent to forwarder: "+l}setExtensionData(e){if(!this.isKitReady()){console.error("Rokt Kit: Not initialized");return}window.Rokt.setExtensionData(e)}setUserAttribute(e,t){return this.userAttributes[e]=t,"Successfully set user attribute for forwarder: "+l}removeUserAttribute(e){return delete this.userAttributes[e],"Successfully removed user attribute for forwarder: "+l}handleIdentityComplete(e,t,i){const r=e;return this.userAttributes=e.getAllUserAttributes(),this.pendingIdentityEvents.push(this.buildIdentityEvent(t,r)),"Successfully called "+i+" for forwarder: "+l}onUserIdentified(e){const t=e;return this.filters.filteredUser=t,this._workspaceSearchInFlightPromise=this.search(t),this.handleIdentityComplete(e,w.IDENTIFY,"onUserIdentified")}search(e){const t=this._workspaceIdSyncApiKey;if(!t)return this.userIdentifiedInWorkspace=!1,this._workspaceLastSearchedIdentitiesKey=void 0,Promise.resolve();const i=a().Identity?.search;if(typeof i!="function")return this.userIdentifiedInWorkspace=!1,this._workspaceLastSearchedIdentitiesKey=void 0,Promise.resolve();const r=e.getUserIdentities?e.getUserIdentities().userIdentities:null,o={};if(r)for(const u of Object.keys(r)){const d=r[u];g(d)&&d.length>0&&(o[u]=d)}const s=Object.keys(o);if(s.length===0)return this.userIdentifiedInWorkspace=!1,this._workspaceLastSearchedIdentitiesKey=void 0,Promise.resolve();const c=s.sort().map(u=>`${u}=${o[u]}`).join("&");return c===this._workspaceLastSearchedIdentitiesKey?this._workspaceSearchInFlightPromise||Promise.resolve():(this.userIdentifiedInWorkspace=!1,this._workspaceLastSearchedIdentitiesKey=c,new Promise(u=>{try{i(t,o,d=>{d?.httpCode===200&&(this.userIdentifiedInWorkspace=!0),u()})}catch(d){console.error("Rokt Kit: Workspace IDSync search failed",d),this._workspaceLastSearchedIdentitiesKey=void 0,u()}}))}onLoginComplete(e,t){return this.handleIdentityComplete(e,w.LOGIN,"onLoginComplete")}onLogoutComplete(e,t){return this.userIdentifiedInWorkspace=!1,this._workspaceSearchInFlightPromise=null,this._workspaceLastSearchedIdentitiesKey=void 0,this.handleIdentityComplete(e,w.LOGOUT,"onLogoutComplete")}onModifyComplete(e,t){return this.handleIdentityComplete(e,w.MODIFY_USER,"onModifyComplete")}selectPlacements(e){if(this._workspaceSearchInFlightPromise){const t=this._workspaceSearchInFlightPromise;return Promise.race([t,new Promise(i=>setTimeout(i,Z))]).then(()=>this._dispatchPlacements(e))}return this._dispatchPlacements(e)}_dispatchPlacements(e){const t=e&&e.attributes||{},i={...this.userAttributes,...t},r=this.filters||{},o=r.userAttributeFilters||[],s=r.filteredUser||null,c=s?s.getMPID():null;let u;r?r.filterUserAttributes?u=r.filterUserAttributes(i,o):u=i:(console.warn("Rokt Kit: No filters available, using user attributes"),u=i),this.userAttributes=u;const d=this._onboardingExpProvider==="Optimizely"?this.fetchOptimizely():{},m=this.returnUserIdentities(s),b=this.returnLocalSessionAttributes(),E={...m,...u,...d,...b,...this.userIdentifiedInWorkspace?{[$]:!0}:{},mpid:c},L={...e,attributes:E},h=this.launcher.selectPlacements(L),I=()=>this.logSelectPlacementsEvent(E);return Promise.resolve(h).then(_=>_?.context?.sessionId?.then(R=>this.setRoktSessionId(R))).catch(()=>{}).finally(I),h}hashAttributes(e){return this.isKitReady()?this.launcher.hashAttributes(e):(console.error("Rokt Kit: Not initialized"),null)}use(e){return this.isKitReady()?!e||!g(e)?Promise.reject(new Error("Rokt Kit: Invalid extension name")):this.launcher.use(e):(console.error("Rokt Kit: Not initialized"),Promise.reject(new Error("Rokt Kit: Not initialized")))}onShoppableAdsReady(e){this._isThankYouElementLoaded?e():this._thankYouElementOnLoadCallback=e}};p._allowedOriginHashes=[-553112570,549508659],p.PERFORMANCE_MARKS={RoktScriptAppended:"mp:RoktScriptAppended"},p.EMAIL_SHA256_KEY="emailsha256";let f=p;function ue(){return S}function le(n){if(!n){window.console.log("You must pass a config object to register the kit "+l);return}if(!O(n)){window.console.log("'config' must be an object. You passed in a "+typeof n);return}O(n.kits)?n.kits[l]={constructor:f}:(n.kits={},n.kits[l]={constructor:f}),window.console.log("Successfully registered "+l+" to your mParticle configuration")}typeof window<"u"&&window.mParticle&&a().addForwarder&&a().addForwarder({name:l,constructor:f,getId:ue});exports.register=le;
|
|
2
2
|
//# sourceMappingURL=Rokt-Kit.common.js.map
|
package/dist/Rokt-Kit.esm.js
CHANGED
|
@@ -94,14 +94,14 @@ function D(n) {
|
|
|
94
94
|
function x(n, e, t) {
|
|
95
95
|
return a().generateHash([n, e, t].join(""));
|
|
96
96
|
}
|
|
97
|
-
function
|
|
97
|
+
function y(n) {
|
|
98
98
|
return n == null ? !0 : typeof n == "object" ? Object.keys(n).length === 0 : Array.isArray(n) ? n.length === 0 : !1;
|
|
99
99
|
}
|
|
100
100
|
function g(n) {
|
|
101
101
|
return typeof n == "string";
|
|
102
102
|
}
|
|
103
103
|
function ie(n) {
|
|
104
|
-
let i = "mParticle_wsdkv_" + a().getVersion() + "_kitv_" + "1.26.
|
|
104
|
+
let i = "mParticle_wsdkv_" + a().getVersion() + "_kitv_" + "1.26.1";
|
|
105
105
|
return n && (i += "_" + n), i;
|
|
106
106
|
}
|
|
107
107
|
function H(n) {
|
|
@@ -254,7 +254,7 @@ const p = class p {
|
|
|
254
254
|
const t = Object.keys(this.placementEventAttributeMappingLookup);
|
|
255
255
|
for (let i = 0; i < t.length; i++) {
|
|
256
256
|
const r = t[i], o = this.placementEventAttributeMappingLookup[r];
|
|
257
|
-
if (
|
|
257
|
+
if (y(o))
|
|
258
258
|
continue;
|
|
259
259
|
let s = !0;
|
|
260
260
|
for (let c = 0; c < o.length; c++)
|
|
@@ -278,7 +278,7 @@ const p = class p {
|
|
|
278
278
|
return this.replaceOtherIdentityWithEmailsha256(t);
|
|
279
279
|
}
|
|
280
280
|
returnLocalSessionAttributes() {
|
|
281
|
-
return !a().Rokt || typeof a().Rokt.getLocalSessionAttributes != "function" ? {} :
|
|
281
|
+
return !a().Rokt || typeof a().Rokt.getLocalSessionAttributes != "function" ? {} : y(this.placementEventMappingLookup) && y(this.placementEventAttributeMappingLookup) ? {} : a().Rokt.getLocalSessionAttributes();
|
|
282
282
|
}
|
|
283
283
|
replaceOtherIdentityWithEmailsha256(e) {
|
|
284
284
|
const t = { ...e || {} }, i = this._mappedEmailSha256Key;
|
|
@@ -356,7 +356,7 @@ const p = class p {
|
|
|
356
356
|
initRoktLauncher(e) {
|
|
357
357
|
window.Rokt && (window.Rokt.currentLauncher = e), this.launcher = e;
|
|
358
358
|
const t = a().Rokt?.filters;
|
|
359
|
-
t ? (this.filters = t, t.filteredUser
|
|
359
|
+
t ? (this.filters = t, t.filteredUser ? this._workspaceSearchInFlightPromise = this.search(t.filteredUser) : console.warn("Rokt Kit: No filtered user has been set.")) : console.warn("Rokt Kit: No filters have been set."), this.isInitialized = !0, Y(this.domain, this.integrationName), a().Rokt.attachKit(this), this.drainBatchQueue();
|
|
360
360
|
}
|
|
361
361
|
fetchOptimizely() {
|
|
362
362
|
const e = a()._getActiveForwarders().filter((t) => t.name === "Optimizely");
|
|
@@ -428,8 +428,8 @@ const p = class p {
|
|
|
428
428
|
sendAdBlockMeasurementSignals: Y,
|
|
429
429
|
createAutoRemovedIframe: O,
|
|
430
430
|
djb2: H,
|
|
431
|
-
setAllowedOriginHashes: (
|
|
432
|
-
p._allowedOriginHashes =
|
|
431
|
+
setAllowedOriginHashes: (I) => {
|
|
432
|
+
p._allowedOriginHashes = I;
|
|
433
433
|
},
|
|
434
434
|
ReportingTransport: N,
|
|
435
435
|
ErrorReportingService: F,
|
|
@@ -441,22 +441,22 @@ const p = class p {
|
|
|
441
441
|
onLoad: () => {
|
|
442
442
|
this._isThankYouElementLoaded = !0, this._thankYouElementOnLoadCallback && this._thankYouElementOnLoadCallback();
|
|
443
443
|
},
|
|
444
|
-
onError: (
|
|
445
|
-
console.error("Error loading Rokt Thank You Element script:",
|
|
444
|
+
onError: (I) => {
|
|
445
|
+
console.error("Error loading Rokt Thank You Element script:", I);
|
|
446
446
|
}
|
|
447
447
|
})), this.isLauncherReadyToAttach() ? this.attachLauncher(c, h, E) : (C(V, P(m, v), {
|
|
448
448
|
onLoad: () => {
|
|
449
449
|
this.isLauncherReadyToAttach() ? this.attachLauncher(c, h, E) : console.error("Rokt object is not available after script load.");
|
|
450
450
|
},
|
|
451
|
-
onError: (
|
|
452
|
-
console.error("Error loading Rokt launcher script:",
|
|
451
|
+
onError: (I) => {
|
|
452
|
+
console.error("Error loading Rokt launcher script:", I);
|
|
453
453
|
}
|
|
454
454
|
}), this.captureTiming(p.PERFORMANCE_MARKS.RoktScriptAppended)), "Successfully initialized: " + l);
|
|
455
455
|
}
|
|
456
456
|
process(e) {
|
|
457
457
|
if (!this.isKitReady())
|
|
458
458
|
return "Kit not ready for forwarder: " + l;
|
|
459
|
-
if (typeof a().Rokt?.setLocalSessionAttribute == "function" && (
|
|
459
|
+
if (typeof a().Rokt?.setLocalSessionAttribute == "function" && (y(this.placementEventAttributeMappingLookup) || this.applyPlacementEventAttributeMapping(e), !y(this.placementEventMappingLookup))) {
|
|
460
460
|
const t = x(e.EventDataType, e.EventCategory, e.EventName ?? "");
|
|
461
461
|
this.placementEventMappingLookup[String(t)] && a().Rokt.setLocalSessionAttribute?.(this.placementEventMappingLookup[String(t)], !0);
|
|
462
462
|
}
|
|
@@ -500,7 +500,7 @@ const p = class p {
|
|
|
500
500
|
if (s.length === 0)
|
|
501
501
|
return this.userIdentifiedInWorkspace = !1, this._workspaceLastSearchedIdentitiesKey = void 0, Promise.resolve();
|
|
502
502
|
const c = s.sort().map((u) => `${u}=${o[u]}`).join("&");
|
|
503
|
-
return c === this._workspaceLastSearchedIdentitiesKey ? Promise.resolve() : (this.userIdentifiedInWorkspace = !1, this._workspaceLastSearchedIdentitiesKey = c, new Promise((u) => {
|
|
503
|
+
return c === this._workspaceLastSearchedIdentitiesKey ? this._workspaceSearchInFlightPromise || Promise.resolve() : (this.userIdentifiedInWorkspace = !1, this._workspaceLastSearchedIdentitiesKey = c, new Promise((u) => {
|
|
504
504
|
try {
|
|
505
505
|
i(t, o, (d) => {
|
|
506
506
|
d?.httpCode === 200 && (this.userIdentifiedInWorkspace = !0), u();
|
package/dist/Rokt-Kit.iife.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var RoktKit=(function(v){"use strict";const l="Rokt",Q="selectPlacements",B="apps.roktecommerce.com",k={LOGIN:"login",LOGOUT:"logout",MODIFY_USER:"modify_user",IDENTIFY:"identify"},V="ThankYouPageJourney",q="rokt-launcher",J="rokt-thank-you-element",X="userIdentifiedInWorkspace",$=500,b={UNKNOWN_ERROR:"UNKNOWN_ERROR",UNHANDLED_EXCEPTION:"UNHANDLED_EXCEPTION",IDENTITY_REQUEST:"IDENTITY_REQUEST"},R={ERROR:"ERROR",INFO:"INFO",WARNING:"WARNING"},Z="apps.rokt-api.com/v1/log",ee="apps.rokt-api.com/v1/errors",te=10;function o(){return window.mParticle}function U(n,e){const i=[M(n),"/wsdk/integrations/launcher.js"].join("");return!e||e.length===0?i:i+"?extensions="+e.join(",")}function C(n){return[M(n),"/rokt-elements/rokt-element-thank-you.js"].join("")}function M(n){return["https://",typeof n<"u"?n:"apps.rokt-api.com"].join("")}function K(n,e,t){if(document.getElementById(n))return;const i=document.head||document.body,r=document.createElement("script");r.id=n,r.type="text/javascript",r.src=e,r.async=!0,r.crossOrigin="anonymous",r.fetchPriority="high",t?.onLoad&&(r.onload=t.onLoad),t?.onError&&(r.onerror=t.onError),i.appendChild(r)}function L(n){return n!=null&&typeof n=="object"&&Array.isArray(n)===!1}function w(n){if(!n)return[];try{return JSON.parse(n.replace(/"/g,'"'))}catch{console.error("Settings string contains invalid JSON")}return[]}function D(n){const e=n?w(n):[],t=[],i=[];let r=!1;for(let a=0;a<e.length;a++){const s=e[a].value;s==="thank-you-journey"?(r=!0,i.push(V)):t.push(s)}return{roktExtensionsQueryParams:t,legacyRoktExtensions:i,loadThankYouElement:r}}async function ie(n,e){const t=[];if(e)for(const i of n)t.push(e.use(i));return Promise.all(t)}function Y(n){if(!n)return{};const e={};for(let t=0;t<n.length;t++){const i=n[t];e[i.jsmap]=i.value}return e}function x(n){const e={};if(!Array.isArray(n))return e;for(let t=0;t<n.length;t++){const i=n[t];if(!i||!g(i.value)||!g(i.map))continue;const r=i.value,a=i.map;e[r]||(e[r]=[]),e[r].push({eventAttributeKey:a,conditions:Array.isArray(i.conditions)?i.conditions:[]})}return e}function F(n,e,t){return o().generateHash([n,e,t].join(""))}function m(n){return n==null?!0:typeof n=="object"?Object.keys(n).length===0:Array.isArray(n)?n.length===0:!1}function g(n){return typeof n=="string"}function ne(n){let i="mParticle_wsdkv_"+o().getVersion()+"_kitv_"+"1.26.0";return n&&(i+="_"+n),i}function j(n){let e=5381;for(let t=0;t<n.length;t++)e=(e<<5)+e+n.charCodeAt(t),e=e&e;return e}function O(n){const e=document.createElement("iframe");e.style.display="none",e.setAttribute("sandbox","allow-scripts allow-same-origin"),e.src=n,e.onload=function(){e.onload=null,e.parentNode&&e.parentNode.removeChild(e)};const t=document.body||document.head;t&&t.appendChild(e)}function G(n,e){const t=j(window.location.origin);if(f._allowedOriginHashes.indexOf(t)===-1||Math.random()>=.1)return;const r=window.__rokt_li_guid__;if(!r)return;const a=window.location.href.split("?")[0].split("#")[0],s="version="+encodeURIComponent(e??"")+"&launcherInstanceGuid="+encodeURIComponent(r)+"&pageUrl="+encodeURIComponent(a);O("https://"+(n||"apps.rokt.com")+"/v1/wsdk-init/index.html?"+s),O("https://"+B+"/v1/wsdk-init/index.html?"+s+"&isControl=true")}function re(){return typeof window<"u"&&!!window.ROKT_DOMAIN}function se(){return typeof window<"u"&&!!window.location?.search?.toLowerCase().includes("mp_enable_logging=true")}function oe(){return typeof window<"u"?window.location?.href:void 0}function ae(){return typeof window<"u"?window.navigator?.userAgent:void 0}class H{constructor(){this._logCount={}}incrementAndCheck(e){const i=(this._logCount[e]||0)+1;return this._logCount[e]=i,i>te}}class T{constructor(e,t,i,r,a){this._reporter="mp-wsdk";const s=e?.isLoggingEnabled===!0||e?.isLoggingEnabled==="true";this._integrationName=t||"",this._launcherInstanceGuid=i,this._accountId=r||null,this._rateLimiter=a||new H,this._isEnabled=se()||re()&&s}send(e,t,i,r,a,s){if(!(!this._isEnabled||this._rateLimiter.incrementAndCheck(t)))try{const c={additionalInformation:{message:i,version:this._integrationName},severity:t,code:r||b.UNKNOWN_ERROR,url:oe(),deviceInfo:ae(),stackTrace:a,reporter:this._reporter,integration:this._integrationName},u={Accept:"text/plain;charset=UTF-8","Content-Type":"application/json","rokt-launcher-version":this._integrationName,"rokt-wsdk-version":"joint"};this._launcherInstanceGuid&&(u["rokt-launcher-instance-guid"]=this._launcherInstanceGuid),this._accountId&&(u["rokt-account-id"]=this._accountId),fetch(e,{method:"POST",headers:u,body:JSON.stringify(c)}).catch(d=>{console.error("ReportingTransport: Failed to send log",d),s&&s(d)})}catch(c){console.error("ReportingTransport: Failed to send log",c),s&&s(c)}}}class W{constructor(e,t,i,r,a){this._transport=new T(e,t,i,r,a),this._errorUrl="https://"+(e?.errorUrl||ee)}report(e){if(!e)return;const t=e.severity||R.ERROR;this._transport.send(this._errorUrl,t,e.message,e.code,e.stackTrace)}}class z{constructor(e,t,i,r,a,s){this._transport=new T(e,i,r,a,s),this._loggingUrl="https://"+(e?.loggingUrl||Z),this._errorReportingService=t}log(e){e&&this._transport.send(this._loggingUrl,R.INFO,e.message,e.code,void 0,t=>{this._errorReportingService&&this._errorReportingService.report({message:"LoggingService: Failed to send log: "+t.message,code:b.UNKNOWN_ERROR,severity:R.ERROR})})}}const h=class h{constructor(){this.name=l,this.id=181,this.moduleId=181,this.isInitialized=!1,this.launcher=null,this.filters={},this.userAttributes={},this.userIdentifiedInWorkspace=!1,this.testHelpers=null,this.placementEventMappingLookup={},this.placementEventAttributeMappingLookup={},this.batchQueue=[],this.batchStreamQueue=[],this.pendingIdentityEvents=[],this.integrationName=null,this.errorReportingService=null,this.loggingService=null,this._thankYouElementOnLoadCallback=null,this._isThankYouElementLoaded=!1,this._workspaceSearchInFlightPromise=null}getEventAttributeValue(e,t){const i=e&&e.EventAttributes;return!i||typeof i[t]>"u"?null:i[t]}doesEventAttributeConditionMatch(e,t){if(!e||!g(e.operator))return!1;const i=e.operator.toLowerCase(),r=e.attributeValue;return i==="exists"?t!==null:t==null?!1:i==="equals"?String(t)===String(r):i==="contains"?String(t).indexOf(String(r))!==-1:!1}doesEventMatchRule(e,t){if(!t||!g(t.eventAttributeKey))return!1;const i=t.conditions;if(!Array.isArray(i))return!1;const r=this.getEventAttributeValue(e,t.eventAttributeKey);if(i.length===0)return r!==null;for(let a=0;a<i.length;a++)if(!this.doesEventAttributeConditionMatch(i[a],r))return!1;return!0}applyPlacementEventAttributeMapping(e){const t=Object.keys(this.placementEventAttributeMappingLookup);for(let i=0;i<t.length;i++){const r=t[i],a=this.placementEventAttributeMappingLookup[r];if(m(a))continue;let s=!0;for(let c=0;c<a.length;c++)if(!this.doesEventMatchRule(e,a[c])){s=!1;break}s&&o().Rokt.setLocalSessionAttribute?.(r,!0)}}isLauncherReadyToAttach(){return!!window.Rokt&&typeof window.Rokt.createLauncher=="function"}returnUserIdentities(e){if(!e||!e.getUserIdentities)return{};const t=e.getUserIdentities().userIdentities;return this.replaceOtherIdentityWithEmailsha256(t)}returnLocalSessionAttributes(){return!o().Rokt||typeof o().Rokt.getLocalSessionAttributes!="function"?{}:m(this.placementEventMappingLookup)&&m(this.placementEventAttributeMappingLookup)?{}:o().Rokt.getLocalSessionAttributes()}replaceOtherIdentityWithEmailsha256(e){const t={...e||{}},i=this._mappedEmailSha256Key;return i&&e[i]&&(t[h.EMAIL_SHA256_KEY]=e[i]),i&&delete t[i],t}logSelectPlacementsEvent(e){if(!window.mParticle||typeof o().logEvent!="function"||!L(e))return;const t=o().EventType.Other;o().logEvent(Q,t,e)}buildIdentityEvent(e,t){const i=t.getMPID(),r=o()&&o().sessionManager&&typeof o().sessionManager.getSession=="function"?o().sessionManager.getSession():void 0;return{event_type:e,data:{timestamp_unixtime_ms:Date.now(),session_uuid:r??void 0,mpid:i}}}mergePendingIdentityEvents(e){if(this.pendingIdentityEvents.length===0)return e;const t={...e,events:[...e.events??[],...this.pendingIdentityEvents]};return this.pendingIdentityEvents=[],t}drainBatchQueue(){this.batchQueue.forEach(e=>{this.processBatch(e)}),this.batchQueue=[]}processBatch(e){return this.isKitReady()?(this.sendBatchStream(this.mergePendingIdentityEvents(e)),"Successfully sent batch to forwarder: "+l):(this.batchQueue.push(e),"Batch queued for forwarder: "+l)}sendBatchStream(e){if(window.Rokt&&typeof window.Rokt.__batch_stream__=="function"){if(this.batchStreamQueue.length){const t=this.batchStreamQueue;this.batchStreamQueue=[];for(let i=0;i<t.length;i++)window.Rokt.__batch_stream__(t[i])}window.Rokt.__batch_stream__(e)}else this.batchStreamQueue.push(e)}setRoktSessionId(e){if(!(!e||typeof e!="string"))try{const t=o().getInstance();t&&typeof t.setIntegrationAttribute=="function"&&t.setIntegrationAttribute(181,{roktSessionId:e})}catch{}}attachLauncher(e,t,i=[]){const r=o()&&o().sessionManager&&typeof o().sessionManager.getSession=="function"?o().sessionManager.getSession():void 0,a={accountId:e,...t||{},...r?{mpSessionId:r}:{}};let s;this.isPartnerInLocalLauncherTestGroup()?s=Promise.resolve(window.Rokt.createLocalLauncher(a)):s=window.Rokt.createLauncher(a),s.then(async c=>{await ie(i,c),this.initRoktLauncher(c)}).catch(c=>{console.error("Error creating Rokt launcher:",c)})}initRoktLauncher(e){window.Rokt&&(window.Rokt.currentLauncher=e),this.launcher=e;const t=o().Rokt?.filters;t?(this.filters=t,t.filteredUser||console.warn("Rokt Kit: No filtered user has been set.")):console.warn("Rokt Kit: No filters have been set."),this.isInitialized=!0,G(this.domain,this.integrationName),o().Rokt.attachKit(this),this.drainBatchQueue()}fetchOptimizely(){const e=o()._getActiveForwarders().filter(t=>t.name==="Optimizely");try{if(e.length>0&&window.optimizely){const t=window.optimizely.get("state");return!t||!t.getActiveExperimentIds?{}:t.getActiveExperimentIds().reduce((a,s)=>(a["rokt.custom.optimizely.experiment."+s+".variationId"]=t.getVariationMap()[s].id,a),{})}}catch(t){console.error("Error fetching Optimizely attributes:",t)}return{}}isKitReady(){return!!(this.isInitialized&&this.launcher)}isPartnerInLocalLauncherTestGroup(){return!!(o().config&&o().config.isLocalLauncherEnabled&&this.isAssignedToSampleGroup())}isAssignedToSampleGroup(){return Math.random()>.5}captureTiming(e){window&&o()&&o().captureTiming&&e&&o().captureTiming(e)}init(e,t,i,r,a){const s=e,c=s.accountId;this.userAttributes=a||{},this._onboardingExpProvider=s.onboardingExpProvider;const u=w(s.placementEventMapping);this.placementEventMappingLookup=Y(u);const d=w(s.placementEventAttributeMapping);this.placementEventAttributeMappingLookup=x(d),s.hashedEmailUserIdentityType&&(this._mappedEmailSha256Key=s.hashedEmailUserIdentityType.toLowerCase()),this._workspaceIdSyncApiKey=g(s.workspaceIdSyncApiKey)?s.workspaceIdSyncApiKey:void 0;const E=o().Rokt?.domain,{roktExtensionsQueryParams:N,legacyRoktExtensions:_,loadThankYouElement:P}=D(s.roktExtensions),p={...o().Rokt?.launcherOptions||{}};this.integrationName=ne(p.integrationName),p.integrationName=this.integrationName,this.domain=E;const S={loggingUrl:s.loggingUrl,errorUrl:s.errorUrl,isLoggingEnabled:s.isLoggingEnabled==="true"||s.isLoggingEnabled===!0},y=new W(S,this.integrationName,window.__rokt_li_guid__,s.accountId),A=new z(S,y,this.integrationName,window.__rokt_li_guid__,s.accountId);return this.errorReportingService=y,this.loggingService=A,o()._registerErrorReportingService&&o()._registerErrorReportingService(y),o()._registerLoggingService&&o()._registerLoggingService(A),i?(this.testHelpers={generateLauncherScript:U,generateThankYouElementScript:C,extractRoktExtensionConfig:D,hashEventMessage:F,parseSettingsString:w,generateMappedEventLookup:Y,generateMappedEventAttributeLookup:x,sendAdBlockMeasurementSignals:G,createAutoRemovedIframe:O,djb2:j,setAllowedOriginHashes:I=>{h._allowedOriginHashes=I},ReportingTransport:T,ErrorReportingService:W,LoggingService:z,RateLimiter:H,ErrorCodes:b,WSDKErrorSeverity:R},this.attachLauncher(c,p),"Successfully initialized: "+l):(P&&(o().Rokt.flushOnShoppableAdsReadyMessageQueue?.(this),K(J,C(E),{onLoad:()=>{this._isThankYouElementLoaded=!0,this._thankYouElementOnLoadCallback&&this._thankYouElementOnLoadCallback()},onError:I=>{console.error("Error loading Rokt Thank You Element script:",I)}})),this.isLauncherReadyToAttach()?this.attachLauncher(c,p,_):(K(q,U(E,N),{onLoad:()=>{this.isLauncherReadyToAttach()?this.attachLauncher(c,p,_):console.error("Rokt object is not available after script load.")},onError:I=>{console.error("Error loading Rokt launcher script:",I)}}),this.captureTiming(h.PERFORMANCE_MARKS.RoktScriptAppended)),"Successfully initialized: "+l)}process(e){if(!this.isKitReady())return"Kit not ready for forwarder: "+l;if(typeof o().Rokt?.setLocalSessionAttribute=="function"&&(m(this.placementEventAttributeMappingLookup)||this.applyPlacementEventAttributeMapping(e),!m(this.placementEventMappingLookup))){const t=F(e.EventDataType,e.EventCategory,e.EventName??"");this.placementEventMappingLookup[String(t)]&&o().Rokt.setLocalSessionAttribute?.(this.placementEventMappingLookup[String(t)],!0)}return"Successfully sent to forwarder: "+l}setExtensionData(e){if(!this.isKitReady()){console.error("Rokt Kit: Not initialized");return}window.Rokt.setExtensionData(e)}setUserAttribute(e,t){return this.userAttributes[e]=t,"Successfully set user attribute for forwarder: "+l}removeUserAttribute(e){return delete this.userAttributes[e],"Successfully removed user attribute for forwarder: "+l}handleIdentityComplete(e,t,i){const r=e;return this.userAttributes=e.getAllUserAttributes(),this.pendingIdentityEvents.push(this.buildIdentityEvent(t,r)),"Successfully called "+i+" for forwarder: "+l}onUserIdentified(e){const t=e;return this.filters.filteredUser=t,this._workspaceSearchInFlightPromise=this.search(t),this.handleIdentityComplete(e,k.IDENTIFY,"onUserIdentified")}search(e){const t=this._workspaceIdSyncApiKey;if(!t)return this.userIdentifiedInWorkspace=!1,this._workspaceLastSearchedIdentitiesKey=void 0,Promise.resolve();const i=o().Identity?.search;if(typeof i!="function")return this.userIdentifiedInWorkspace=!1,this._workspaceLastSearchedIdentitiesKey=void 0,Promise.resolve();const r=e.getUserIdentities?e.getUserIdentities().userIdentities:null,a={};if(r)for(const u of Object.keys(r)){const d=r[u];g(d)&&d.length>0&&(a[u]=d)}const s=Object.keys(a);if(s.length===0)return this.userIdentifiedInWorkspace=!1,this._workspaceLastSearchedIdentitiesKey=void 0,Promise.resolve();const c=s.sort().map(u=>`${u}=${a[u]}`).join("&");return c===this._workspaceLastSearchedIdentitiesKey?Promise.resolve():(this.userIdentifiedInWorkspace=!1,this._workspaceLastSearchedIdentitiesKey=c,new Promise(u=>{try{i(t,a,d=>{d?.httpCode===200&&(this.userIdentifiedInWorkspace=!0),u()})}catch(d){console.error("Rokt Kit: Workspace IDSync search failed",d),this._workspaceLastSearchedIdentitiesKey=void 0,u()}}))}onLoginComplete(e,t){return this.handleIdentityComplete(e,k.LOGIN,"onLoginComplete")}onLogoutComplete(e,t){return this.userIdentifiedInWorkspace=!1,this._workspaceSearchInFlightPromise=null,this._workspaceLastSearchedIdentitiesKey=void 0,this.handleIdentityComplete(e,k.LOGOUT,"onLogoutComplete")}onModifyComplete(e,t){return this.handleIdentityComplete(e,k.MODIFY_USER,"onModifyComplete")}selectPlacements(e){if(this._workspaceSearchInFlightPromise){const t=this._workspaceSearchInFlightPromise;return Promise.race([t,new Promise(i=>setTimeout(i,$))]).then(()=>this._dispatchPlacements(e))}return this._dispatchPlacements(e)}_dispatchPlacements(e){const t=e&&e.attributes||{},i={...this.userAttributes,...t},r=this.filters||{},a=r.userAttributeFilters||[],s=r.filteredUser||null,c=s?s.getMPID():null;let u;r?r.filterUserAttributes?u=r.filterUserAttributes(i,a):u=i:(console.warn("Rokt Kit: No filters available, using user attributes"),u=i),this.userAttributes=u;const d=this._onboardingExpProvider==="Optimizely"?this.fetchOptimizely():{},E=this.returnUserIdentities(s),N=this.returnLocalSessionAttributes(),_={...E,...u,...d,...N,...this.userIdentifiedInWorkspace?{[X]:!0}:{},mpid:c},P={...e,attributes:_},p=this.launcher.selectPlacements(P),S=()=>this.logSelectPlacementsEvent(_);return Promise.resolve(p).then(y=>y?.context?.sessionId?.then(A=>this.setRoktSessionId(A))).catch(()=>{}).finally(S),p}hashAttributes(e){return this.isKitReady()?this.launcher.hashAttributes(e):(console.error("Rokt Kit: Not initialized"),null)}use(e){return this.isKitReady()?!e||!g(e)?Promise.reject(new Error("Rokt Kit: Invalid extension name")):this.launcher.use(e):(console.error("Rokt Kit: Not initialized"),Promise.reject(new Error("Rokt Kit: Not initialized")))}onShoppableAdsReady(e){this._isThankYouElementLoaded?e():this._thankYouElementOnLoadCallback=e}};h._allowedOriginHashes=[-553112570,549508659],h.PERFORMANCE_MARKS={RoktScriptAppended:"mp:RoktScriptAppended"},h.EMAIL_SHA256_KEY="emailsha256";let f=h;function ce(){return 181}function ue(n){if(!n){window.console.log("You must pass a config object to register the kit "+l);return}if(!L(n)){window.console.log("'config' must be an object. You passed in a "+typeof n);return}L(n.kits)?n.kits[l]={constructor:f}:(n.kits={},n.kits[l]={constructor:f}),window.console.log("Successfully registered "+l+" to your mParticle configuration")}return typeof window<"u"&&window.mParticle&&o().addForwarder&&o().addForwarder({name:l,constructor:f,getId:ce}),v.register=ue,Object.defineProperty(v,Symbol.toStringTag,{value:"Module"}),v})({});
|
|
1
|
+
var RoktKit=(function(v){"use strict";const l="Rokt",Q="selectPlacements",B="apps.roktecommerce.com",k={LOGIN:"login",LOGOUT:"logout",MODIFY_USER:"modify_user",IDENTIFY:"identify"},V="ThankYouPageJourney",q="rokt-launcher",J="rokt-thank-you-element",X="userIdentifiedInWorkspace",$=500,b={UNKNOWN_ERROR:"UNKNOWN_ERROR",UNHANDLED_EXCEPTION:"UNHANDLED_EXCEPTION",IDENTITY_REQUEST:"IDENTITY_REQUEST"},R={ERROR:"ERROR",INFO:"INFO",WARNING:"WARNING"},Z="apps.rokt-api.com/v1/log",ee="apps.rokt-api.com/v1/errors",te=10;function o(){return window.mParticle}function U(n,e){const i=[M(n),"/wsdk/integrations/launcher.js"].join("");return!e||e.length===0?i:i+"?extensions="+e.join(",")}function C(n){return[M(n),"/rokt-elements/rokt-element-thank-you.js"].join("")}function M(n){return["https://",typeof n<"u"?n:"apps.rokt-api.com"].join("")}function K(n,e,t){if(document.getElementById(n))return;const i=document.head||document.body,r=document.createElement("script");r.id=n,r.type="text/javascript",r.src=e,r.async=!0,r.crossOrigin="anonymous",r.fetchPriority="high",t?.onLoad&&(r.onload=t.onLoad),t?.onError&&(r.onerror=t.onError),i.appendChild(r)}function L(n){return n!=null&&typeof n=="object"&&Array.isArray(n)===!1}function w(n){if(!n)return[];try{return JSON.parse(n.replace(/"/g,'"'))}catch{console.error("Settings string contains invalid JSON")}return[]}function D(n){const e=n?w(n):[],t=[],i=[];let r=!1;for(let a=0;a<e.length;a++){const s=e[a].value;s==="thank-you-journey"?(r=!0,i.push(V)):t.push(s)}return{roktExtensionsQueryParams:t,legacyRoktExtensions:i,loadThankYouElement:r}}async function ie(n,e){const t=[];if(e)for(const i of n)t.push(e.use(i));return Promise.all(t)}function Y(n){if(!n)return{};const e={};for(let t=0;t<n.length;t++){const i=n[t];e[i.jsmap]=i.value}return e}function x(n){const e={};if(!Array.isArray(n))return e;for(let t=0;t<n.length;t++){const i=n[t];if(!i||!g(i.value)||!g(i.map))continue;const r=i.value,a=i.map;e[r]||(e[r]=[]),e[r].push({eventAttributeKey:a,conditions:Array.isArray(i.conditions)?i.conditions:[]})}return e}function F(n,e,t){return o().generateHash([n,e,t].join(""))}function m(n){return n==null?!0:typeof n=="object"?Object.keys(n).length===0:Array.isArray(n)?n.length===0:!1}function g(n){return typeof n=="string"}function ne(n){let i="mParticle_wsdkv_"+o().getVersion()+"_kitv_"+"1.26.1";return n&&(i+="_"+n),i}function j(n){let e=5381;for(let t=0;t<n.length;t++)e=(e<<5)+e+n.charCodeAt(t),e=e&e;return e}function O(n){const e=document.createElement("iframe");e.style.display="none",e.setAttribute("sandbox","allow-scripts allow-same-origin"),e.src=n,e.onload=function(){e.onload=null,e.parentNode&&e.parentNode.removeChild(e)};const t=document.body||document.head;t&&t.appendChild(e)}function G(n,e){const t=j(window.location.origin);if(f._allowedOriginHashes.indexOf(t)===-1||Math.random()>=.1)return;const r=window.__rokt_li_guid__;if(!r)return;const a=window.location.href.split("?")[0].split("#")[0],s="version="+encodeURIComponent(e??"")+"&launcherInstanceGuid="+encodeURIComponent(r)+"&pageUrl="+encodeURIComponent(a);O("https://"+(n||"apps.rokt.com")+"/v1/wsdk-init/index.html?"+s),O("https://"+B+"/v1/wsdk-init/index.html?"+s+"&isControl=true")}function re(){return typeof window<"u"&&!!window.ROKT_DOMAIN}function se(){return typeof window<"u"&&!!window.location?.search?.toLowerCase().includes("mp_enable_logging=true")}function oe(){return typeof window<"u"?window.location?.href:void 0}function ae(){return typeof window<"u"?window.navigator?.userAgent:void 0}class H{constructor(){this._logCount={}}incrementAndCheck(e){const i=(this._logCount[e]||0)+1;return this._logCount[e]=i,i>te}}class T{constructor(e,t,i,r,a){this._reporter="mp-wsdk";const s=e?.isLoggingEnabled===!0||e?.isLoggingEnabled==="true";this._integrationName=t||"",this._launcherInstanceGuid=i,this._accountId=r||null,this._rateLimiter=a||new H,this._isEnabled=se()||re()&&s}send(e,t,i,r,a,s){if(!(!this._isEnabled||this._rateLimiter.incrementAndCheck(t)))try{const c={additionalInformation:{message:i,version:this._integrationName},severity:t,code:r||b.UNKNOWN_ERROR,url:oe(),deviceInfo:ae(),stackTrace:a,reporter:this._reporter,integration:this._integrationName},u={Accept:"text/plain;charset=UTF-8","Content-Type":"application/json","rokt-launcher-version":this._integrationName,"rokt-wsdk-version":"joint"};this._launcherInstanceGuid&&(u["rokt-launcher-instance-guid"]=this._launcherInstanceGuid),this._accountId&&(u["rokt-account-id"]=this._accountId),fetch(e,{method:"POST",headers:u,body:JSON.stringify(c)}).catch(d=>{console.error("ReportingTransport: Failed to send log",d),s&&s(d)})}catch(c){console.error("ReportingTransport: Failed to send log",c),s&&s(c)}}}class W{constructor(e,t,i,r,a){this._transport=new T(e,t,i,r,a),this._errorUrl="https://"+(e?.errorUrl||ee)}report(e){if(!e)return;const t=e.severity||R.ERROR;this._transport.send(this._errorUrl,t,e.message,e.code,e.stackTrace)}}class z{constructor(e,t,i,r,a,s){this._transport=new T(e,i,r,a,s),this._loggingUrl="https://"+(e?.loggingUrl||Z),this._errorReportingService=t}log(e){e&&this._transport.send(this._loggingUrl,R.INFO,e.message,e.code,void 0,t=>{this._errorReportingService&&this._errorReportingService.report({message:"LoggingService: Failed to send log: "+t.message,code:b.UNKNOWN_ERROR,severity:R.ERROR})})}}const h=class h{constructor(){this.name=l,this.id=181,this.moduleId=181,this.isInitialized=!1,this.launcher=null,this.filters={},this.userAttributes={},this.userIdentifiedInWorkspace=!1,this.testHelpers=null,this.placementEventMappingLookup={},this.placementEventAttributeMappingLookup={},this.batchQueue=[],this.batchStreamQueue=[],this.pendingIdentityEvents=[],this.integrationName=null,this.errorReportingService=null,this.loggingService=null,this._thankYouElementOnLoadCallback=null,this._isThankYouElementLoaded=!1,this._workspaceSearchInFlightPromise=null}getEventAttributeValue(e,t){const i=e&&e.EventAttributes;return!i||typeof i[t]>"u"?null:i[t]}doesEventAttributeConditionMatch(e,t){if(!e||!g(e.operator))return!1;const i=e.operator.toLowerCase(),r=e.attributeValue;return i==="exists"?t!==null:t==null?!1:i==="equals"?String(t)===String(r):i==="contains"?String(t).indexOf(String(r))!==-1:!1}doesEventMatchRule(e,t){if(!t||!g(t.eventAttributeKey))return!1;const i=t.conditions;if(!Array.isArray(i))return!1;const r=this.getEventAttributeValue(e,t.eventAttributeKey);if(i.length===0)return r!==null;for(let a=0;a<i.length;a++)if(!this.doesEventAttributeConditionMatch(i[a],r))return!1;return!0}applyPlacementEventAttributeMapping(e){const t=Object.keys(this.placementEventAttributeMappingLookup);for(let i=0;i<t.length;i++){const r=t[i],a=this.placementEventAttributeMappingLookup[r];if(m(a))continue;let s=!0;for(let c=0;c<a.length;c++)if(!this.doesEventMatchRule(e,a[c])){s=!1;break}s&&o().Rokt.setLocalSessionAttribute?.(r,!0)}}isLauncherReadyToAttach(){return!!window.Rokt&&typeof window.Rokt.createLauncher=="function"}returnUserIdentities(e){if(!e||!e.getUserIdentities)return{};const t=e.getUserIdentities().userIdentities;return this.replaceOtherIdentityWithEmailsha256(t)}returnLocalSessionAttributes(){return!o().Rokt||typeof o().Rokt.getLocalSessionAttributes!="function"?{}:m(this.placementEventMappingLookup)&&m(this.placementEventAttributeMappingLookup)?{}:o().Rokt.getLocalSessionAttributes()}replaceOtherIdentityWithEmailsha256(e){const t={...e||{}},i=this._mappedEmailSha256Key;return i&&e[i]&&(t[h.EMAIL_SHA256_KEY]=e[i]),i&&delete t[i],t}logSelectPlacementsEvent(e){if(!window.mParticle||typeof o().logEvent!="function"||!L(e))return;const t=o().EventType.Other;o().logEvent(Q,t,e)}buildIdentityEvent(e,t){const i=t.getMPID(),r=o()&&o().sessionManager&&typeof o().sessionManager.getSession=="function"?o().sessionManager.getSession():void 0;return{event_type:e,data:{timestamp_unixtime_ms:Date.now(),session_uuid:r??void 0,mpid:i}}}mergePendingIdentityEvents(e){if(this.pendingIdentityEvents.length===0)return e;const t={...e,events:[...e.events??[],...this.pendingIdentityEvents]};return this.pendingIdentityEvents=[],t}drainBatchQueue(){this.batchQueue.forEach(e=>{this.processBatch(e)}),this.batchQueue=[]}processBatch(e){return this.isKitReady()?(this.sendBatchStream(this.mergePendingIdentityEvents(e)),"Successfully sent batch to forwarder: "+l):(this.batchQueue.push(e),"Batch queued for forwarder: "+l)}sendBatchStream(e){if(window.Rokt&&typeof window.Rokt.__batch_stream__=="function"){if(this.batchStreamQueue.length){const t=this.batchStreamQueue;this.batchStreamQueue=[];for(let i=0;i<t.length;i++)window.Rokt.__batch_stream__(t[i])}window.Rokt.__batch_stream__(e)}else this.batchStreamQueue.push(e)}setRoktSessionId(e){if(!(!e||typeof e!="string"))try{const t=o().getInstance();t&&typeof t.setIntegrationAttribute=="function"&&t.setIntegrationAttribute(181,{roktSessionId:e})}catch{}}attachLauncher(e,t,i=[]){const r=o()&&o().sessionManager&&typeof o().sessionManager.getSession=="function"?o().sessionManager.getSession():void 0,a={accountId:e,...t||{},...r?{mpSessionId:r}:{}};let s;this.isPartnerInLocalLauncherTestGroup()?s=Promise.resolve(window.Rokt.createLocalLauncher(a)):s=window.Rokt.createLauncher(a),s.then(async c=>{await ie(i,c),this.initRoktLauncher(c)}).catch(c=>{console.error("Error creating Rokt launcher:",c)})}initRoktLauncher(e){window.Rokt&&(window.Rokt.currentLauncher=e),this.launcher=e;const t=o().Rokt?.filters;t?(this.filters=t,t.filteredUser?this._workspaceSearchInFlightPromise=this.search(t.filteredUser):console.warn("Rokt Kit: No filtered user has been set.")):console.warn("Rokt Kit: No filters have been set."),this.isInitialized=!0,G(this.domain,this.integrationName),o().Rokt.attachKit(this),this.drainBatchQueue()}fetchOptimizely(){const e=o()._getActiveForwarders().filter(t=>t.name==="Optimizely");try{if(e.length>0&&window.optimizely){const t=window.optimizely.get("state");return!t||!t.getActiveExperimentIds?{}:t.getActiveExperimentIds().reduce((a,s)=>(a["rokt.custom.optimizely.experiment."+s+".variationId"]=t.getVariationMap()[s].id,a),{})}}catch(t){console.error("Error fetching Optimizely attributes:",t)}return{}}isKitReady(){return!!(this.isInitialized&&this.launcher)}isPartnerInLocalLauncherTestGroup(){return!!(o().config&&o().config.isLocalLauncherEnabled&&this.isAssignedToSampleGroup())}isAssignedToSampleGroup(){return Math.random()>.5}captureTiming(e){window&&o()&&o().captureTiming&&e&&o().captureTiming(e)}init(e,t,i,r,a){const s=e,c=s.accountId;this.userAttributes=a||{},this._onboardingExpProvider=s.onboardingExpProvider;const u=w(s.placementEventMapping);this.placementEventMappingLookup=Y(u);const d=w(s.placementEventAttributeMapping);this.placementEventAttributeMappingLookup=x(d),s.hashedEmailUserIdentityType&&(this._mappedEmailSha256Key=s.hashedEmailUserIdentityType.toLowerCase()),this._workspaceIdSyncApiKey=g(s.workspaceIdSyncApiKey)?s.workspaceIdSyncApiKey:void 0;const E=o().Rokt?.domain,{roktExtensionsQueryParams:N,legacyRoktExtensions:_,loadThankYouElement:P}=D(s.roktExtensions),p={...o().Rokt?.launcherOptions||{}};this.integrationName=ne(p.integrationName),p.integrationName=this.integrationName,this.domain=E;const S={loggingUrl:s.loggingUrl,errorUrl:s.errorUrl,isLoggingEnabled:s.isLoggingEnabled==="true"||s.isLoggingEnabled===!0},y=new W(S,this.integrationName,window.__rokt_li_guid__,s.accountId),A=new z(S,y,this.integrationName,window.__rokt_li_guid__,s.accountId);return this.errorReportingService=y,this.loggingService=A,o()._registerErrorReportingService&&o()._registerErrorReportingService(y),o()._registerLoggingService&&o()._registerLoggingService(A),i?(this.testHelpers={generateLauncherScript:U,generateThankYouElementScript:C,extractRoktExtensionConfig:D,hashEventMessage:F,parseSettingsString:w,generateMappedEventLookup:Y,generateMappedEventAttributeLookup:x,sendAdBlockMeasurementSignals:G,createAutoRemovedIframe:O,djb2:j,setAllowedOriginHashes:I=>{h._allowedOriginHashes=I},ReportingTransport:T,ErrorReportingService:W,LoggingService:z,RateLimiter:H,ErrorCodes:b,WSDKErrorSeverity:R},this.attachLauncher(c,p),"Successfully initialized: "+l):(P&&(o().Rokt.flushOnShoppableAdsReadyMessageQueue?.(this),K(J,C(E),{onLoad:()=>{this._isThankYouElementLoaded=!0,this._thankYouElementOnLoadCallback&&this._thankYouElementOnLoadCallback()},onError:I=>{console.error("Error loading Rokt Thank You Element script:",I)}})),this.isLauncherReadyToAttach()?this.attachLauncher(c,p,_):(K(q,U(E,N),{onLoad:()=>{this.isLauncherReadyToAttach()?this.attachLauncher(c,p,_):console.error("Rokt object is not available after script load.")},onError:I=>{console.error("Error loading Rokt launcher script:",I)}}),this.captureTiming(h.PERFORMANCE_MARKS.RoktScriptAppended)),"Successfully initialized: "+l)}process(e){if(!this.isKitReady())return"Kit not ready for forwarder: "+l;if(typeof o().Rokt?.setLocalSessionAttribute=="function"&&(m(this.placementEventAttributeMappingLookup)||this.applyPlacementEventAttributeMapping(e),!m(this.placementEventMappingLookup))){const t=F(e.EventDataType,e.EventCategory,e.EventName??"");this.placementEventMappingLookup[String(t)]&&o().Rokt.setLocalSessionAttribute?.(this.placementEventMappingLookup[String(t)],!0)}return"Successfully sent to forwarder: "+l}setExtensionData(e){if(!this.isKitReady()){console.error("Rokt Kit: Not initialized");return}window.Rokt.setExtensionData(e)}setUserAttribute(e,t){return this.userAttributes[e]=t,"Successfully set user attribute for forwarder: "+l}removeUserAttribute(e){return delete this.userAttributes[e],"Successfully removed user attribute for forwarder: "+l}handleIdentityComplete(e,t,i){const r=e;return this.userAttributes=e.getAllUserAttributes(),this.pendingIdentityEvents.push(this.buildIdentityEvent(t,r)),"Successfully called "+i+" for forwarder: "+l}onUserIdentified(e){const t=e;return this.filters.filteredUser=t,this._workspaceSearchInFlightPromise=this.search(t),this.handleIdentityComplete(e,k.IDENTIFY,"onUserIdentified")}search(e){const t=this._workspaceIdSyncApiKey;if(!t)return this.userIdentifiedInWorkspace=!1,this._workspaceLastSearchedIdentitiesKey=void 0,Promise.resolve();const i=o().Identity?.search;if(typeof i!="function")return this.userIdentifiedInWorkspace=!1,this._workspaceLastSearchedIdentitiesKey=void 0,Promise.resolve();const r=e.getUserIdentities?e.getUserIdentities().userIdentities:null,a={};if(r)for(const u of Object.keys(r)){const d=r[u];g(d)&&d.length>0&&(a[u]=d)}const s=Object.keys(a);if(s.length===0)return this.userIdentifiedInWorkspace=!1,this._workspaceLastSearchedIdentitiesKey=void 0,Promise.resolve();const c=s.sort().map(u=>`${u}=${a[u]}`).join("&");return c===this._workspaceLastSearchedIdentitiesKey?this._workspaceSearchInFlightPromise||Promise.resolve():(this.userIdentifiedInWorkspace=!1,this._workspaceLastSearchedIdentitiesKey=c,new Promise(u=>{try{i(t,a,d=>{d?.httpCode===200&&(this.userIdentifiedInWorkspace=!0),u()})}catch(d){console.error("Rokt Kit: Workspace IDSync search failed",d),this._workspaceLastSearchedIdentitiesKey=void 0,u()}}))}onLoginComplete(e,t){return this.handleIdentityComplete(e,k.LOGIN,"onLoginComplete")}onLogoutComplete(e,t){return this.userIdentifiedInWorkspace=!1,this._workspaceSearchInFlightPromise=null,this._workspaceLastSearchedIdentitiesKey=void 0,this.handleIdentityComplete(e,k.LOGOUT,"onLogoutComplete")}onModifyComplete(e,t){return this.handleIdentityComplete(e,k.MODIFY_USER,"onModifyComplete")}selectPlacements(e){if(this._workspaceSearchInFlightPromise){const t=this._workspaceSearchInFlightPromise;return Promise.race([t,new Promise(i=>setTimeout(i,$))]).then(()=>this._dispatchPlacements(e))}return this._dispatchPlacements(e)}_dispatchPlacements(e){const t=e&&e.attributes||{},i={...this.userAttributes,...t},r=this.filters||{},a=r.userAttributeFilters||[],s=r.filteredUser||null,c=s?s.getMPID():null;let u;r?r.filterUserAttributes?u=r.filterUserAttributes(i,a):u=i:(console.warn("Rokt Kit: No filters available, using user attributes"),u=i),this.userAttributes=u;const d=this._onboardingExpProvider==="Optimizely"?this.fetchOptimizely():{},E=this.returnUserIdentities(s),N=this.returnLocalSessionAttributes(),_={...E,...u,...d,...N,...this.userIdentifiedInWorkspace?{[X]:!0}:{},mpid:c},P={...e,attributes:_},p=this.launcher.selectPlacements(P),S=()=>this.logSelectPlacementsEvent(_);return Promise.resolve(p).then(y=>y?.context?.sessionId?.then(A=>this.setRoktSessionId(A))).catch(()=>{}).finally(S),p}hashAttributes(e){return this.isKitReady()?this.launcher.hashAttributes(e):(console.error("Rokt Kit: Not initialized"),null)}use(e){return this.isKitReady()?!e||!g(e)?Promise.reject(new Error("Rokt Kit: Invalid extension name")):this.launcher.use(e):(console.error("Rokt Kit: Not initialized"),Promise.reject(new Error("Rokt Kit: Not initialized")))}onShoppableAdsReady(e){this._isThankYouElementLoaded?e():this._thankYouElementOnLoadCallback=e}};h._allowedOriginHashes=[-553112570,549508659],h.PERFORMANCE_MARKS={RoktScriptAppended:"mp:RoktScriptAppended"},h.EMAIL_SHA256_KEY="emailsha256";let f=h;function ce(){return 181}function ue(n){if(!n){window.console.log("You must pass a config object to register the kit "+l);return}if(!L(n)){window.console.log("'config' must be an object. You passed in a "+typeof n);return}L(n.kits)?n.kits[l]={constructor:f}:(n.kits={},n.kits[l]={constructor:f}),window.console.log("Successfully registered "+l+" to your mParticle configuration")}return typeof window<"u"&&window.mParticle&&o().addForwarder&&o().addForwarder({name:l,constructor:f,getId:ce}),v.register=ue,Object.defineProperty(v,Symbol.toStringTag,{value:"Module"}),v})({});
|
|
2
2
|
//# sourceMappingURL=Rokt-Kit.iife.js.map
|