@mparticle/web-rokt-kit 1.26.1 → 1.26.3
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.d.ts +0 -1
- package/dist/Rokt-Kit.esm.js +70 -73
- 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.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;
|
|
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 o(){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 a=0;a<e.length;a++){const s=e[a].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,a=i.map;e[r]||(e[r]=[]),e[r].push({eventAttributeKey:a,conditions:Array.isArray(i.conditions)?i.conditions:[]})}return e}function Y(n,e,t){return o().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_"+o().getVersion()+"_kitv_"+"1.26.3";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 a=window.location.href.split("?")[0].split("#")[0],s="version="+encodeURIComponent(e??"")+"&launcherInstanceGuid="+encodeURIComponent(r)+"&pageUrl="+encodeURIComponent(a);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.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 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,a){this._reporter="mp-wsdk";const s=e.isLoggingEnabled;this._integrationName=t||"",this._launcherInstanceGuid=i,this._accountId=r||null,this._rateLimiter=a||new z,this._isEnabled=se()||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||N.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 j{constructor(e,t,i,r,a){this._transport=new P(e,t,i,r,a),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,a,s){this._transport=new P(e,i,r,a,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 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(k(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"?{}:k(this.placementEventMappingLookup)&&k(this.placementEventAttributeMappingLookup)?{}:o().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 o().logEvent!="function"||!O(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(S,{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 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=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,F(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=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=o().Rokt?.domain,{roktExtensionsQueryParams:b,legacyRoktExtensions:E,loadThankYouElement:L}=K(s.roktExtensions),h={...o().Rokt?.launcherOptions||{}};this.integrationName=re(h.integrationName),h.integrationName=this.integrationName,this.domain=m;const I={loggingUrl:s.loggingUrl,errorUrl:s.errorUrl,isLoggingEnabled:o().config?.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,o()._registerErrorReportingService&&o()._registerErrorReportingService(_),o()._registerLoggingService&&o()._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&&(o().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 o().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)]&&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,w.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,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||{},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():{},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 ce(){return S}function ue(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&&o().addForwarder&&o().addForwarder({name:l,constructor:f,getId:ce});exports.register=ue;
|
|
2
2
|
//# sourceMappingURL=Rokt-Kit.common.js.map
|
package/dist/Rokt-Kit.d.ts
CHANGED
package/dist/Rokt-Kit.esm.js
CHANGED
|
@@ -14,7 +14,7 @@ const w = {
|
|
|
14
14
|
INFO: "INFO",
|
|
15
15
|
WARNING: "WARNING"
|
|
16
16
|
}, $ = "apps.rokt-api.com/v1/log", Z = "apps.rokt-api.com/v1/errors", ee = 10;
|
|
17
|
-
function
|
|
17
|
+
function o() {
|
|
18
18
|
return window.mParticle;
|
|
19
19
|
}
|
|
20
20
|
function P(n, e) {
|
|
@@ -48,8 +48,8 @@ function S(n) {
|
|
|
48
48
|
function M(n) {
|
|
49
49
|
const e = n ? S(n) : [], t = [], i = [];
|
|
50
50
|
let r = !1;
|
|
51
|
-
for (let
|
|
52
|
-
const s = e[
|
|
51
|
+
for (let a = 0; a < e.length; a++) {
|
|
52
|
+
const s = e[a].value;
|
|
53
53
|
s === "thank-you-journey" ? (r = !0, i.push(B)) : t.push(s);
|
|
54
54
|
}
|
|
55
55
|
return {
|
|
@@ -75,7 +75,7 @@ function K(n) {
|
|
|
75
75
|
}
|
|
76
76
|
return e;
|
|
77
77
|
}
|
|
78
|
-
function
|
|
78
|
+
function x(n) {
|
|
79
79
|
const e = {};
|
|
80
80
|
if (!Array.isArray(n))
|
|
81
81
|
return e;
|
|
@@ -83,16 +83,16 @@ function D(n) {
|
|
|
83
83
|
const i = n[t];
|
|
84
84
|
if (!i || !g(i.value) || !g(i.map))
|
|
85
85
|
continue;
|
|
86
|
-
const r = i.value,
|
|
86
|
+
const r = i.value, a = i.map;
|
|
87
87
|
e[r] || (e[r] = []), e[r].push({
|
|
88
|
-
eventAttributeKey:
|
|
88
|
+
eventAttributeKey: a,
|
|
89
89
|
conditions: Array.isArray(i.conditions) ? i.conditions : []
|
|
90
90
|
});
|
|
91
91
|
}
|
|
92
92
|
return e;
|
|
93
93
|
}
|
|
94
|
-
function
|
|
95
|
-
return
|
|
94
|
+
function D(n, e, t) {
|
|
95
|
+
return o().generateHash([n, e, t].join(""));
|
|
96
96
|
}
|
|
97
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;
|
|
@@ -101,7 +101,7 @@ function g(n) {
|
|
|
101
101
|
return typeof n == "string";
|
|
102
102
|
}
|
|
103
103
|
function ie(n) {
|
|
104
|
-
let i = "mParticle_wsdkv_" +
|
|
104
|
+
let i = "mParticle_wsdkv_" + o().getVersion() + "_kitv_" + "1.26.3";
|
|
105
105
|
return n && (i += "_" + n), i;
|
|
106
106
|
}
|
|
107
107
|
function H(n) {
|
|
@@ -125,21 +125,18 @@ function Y(n, e) {
|
|
|
125
125
|
const r = window.__rokt_li_guid__;
|
|
126
126
|
if (!r)
|
|
127
127
|
return;
|
|
128
|
-
const
|
|
128
|
+
const a = window.location.href.split("?")[0].split("#")[0], s = "version=" + encodeURIComponent(e ?? "") + "&launcherInstanceGuid=" + encodeURIComponent(r) + "&pageUrl=" + encodeURIComponent(a);
|
|
129
129
|
O("https://" + (n || "apps.rokt.com") + "/v1/wsdk-init/index.html?" + s), O(
|
|
130
130
|
"https://" + Q + "/v1/wsdk-init/index.html?" + s + "&isControl=true"
|
|
131
131
|
);
|
|
132
132
|
}
|
|
133
133
|
function ne() {
|
|
134
|
-
return typeof window < "u" && !!window.ROKT_DOMAIN;
|
|
135
|
-
}
|
|
136
|
-
function re() {
|
|
137
134
|
return typeof window < "u" && !!window.location?.search?.toLowerCase().includes("mp_enable_logging=true");
|
|
138
135
|
}
|
|
139
|
-
function
|
|
136
|
+
function re() {
|
|
140
137
|
return typeof window < "u" ? window.location?.href : void 0;
|
|
141
138
|
}
|
|
142
|
-
function
|
|
139
|
+
function se() {
|
|
143
140
|
return typeof window < "u" ? window.navigator?.userAgent : void 0;
|
|
144
141
|
}
|
|
145
142
|
class W {
|
|
@@ -152,12 +149,12 @@ class W {
|
|
|
152
149
|
}
|
|
153
150
|
}
|
|
154
151
|
class N {
|
|
155
|
-
constructor(e, t, i, r,
|
|
152
|
+
constructor(e, t, i, r, a) {
|
|
156
153
|
this._reporter = "mp-wsdk";
|
|
157
|
-
const s = e
|
|
158
|
-
this._integrationName = t || "", this._launcherInstanceGuid = i, this._accountId = r || null, this._rateLimiter =
|
|
154
|
+
const s = e.isLoggingEnabled;
|
|
155
|
+
this._integrationName = t || "", this._launcherInstanceGuid = i, this._accountId = r || null, this._rateLimiter = a || new W(), this._isEnabled = ne() || s;
|
|
159
156
|
}
|
|
160
|
-
send(e, t, i, r,
|
|
157
|
+
send(e, t, i, r, a, s) {
|
|
161
158
|
if (!(!this._isEnabled || this._rateLimiter.incrementAndCheck(t)))
|
|
162
159
|
try {
|
|
163
160
|
const c = {
|
|
@@ -167,9 +164,9 @@ class N {
|
|
|
167
164
|
},
|
|
168
165
|
severity: t,
|
|
169
166
|
code: r || T.UNKNOWN_ERROR,
|
|
170
|
-
url:
|
|
171
|
-
deviceInfo:
|
|
172
|
-
stackTrace:
|
|
167
|
+
url: re(),
|
|
168
|
+
deviceInfo: se(),
|
|
169
|
+
stackTrace: a,
|
|
173
170
|
reporter: this._reporter,
|
|
174
171
|
integration: this._integrationName
|
|
175
172
|
}, u = {
|
|
@@ -191,8 +188,8 @@ class N {
|
|
|
191
188
|
}
|
|
192
189
|
}
|
|
193
190
|
class F {
|
|
194
|
-
constructor(e, t, i, r,
|
|
195
|
-
this._transport = new N(e, t, i, r,
|
|
191
|
+
constructor(e, t, i, r, a) {
|
|
192
|
+
this._transport = new N(e, t, i, r, a), this._errorUrl = "https://" + (e?.errorUrl || Z);
|
|
196
193
|
}
|
|
197
194
|
report(e) {
|
|
198
195
|
if (!e) return;
|
|
@@ -201,8 +198,8 @@ class F {
|
|
|
201
198
|
}
|
|
202
199
|
}
|
|
203
200
|
class j {
|
|
204
|
-
constructor(e, t, i, r,
|
|
205
|
-
this._transport = new N(e, i, r,
|
|
201
|
+
constructor(e, t, i, r, a, s) {
|
|
202
|
+
this._transport = new N(e, i, r, a, s), this._loggingUrl = "https://" + (e?.loggingUrl || $), this._errorReportingService = t;
|
|
206
203
|
}
|
|
207
204
|
log(e) {
|
|
208
205
|
e && this._transport.send(
|
|
@@ -245,24 +242,24 @@ const p = class p {
|
|
|
245
242
|
const r = this.getEventAttributeValue(e, t.eventAttributeKey);
|
|
246
243
|
if (i.length === 0)
|
|
247
244
|
return r !== null;
|
|
248
|
-
for (let
|
|
249
|
-
if (!this.doesEventAttributeConditionMatch(i[
|
|
245
|
+
for (let a = 0; a < i.length; a++)
|
|
246
|
+
if (!this.doesEventAttributeConditionMatch(i[a], r))
|
|
250
247
|
return !1;
|
|
251
248
|
return !0;
|
|
252
249
|
}
|
|
253
250
|
applyPlacementEventAttributeMapping(e) {
|
|
254
251
|
const t = Object.keys(this.placementEventAttributeMappingLookup);
|
|
255
252
|
for (let i = 0; i < t.length; i++) {
|
|
256
|
-
const r = t[i],
|
|
257
|
-
if (y(
|
|
253
|
+
const r = t[i], a = this.placementEventAttributeMappingLookup[r];
|
|
254
|
+
if (y(a))
|
|
258
255
|
continue;
|
|
259
256
|
let s = !0;
|
|
260
|
-
for (let c = 0; c <
|
|
261
|
-
if (!this.doesEventMatchRule(e,
|
|
257
|
+
for (let c = 0; c < a.length; c++)
|
|
258
|
+
if (!this.doesEventMatchRule(e, a[c])) {
|
|
262
259
|
s = !1;
|
|
263
260
|
break;
|
|
264
261
|
}
|
|
265
|
-
s &&
|
|
262
|
+
s && o().Rokt.setLocalSessionAttribute?.(r, !0);
|
|
266
263
|
}
|
|
267
264
|
}
|
|
268
265
|
isLauncherReadyToAttach() {
|
|
@@ -278,20 +275,20 @@ const p = class p {
|
|
|
278
275
|
return this.replaceOtherIdentityWithEmailsha256(t);
|
|
279
276
|
}
|
|
280
277
|
returnLocalSessionAttributes() {
|
|
281
|
-
return !
|
|
278
|
+
return !o().Rokt || typeof o().Rokt.getLocalSessionAttributes != "function" ? {} : y(this.placementEventMappingLookup) && y(this.placementEventAttributeMappingLookup) ? {} : o().Rokt.getLocalSessionAttributes();
|
|
282
279
|
}
|
|
283
280
|
replaceOtherIdentityWithEmailsha256(e) {
|
|
284
281
|
const t = { ...e || {} }, i = this._mappedEmailSha256Key;
|
|
285
282
|
return i && e[i] && (t[p.EMAIL_SHA256_KEY] = e[i]), i && delete t[i], t;
|
|
286
283
|
}
|
|
287
284
|
logSelectPlacementsEvent(e) {
|
|
288
|
-
if (!window.mParticle || typeof
|
|
285
|
+
if (!window.mParticle || typeof o().logEvent != "function" || !L(e))
|
|
289
286
|
return;
|
|
290
|
-
const t =
|
|
291
|
-
|
|
287
|
+
const t = o().EventType.Other;
|
|
288
|
+
o().logEvent(z, t, e);
|
|
292
289
|
}
|
|
293
290
|
buildIdentityEvent(e, t) {
|
|
294
|
-
const i = t.getMPID(), r =
|
|
291
|
+
const i = t.getMPID(), r = o() && o().sessionManager && typeof o().sessionManager.getSession == "function" ? o().sessionManager.getSession() : void 0;
|
|
295
292
|
return {
|
|
296
293
|
event_type: e,
|
|
297
294
|
data: {
|
|
@@ -333,7 +330,7 @@ const p = class p {
|
|
|
333
330
|
setRoktSessionId(e) {
|
|
334
331
|
if (!(!e || typeof e != "string"))
|
|
335
332
|
try {
|
|
336
|
-
const t =
|
|
333
|
+
const t = o().getInstance();
|
|
337
334
|
t && typeof t.setIntegrationAttribute == "function" && t.setIntegrationAttribute(181, {
|
|
338
335
|
roktSessionId: e
|
|
339
336
|
});
|
|
@@ -341,13 +338,13 @@ const p = class p {
|
|
|
341
338
|
}
|
|
342
339
|
}
|
|
343
340
|
attachLauncher(e, t, i = []) {
|
|
344
|
-
const r =
|
|
341
|
+
const r = o() && o().sessionManager && typeof o().sessionManager.getSession == "function" ? o().sessionManager.getSession() : void 0, a = {
|
|
345
342
|
accountId: e,
|
|
346
343
|
...t || {},
|
|
347
344
|
...r ? { mpSessionId: r } : {}
|
|
348
345
|
};
|
|
349
346
|
let s;
|
|
350
|
-
this.isPartnerInLocalLauncherTestGroup() ? s = Promise.resolve(window.Rokt.createLocalLauncher(
|
|
347
|
+
this.isPartnerInLocalLauncherTestGroup() ? s = Promise.resolve(window.Rokt.createLocalLauncher(a)) : s = window.Rokt.createLauncher(a), s.then(async (c) => {
|
|
351
348
|
await te(i, c), this.initRoktLauncher(c);
|
|
352
349
|
}).catch((c) => {
|
|
353
350
|
console.error("Error creating Rokt launcher:", c);
|
|
@@ -355,15 +352,15 @@ const p = class p {
|
|
|
355
352
|
}
|
|
356
353
|
initRoktLauncher(e) {
|
|
357
354
|
window.Rokt && (window.Rokt.currentLauncher = e), this.launcher = e;
|
|
358
|
-
const t =
|
|
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),
|
|
355
|
+
const t = o().Rokt?.filters;
|
|
356
|
+
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), o().Rokt.attachKit(this), this.drainBatchQueue();
|
|
360
357
|
}
|
|
361
358
|
fetchOptimizely() {
|
|
362
|
-
const e =
|
|
359
|
+
const e = o()._getActiveForwarders().filter((t) => t.name === "Optimizely");
|
|
363
360
|
try {
|
|
364
361
|
if (e.length > 0 && window.optimizely) {
|
|
365
362
|
const t = window.optimizely.get("state");
|
|
366
|
-
return !t || !t.getActiveExperimentIds ? {} : t.getActiveExperimentIds().reduce((
|
|
363
|
+
return !t || !t.getActiveExperimentIds ? {} : t.getActiveExperimentIds().reduce((a, s) => (a["rokt.custom.optimizely.experiment." + s + ".variationId"] = t.getVariationMap()[s].id, a), {});
|
|
367
364
|
}
|
|
368
365
|
} catch (t) {
|
|
369
366
|
console.error("Error fetching Optimizely attributes:", t);
|
|
@@ -374,37 +371,37 @@ const p = class p {
|
|
|
374
371
|
return !!(this.isInitialized && this.launcher);
|
|
375
372
|
}
|
|
376
373
|
isPartnerInLocalLauncherTestGroup() {
|
|
377
|
-
return !!(
|
|
374
|
+
return !!(o().config && o().config.isLocalLauncherEnabled && this.isAssignedToSampleGroup());
|
|
378
375
|
}
|
|
379
376
|
isAssignedToSampleGroup() {
|
|
380
377
|
return Math.random() > 0.5;
|
|
381
378
|
}
|
|
382
379
|
captureTiming(e) {
|
|
383
|
-
window &&
|
|
380
|
+
window && o() && o().captureTiming && e && o().captureTiming(e);
|
|
384
381
|
}
|
|
385
382
|
// ---- Public methods (mParticle Kit Callbacks) ----
|
|
386
383
|
/**
|
|
387
384
|
* Initializes the Rokt forwarder with settings from the mParticle server.
|
|
388
385
|
*/
|
|
389
|
-
init(e, t, i, r,
|
|
386
|
+
init(e, t, i, r, a) {
|
|
390
387
|
const s = e, c = s.accountId;
|
|
391
|
-
this.userAttributes =
|
|
388
|
+
this.userAttributes = a || {}, this._onboardingExpProvider = s.onboardingExpProvider;
|
|
392
389
|
const u = S(s.placementEventMapping);
|
|
393
390
|
this.placementEventMappingLookup = K(u);
|
|
394
391
|
const d = S(
|
|
395
392
|
s.placementEventAttributeMapping
|
|
396
393
|
);
|
|
397
|
-
this.placementEventAttributeMappingLookup =
|
|
398
|
-
const m =
|
|
394
|
+
this.placementEventAttributeMappingLookup = x(d), s.hashedEmailUserIdentityType && (this._mappedEmailSha256Key = s.hashedEmailUserIdentityType.toLowerCase()), this._workspaceIdSyncApiKey = g(s.workspaceIdSyncApiKey) ? s.workspaceIdSyncApiKey : void 0;
|
|
395
|
+
const m = o().Rokt?.domain, { roktExtensionsQueryParams: v, legacyRoktExtensions: E, loadThankYouElement: b } = M(
|
|
399
396
|
s.roktExtensions
|
|
400
397
|
), h = {
|
|
401
|
-
...
|
|
398
|
+
...o().Rokt?.launcherOptions || {}
|
|
402
399
|
};
|
|
403
400
|
this.integrationName = ie(h.integrationName), h.integrationName = this.integrationName, this.domain = m;
|
|
404
401
|
const k = {
|
|
405
402
|
loggingUrl: s.loggingUrl,
|
|
406
403
|
errorUrl: s.errorUrl,
|
|
407
|
-
isLoggingEnabled:
|
|
404
|
+
isLoggingEnabled: o().config?.isLoggingEnabled === !0
|
|
408
405
|
}, _ = new F(
|
|
409
406
|
k,
|
|
410
407
|
this.integrationName,
|
|
@@ -417,14 +414,14 @@ const p = class p {
|
|
|
417
414
|
window.__rokt_li_guid__,
|
|
418
415
|
s.accountId
|
|
419
416
|
);
|
|
420
|
-
return this.errorReportingService = _, this.loggingService = R,
|
|
417
|
+
return this.errorReportingService = _, this.loggingService = R, o()._registerErrorReportingService && o()._registerErrorReportingService(_), o()._registerLoggingService && o()._registerLoggingService(R), i ? (this.testHelpers = {
|
|
421
418
|
generateLauncherScript: P,
|
|
422
419
|
generateThankYouElementScript: U,
|
|
423
420
|
extractRoktExtensionConfig: M,
|
|
424
|
-
hashEventMessage:
|
|
421
|
+
hashEventMessage: D,
|
|
425
422
|
parseSettingsString: S,
|
|
426
423
|
generateMappedEventLookup: K,
|
|
427
|
-
generateMappedEventAttributeLookup:
|
|
424
|
+
generateMappedEventAttributeLookup: x,
|
|
428
425
|
sendAdBlockMeasurementSignals: Y,
|
|
429
426
|
createAutoRemovedIframe: O,
|
|
430
427
|
djb2: H,
|
|
@@ -437,7 +434,7 @@ const p = class p {
|
|
|
437
434
|
RateLimiter: W,
|
|
438
435
|
ErrorCodes: T,
|
|
439
436
|
WSDKErrorSeverity: A
|
|
440
|
-
}, this.attachLauncher(c, h), "Successfully initialized: " + l) : (b && (
|
|
437
|
+
}, this.attachLauncher(c, h), "Successfully initialized: " + l) : (b && (o().Rokt.flushOnShoppableAdsReadyMessageQueue?.(this), C(q, U(m), {
|
|
441
438
|
onLoad: () => {
|
|
442
439
|
this._isThankYouElementLoaded = !0, this._thankYouElementOnLoadCallback && this._thankYouElementOnLoadCallback();
|
|
443
440
|
},
|
|
@@ -456,9 +453,9 @@ const p = class p {
|
|
|
456
453
|
process(e) {
|
|
457
454
|
if (!this.isKitReady())
|
|
458
455
|
return "Kit not ready for forwarder: " + l;
|
|
459
|
-
if (typeof
|
|
460
|
-
const t =
|
|
461
|
-
this.placementEventMappingLookup[String(t)] &&
|
|
456
|
+
if (typeof o().Rokt?.setLocalSessionAttribute == "function" && (y(this.placementEventAttributeMappingLookup) || this.applyPlacementEventAttributeMapping(e), !y(this.placementEventMappingLookup))) {
|
|
457
|
+
const t = D(e.EventDataType, e.EventCategory, e.EventName ?? "");
|
|
458
|
+
this.placementEventMappingLookup[String(t)] && o().Rokt.setLocalSessionAttribute?.(this.placementEventMappingLookup[String(t)], !0);
|
|
462
459
|
}
|
|
463
460
|
return "Successfully sent to forwarder: " + l;
|
|
464
461
|
}
|
|
@@ -487,22 +484,22 @@ const p = class p {
|
|
|
487
484
|
const t = this._workspaceIdSyncApiKey;
|
|
488
485
|
if (!t)
|
|
489
486
|
return this.userIdentifiedInWorkspace = !1, this._workspaceLastSearchedIdentitiesKey = void 0, Promise.resolve();
|
|
490
|
-
const i =
|
|
487
|
+
const i = o().Identity?.search;
|
|
491
488
|
if (typeof i != "function")
|
|
492
489
|
return this.userIdentifiedInWorkspace = !1, this._workspaceLastSearchedIdentitiesKey = void 0, Promise.resolve();
|
|
493
|
-
const r = e.getUserIdentities ? e.getUserIdentities().userIdentities : null,
|
|
490
|
+
const r = e.getUserIdentities ? e.getUserIdentities().userIdentities : null, a = {};
|
|
494
491
|
if (r)
|
|
495
492
|
for (const u of Object.keys(r)) {
|
|
496
493
|
const d = r[u];
|
|
497
|
-
g(d) && d.length > 0 && (
|
|
494
|
+
g(d) && d.length > 0 && (a[u] = d);
|
|
498
495
|
}
|
|
499
|
-
const s = Object.keys(
|
|
496
|
+
const s = Object.keys(a);
|
|
500
497
|
if (s.length === 0)
|
|
501
498
|
return this.userIdentifiedInWorkspace = !1, this._workspaceLastSearchedIdentitiesKey = void 0, Promise.resolve();
|
|
502
|
-
const c = s.sort().map((u) => `${u}=${
|
|
499
|
+
const c = s.sort().map((u) => `${u}=${a[u]}`).join("&");
|
|
503
500
|
return c === this._workspaceLastSearchedIdentitiesKey ? this._workspaceSearchInFlightPromise || Promise.resolve() : (this.userIdentifiedInWorkspace = !1, this._workspaceLastSearchedIdentitiesKey = c, new Promise((u) => {
|
|
504
501
|
try {
|
|
505
|
-
i(t,
|
|
502
|
+
i(t, a, (d) => {
|
|
506
503
|
d?.httpCode === 200 && (this.userIdentifiedInWorkspace = !0), u();
|
|
507
504
|
});
|
|
508
505
|
} catch (d) {
|
|
@@ -553,9 +550,9 @@ const p = class p {
|
|
|
553
550
|
return this._dispatchPlacements(e);
|
|
554
551
|
}
|
|
555
552
|
_dispatchPlacements(e) {
|
|
556
|
-
const t = e && e.attributes || {}, i = { ...this.userAttributes, ...t }, r = this.filters || {},
|
|
553
|
+
const t = e && e.attributes || {}, i = { ...this.userAttributes, ...t }, r = this.filters || {}, a = r.userAttributeFilters || [], s = r.filteredUser || null, c = s ? s.getMPID() : null;
|
|
557
554
|
let u;
|
|
558
|
-
r ? r.filterUserAttributes ? u = r.filterUserAttributes(i,
|
|
555
|
+
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;
|
|
559
556
|
const d = this._onboardingExpProvider === "Optimizely" ? this.fetchOptimizely() : {}, m = this.returnUserIdentities(s), v = this.returnLocalSessionAttributes(), E = {
|
|
560
557
|
...m,
|
|
561
558
|
...u,
|
|
@@ -592,10 +589,10 @@ p._allowedOriginHashes = [-553112570, 549508659], p.PERFORMANCE_MARKS = {
|
|
|
592
589
|
RoktScriptAppended: "mp:RoktScriptAppended"
|
|
593
590
|
}, p.EMAIL_SHA256_KEY = "emailsha256";
|
|
594
591
|
let f = p;
|
|
595
|
-
function
|
|
592
|
+
function oe() {
|
|
596
593
|
return 181;
|
|
597
594
|
}
|
|
598
|
-
function
|
|
595
|
+
function ae(n) {
|
|
599
596
|
if (!n) {
|
|
600
597
|
window.console.log("You must pass a config object to register the kit " + l);
|
|
601
598
|
return;
|
|
@@ -610,12 +607,12 @@ function ce(n) {
|
|
|
610
607
|
constructor: f
|
|
611
608
|
}), window.console.log("Successfully registered " + l + " to your mParticle configuration");
|
|
612
609
|
}
|
|
613
|
-
typeof window < "u" && window.mParticle &&
|
|
610
|
+
typeof window < "u" && window.mParticle && o().addForwarder && o().addForwarder({
|
|
614
611
|
name: l,
|
|
615
612
|
constructor: f,
|
|
616
|
-
getId:
|
|
613
|
+
getId: oe
|
|
617
614
|
});
|
|
618
615
|
export {
|
|
619
|
-
|
|
616
|
+
ae as register
|
|
620
617
|
};
|
|
621
618
|
//# sourceMappingURL=Rokt-Kit.esm.js.map
|
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.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})({});
|
|
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 S(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?S(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.3";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.location?.search?.toLowerCase().includes("mp_enable_logging=true")}function se(){return typeof window<"u"?window.location?.href:void 0}function oe(){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;this._integrationName=t||"",this._launcherInstanceGuid=i,this._accountId=r||null,this._rateLimiter=a||new H,this._isEnabled=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:se(),deviceInfo:oe(),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=S(s.placementEventMapping);this.placementEventMappingLookup=Y(u);const d=S(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 w={loggingUrl:s.loggingUrl,errorUrl:s.errorUrl,isLoggingEnabled:o().config?.isLoggingEnabled===!0},y=new W(w,this.integrationName,window.__rokt_li_guid__,s.accountId),A=new z(w,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:S,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),w=()=>this.logSelectPlacementsEvent(_);return Promise.resolve(p).then(y=>y?.context?.sessionId?.then(A=>this.setRoktSessionId(A))).catch(()=>{}).finally(w),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 ae(){return 181}function ce(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:ae}),v.register=ce,Object.defineProperty(v,Symbol.toStringTag,{value:"Module"}),v})({});
|
|
2
2
|
//# sourceMappingURL=Rokt-Kit.iife.js.map
|