@mparticle/web-rokt-kit 1.28.3 → 1.30.0
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 +350 -259
- 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 B=["billingaddress1","billingaddress2","billingcity","billingstate","billingzipcode","cartitems","ccbin","confirmationref","conversiontype","country","couponcode","currency","language","paymentserviceprovider","paymentserviceproviderattribute","paymenttype","shippingaddress1","shippingcity","shippingcountry","shippingmethod","shippingstate","shippingzipcode","totalprice"],J=new Set(B);function G(n){return J.has(n.toLowerCase())}function w(n){const t={},e=n||{},i=Object.keys(e);for(let r=0;r<i.length;r++){const s=i[r];G(s)||(t[s]=e[s])}return t}const d="Rokt",b=181,Q="selectPlacements",X="apps.roktecommerce.com",$=.1,Z="ThankYouPageJourney",tt="rokt-launcher",et="rokt-thank-you-element",it="userIdentifiedInWorkspace",nt=500,N={UNKNOWN_ERROR:"UNKNOWN_ERROR",UNHANDLED_EXCEPTION:"UNHANDLED_EXCEPTION",IDENTITY_REQUEST:"IDENTITY_REQUEST",LOG_DELIVERY_FAILURE:"LOG_DELIVERY_FAILURE"},I={ERROR:"ERROR",INFO:"INFO",WARNING:"WARNING"},rt="apps.rokt-api.com",st="/v1/log",ot="/v1/errors",at=10;function a(){return window.mParticle}function U(n,t){const i=[P(n),"/wsdk/integrations/launcher.js"].join("");return!t||t.length===0?i:i+"?extensions="+t.join(",")}function K(n){return[P(n),"/rokt-elements/rokt-element-thank-you.js"].join("")}function P(n){return["https://",typeof n<"u"?n:rt].join("")}function z(n,t,e){return n?n.startsWith("http://")||n.startsWith("https://")?n:"https://"+n:P(t)+e}function M(n,t,e){if(document.getElementById(n))return;const i=document.head||document.body,r=document.createElement("script");r.id=n,r.type="text/javascript",r.src=t,r.async=!0,r.crossOrigin="anonymous",r.fetchPriority="high",e?.onLoad&&(r.onload=e.onLoad),e?.onError&&(r.onerror=e.onError),i.appendChild(r)}function T(n){return n!=null&&typeof n=="object"&&Array.isArray(n)===!1}function L(n){if(!n)return[];try{return JSON.parse(n.replace(/"/g,'"'))}catch{console.error("Settings string contains invalid JSON")}return[]}function D(n){const t=n?L(n):[],e=[],i=[];let r=!1;for(let s=0;s<t.length;s++){const o=t[s].value;o==="thank-you-journey"?(r=!0,i.push(Z)):e.push(o)}return{roktExtensionsQueryParams:e,legacyRoktExtensions:i,loadThankYouElement:r}}async function ct(n,t){const e=[];if(t)for(const i of n)e.push(t.use(i));return Promise.all(e)}function x(n){if(!n)return{};const t={};for(let e=0;e<n.length;e++){const i=n[e];t[i.jsmap]=i.value}return t}function Y(n){const t={};if(!Array.isArray(n))return t;for(let e=0;e<n.length;e++){const i=n[e];if(!i||!m(i.value)||!m(i.map))continue;const r=i.value,s=i.map;t[r]||(t[r]=[]),t[r].push({eventAttributeKey:s,conditions:Array.isArray(i.conditions)?i.conditions:[]})}return t}function j(n,t,e){return a().generateHash([n,t,e].join(""))}function k(n){return n==null?!0:typeof n=="object"?Object.keys(n).length===0:Array.isArray(n)?n.length===0:!1}function m(n){return typeof n=="string"}function lt(n){let i="mParticle_wsdkv_"+a().getVersion()+"_kitv_"+"1.28.3";return n&&(i+="_"+n),i}function V(n){let t=5381;for(let e=0;e<n.length;e++)t=(t<<5)+t+n.charCodeAt(e),t=t&t;return t}function O(n){const t=document.createElement("iframe");t.style.display="none",t.setAttribute("sandbox","allow-scripts allow-same-origin"),t.src=n,t.onload=function(){t.onload=null,t.parentNode&&t.parentNode.removeChild(t)};const e=document.body||document.head;e&&e.appendChild(t)}function F(n,t){const e=V(window.location.origin);if(E._allowedOriginHashes.indexOf(e)===-1||Math.random()>=$)return;const r=window.__rokt_li_guid__;if(!r)return;const s=window.location.href.split("?")[0].split("#")[0],o="version="+encodeURIComponent(t??"")+"&launcherInstanceGuid="+encodeURIComponent(r)+"&pageUrl="+encodeURIComponent(s);O("https://"+(n||"apps.rokt.com")+"/v1/wsdk-init/index.html?"+o),O("https://"+X+"/v1/wsdk-init/index.html?"+o+"&isControl=true")}function ut(){return typeof window<"u"&&!!window.location?.search?.toLowerCase().includes("mp_enable_logging=true")}function dt(){return typeof window<"u"?window.location?.href:void 0}function ht(){return typeof window<"u"?window.navigator?.userAgent:void 0}class q{constructor(){this._logCount={}}incrementAndCheck(t){const i=(this._logCount[t]||0)+1;return this._logCount[t]=i,i>at}}class C{constructor(t,e,i,r,s){this._reporter="mp-wsdk";const o=t.isLoggingEnabled;this._integrationName=e||"",this._launcherInstanceGuid=i,this._accountId=r||null,this._rateLimiter=s||new q,this._isEnabled=ut()||o}send(t,e,i,r,s,o){if(!(!this._isEnabled||this._rateLimiter.incrementAndCheck(e)))try{const c={additionalInformation:{message:i,version:this._integrationName},severity:e,code:r||N.UNKNOWN_ERROR,url:dt(),deviceInfo:ht(),stackTrace:s,reporter:this._reporter,integration:this._integrationName},u={Accept:"text/plain;charset=UTF-8","Content-Type":"application/json","rokt-launcher-version":this._integrationName,"rokt-wsdk-version":"joint"};this._launcherInstanceGuid&&(u["rokt-launcher-instance-guid"]=this._launcherInstanceGuid),this._accountId&&(u["rokt-account-id"]=this._accountId),fetch(t,{method:"POST",headers:u,body:JSON.stringify(c)}).then(l=>{if(!l.ok){const h=new Error("HTTP "+l.status+" from log endpoint");throw h.statusCode=l.status,h}}).catch(l=>{console.error("ReportingTransport: Failed to send log",l),o&&o(l)})}catch(c){console.error("ReportingTransport: Failed to send log",c),o&&o(c)}}}class H{constructor(t,e,i,r,s){this._transport=new C(t,e,i,r,s),this._errorUrl=z(t?.errorUrl,t?.integrationDomain,ot)}report(t){if(!t)return;const e=t.severity||I.ERROR;this._transport.send(this._errorUrl,e,t.message,t.code,t.stackTrace)}}class W{constructor(t,e,i,r,s,o){this._transport=new C(t,i,r,s,o),this._loggingUrl=z(t?.loggingUrl,t?.integrationDomain,st),this._errorReportingService=e}log(t){t&&this._transport.send(this._loggingUrl,I.INFO,t.message,t.code,void 0,e=>{if(this._errorReportingService){const i=typeof e.statusCode=="number";this._errorReportingService.report({message:"LoggingService: Failed to send log: "+e.message,code:N.LOG_DELIVERY_FAILURE,severity:i?I.ERROR:I.WARNING})}})}}const p=class p{constructor(){this.name=d,this.id=b,this.moduleId=b,this.isInitialized=!1,this.launcher=null,this.filters={},this.userAttributes={},this.userIdentifiedInWorkspace=!1,this.testHelpers=null,this.placementEventMappingLookup={},this.placementEventAttributeMappingLookup={},this.integrationName=null,this.errorReportingService=null,this.loggingService=null,this._thankYouElementOnLoadCallback=null,this._isThankYouElementLoaded=!1,this._workspaceSearchInFlightPromise=null}getEventAttributeValue(t,e){const i=t&&t.EventAttributes;return!i||typeof i[e]>"u"?null:i[e]}doesEventAttributeConditionMatch(t,e){if(!t||!m(t.operator))return!1;const i=t.operator.toLowerCase(),r=t.attributeValue;return i==="exists"?e!==null:e==null?!1:i==="equals"?String(e)===String(r):i==="contains"?String(e).indexOf(String(r))!==-1:!1}doesEventMatchRule(t,e){if(!e||!m(e.eventAttributeKey))return!1;const i=e.conditions;if(!Array.isArray(i))return!1;const r=this.getEventAttributeValue(t,e.eventAttributeKey);if(i.length===0)return r!==null;for(let s=0;s<i.length;s++)if(!this.doesEventAttributeConditionMatch(i[s],r))return!1;return!0}applyPlacementEventAttributeMapping(t){const e=Object.keys(this.placementEventAttributeMappingLookup);for(let i=0;i<e.length;i++){const r=e[i],s=this.placementEventAttributeMappingLookup[r];if(k(s))continue;let o=!0;for(let c=0;c<s.length;c++)if(!this.doesEventMatchRule(t,s[c])){o=!1;break}o&&a().Rokt.setLocalSessionAttribute?.(r,!0)}}isLauncherReadyToAttach(){return!!window.Rokt&&typeof window.Rokt.createLauncher=="function"}returnUserIdentities(t){if(!t||!t.getUserIdentities)return{};const e=t.getUserIdentities().userIdentities;return this.replaceOtherIdentityWithEmailsha256(e)}returnLocalSessionAttributes(){return!a().Rokt||typeof a().Rokt.getLocalSessionAttributes!="function"?{}:k(this.placementEventMappingLookup)&&k(this.placementEventAttributeMappingLookup)?{}:a().Rokt.getLocalSessionAttributes()}replaceOtherIdentityWithEmailsha256(t){const e={...t||{}},i=this._mappedEmailSha256Key;return i&&t[i]&&(e[p.EMAIL_SHA256_KEY]=t[i]),i&&delete e[i],e}logSelectPlacementsEvent(t){if(!window.mParticle||typeof a().logEvent!="function"||!T(t))return;const e=a().EventType.Other;a().logEvent(Q,e,t)}setRoktSessionId(t){if(!(!t||typeof t!="string"))try{const e=a().getInstance();e&&typeof e.setIntegrationAttribute=="function"&&e.setIntegrationAttribute(b,{roktSessionId:t})}catch{}}attachLauncher(t,e,i=[]){const r=a()&&a().sessionManager&&typeof a().sessionManager.getSession=="function"?a().sessionManager.getSession():void 0,s={accountId:t,...e||{},...r?{mpSessionId:r}:{}};let o;this.isPartnerInLocalLauncherTestGroup()?o=Promise.resolve(window.Rokt.createLocalLauncher(s)):o=window.Rokt.createLauncher(s),o.then(async c=>{await ct(i,c),this.initRoktLauncher(c)}).catch(c=>{console.error("Error creating Rokt launcher:",c)})}initRoktLauncher(t){window.Rokt&&(window.Rokt.currentLauncher=t),this.launcher=t;const e=a().Rokt?.filters;e?(this.filters=e,e.filteredUser?this._workspaceSearchInFlightPromise=this.search(e.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)}fetchOptimizely(){const t=a()._getActiveForwarders().filter(e=>e.name==="Optimizely");try{if(t.length>0&&window.optimizely){const e=window.optimizely.get("state");return!e||!e.getActiveExperimentIds?{}:e.getActiveExperimentIds().reduce((s,o)=>(s["rokt.custom.optimizely.experiment."+o+".variationId"]=e.getVariationMap()[o].id,s),{})}}catch(e){console.error("Error fetching Optimizely attributes:",e)}return{}}isKitReady(){return!!(this.isInitialized&&this.launcher)}isPartnerInLocalLauncherTestGroup(){return!!(a().config&&a().config.isLocalLauncherEnabled&&this.isAssignedToSampleGroup())}isAssignedToSampleGroup(){return Math.random()>.5}captureTiming(t){window&&a()&&a().captureTiming&&t&&a().captureTiming(t)}init(t,e,i,r,s){const o=t,c=o.accountId;this.userAttributes=w(s),this._onboardingExpProvider=o.onboardingExpProvider;const u=L(o.placementEventMapping);this.placementEventMappingLookup=x(u);const l=L(o.placementEventAttributeMapping);this.placementEventAttributeMappingLookup=Y(l),o.hashedEmailUserIdentityType&&(this._mappedEmailSha256Key=o.hashedEmailUserIdentityType.toLowerCase()),this._workspaceIdSyncApiKey=m(o.workspaceIdSyncApiKey)?o.workspaceIdSyncApiKey:void 0;const h=a().Rokt?.domain,{roktExtensionsQueryParams:v,legacyRoktExtensions:R,loadThankYouElement:A}=D(o.roktExtensions),g={...a().Rokt?.launcherOptions||{}};this.integrationName=lt(g.integrationName),g.integrationName=this.integrationName,this.domain=h;const _={loggingUrl:o.loggingUrl,errorUrl:o.errorUrl,integrationDomain:h,isLoggingEnabled:a().config?.isLoggingEnabled===!0},y=new H(_,this.integrationName,window.__rokt_li_guid__,o.accountId),S=new W(_,y,this.integrationName,window.__rokt_li_guid__,o.accountId);return this.errorReportingService=y,this.loggingService=S,a()._registerErrorReportingService&&a()._registerErrorReportingService(y),a()._registerLoggingService&&a()._registerLoggingService(S),i?(this.testHelpers={generateLauncherScript:U,generateThankYouElementScript:K,extractRoktExtensionConfig:D,hashEventMessage:j,parseSettingsString:L,generateMappedEventLookup:x,generateMappedEventAttributeLookup:Y,sendAdBlockMeasurementSignals:F,createAutoRemovedIframe:O,djb2:V,setAllowedOriginHashes:f=>{p._allowedOriginHashes=f},ReportingTransport:C,ErrorReportingService:H,LoggingService:W,RateLimiter:q,ErrorCodes:N,WSDKErrorSeverity:I},this.attachLauncher(c,g),"Successfully initialized: "+d):(A&&(a().Rokt.flushOnShoppableAdsReadyMessageQueue?.(this),M(et,K(h),{onLoad:()=>{this._isThankYouElementLoaded=!0,this._thankYouElementOnLoadCallback&&this._thankYouElementOnLoadCallback()},onError:f=>{console.error("Error loading Rokt Thank You Element script:",f)}})),this.isLauncherReadyToAttach()?this.attachLauncher(c,g,R):(M(tt,U(h,v),{onLoad:()=>{this.isLauncherReadyToAttach()?this.attachLauncher(c,g,R):console.error("Rokt object is not available after script load.")},onError:f=>{console.error("Error loading Rokt launcher script:",f)}}),this.captureTiming(p.PERFORMANCE_MARKS.RoktScriptAppended)),"Successfully initialized: "+d)}process(t){if(!this.isKitReady())return"Kit not ready for forwarder: "+d;if(typeof a().Rokt?.setLocalSessionAttribute=="function"&&(k(this.placementEventAttributeMappingLookup)||this.applyPlacementEventAttributeMapping(t),!k(this.placementEventMappingLookup))){const e=j(t.EventDataType,t.EventCategory,t.EventName??"");this.placementEventMappingLookup[String(e)]&&a().Rokt.setLocalSessionAttribute?.(this.placementEventMappingLookup[String(e)],!0)}return"Successfully sent to forwarder: "+d}setExtensionData(t){if(!this.isKitReady()){console.error("Rokt Kit: Not initialized");return}window.Rokt.setExtensionData(t)}setUserAttribute(t,e){return G(t)||(this.userAttributes[t]=e),"Successfully set user attribute for forwarder: "+d}removeUserAttribute(t){return delete this.userAttributes[t],"Successfully removed user attribute for forwarder: "+d}handleIdentityComplete(t,e){return this.userAttributes=w(t.getAllUserAttributes()),"Successfully called "+e+" for forwarder: "+d}onUserIdentified(t){const e=t;return this.filters.filteredUser=e,this._workspaceSearchInFlightPromise=this.search(e),this.handleIdentityComplete(t,"onUserIdentified")}search(t){const e=this._workspaceIdSyncApiKey;if(!e)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=t.getUserIdentities?t.getUserIdentities().userIdentities:null,s={};if(r)for(const u of Object.keys(r)){const l=r[u];m(l)&&l.length>0&&(s[u]=l)}const o=Object.keys(s);if(o.length===0)return this.userIdentifiedInWorkspace=!1,this._workspaceLastSearchedIdentitiesKey=void 0,Promise.resolve();const c=o.sort().map(u=>`${u}=${s[u]}`).join("&");return c===this._workspaceLastSearchedIdentitiesKey?this._workspaceSearchInFlightPromise||Promise.resolve():(this.userIdentifiedInWorkspace=!1,this._workspaceLastSearchedIdentitiesKey=c,new Promise(u=>{try{i(e,s,l=>{l?.httpCode===200&&(this.userIdentifiedInWorkspace=!0),u()})}catch(l){console.error("Rokt Kit: Workspace IDSync search failed",l),this._workspaceLastSearchedIdentitiesKey=void 0,u()}}))}onLoginComplete(t,e){return this.handleIdentityComplete(t,"onLoginComplete")}onLogoutComplete(t,e){return this.userIdentifiedInWorkspace=!1,this._workspaceSearchInFlightPromise=null,this._workspaceLastSearchedIdentitiesKey=void 0,this.handleIdentityComplete(t,"onLogoutComplete")}onModifyComplete(t,e){return this.handleIdentityComplete(t,"onModifyComplete")}selectPlacements(t){if(this._workspaceSearchInFlightPromise){const e=this._workspaceSearchInFlightPromise;return Promise.race([e,new Promise(i=>setTimeout(i,nt))]).then(()=>this._dispatchPlacements(t))}return this._dispatchPlacements(t)}_dispatchPlacements(t){const e=t&&t.attributes||{},r={...w(this.userAttributes),...e},s=this.filters||{},o=s.userAttributeFilters||[],c=s.filteredUser||null,u=c?c.getMPID():null;let l;s?s.filterUserAttributes?l=s.filterUserAttributes(r,o):l=r:(console.warn("Rokt Kit: No filters available, using user attributes"),l=r),this.userAttributes=w(l);const h=this._onboardingExpProvider==="Optimizely"?this.fetchOptimizely():{},v=this.returnUserIdentities(c),R=this.returnLocalSessionAttributes(),A={...v,...l,...h,...R,...this.userIdentifiedInWorkspace?{[it]:!0}:{},mpid:u},g={...t,attributes:A},_=this.launcher.selectPlacements(g),y=()=>this.logSelectPlacementsEvent(A);return Promise.resolve(_).then(S=>S?.context?.sessionId?.then(f=>this.setRoktSessionId(f))).catch(()=>{}).finally(y),_}hashAttributes(t){return this.isKitReady()?this.launcher.hashAttributes(t):(console.error("Rokt Kit: Not initialized"),null)}use(t){return this.isKitReady()?!t||!m(t)?Promise.reject(new Error("Rokt Kit: Invalid extension name")):this.launcher.use(t):(console.error("Rokt Kit: Not initialized"),Promise.reject(new Error("Rokt Kit: Not initialized")))}onShoppableAdsReady(t){this._isThankYouElementLoaded?t():this._thankYouElementOnLoadCallback=t}};p._allowedOriginHashes=[-553112570,549508659],p.PERFORMANCE_MARKS={RoktScriptAppended:"mp:RoktScriptAppended"},p.EMAIL_SHA256_KEY="emailsha256";let E=p;function pt(){return b}function gt(n){if(!n){window.console.log("You must pass a config object to register the kit "+d);return}if(!T(n)){window.console.log("'config' must be an object. You passed in a "+typeof n);return}T(n.kits)?n.kits[d]={constructor:E}:(n.kits={},n.kits[d]={constructor:E}),window.console.log("Successfully registered "+d+" to your mParticle configuration")}typeof window<"u"&&window.mParticle&&a().addForwarder&&a().addForwarder({name:d,constructor:E,getId:pt});exports.register=gt;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const $=["active_time_on_site_ms","billingaddress1","billingaddress2","billingcity","billingstate","billingzipcode","cartitems","ccbin","confirmationref","conversiontype","country","couponcode","currency","language","paymentserviceprovider","paymentserviceproviderattribute","paymenttype","shippingaddress1","shippingcity","shippingcountry","shippingmethod","shippingstate","shippingzipcode","totalprice"],Z=new Set($);function J(n){return Z.has(n.toLowerCase())}function R(n){const e={},t=n||{},i=Object.keys(t);for(let r=0;r<i.length;r++){const s=i[r];J(s)||(e[s]=t[s])}return e}const d="Rokt",w=181,ee="selectPlacements",te="apps.roktecommerce.com",ie=.1,ne="ThankYouPageJourney",re="rokt-launcher",se="rokt-thank-you-element",oe="userIdentifiedInWorkspace",ae=3,ce=2,O="mpPageViews",le=25,ue="page_events",de=500,P={UNKNOWN_ERROR:"UNKNOWN_ERROR",UNHANDLED_EXCEPTION:"UNHANDLED_EXCEPTION",IDENTITY_REQUEST:"IDENTITY_REQUEST",LOG_DELIVERY_FAILURE:"LOG_DELIVERY_FAILURE"},m={ERROR:"ERROR",INFO:"INFO",WARNING:"WARNING"},he="apps.rokt-api.com",pe="/v1/log",ge="/v1/errors",fe=10;function a(){return window.mParticle}function K(){try{const n=window.localStorage.getItem(O);if(n===null)return[];const e=JSON.parse(n);return Array.isArray(e)?e:[]}catch{return[]}}function me(n){window.localStorage.setItem(O,JSON.stringify(n))}function M(){window.localStorage.removeItem(O)}function D(n,e){const i=[C(n),"/wsdk/integrations/launcher.js"].join("");return!e||e.length===0?i:i+"?extensions="+e.join(",")}function F(n){return[C(n),"/rokt-elements/rokt-element-thank-you.js"].join("")}function C(n){return["https://",typeof n<"u"?n:he].join("")}function q(n,e,t){return n?n.startsWith("http://")||n.startsWith("https://")?n:"https://"+n:C(e)+t}function x(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 T(n){return n!=null&&typeof n=="object"&&Array.isArray(n)===!1}function v(n){if(!n)return[];try{return JSON.parse(n.replace(/"/g,'"'))}catch{console.error("Settings string contains invalid JSON")}return[]}function Y(n){const e=n?v(n):[],t=[],i=[];let r=!1;for(let s=0;s<e.length;s++){const o=e[s].value;o==="thank-you-journey"?(r=!0,i.push(ne)):t.push(o)}return{roktExtensionsQueryParams:t,legacyRoktExtensions:i,loadThankYouElement:r}}async function Ee(n,e){const t=[];if(e)for(const i of n)t.push(e.use(i));return Promise.all(t)}function G(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 W(n){const e={};if(!Array.isArray(n))return e;for(let t=0;t<n.length;t++){const i=n[t];if(!i||!E(i.value)||!E(i.map))continue;const r=i.value,s=i.map;e[r]||(e[r]=[]),e[r].push({eventAttributeKey:s,conditions:Array.isArray(i.conditions)?i.conditions:[]})}return e}function j(n,e,t){return a().generateHash([n,e,t].join(""))}function L(n){return n==null?!0:typeof n=="object"?Object.keys(n).length===0:Array.isArray(n)?n.length===0:!1}function E(n){return typeof n=="string"}function _e(n){try{const e=new URL(n);return e.search="",e.toString()}catch{return n}}function ye(n){let i="mParticle_wsdkv_"+a().getVersion()+"_kitv_"+"1.30.0";return n&&(i+="_"+n),i}function B(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 N(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 H(n,e){const t=B(window.location.origin);if(y._allowedOriginHashes.indexOf(t)===-1||Math.random()>=ie)return;const r=window.__rokt_li_guid__;if(!r)return;const s=window.location.href.split("?")[0].split("#")[0],o="version="+encodeURIComponent(e??"")+"&launcherInstanceGuid="+encodeURIComponent(r)+"&pageUrl="+encodeURIComponent(s);N("https://"+(n||"apps.rokt.com")+"/v1/wsdk-init/index.html?"+o),N("https://"+te+"/v1/wsdk-init/index.html?"+o+"&isControl=true")}function Ie(){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 ke(){return typeof window<"u"?window.navigator?.userAgent:void 0}class Q{constructor(){this._logCount={}}incrementAndCheck(e){const i=(this._logCount[e]||0)+1;return this._logCount[e]=i,i>fe}}class U{constructor(e,t,i,r,s){this._reporter="mp-wsdk";const o=e.isLoggingEnabled;this._integrationName=t||"",this._launcherInstanceGuid=i,this._accountId=r||null,this._rateLimiter=s||new Q,this._isEnabled=Ie()||o}send(e,t,i,r,s,o){if(!(!this._isEnabled||this._rateLimiter.incrementAndCheck(t)))try{const c={additionalInformation:{message:i,version:this._integrationName},severity:t,code:r||P.UNKNOWN_ERROR,url:Se(),deviceInfo:ke(),stackTrace:s,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)}).then(l=>{if(!l.ok){const h=new Error("HTTP "+l.status+" from log endpoint");throw h.statusCode=l.status,h}}).catch(l=>{console.error("ReportingTransport: Failed to send log",l),o&&o(l)})}catch(c){console.error("ReportingTransport: Failed to send log",c),o&&o(c)}}}class V{constructor(e,t,i,r,s){this._transport=new U(e,t,i,r,s),this._errorUrl=q(e?.errorUrl,e?.integrationDomain,ge)}report(e){if(!e)return;const t=e.severity||m.ERROR;this._transport.send(this._errorUrl,t,e.message,e.code,e.stackTrace)}}class z{constructor(e,t,i,r,s,o){this._transport=new U(e,i,r,s,o),this._loggingUrl=q(e?.loggingUrl,e?.integrationDomain,pe),this._errorReportingService=t}log(e){e&&this._transport.send(this._loggingUrl,m.INFO,e.message,e.code,void 0,t=>{if(this._errorReportingService){const i=typeof t.statusCode=="number";this._errorReportingService.report({message:"LoggingService: Failed to send log: "+t.message,code:P.LOG_DELIVERY_FAILURE,severity:i?m.ERROR:m.WARNING})}})}}const f=class f{constructor(){this.name=d,this.id=w,this.moduleId=w,this.isInitialized=!1,this.launcher=null,this.filters={},this.userAttributes={},this.userIdentifiedInWorkspace=!1,this.testHelpers=null,this.placementEventMappingLookup={},this.placementEventAttributeMappingLookup={},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||!E(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||!E(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 s=0;s<i.length;s++)if(!this.doesEventAttributeConditionMatch(i[s],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],s=this.placementEventAttributeMappingLookup[r];if(L(s))continue;let o=!0;for(let c=0;c<s.length;c++)if(!this.doesEventMatchRule(e,s[c])){o=!1;break}o&&a().Rokt.setLocalSessionAttribute?.(r,!0)}}capturePageView(e){let t;try{t=_e(window.location.href);const i=K(),r={pageUrl:t,sourceMessageId:e.SourceMessageId,timestamp:e.Timestamp};for(Number.isFinite(e.ActiveTimeOnSite)&&(r.activeTimeOnSite=e.ActiveTimeOnSite),i.push(r);i.length>le;)i.shift();me(i)}catch(i){this.errorReportingService?.report({message:`Rokt Kit: Failed to capture page view for ${t}`,code:"PAGE_VIEW_CAPTURE_FAILED",severity:m.WARNING,stackTrace:i instanceof Error?i.stack:void 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"?{}:a().Rokt.getLocalSessionAttributes()}buildPageEvents(e){return e.map((t,i)=>{const r={pageUrl:t.pageUrl,sourceMessageId:t.sourceMessageId,timestamp:t.timestamp},s=t.activeTimeOnSite,o=s!==void 0&&Number.isFinite(s);o&&(r.activeTimeOnSite=s);const u=e[i+1]?.activeTimeOnSite,l=u!==void 0&&Number.isFinite(u);if(o&&l){const h=u-s;h>=0&&(r.timeOnPage=h)}return r})}replaceOtherIdentityWithEmailsha256(e){const t={...e||{}},i=this._mappedEmailSha256Key;return i&&e[i]&&(t[f.EMAIL_SHA256_KEY]=e[i]),i&&delete t[i],t}logSelectPlacementsEvent(e){if(!window.mParticle||typeof a().logEvent!="function"||!T(e))return;const t=a().EventType.Other;a().logEvent(ee,t,e)}setRoktSessionId(e){if(!(!e||typeof e!="string"))try{const t=a().getInstance();t&&typeof t.setIntegrationAttribute=="function"&&t.setIntegrationAttribute(w,{roktSessionId:e})}catch{}}attachLauncher(e,t,i=[]){const r=a()&&a().sessionManager&&typeof a().sessionManager.getSession=="function"?a().sessionManager.getSession():void 0,s={accountId:e,...t||{},...r?{mpSessionId:r}:{}};let o;this.isPartnerInLocalLauncherTestGroup()?o=Promise.resolve(window.Rokt.createLocalLauncher(s)):o=window.Rokt.createLauncher(s),o.then(async c=>{await Ee(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,H(this.domain,this.integrationName),a().Rokt.attachKit(this)}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((s,o)=>(s["rokt.custom.optimizely.experiment."+o+".variationId"]=t.getVariationMap()[o].id,s),{})}}catch(t){console.error("Error fetching Optimizely attributes:",t)}return{}}isKitReady(){return!!(this.isInitialized&&this.launcher)}isTargetingDisabled(){return a().Rokt?.launcherOptions?.noTargeting===!0}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,s){const o=e,c=o.accountId;this.userAttributes=R(s),this._onboardingExpProvider=o.onboardingExpProvider;const u=v(o.placementEventMapping);this.placementEventMappingLookup=G(u);const l=v(o.placementEventAttributeMapping);this.placementEventAttributeMappingLookup=W(l),o.hashedEmailUserIdentityType&&(this._mappedEmailSha256Key=o.hashedEmailUserIdentityType.toLowerCase()),this._workspaceIdSyncApiKey=E(o.workspaceIdSyncApiKey)?o.workspaceIdSyncApiKey:void 0;const h=a().Rokt?.domain,{roktExtensionsQueryParams:b,legacyRoktExtensions:I,loadThankYouElement:S}=Y(o.roktExtensions),g={...a().Rokt?.launcherOptions||{}};this.integrationName=ye(g.integrationName),g.integrationName=this.integrationName,this.domain=h;const k={loggingUrl:o.loggingUrl,errorUrl:o.errorUrl,integrationDomain:h,isLoggingEnabled:a().config?.isLoggingEnabled===!0},_=new V(k,this.integrationName,window.__rokt_li_guid__,o.accountId),A=new z(k,_,this.integrationName,window.__rokt_li_guid__,o.accountId);if(this.errorReportingService=_,this.loggingService=A,this.isTargetingDisabled())try{M()}catch(p){this.errorReportingService?.report({message:"Rokt Kit: Failed to clear page views when targeting is disabled",code:"PAGE_VIEW_CAPTURE_FAILED",severity:m.WARNING,stackTrace:p instanceof Error?p.stack:void 0})}return a()._registerErrorReportingService&&a()._registerErrorReportingService(_),a()._registerLoggingService&&a()._registerLoggingService(A),i?(this.testHelpers={generateLauncherScript:D,generateThankYouElementScript:F,extractRoktExtensionConfig:Y,hashEventMessage:j,parseSettingsString:v,generateMappedEventLookup:G,generateMappedEventAttributeLookup:W,sendAdBlockMeasurementSignals:H,createAutoRemovedIframe:N,djb2:B,setAllowedOriginHashes:p=>{f._allowedOriginHashes=p},ReportingTransport:U,ErrorReportingService:V,LoggingService:z,RateLimiter:Q,ErrorCodes:P,WSDKErrorSeverity:m},this.attachLauncher(c,g),"Successfully initialized: "+d):(S&&(a().Rokt.flushOnShoppableAdsReadyMessageQueue?.(this),x(se,F(h),{onLoad:()=>{this._isThankYouElementLoaded=!0,this._thankYouElementOnLoadCallback&&this._thankYouElementOnLoadCallback()},onError:p=>{console.error("Error loading Rokt Thank You Element script:",p)}})),this.isLauncherReadyToAttach()?this.attachLauncher(c,g,I):(x(re,D(h,b),{onLoad:()=>{this.isLauncherReadyToAttach()?this.attachLauncher(c,g,I):console.error("Rokt object is not available after script load.")},onError:p=>{console.error("Error loading Rokt launcher script:",p)}}),this.captureTiming(f.PERFORMANCE_MARKS.RoktScriptAppended)),"Successfully initialized: "+d)}process(e){if(!this.isTargetingDisabled()&&(e.EventDataType===ae&&this.capturePageView(e),e.EventDataType===ce))try{M()}catch(t){this.errorReportingService?.report({message:"Rokt Kit: Failed to clear page views on session end",code:"PAGE_VIEW_CAPTURE_FAILED",severity:m.WARNING,stackTrace:t instanceof Error?t.stack:void 0})}if(!this.isKitReady())return"Kit not ready for forwarder: "+d;if(typeof a().Rokt?.setLocalSessionAttribute=="function"&&(L(this.placementEventAttributeMappingLookup)||this.applyPlacementEventAttributeMapping(e),!L(this.placementEventMappingLookup))){const t=j(e.EventDataType,e.EventCategory,e.EventName??"");this.placementEventMappingLookup[String(t)]&&a().Rokt.setLocalSessionAttribute?.(this.placementEventMappingLookup[String(t)],!0)}return"Successfully sent to forwarder: "+d}setExtensionData(e){if(!this.isKitReady()){console.error("Rokt Kit: Not initialized");return}window.Rokt.setExtensionData(e)}setUserAttribute(e,t){return J(e)||(this.userAttributes[e]=t),"Successfully set user attribute for forwarder: "+d}removeUserAttribute(e){return delete this.userAttributes[e],"Successfully removed user attribute for forwarder: "+d}handleIdentityComplete(e,t){return this.userAttributes=R(e.getAllUserAttributes()),"Successfully called "+t+" for forwarder: "+d}onUserIdentified(e){const t=e;return this.filters.filteredUser=t,this._workspaceSearchInFlightPromise=this.search(t),this.handleIdentityComplete(e,"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,s={};if(r)for(const u of Object.keys(r)){const l=r[u];E(l)&&l.length>0&&(s[u]=l)}const o=Object.keys(s);if(o.length===0)return this.userIdentifiedInWorkspace=!1,this._workspaceLastSearchedIdentitiesKey=void 0,Promise.resolve();const c=o.sort().map(u=>`${u}=${s[u]}`).join("&");return c===this._workspaceLastSearchedIdentitiesKey?this._workspaceSearchInFlightPromise||Promise.resolve():(this.userIdentifiedInWorkspace=!1,this._workspaceLastSearchedIdentitiesKey=c,new Promise(u=>{try{i(t,s,l=>{l?.httpCode===200&&(this.userIdentifiedInWorkspace=!0),u()})}catch(l){console.error("Rokt Kit: Workspace IDSync search failed",l),this._workspaceLastSearchedIdentitiesKey=void 0,u()}}))}onLoginComplete(e,t){return this.handleIdentityComplete(e,"onLoginComplete")}onLogoutComplete(e,t){return this.userIdentifiedInWorkspace=!1,this._workspaceSearchInFlightPromise=null,this._workspaceLastSearchedIdentitiesKey=void 0,this.handleIdentityComplete(e,"onLogoutComplete")}onModifyComplete(e,t){return this.handleIdentityComplete(e,"onModifyComplete")}selectPlacements(e){if(this._workspaceSearchInFlightPromise){const t=this._workspaceSearchInFlightPromise;return Promise.race([t,new Promise(i=>setTimeout(i,de))]).then(()=>this._dispatchPlacements(e))}return this._dispatchPlacements(e)}_dispatchPlacements(e){const t=e&&e.attributes||{},r={...R(this.userAttributes),...t},s=this.filters||{},o=s.userAttributeFilters||[],c=s.filteredUser||null,u=c?c.getMPID():null;let l;s?s.filterUserAttributes?l=s.filterUserAttributes(r,o):l=r:(console.warn("Rokt Kit: No filters available, using user attributes"),l=r),this.userAttributes=R(l);const h=this._onboardingExpProvider==="Optimizely"?this.fetchOptimizely():{},b=this.returnUserIdentities(c),I=this.returnLocalSessionAttributes(),S=this.buildPageEvents(K()),g={...b,...l,...h,...I,...S.length?{[ue]:JSON.stringify(S)}:{},...this.userIdentifiedInWorkspace?{[oe]:!0}:{},mpid:u},k={...e,attributes:g},_=this.launcher.selectPlacements(k),A=()=>this.logSelectPlacementsEvent(g);return Promise.resolve(_).then(p=>p?.context?.sessionId?.then(X=>this.setRoktSessionId(X))).catch(()=>{}).finally(A),_}hashAttributes(e){return this.isKitReady()?this.launcher.hashAttributes(e):(console.error("Rokt Kit: Not initialized"),null)}use(e){return this.isKitReady()?!e||!E(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}};f._allowedOriginHashes=[-553112570,549508659],f.PERFORMANCE_MARKS={RoktScriptAppended:"mp:RoktScriptAppended"},f.EMAIL_SHA256_KEY="emailsha256";let y=f;function Ae(){return w}function Re(n){if(!n){window.console.log("You must pass a config object to register the kit "+d);return}if(!T(n)){window.console.log("'config' must be an object. You passed in a "+typeof n);return}T(n.kits)?n.kits[d]={constructor:y}:(n.kits={},n.kits[d]={constructor:y}),window.console.log("Successfully registered "+d+" to your mParticle configuration")}typeof window<"u"&&window.mParticle&&a().addForwarder&&a().addForwarder({name:d,constructor:y,getId:Ae});exports.register=Re;
|
|
2
2
|
//# sourceMappingURL=Rokt-Kit.common.js.map
|
package/dist/Rokt-Kit.esm.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
const
|
|
1
|
+
const $ = [
|
|
2
|
+
"active_time_on_site_ms",
|
|
2
3
|
"billingaddress1",
|
|
3
4
|
"billingaddress2",
|
|
4
5
|
"billingcity",
|
|
@@ -22,53 +23,70 @@ const B = [
|
|
|
22
23
|
"shippingstate",
|
|
23
24
|
"shippingzipcode",
|
|
24
25
|
"totalprice"
|
|
25
|
-
],
|
|
26
|
-
function
|
|
27
|
-
return
|
|
26
|
+
], Z = new Set($);
|
|
27
|
+
function J(n) {
|
|
28
|
+
return Z.has(n.toLowerCase());
|
|
28
29
|
}
|
|
29
|
-
function
|
|
30
|
-
const
|
|
30
|
+
function R(n) {
|
|
31
|
+
const e = {}, t = n || {}, i = Object.keys(t);
|
|
31
32
|
for (let r = 0; r < i.length; r++) {
|
|
32
33
|
const s = i[r];
|
|
33
|
-
|
|
34
|
+
J(s) || (e[s] = t[s]);
|
|
34
35
|
}
|
|
35
|
-
return
|
|
36
|
+
return e;
|
|
36
37
|
}
|
|
37
|
-
const d = "Rokt",
|
|
38
|
+
const d = "Rokt", w = 181, ee = "selectPlacements", te = "apps.roktecommerce.com", ie = 0.1, ne = "ThankYouPageJourney", re = "rokt-launcher", se = "rokt-thank-you-element", oe = "userIdentifiedInWorkspace", ae = 3, ce = 2, O = "mpPageViews", le = 25, ue = "page_events", de = 500, P = {
|
|
38
39
|
UNKNOWN_ERROR: "UNKNOWN_ERROR",
|
|
39
40
|
UNHANDLED_EXCEPTION: "UNHANDLED_EXCEPTION",
|
|
40
41
|
IDENTITY_REQUEST: "IDENTITY_REQUEST",
|
|
41
42
|
LOG_DELIVERY_FAILURE: "LOG_DELIVERY_FAILURE"
|
|
42
|
-
},
|
|
43
|
+
}, m = {
|
|
43
44
|
ERROR: "ERROR",
|
|
44
45
|
INFO: "INFO",
|
|
45
46
|
WARNING: "WARNING"
|
|
46
|
-
},
|
|
47
|
+
}, he = "apps.rokt-api.com", pe = "/v1/log", ge = "/v1/errors", fe = 10;
|
|
47
48
|
function a() {
|
|
48
49
|
return window.mParticle;
|
|
49
50
|
}
|
|
50
|
-
function
|
|
51
|
-
|
|
52
|
-
|
|
51
|
+
function K() {
|
|
52
|
+
try {
|
|
53
|
+
const n = window.localStorage.getItem(O);
|
|
54
|
+
if (n === null)
|
|
55
|
+
return [];
|
|
56
|
+
const e = JSON.parse(n);
|
|
57
|
+
return Array.isArray(e) ? e : [];
|
|
58
|
+
} catch {
|
|
59
|
+
return [];
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
function me(n) {
|
|
63
|
+
window.localStorage.setItem(O, JSON.stringify(n));
|
|
64
|
+
}
|
|
65
|
+
function M() {
|
|
66
|
+
window.localStorage.removeItem(O);
|
|
67
|
+
}
|
|
68
|
+
function D(n, e) {
|
|
69
|
+
const i = [C(n), "/wsdk/integrations/launcher.js"].join("");
|
|
70
|
+
return !e || e.length === 0 ? i : i + "?extensions=" + e.join(",");
|
|
53
71
|
}
|
|
54
|
-
function
|
|
55
|
-
return [
|
|
72
|
+
function F(n) {
|
|
73
|
+
return [C(n), "/rokt-elements/rokt-element-thank-you.js"].join("");
|
|
56
74
|
}
|
|
57
|
-
function
|
|
58
|
-
return ["https://", typeof n < "u" ? n :
|
|
75
|
+
function C(n) {
|
|
76
|
+
return ["https://", typeof n < "u" ? n : he].join("");
|
|
59
77
|
}
|
|
60
|
-
function
|
|
61
|
-
return n ? n.startsWith("http://") || n.startsWith("https://") ? n : "https://" + n :
|
|
78
|
+
function q(n, e, t) {
|
|
79
|
+
return n ? n.startsWith("http://") || n.startsWith("https://") ? n : "https://" + n : C(e) + t;
|
|
62
80
|
}
|
|
63
|
-
function
|
|
81
|
+
function x(n, e, t) {
|
|
64
82
|
if (document.getElementById(n)) return;
|
|
65
83
|
const i = document.head || document.body, r = document.createElement("script");
|
|
66
|
-
r.id = n, r.type = "text/javascript", r.src =
|
|
84
|
+
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);
|
|
67
85
|
}
|
|
68
86
|
function T(n) {
|
|
69
87
|
return n != null && typeof n == "object" && Array.isArray(n) === !1;
|
|
70
88
|
}
|
|
71
|
-
function
|
|
89
|
+
function v(n) {
|
|
72
90
|
if (!n)
|
|
73
91
|
return [];
|
|
74
92
|
try {
|
|
@@ -78,127 +96,135 @@ function L(n) {
|
|
|
78
96
|
}
|
|
79
97
|
return [];
|
|
80
98
|
}
|
|
81
|
-
function
|
|
82
|
-
const
|
|
99
|
+
function Y(n) {
|
|
100
|
+
const e = n ? v(n) : [], t = [], i = [];
|
|
83
101
|
let r = !1;
|
|
84
|
-
for (let s = 0; s <
|
|
85
|
-
const o =
|
|
86
|
-
o === "thank-you-journey" ? (r = !0, i.push(
|
|
102
|
+
for (let s = 0; s < e.length; s++) {
|
|
103
|
+
const o = e[s].value;
|
|
104
|
+
o === "thank-you-journey" ? (r = !0, i.push(ne)) : t.push(o);
|
|
87
105
|
}
|
|
88
106
|
return {
|
|
89
|
-
roktExtensionsQueryParams:
|
|
107
|
+
roktExtensionsQueryParams: t,
|
|
90
108
|
legacyRoktExtensions: i,
|
|
91
109
|
loadThankYouElement: r
|
|
92
110
|
};
|
|
93
111
|
}
|
|
94
|
-
async function
|
|
95
|
-
const
|
|
96
|
-
if (
|
|
112
|
+
async function Ee(n, e) {
|
|
113
|
+
const t = [];
|
|
114
|
+
if (e)
|
|
97
115
|
for (const i of n)
|
|
98
|
-
|
|
99
|
-
return Promise.all(
|
|
116
|
+
t.push(e.use(i));
|
|
117
|
+
return Promise.all(t);
|
|
100
118
|
}
|
|
101
|
-
function
|
|
119
|
+
function G(n) {
|
|
102
120
|
if (!n)
|
|
103
121
|
return {};
|
|
104
|
-
const
|
|
105
|
-
for (let
|
|
106
|
-
const i = n[
|
|
107
|
-
|
|
122
|
+
const e = {};
|
|
123
|
+
for (let t = 0; t < n.length; t++) {
|
|
124
|
+
const i = n[t];
|
|
125
|
+
e[i.jsmap] = i.value;
|
|
108
126
|
}
|
|
109
|
-
return
|
|
127
|
+
return e;
|
|
110
128
|
}
|
|
111
|
-
function
|
|
112
|
-
const
|
|
129
|
+
function W(n) {
|
|
130
|
+
const e = {};
|
|
113
131
|
if (!Array.isArray(n))
|
|
114
|
-
return
|
|
115
|
-
for (let
|
|
116
|
-
const i = n[
|
|
117
|
-
if (!i || !
|
|
132
|
+
return e;
|
|
133
|
+
for (let t = 0; t < n.length; t++) {
|
|
134
|
+
const i = n[t];
|
|
135
|
+
if (!i || !E(i.value) || !E(i.map))
|
|
118
136
|
continue;
|
|
119
137
|
const r = i.value, s = i.map;
|
|
120
|
-
|
|
138
|
+
e[r] || (e[r] = []), e[r].push({
|
|
121
139
|
eventAttributeKey: s,
|
|
122
140
|
conditions: Array.isArray(i.conditions) ? i.conditions : []
|
|
123
141
|
});
|
|
124
142
|
}
|
|
125
|
-
return
|
|
143
|
+
return e;
|
|
126
144
|
}
|
|
127
|
-
function
|
|
128
|
-
return a().generateHash([n,
|
|
145
|
+
function j(n, e, t) {
|
|
146
|
+
return a().generateHash([n, e, t].join(""));
|
|
129
147
|
}
|
|
130
|
-
function
|
|
148
|
+
function L(n) {
|
|
131
149
|
return n == null ? !0 : typeof n == "object" ? Object.keys(n).length === 0 : Array.isArray(n) ? n.length === 0 : !1;
|
|
132
150
|
}
|
|
133
|
-
function
|
|
151
|
+
function E(n) {
|
|
134
152
|
return typeof n == "string";
|
|
135
153
|
}
|
|
136
|
-
function
|
|
137
|
-
|
|
154
|
+
function _e(n) {
|
|
155
|
+
try {
|
|
156
|
+
const e = new URL(n);
|
|
157
|
+
return e.search = "", e.toString();
|
|
158
|
+
} catch {
|
|
159
|
+
return n;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
function ye(n) {
|
|
163
|
+
let i = "mParticle_wsdkv_" + a().getVersion() + "_kitv_" + "1.30.0";
|
|
138
164
|
return n && (i += "_" + n), i;
|
|
139
165
|
}
|
|
140
|
-
function
|
|
141
|
-
let
|
|
142
|
-
for (let
|
|
143
|
-
|
|
144
|
-
return
|
|
166
|
+
function B(n) {
|
|
167
|
+
let e = 5381;
|
|
168
|
+
for (let t = 0; t < n.length; t++)
|
|
169
|
+
e = (e << 5) + e + n.charCodeAt(t), e = e & e;
|
|
170
|
+
return e;
|
|
145
171
|
}
|
|
146
172
|
function N(n) {
|
|
147
|
-
const
|
|
148
|
-
|
|
149
|
-
|
|
173
|
+
const e = document.createElement("iframe");
|
|
174
|
+
e.style.display = "none", e.setAttribute("sandbox", "allow-scripts allow-same-origin"), e.src = n, e.onload = function() {
|
|
175
|
+
e.onload = null, e.parentNode && e.parentNode.removeChild(e);
|
|
150
176
|
};
|
|
151
|
-
const
|
|
152
|
-
|
|
177
|
+
const t = document.body || document.head;
|
|
178
|
+
t && t.appendChild(e);
|
|
153
179
|
}
|
|
154
|
-
function
|
|
155
|
-
const
|
|
156
|
-
if (
|
|
180
|
+
function H(n, e) {
|
|
181
|
+
const t = B(window.location.origin);
|
|
182
|
+
if (y._allowedOriginHashes.indexOf(t) === -1 || Math.random() >= ie)
|
|
157
183
|
return;
|
|
158
184
|
const r = window.__rokt_li_guid__;
|
|
159
185
|
if (!r)
|
|
160
186
|
return;
|
|
161
|
-
const s = window.location.href.split("?")[0].split("#")[0], o = "version=" + encodeURIComponent(
|
|
187
|
+
const s = window.location.href.split("?")[0].split("#")[0], o = "version=" + encodeURIComponent(e ?? "") + "&launcherInstanceGuid=" + encodeURIComponent(r) + "&pageUrl=" + encodeURIComponent(s);
|
|
162
188
|
N("https://" + (n || "apps.rokt.com") + "/v1/wsdk-init/index.html?" + o), N(
|
|
163
|
-
"https://" +
|
|
189
|
+
"https://" + te + "/v1/wsdk-init/index.html?" + o + "&isControl=true"
|
|
164
190
|
);
|
|
165
191
|
}
|
|
166
|
-
function
|
|
192
|
+
function Ie() {
|
|
167
193
|
return typeof window < "u" && !!window.location?.search?.toLowerCase().includes("mp_enable_logging=true");
|
|
168
194
|
}
|
|
169
|
-
function
|
|
195
|
+
function Se() {
|
|
170
196
|
return typeof window < "u" ? window.location?.href : void 0;
|
|
171
197
|
}
|
|
172
|
-
function
|
|
198
|
+
function ke() {
|
|
173
199
|
return typeof window < "u" ? window.navigator?.userAgent : void 0;
|
|
174
200
|
}
|
|
175
|
-
class
|
|
201
|
+
class Q {
|
|
176
202
|
constructor() {
|
|
177
203
|
this._logCount = {};
|
|
178
204
|
}
|
|
179
|
-
incrementAndCheck(
|
|
180
|
-
const i = (this._logCount[
|
|
181
|
-
return this._logCount[
|
|
205
|
+
incrementAndCheck(e) {
|
|
206
|
+
const i = (this._logCount[e] || 0) + 1;
|
|
207
|
+
return this._logCount[e] = i, i > fe;
|
|
182
208
|
}
|
|
183
209
|
}
|
|
184
|
-
class
|
|
185
|
-
constructor(
|
|
210
|
+
class U {
|
|
211
|
+
constructor(e, t, i, r, s) {
|
|
186
212
|
this._reporter = "mp-wsdk";
|
|
187
|
-
const o =
|
|
188
|
-
this._integrationName =
|
|
213
|
+
const o = e.isLoggingEnabled;
|
|
214
|
+
this._integrationName = t || "", this._launcherInstanceGuid = i, this._accountId = r || null, this._rateLimiter = s || new Q(), this._isEnabled = Ie() || o;
|
|
189
215
|
}
|
|
190
|
-
send(
|
|
191
|
-
if (!(!this._isEnabled || this._rateLimiter.incrementAndCheck(
|
|
216
|
+
send(e, t, i, r, s, o) {
|
|
217
|
+
if (!(!this._isEnabled || this._rateLimiter.incrementAndCheck(t)))
|
|
192
218
|
try {
|
|
193
219
|
const c = {
|
|
194
220
|
additionalInformation: {
|
|
195
221
|
message: i,
|
|
196
222
|
version: this._integrationName
|
|
197
223
|
},
|
|
198
|
-
severity:
|
|
199
|
-
code: r ||
|
|
200
|
-
url:
|
|
201
|
-
deviceInfo:
|
|
224
|
+
severity: t,
|
|
225
|
+
code: r || P.UNKNOWN_ERROR,
|
|
226
|
+
url: Se(),
|
|
227
|
+
deviceInfo: ke(),
|
|
202
228
|
stackTrace: s,
|
|
203
229
|
reporter: this._reporter,
|
|
204
230
|
integration: this._integrationName
|
|
@@ -208,7 +234,7 @@ class C {
|
|
|
208
234
|
"rokt-launcher-version": this._integrationName,
|
|
209
235
|
"rokt-wsdk-version": "joint"
|
|
210
236
|
};
|
|
211
|
-
this._launcherInstanceGuid && (u["rokt-launcher-instance-guid"] = this._launcherInstanceGuid), this._accountId && (u["rokt-account-id"] = this._accountId), fetch(
|
|
237
|
+
this._launcherInstanceGuid && (u["rokt-launcher-instance-guid"] = this._launcherInstanceGuid), this._accountId && (u["rokt-account-id"] = this._accountId), fetch(e, {
|
|
212
238
|
method: "POST",
|
|
213
239
|
headers: u,
|
|
214
240
|
body: JSON.stringify(c)
|
|
@@ -225,62 +251,62 @@ class C {
|
|
|
225
251
|
}
|
|
226
252
|
}
|
|
227
253
|
}
|
|
228
|
-
class
|
|
229
|
-
constructor(
|
|
230
|
-
this._transport = new
|
|
254
|
+
class V {
|
|
255
|
+
constructor(e, t, i, r, s) {
|
|
256
|
+
this._transport = new U(e, t, i, r, s), this._errorUrl = q(e?.errorUrl, e?.integrationDomain, ge);
|
|
231
257
|
}
|
|
232
|
-
report(
|
|
233
|
-
if (!
|
|
234
|
-
const
|
|
235
|
-
this._transport.send(this._errorUrl,
|
|
258
|
+
report(e) {
|
|
259
|
+
if (!e) return;
|
|
260
|
+
const t = e.severity || m.ERROR;
|
|
261
|
+
this._transport.send(this._errorUrl, t, e.message, e.code, e.stackTrace);
|
|
236
262
|
}
|
|
237
263
|
}
|
|
238
|
-
class
|
|
239
|
-
constructor(
|
|
240
|
-
this._transport = new
|
|
264
|
+
class z {
|
|
265
|
+
constructor(e, t, i, r, s, o) {
|
|
266
|
+
this._transport = new U(e, i, r, s, o), this._loggingUrl = q(e?.loggingUrl, e?.integrationDomain, pe), this._errorReportingService = t;
|
|
241
267
|
}
|
|
242
|
-
log(
|
|
243
|
-
|
|
268
|
+
log(e) {
|
|
269
|
+
e && this._transport.send(
|
|
244
270
|
this._loggingUrl,
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
271
|
+
m.INFO,
|
|
272
|
+
e.message,
|
|
273
|
+
e.code,
|
|
248
274
|
void 0,
|
|
249
|
-
(
|
|
275
|
+
(t) => {
|
|
250
276
|
if (this._errorReportingService) {
|
|
251
|
-
const i = typeof
|
|
277
|
+
const i = typeof t.statusCode == "number";
|
|
252
278
|
this._errorReportingService.report({
|
|
253
|
-
message: "LoggingService: Failed to send log: " +
|
|
254
|
-
code:
|
|
255
|
-
severity: i ?
|
|
279
|
+
message: "LoggingService: Failed to send log: " + t.message,
|
|
280
|
+
code: P.LOG_DELIVERY_FAILURE,
|
|
281
|
+
severity: i ? m.ERROR : m.WARNING
|
|
256
282
|
});
|
|
257
283
|
}
|
|
258
284
|
}
|
|
259
285
|
);
|
|
260
286
|
}
|
|
261
287
|
}
|
|
262
|
-
const
|
|
288
|
+
const f = class f {
|
|
263
289
|
constructor() {
|
|
264
|
-
this.name = d, this.id =
|
|
290
|
+
this.name = d, this.id = w, this.moduleId = w, this.isInitialized = !1, this.launcher = null, this.filters = {}, this.userAttributes = {}, this.userIdentifiedInWorkspace = !1, this.testHelpers = null, this.placementEventMappingLookup = {}, this.placementEventAttributeMappingLookup = {}, this.integrationName = null, this.errorReportingService = null, this.loggingService = null, this._thankYouElementOnLoadCallback = null, this._isThankYouElementLoaded = !1, this._workspaceSearchInFlightPromise = null;
|
|
265
291
|
}
|
|
266
292
|
// ---- Private helpers ----
|
|
267
|
-
getEventAttributeValue(
|
|
268
|
-
const i =
|
|
269
|
-
return !i || typeof i[
|
|
293
|
+
getEventAttributeValue(e, t) {
|
|
294
|
+
const i = e && e.EventAttributes;
|
|
295
|
+
return !i || typeof i[t] > "u" ? null : i[t];
|
|
270
296
|
}
|
|
271
|
-
doesEventAttributeConditionMatch(
|
|
272
|
-
if (!
|
|
297
|
+
doesEventAttributeConditionMatch(e, t) {
|
|
298
|
+
if (!e || !E(e.operator))
|
|
273
299
|
return !1;
|
|
274
|
-
const i =
|
|
275
|
-
return i === "exists" ?
|
|
300
|
+
const i = e.operator.toLowerCase(), r = e.attributeValue;
|
|
301
|
+
return i === "exists" ? t !== null : t == null ? !1 : i === "equals" ? String(t) === String(r) : i === "contains" ? String(t).indexOf(String(r)) !== -1 : !1;
|
|
276
302
|
}
|
|
277
|
-
doesEventMatchRule(
|
|
278
|
-
if (!
|
|
303
|
+
doesEventMatchRule(e, t) {
|
|
304
|
+
if (!t || !E(t.eventAttributeKey))
|
|
279
305
|
return !1;
|
|
280
|
-
const i =
|
|
306
|
+
const i = t.conditions;
|
|
281
307
|
if (!Array.isArray(i))
|
|
282
308
|
return !1;
|
|
283
|
-
const r = this.getEventAttributeValue(
|
|
309
|
+
const r = this.getEventAttributeValue(e, t.eventAttributeKey);
|
|
284
310
|
if (i.length === 0)
|
|
285
311
|
return r !== null;
|
|
286
312
|
for (let s = 0; s < i.length; s++)
|
|
@@ -288,211 +314,275 @@ const p = class p {
|
|
|
288
314
|
return !1;
|
|
289
315
|
return !0;
|
|
290
316
|
}
|
|
291
|
-
applyPlacementEventAttributeMapping(
|
|
292
|
-
const
|
|
293
|
-
for (let i = 0; i <
|
|
294
|
-
const r =
|
|
295
|
-
if (
|
|
317
|
+
applyPlacementEventAttributeMapping(e) {
|
|
318
|
+
const t = Object.keys(this.placementEventAttributeMappingLookup);
|
|
319
|
+
for (let i = 0; i < t.length; i++) {
|
|
320
|
+
const r = t[i], s = this.placementEventAttributeMappingLookup[r];
|
|
321
|
+
if (L(s))
|
|
296
322
|
continue;
|
|
297
323
|
let o = !0;
|
|
298
324
|
for (let c = 0; c < s.length; c++)
|
|
299
|
-
if (!this.doesEventMatchRule(
|
|
325
|
+
if (!this.doesEventMatchRule(e, s[c])) {
|
|
300
326
|
o = !1;
|
|
301
327
|
break;
|
|
302
328
|
}
|
|
303
329
|
o && a().Rokt.setLocalSessionAttribute?.(r, !0);
|
|
304
330
|
}
|
|
305
331
|
}
|
|
332
|
+
capturePageView(e) {
|
|
333
|
+
let t;
|
|
334
|
+
try {
|
|
335
|
+
t = _e(window.location.href);
|
|
336
|
+
const i = K(), r = {
|
|
337
|
+
pageUrl: t,
|
|
338
|
+
sourceMessageId: e.SourceMessageId,
|
|
339
|
+
timestamp: e.Timestamp
|
|
340
|
+
};
|
|
341
|
+
for (Number.isFinite(e.ActiveTimeOnSite) && (r.activeTimeOnSite = e.ActiveTimeOnSite), i.push(r); i.length > le; )
|
|
342
|
+
i.shift();
|
|
343
|
+
me(i);
|
|
344
|
+
} catch (i) {
|
|
345
|
+
this.errorReportingService?.report({
|
|
346
|
+
message: `Rokt Kit: Failed to capture page view for ${t}`,
|
|
347
|
+
code: "PAGE_VIEW_CAPTURE_FAILED",
|
|
348
|
+
severity: m.WARNING,
|
|
349
|
+
stackTrace: i instanceof Error ? i.stack : void 0
|
|
350
|
+
});
|
|
351
|
+
}
|
|
352
|
+
}
|
|
306
353
|
isLauncherReadyToAttach() {
|
|
307
354
|
return !!window.Rokt && typeof window.Rokt.createLauncher == "function";
|
|
308
355
|
}
|
|
309
356
|
/**
|
|
310
357
|
* Returns the user identities from the filtered user, if any.
|
|
311
358
|
*/
|
|
312
|
-
returnUserIdentities(
|
|
313
|
-
if (!
|
|
359
|
+
returnUserIdentities(e) {
|
|
360
|
+
if (!e || !e.getUserIdentities)
|
|
314
361
|
return {};
|
|
315
|
-
const
|
|
316
|
-
return this.replaceOtherIdentityWithEmailsha256(
|
|
362
|
+
const t = e.getUserIdentities().userIdentities;
|
|
363
|
+
return this.replaceOtherIdentityWithEmailsha256(t);
|
|
317
364
|
}
|
|
318
365
|
returnLocalSessionAttributes() {
|
|
319
|
-
return !a().Rokt || typeof a().Rokt.getLocalSessionAttributes != "function" ? {} :
|
|
366
|
+
return !a().Rokt || typeof a().Rokt.getLocalSessionAttributes != "function" ? {} : a().Rokt.getLocalSessionAttributes();
|
|
367
|
+
}
|
|
368
|
+
buildPageEvents(e) {
|
|
369
|
+
return e.map((t, i) => {
|
|
370
|
+
const r = {
|
|
371
|
+
pageUrl: t.pageUrl,
|
|
372
|
+
sourceMessageId: t.sourceMessageId,
|
|
373
|
+
timestamp: t.timestamp
|
|
374
|
+
}, s = t.activeTimeOnSite, o = s !== void 0 && Number.isFinite(s);
|
|
375
|
+
o && (r.activeTimeOnSite = s);
|
|
376
|
+
const u = e[i + 1]?.activeTimeOnSite, l = u !== void 0 && Number.isFinite(u);
|
|
377
|
+
if (o && l) {
|
|
378
|
+
const h = u - s;
|
|
379
|
+
h >= 0 && (r.timeOnPage = h);
|
|
380
|
+
}
|
|
381
|
+
return r;
|
|
382
|
+
});
|
|
320
383
|
}
|
|
321
|
-
replaceOtherIdentityWithEmailsha256(
|
|
322
|
-
const
|
|
323
|
-
return i &&
|
|
384
|
+
replaceOtherIdentityWithEmailsha256(e) {
|
|
385
|
+
const t = { ...e || {} }, i = this._mappedEmailSha256Key;
|
|
386
|
+
return i && e[i] && (t[f.EMAIL_SHA256_KEY] = e[i]), i && delete t[i], t;
|
|
324
387
|
}
|
|
325
|
-
logSelectPlacementsEvent(
|
|
326
|
-
if (!window.mParticle || typeof a().logEvent != "function" || !T(
|
|
388
|
+
logSelectPlacementsEvent(e) {
|
|
389
|
+
if (!window.mParticle || typeof a().logEvent != "function" || !T(e))
|
|
327
390
|
return;
|
|
328
|
-
const
|
|
329
|
-
a().logEvent(
|
|
391
|
+
const t = a().EventType.Other;
|
|
392
|
+
a().logEvent(ee, t, e);
|
|
330
393
|
}
|
|
331
|
-
setRoktSessionId(
|
|
332
|
-
if (!(!
|
|
394
|
+
setRoktSessionId(e) {
|
|
395
|
+
if (!(!e || typeof e != "string"))
|
|
333
396
|
try {
|
|
334
|
-
const
|
|
335
|
-
|
|
336
|
-
roktSessionId:
|
|
397
|
+
const t = a().getInstance();
|
|
398
|
+
t && typeof t.setIntegrationAttribute == "function" && t.setIntegrationAttribute(w, {
|
|
399
|
+
roktSessionId: e
|
|
337
400
|
});
|
|
338
401
|
} catch {
|
|
339
402
|
}
|
|
340
403
|
}
|
|
341
|
-
attachLauncher(
|
|
404
|
+
attachLauncher(e, t, i = []) {
|
|
342
405
|
const r = a() && a().sessionManager && typeof a().sessionManager.getSession == "function" ? a().sessionManager.getSession() : void 0, s = {
|
|
343
|
-
accountId:
|
|
344
|
-
...
|
|
406
|
+
accountId: e,
|
|
407
|
+
...t || {},
|
|
345
408
|
...r ? { mpSessionId: r } : {}
|
|
346
409
|
};
|
|
347
410
|
let o;
|
|
348
411
|
this.isPartnerInLocalLauncherTestGroup() ? o = Promise.resolve(window.Rokt.createLocalLauncher(s)) : o = window.Rokt.createLauncher(s), o.then(async (c) => {
|
|
349
|
-
await
|
|
412
|
+
await Ee(i, c), this.initRoktLauncher(c);
|
|
350
413
|
}).catch((c) => {
|
|
351
414
|
console.error("Error creating Rokt launcher:", c);
|
|
352
415
|
});
|
|
353
416
|
}
|
|
354
|
-
initRoktLauncher(
|
|
355
|
-
window.Rokt && (window.Rokt.currentLauncher =
|
|
356
|
-
const
|
|
357
|
-
|
|
417
|
+
initRoktLauncher(e) {
|
|
418
|
+
window.Rokt && (window.Rokt.currentLauncher = e), this.launcher = e;
|
|
419
|
+
const t = a().Rokt?.filters;
|
|
420
|
+
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, H(this.domain, this.integrationName), a().Rokt.attachKit(this);
|
|
358
421
|
}
|
|
359
422
|
fetchOptimizely() {
|
|
360
|
-
const
|
|
423
|
+
const e = a()._getActiveForwarders().filter((t) => t.name === "Optimizely");
|
|
361
424
|
try {
|
|
362
|
-
if (
|
|
363
|
-
const
|
|
364
|
-
return !
|
|
425
|
+
if (e.length > 0 && window.optimizely) {
|
|
426
|
+
const t = window.optimizely.get("state");
|
|
427
|
+
return !t || !t.getActiveExperimentIds ? {} : t.getActiveExperimentIds().reduce((s, o) => (s["rokt.custom.optimizely.experiment." + o + ".variationId"] = t.getVariationMap()[o].id, s), {});
|
|
365
428
|
}
|
|
366
|
-
} catch (
|
|
367
|
-
console.error("Error fetching Optimizely attributes:",
|
|
429
|
+
} catch (t) {
|
|
430
|
+
console.error("Error fetching Optimizely attributes:", t);
|
|
368
431
|
}
|
|
369
432
|
return {};
|
|
370
433
|
}
|
|
371
434
|
isKitReady() {
|
|
372
435
|
return !!(this.isInitialized && this.launcher);
|
|
373
436
|
}
|
|
437
|
+
// When the partner has opted out of targeting (noTargeting launcher option),
|
|
438
|
+
// the kit must not collect behavioral targeting signals such as page views.
|
|
439
|
+
isTargetingDisabled() {
|
|
440
|
+
return a().Rokt?.launcherOptions?.noTargeting === !0;
|
|
441
|
+
}
|
|
374
442
|
isPartnerInLocalLauncherTestGroup() {
|
|
375
443
|
return !!(a().config && a().config.isLocalLauncherEnabled && this.isAssignedToSampleGroup());
|
|
376
444
|
}
|
|
377
445
|
isAssignedToSampleGroup() {
|
|
378
446
|
return Math.random() > 0.5;
|
|
379
447
|
}
|
|
380
|
-
captureTiming(
|
|
381
|
-
window && a() && a().captureTiming &&
|
|
448
|
+
captureTiming(e) {
|
|
449
|
+
window && a() && a().captureTiming && e && a().captureTiming(e);
|
|
382
450
|
}
|
|
383
451
|
// ---- Public methods (mParticle Kit Callbacks) ----
|
|
384
452
|
/**
|
|
385
453
|
* Initializes the Rokt forwarder with settings from the mParticle server.
|
|
386
454
|
*/
|
|
387
|
-
init(
|
|
388
|
-
const o =
|
|
389
|
-
this.userAttributes =
|
|
390
|
-
const u =
|
|
391
|
-
this.placementEventMappingLookup =
|
|
392
|
-
const l =
|
|
455
|
+
init(e, t, i, r, s) {
|
|
456
|
+
const o = e, c = o.accountId;
|
|
457
|
+
this.userAttributes = R(s), this._onboardingExpProvider = o.onboardingExpProvider;
|
|
458
|
+
const u = v(o.placementEventMapping);
|
|
459
|
+
this.placementEventMappingLookup = G(u);
|
|
460
|
+
const l = v(
|
|
393
461
|
o.placementEventAttributeMapping
|
|
394
462
|
);
|
|
395
|
-
this.placementEventAttributeMappingLookup =
|
|
396
|
-
const h = a().Rokt?.domain, { roktExtensionsQueryParams:
|
|
463
|
+
this.placementEventAttributeMappingLookup = W(l), o.hashedEmailUserIdentityType && (this._mappedEmailSha256Key = o.hashedEmailUserIdentityType.toLowerCase()), this._workspaceIdSyncApiKey = E(o.workspaceIdSyncApiKey) ? o.workspaceIdSyncApiKey : void 0;
|
|
464
|
+
const h = a().Rokt?.domain, { roktExtensionsQueryParams: b, legacyRoktExtensions: I, loadThankYouElement: S } = Y(
|
|
397
465
|
o.roktExtensions
|
|
398
466
|
), g = {
|
|
399
467
|
...a().Rokt?.launcherOptions || {}
|
|
400
468
|
};
|
|
401
|
-
this.integrationName =
|
|
402
|
-
const
|
|
469
|
+
this.integrationName = ye(g.integrationName), g.integrationName = this.integrationName, this.domain = h;
|
|
470
|
+
const k = {
|
|
403
471
|
loggingUrl: o.loggingUrl,
|
|
404
472
|
errorUrl: o.errorUrl,
|
|
405
473
|
integrationDomain: h,
|
|
406
474
|
isLoggingEnabled: a().config?.isLoggingEnabled === !0
|
|
407
|
-
},
|
|
408
|
-
|
|
475
|
+
}, _ = new V(
|
|
476
|
+
k,
|
|
409
477
|
this.integrationName,
|
|
410
478
|
window.__rokt_li_guid__,
|
|
411
479
|
o.accountId
|
|
412
|
-
),
|
|
480
|
+
), A = new z(
|
|
481
|
+
k,
|
|
413
482
|
_,
|
|
414
|
-
y,
|
|
415
483
|
this.integrationName,
|
|
416
484
|
window.__rokt_li_guid__,
|
|
417
485
|
o.accountId
|
|
418
486
|
);
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
487
|
+
if (this.errorReportingService = _, this.loggingService = A, this.isTargetingDisabled())
|
|
488
|
+
try {
|
|
489
|
+
M();
|
|
490
|
+
} catch (p) {
|
|
491
|
+
this.errorReportingService?.report({
|
|
492
|
+
message: "Rokt Kit: Failed to clear page views when targeting is disabled",
|
|
493
|
+
code: "PAGE_VIEW_CAPTURE_FAILED",
|
|
494
|
+
severity: m.WARNING,
|
|
495
|
+
stackTrace: p instanceof Error ? p.stack : void 0
|
|
496
|
+
});
|
|
497
|
+
}
|
|
498
|
+
return a()._registerErrorReportingService && a()._registerErrorReportingService(_), a()._registerLoggingService && a()._registerLoggingService(A), i ? (this.testHelpers = {
|
|
499
|
+
generateLauncherScript: D,
|
|
500
|
+
generateThankYouElementScript: F,
|
|
501
|
+
extractRoktExtensionConfig: Y,
|
|
502
|
+
hashEventMessage: j,
|
|
503
|
+
parseSettingsString: v,
|
|
504
|
+
generateMappedEventLookup: G,
|
|
505
|
+
generateMappedEventAttributeLookup: W,
|
|
506
|
+
sendAdBlockMeasurementSignals: H,
|
|
428
507
|
createAutoRemovedIframe: N,
|
|
429
|
-
djb2:
|
|
430
|
-
setAllowedOriginHashes: (
|
|
431
|
-
|
|
508
|
+
djb2: B,
|
|
509
|
+
setAllowedOriginHashes: (p) => {
|
|
510
|
+
f._allowedOriginHashes = p;
|
|
432
511
|
},
|
|
433
|
-
ReportingTransport:
|
|
434
|
-
ErrorReportingService:
|
|
435
|
-
LoggingService:
|
|
436
|
-
RateLimiter:
|
|
437
|
-
ErrorCodes:
|
|
438
|
-
WSDKErrorSeverity:
|
|
439
|
-
}, this.attachLauncher(c, g), "Successfully initialized: " + d) : (
|
|
512
|
+
ReportingTransport: U,
|
|
513
|
+
ErrorReportingService: V,
|
|
514
|
+
LoggingService: z,
|
|
515
|
+
RateLimiter: Q,
|
|
516
|
+
ErrorCodes: P,
|
|
517
|
+
WSDKErrorSeverity: m
|
|
518
|
+
}, this.attachLauncher(c, g), "Successfully initialized: " + d) : (S && (a().Rokt.flushOnShoppableAdsReadyMessageQueue?.(this), x(se, F(h), {
|
|
440
519
|
onLoad: () => {
|
|
441
520
|
this._isThankYouElementLoaded = !0, this._thankYouElementOnLoadCallback && this._thankYouElementOnLoadCallback();
|
|
442
521
|
},
|
|
443
|
-
onError: (
|
|
444
|
-
console.error("Error loading Rokt Thank You Element script:",
|
|
522
|
+
onError: (p) => {
|
|
523
|
+
console.error("Error loading Rokt Thank You Element script:", p);
|
|
445
524
|
}
|
|
446
|
-
})), this.isLauncherReadyToAttach() ? this.attachLauncher(c, g,
|
|
525
|
+
})), this.isLauncherReadyToAttach() ? this.attachLauncher(c, g, I) : (x(re, D(h, b), {
|
|
447
526
|
onLoad: () => {
|
|
448
|
-
this.isLauncherReadyToAttach() ? this.attachLauncher(c, g,
|
|
527
|
+
this.isLauncherReadyToAttach() ? this.attachLauncher(c, g, I) : console.error("Rokt object is not available after script load.");
|
|
449
528
|
},
|
|
450
|
-
onError: (
|
|
451
|
-
console.error("Error loading Rokt launcher script:",
|
|
529
|
+
onError: (p) => {
|
|
530
|
+
console.error("Error loading Rokt launcher script:", p);
|
|
452
531
|
}
|
|
453
|
-
}), this.captureTiming(
|
|
532
|
+
}), this.captureTiming(f.PERFORMANCE_MARKS.RoktScriptAppended)), "Successfully initialized: " + d);
|
|
454
533
|
}
|
|
455
|
-
process(
|
|
534
|
+
process(e) {
|
|
535
|
+
if (!this.isTargetingDisabled() && (e.EventDataType === ae && this.capturePageView(e), e.EventDataType === ce))
|
|
536
|
+
try {
|
|
537
|
+
M();
|
|
538
|
+
} catch (t) {
|
|
539
|
+
this.errorReportingService?.report({
|
|
540
|
+
message: "Rokt Kit: Failed to clear page views on session end",
|
|
541
|
+
code: "PAGE_VIEW_CAPTURE_FAILED",
|
|
542
|
+
severity: m.WARNING,
|
|
543
|
+
stackTrace: t instanceof Error ? t.stack : void 0
|
|
544
|
+
});
|
|
545
|
+
}
|
|
456
546
|
if (!this.isKitReady())
|
|
457
547
|
return "Kit not ready for forwarder: " + d;
|
|
458
|
-
if (typeof a().Rokt?.setLocalSessionAttribute == "function" && (
|
|
459
|
-
const
|
|
460
|
-
this.placementEventMappingLookup[String(
|
|
548
|
+
if (typeof a().Rokt?.setLocalSessionAttribute == "function" && (L(this.placementEventAttributeMappingLookup) || this.applyPlacementEventAttributeMapping(e), !L(this.placementEventMappingLookup))) {
|
|
549
|
+
const t = j(e.EventDataType, e.EventCategory, e.EventName ?? "");
|
|
550
|
+
this.placementEventMappingLookup[String(t)] && a().Rokt.setLocalSessionAttribute?.(this.placementEventMappingLookup[String(t)], !0);
|
|
461
551
|
}
|
|
462
552
|
return "Successfully sent to forwarder: " + d;
|
|
463
553
|
}
|
|
464
|
-
setExtensionData(
|
|
554
|
+
setExtensionData(e) {
|
|
465
555
|
if (!this.isKitReady()) {
|
|
466
556
|
console.error("Rokt Kit: Not initialized");
|
|
467
557
|
return;
|
|
468
558
|
}
|
|
469
|
-
window.Rokt.setExtensionData(
|
|
559
|
+
window.Rokt.setExtensionData(e);
|
|
470
560
|
}
|
|
471
|
-
setUserAttribute(
|
|
472
|
-
return
|
|
561
|
+
setUserAttribute(e, t) {
|
|
562
|
+
return J(e) || (this.userAttributes[e] = t), "Successfully set user attribute for forwarder: " + d;
|
|
473
563
|
}
|
|
474
|
-
removeUserAttribute(
|
|
475
|
-
return delete this.userAttributes[
|
|
564
|
+
removeUserAttribute(e) {
|
|
565
|
+
return delete this.userAttributes[e], "Successfully removed user attribute for forwarder: " + d;
|
|
476
566
|
}
|
|
477
|
-
handleIdentityComplete(
|
|
478
|
-
return this.userAttributes =
|
|
567
|
+
handleIdentityComplete(e, t) {
|
|
568
|
+
return this.userAttributes = R(e.getAllUserAttributes()), "Successfully called " + t + " for forwarder: " + d;
|
|
479
569
|
}
|
|
480
|
-
onUserIdentified(
|
|
481
|
-
const
|
|
482
|
-
return this.filters.filteredUser =
|
|
570
|
+
onUserIdentified(e) {
|
|
571
|
+
const t = e;
|
|
572
|
+
return this.filters.filteredUser = t, this._workspaceSearchInFlightPromise = this.search(t), this.handleIdentityComplete(e, "onUserIdentified");
|
|
483
573
|
}
|
|
484
|
-
search(
|
|
485
|
-
const
|
|
486
|
-
if (!
|
|
574
|
+
search(e) {
|
|
575
|
+
const t = this._workspaceIdSyncApiKey;
|
|
576
|
+
if (!t)
|
|
487
577
|
return this.userIdentifiedInWorkspace = !1, this._workspaceLastSearchedIdentitiesKey = void 0, Promise.resolve();
|
|
488
578
|
const i = a().Identity?.search;
|
|
489
579
|
if (typeof i != "function")
|
|
490
580
|
return this.userIdentifiedInWorkspace = !1, this._workspaceLastSearchedIdentitiesKey = void 0, Promise.resolve();
|
|
491
|
-
const r =
|
|
581
|
+
const r = e.getUserIdentities ? e.getUserIdentities().userIdentities : null, s = {};
|
|
492
582
|
if (r)
|
|
493
583
|
for (const u of Object.keys(r)) {
|
|
494
584
|
const l = r[u];
|
|
495
|
-
|
|
585
|
+
E(l) && l.length > 0 && (s[u] = l);
|
|
496
586
|
}
|
|
497
587
|
const o = Object.keys(s);
|
|
498
588
|
if (o.length === 0)
|
|
@@ -500,7 +590,7 @@ const p = class p {
|
|
|
500
590
|
const c = o.sort().map((u) => `${u}=${s[u]}`).join("&");
|
|
501
591
|
return c === this._workspaceLastSearchedIdentitiesKey ? this._workspaceSearchInFlightPromise || Promise.resolve() : (this.userIdentifiedInWorkspace = !1, this._workspaceLastSearchedIdentitiesKey = c, new Promise((u) => {
|
|
502
592
|
try {
|
|
503
|
-
i(
|
|
593
|
+
i(t, s, (l) => {
|
|
504
594
|
l?.httpCode === 200 && (this.userIdentifiedInWorkspace = !0), u();
|
|
505
595
|
});
|
|
506
596
|
} catch (l) {
|
|
@@ -508,14 +598,14 @@ const p = class p {
|
|
|
508
598
|
}
|
|
509
599
|
}));
|
|
510
600
|
}
|
|
511
|
-
onLoginComplete(
|
|
512
|
-
return this.handleIdentityComplete(
|
|
601
|
+
onLoginComplete(e, t) {
|
|
602
|
+
return this.handleIdentityComplete(e, "onLoginComplete");
|
|
513
603
|
}
|
|
514
|
-
onLogoutComplete(
|
|
515
|
-
return this.userIdentifiedInWorkspace = !1, this._workspaceSearchInFlightPromise = null, this._workspaceLastSearchedIdentitiesKey = void 0, this.handleIdentityComplete(
|
|
604
|
+
onLogoutComplete(e, t) {
|
|
605
|
+
return this.userIdentifiedInWorkspace = !1, this._workspaceSearchInFlightPromise = null, this._workspaceLastSearchedIdentitiesKey = void 0, this.handleIdentityComplete(e, "onLogoutComplete");
|
|
516
606
|
}
|
|
517
|
-
onModifyComplete(
|
|
518
|
-
return this.handleIdentityComplete(
|
|
607
|
+
onModifyComplete(e, t) {
|
|
608
|
+
return this.handleIdentityComplete(e, "onModifyComplete");
|
|
519
609
|
}
|
|
520
610
|
/**
|
|
521
611
|
* Selects placements for Rokt Web SDK with merged attributes, filters, and experimentation options.
|
|
@@ -540,60 +630,61 @@ const p = class p {
|
|
|
540
630
|
* `Promise.resolve(...)`. The inner work runs in `_dispatchPlacements`;
|
|
541
631
|
* this wrapper just gates it on the in-flight search via `Promise.race`.
|
|
542
632
|
*/
|
|
543
|
-
selectPlacements(
|
|
633
|
+
selectPlacements(e) {
|
|
544
634
|
if (this._workspaceSearchInFlightPromise) {
|
|
545
|
-
const
|
|
635
|
+
const t = this._workspaceSearchInFlightPromise;
|
|
546
636
|
return Promise.race([
|
|
547
|
-
|
|
548
|
-
new Promise((i) => setTimeout(i,
|
|
549
|
-
]).then(() => this._dispatchPlacements(
|
|
637
|
+
t,
|
|
638
|
+
new Promise((i) => setTimeout(i, de))
|
|
639
|
+
]).then(() => this._dispatchPlacements(e));
|
|
550
640
|
}
|
|
551
|
-
return this._dispatchPlacements(
|
|
641
|
+
return this._dispatchPlacements(e);
|
|
552
642
|
}
|
|
553
|
-
_dispatchPlacements(
|
|
554
|
-
const
|
|
643
|
+
_dispatchPlacements(e) {
|
|
644
|
+
const t = e && e.attributes || {}, r = { ...R(this.userAttributes), ...t }, s = this.filters || {}, o = s.userAttributeFilters || [], c = s.filteredUser || null, u = c ? c.getMPID() : null;
|
|
555
645
|
let l;
|
|
556
|
-
s ? s.filterUserAttributes ? l = s.filterUserAttributes(r, o) : l = r : (console.warn("Rokt Kit: No filters available, using user attributes"), l = r), this.userAttributes =
|
|
557
|
-
const h = this._onboardingExpProvider === "Optimizely" ? this.fetchOptimizely() : {},
|
|
558
|
-
...
|
|
646
|
+
s ? s.filterUserAttributes ? l = s.filterUserAttributes(r, o) : l = r : (console.warn("Rokt Kit: No filters available, using user attributes"), l = r), this.userAttributes = R(l);
|
|
647
|
+
const h = this._onboardingExpProvider === "Optimizely" ? this.fetchOptimizely() : {}, b = this.returnUserIdentities(c), I = this.returnLocalSessionAttributes(), S = this.buildPageEvents(K()), g = {
|
|
648
|
+
...b,
|
|
559
649
|
...l,
|
|
560
650
|
...h,
|
|
561
|
-
...
|
|
562
|
-
...
|
|
651
|
+
...I,
|
|
652
|
+
...S.length ? { [ue]: JSON.stringify(S) } : {},
|
|
653
|
+
...this.userIdentifiedInWorkspace ? { [oe]: !0 } : {},
|
|
563
654
|
mpid: u
|
|
564
|
-
},
|
|
565
|
-
return Promise.resolve(_).then((
|
|
566
|
-
}).finally(
|
|
655
|
+
}, k = { ...e, attributes: g }, _ = this.launcher.selectPlacements(k), A = () => this.logSelectPlacementsEvent(g);
|
|
656
|
+
return Promise.resolve(_).then((p) => p?.context?.sessionId?.then((X) => this.setRoktSessionId(X))).catch(() => {
|
|
657
|
+
}).finally(A), _;
|
|
567
658
|
}
|
|
568
659
|
/**
|
|
569
660
|
* Passes attributes to the Rokt Web SDK for client-side hashing.
|
|
570
661
|
*/
|
|
571
|
-
hashAttributes(
|
|
572
|
-
return this.isKitReady() ? this.launcher.hashAttributes(
|
|
662
|
+
hashAttributes(e) {
|
|
663
|
+
return this.isKitReady() ? this.launcher.hashAttributes(e) : (console.error("Rokt Kit: Not initialized"), null);
|
|
573
664
|
}
|
|
574
665
|
/**
|
|
575
666
|
* Enables optional Integration Launcher extensions before selecting placements.
|
|
576
667
|
*
|
|
577
668
|
* @deprecated This functionality has been internalized and will be removed in a future release.
|
|
578
669
|
*/
|
|
579
|
-
use(
|
|
580
|
-
return this.isKitReady() ? !
|
|
670
|
+
use(e) {
|
|
671
|
+
return this.isKitReady() ? !e || !E(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")));
|
|
581
672
|
}
|
|
582
673
|
/**
|
|
583
674
|
* Registers a callback to be invoked once rokt-thank-you-element.js becomes available.
|
|
584
675
|
*/
|
|
585
|
-
onShoppableAdsReady(
|
|
586
|
-
this._isThankYouElementLoaded ?
|
|
676
|
+
onShoppableAdsReady(e) {
|
|
677
|
+
this._isThankYouElementLoaded ? e() : this._thankYouElementOnLoadCallback = e;
|
|
587
678
|
}
|
|
588
679
|
};
|
|
589
|
-
|
|
680
|
+
f._allowedOriginHashes = [-553112570, 549508659], f.PERFORMANCE_MARKS = {
|
|
590
681
|
RoktScriptAppended: "mp:RoktScriptAppended"
|
|
591
|
-
},
|
|
592
|
-
let
|
|
593
|
-
function
|
|
594
|
-
return
|
|
682
|
+
}, f.EMAIL_SHA256_KEY = "emailsha256";
|
|
683
|
+
let y = f;
|
|
684
|
+
function Ae() {
|
|
685
|
+
return w;
|
|
595
686
|
}
|
|
596
|
-
function
|
|
687
|
+
function Re(n) {
|
|
597
688
|
if (!n) {
|
|
598
689
|
window.console.log("You must pass a config object to register the kit " + d);
|
|
599
690
|
return;
|
|
@@ -603,17 +694,17 @@ function gt(n) {
|
|
|
603
694
|
return;
|
|
604
695
|
}
|
|
605
696
|
T(n.kits) ? n.kits[d] = {
|
|
606
|
-
constructor:
|
|
697
|
+
constructor: y
|
|
607
698
|
} : (n.kits = {}, n.kits[d] = {
|
|
608
|
-
constructor:
|
|
699
|
+
constructor: y
|
|
609
700
|
}), window.console.log("Successfully registered " + d + " to your mParticle configuration");
|
|
610
701
|
}
|
|
611
702
|
typeof window < "u" && window.mParticle && a().addForwarder && a().addForwarder({
|
|
612
703
|
name: d,
|
|
613
|
-
constructor:
|
|
614
|
-
getId:
|
|
704
|
+
constructor: y,
|
|
705
|
+
getId: Ae
|
|
615
706
|
});
|
|
616
707
|
export {
|
|
617
|
-
|
|
708
|
+
Re as register
|
|
618
709
|
};
|
|
619
710
|
//# 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 J=["billingaddress1","billingaddress2","billingcity","billingstate","billingzipcode","cartitems","ccbin","confirmationref","conversiontype","country","couponcode","currency","language","paymentserviceprovider","paymentserviceproviderattribute","paymenttype","shippingaddress1","shippingcity","shippingcountry","shippingmethod","shippingstate","shippingzipcode","totalprice"],Q=new Set(J);function K(n){return Q.has(n.toLowerCase())}function R(n){const t={},e=n||{},i=Object.keys(e);for(let r=0;r<i.length;r++){const s=i[r];K(s)||(t[s]=e[s])}return t}const d="Rokt",A=181,X="selectPlacements",$="apps.roktecommerce.com",Z=.1,tt="ThankYouPageJourney",et="rokt-launcher",it="rokt-thank-you-element",nt="userIdentifiedInWorkspace",rt=500,T={UNKNOWN_ERROR:"UNKNOWN_ERROR",UNHANDLED_EXCEPTION:"UNHANDLED_EXCEPTION",IDENTITY_REQUEST:"IDENTITY_REQUEST",LOG_DELIVERY_FAILURE:"LOG_DELIVERY_FAILURE"},_={ERROR:"ERROR",INFO:"INFO",WARNING:"WARNING"},st="apps.rokt-api.com",ot="/v1/log",at="/v1/errors",ct=10;function a(){return window.mParticle}function M(n,t){const i=[O(n),"/wsdk/integrations/launcher.js"].join("");return!t||t.length===0?i:i+"?extensions="+t.join(",")}function D(n){return[O(n),"/rokt-elements/rokt-element-thank-you.js"].join("")}function O(n){return["https://",typeof n<"u"?n:st].join("")}function Y(n,t,e){return n?n.startsWith("http://")||n.startsWith("https://")?n:"https://"+n:O(t)+e}function x(n,t,e){if(document.getElementById(n))return;const i=document.head||document.body,r=document.createElement("script");r.id=n,r.type="text/javascript",r.src=t,r.async=!0,r.crossOrigin="anonymous",r.fetchPriority="high",e?.onLoad&&(r.onload=e.onLoad),e?.onError&&(r.onerror=e.onError),i.appendChild(r)}function N(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 j(n){const t=n?S(n):[],e=[],i=[];let r=!1;for(let s=0;s<t.length;s++){const o=t[s].value;o==="thank-you-journey"?(r=!0,i.push(tt)):e.push(o)}return{roktExtensionsQueryParams:e,legacyRoktExtensions:i,loadThankYouElement:r}}async function lt(n,t){const e=[];if(t)for(const i of n)e.push(t.use(i));return Promise.all(e)}function F(n){if(!n)return{};const t={};for(let e=0;e<n.length;e++){const i=n[e];t[i.jsmap]=i.value}return t}function H(n){const t={};if(!Array.isArray(n))return t;for(let e=0;e<n.length;e++){const i=n[e];if(!i||!g(i.value)||!g(i.map))continue;const r=i.value,s=i.map;t[r]||(t[r]=[]),t[r].push({eventAttributeKey:s,conditions:Array.isArray(i.conditions)?i.conditions:[]})}return t}function W(n,t,e){return a().generateHash([n,t,e].join(""))}function y(n){return n==null?!0:typeof n=="object"?Object.keys(n).length===0:Array.isArray(n)?n.length===0:!1}function g(n){return typeof n=="string"}function ut(n){let i="mParticle_wsdkv_"+a().getVersion()+"_kitv_"+"1.28.3";return n&&(i+="_"+n),i}function G(n){let t=5381;for(let e=0;e<n.length;e++)t=(t<<5)+t+n.charCodeAt(e),t=t&t;return t}function P(n){const t=document.createElement("iframe");t.style.display="none",t.setAttribute("sandbox","allow-scripts allow-same-origin"),t.src=n,t.onload=function(){t.onload=null,t.parentNode&&t.parentNode.removeChild(t)};const e=document.body||document.head;e&&e.appendChild(t)}function z(n,t){const e=G(window.location.origin);if(E._allowedOriginHashes.indexOf(e)===-1||Math.random()>=Z)return;const r=window.__rokt_li_guid__;if(!r)return;const s=window.location.href.split("?")[0].split("#")[0],o="version="+encodeURIComponent(t??"")+"&launcherInstanceGuid="+encodeURIComponent(r)+"&pageUrl="+encodeURIComponent(s);P("https://"+(n||"apps.rokt.com")+"/v1/wsdk-init/index.html?"+o),P("https://"+$+"/v1/wsdk-init/index.html?"+o+"&isControl=true")}function dt(){return typeof window<"u"&&!!window.location?.search?.toLowerCase().includes("mp_enable_logging=true")}function ht(){return typeof window<"u"?window.location?.href:void 0}function pt(){return typeof window<"u"?window.navigator?.userAgent:void 0}class V{constructor(){this._logCount={}}incrementAndCheck(t){const i=(this._logCount[t]||0)+1;return this._logCount[t]=i,i>ct}}class C{constructor(t,e,i,r,s){this._reporter="mp-wsdk";const o=t.isLoggingEnabled;this._integrationName=e||"",this._launcherInstanceGuid=i,this._accountId=r||null,this._rateLimiter=s||new V,this._isEnabled=dt()||o}send(t,e,i,r,s,o){if(!(!this._isEnabled||this._rateLimiter.incrementAndCheck(e)))try{const c={additionalInformation:{message:i,version:this._integrationName},severity:e,code:r||T.UNKNOWN_ERROR,url:ht(),deviceInfo:pt(),stackTrace:s,reporter:this._reporter,integration:this._integrationName},u={Accept:"text/plain;charset=UTF-8","Content-Type":"application/json","rokt-launcher-version":this._integrationName,"rokt-wsdk-version":"joint"};this._launcherInstanceGuid&&(u["rokt-launcher-instance-guid"]=this._launcherInstanceGuid),this._accountId&&(u["rokt-account-id"]=this._accountId),fetch(t,{method:"POST",headers:u,body:JSON.stringify(c)}).then(l=>{if(!l.ok){const h=new Error("HTTP "+l.status+" from log endpoint");throw h.statusCode=l.status,h}}).catch(l=>{console.error("ReportingTransport: Failed to send log",l),o&&o(l)})}catch(c){console.error("ReportingTransport: Failed to send log",c),o&&o(c)}}}class q{constructor(t,e,i,r,s){this._transport=new C(t,e,i,r,s),this._errorUrl=Y(t?.errorUrl,t?.integrationDomain,at)}report(t){if(!t)return;const e=t.severity||_.ERROR;this._transport.send(this._errorUrl,e,t.message,t.code,t.stackTrace)}}class B{constructor(t,e,i,r,s,o){this._transport=new C(t,i,r,s,o),this._loggingUrl=Y(t?.loggingUrl,t?.integrationDomain,ot),this._errorReportingService=e}log(t){t&&this._transport.send(this._loggingUrl,_.INFO,t.message,t.code,void 0,e=>{if(this._errorReportingService){const i=typeof e.statusCode=="number";this._errorReportingService.report({message:"LoggingService: Failed to send log: "+e.message,code:T.LOG_DELIVERY_FAILURE,severity:i?_.ERROR:_.WARNING})}})}}const p=class p{constructor(){this.name=d,this.id=A,this.moduleId=A,this.isInitialized=!1,this.launcher=null,this.filters={},this.userAttributes={},this.userIdentifiedInWorkspace=!1,this.testHelpers=null,this.placementEventMappingLookup={},this.placementEventAttributeMappingLookup={},this.integrationName=null,this.errorReportingService=null,this.loggingService=null,this._thankYouElementOnLoadCallback=null,this._isThankYouElementLoaded=!1,this._workspaceSearchInFlightPromise=null}getEventAttributeValue(t,e){const i=t&&t.EventAttributes;return!i||typeof i[e]>"u"?null:i[e]}doesEventAttributeConditionMatch(t,e){if(!t||!g(t.operator))return!1;const i=t.operator.toLowerCase(),r=t.attributeValue;return i==="exists"?e!==null:e==null?!1:i==="equals"?String(e)===String(r):i==="contains"?String(e).indexOf(String(r))!==-1:!1}doesEventMatchRule(t,e){if(!e||!g(e.eventAttributeKey))return!1;const i=e.conditions;if(!Array.isArray(i))return!1;const r=this.getEventAttributeValue(t,e.eventAttributeKey);if(i.length===0)return r!==null;for(let s=0;s<i.length;s++)if(!this.doesEventAttributeConditionMatch(i[s],r))return!1;return!0}applyPlacementEventAttributeMapping(t){const e=Object.keys(this.placementEventAttributeMappingLookup);for(let i=0;i<e.length;i++){const r=e[i],s=this.placementEventAttributeMappingLookup[r];if(y(s))continue;let o=!0;for(let c=0;c<s.length;c++)if(!this.doesEventMatchRule(t,s[c])){o=!1;break}o&&a().Rokt.setLocalSessionAttribute?.(r,!0)}}isLauncherReadyToAttach(){return!!window.Rokt&&typeof window.Rokt.createLauncher=="function"}returnUserIdentities(t){if(!t||!t.getUserIdentities)return{};const e=t.getUserIdentities().userIdentities;return this.replaceOtherIdentityWithEmailsha256(e)}returnLocalSessionAttributes(){return!a().Rokt||typeof a().Rokt.getLocalSessionAttributes!="function"?{}:y(this.placementEventMappingLookup)&&y(this.placementEventAttributeMappingLookup)?{}:a().Rokt.getLocalSessionAttributes()}replaceOtherIdentityWithEmailsha256(t){const e={...t||{}},i=this._mappedEmailSha256Key;return i&&t[i]&&(e[p.EMAIL_SHA256_KEY]=t[i]),i&&delete e[i],e}logSelectPlacementsEvent(t){if(!window.mParticle||typeof a().logEvent!="function"||!N(t))return;const e=a().EventType.Other;a().logEvent(X,e,t)}setRoktSessionId(t){if(!(!t||typeof t!="string"))try{const e=a().getInstance();e&&typeof e.setIntegrationAttribute=="function"&&e.setIntegrationAttribute(A,{roktSessionId:t})}catch{}}attachLauncher(t,e,i=[]){const r=a()&&a().sessionManager&&typeof a().sessionManager.getSession=="function"?a().sessionManager.getSession():void 0,s={accountId:t,...e||{},...r?{mpSessionId:r}:{}};let o;this.isPartnerInLocalLauncherTestGroup()?o=Promise.resolve(window.Rokt.createLocalLauncher(s)):o=window.Rokt.createLauncher(s),o.then(async c=>{await lt(i,c),this.initRoktLauncher(c)}).catch(c=>{console.error("Error creating Rokt launcher:",c)})}initRoktLauncher(t){window.Rokt&&(window.Rokt.currentLauncher=t),this.launcher=t;const e=a().Rokt?.filters;e?(this.filters=e,e.filteredUser?this._workspaceSearchInFlightPromise=this.search(e.filteredUser):console.warn("Rokt Kit: No filtered user has been set.")):console.warn("Rokt Kit: No filters have been set."),this.isInitialized=!0,z(this.domain,this.integrationName),a().Rokt.attachKit(this)}fetchOptimizely(){const t=a()._getActiveForwarders().filter(e=>e.name==="Optimizely");try{if(t.length>0&&window.optimizely){const e=window.optimizely.get("state");return!e||!e.getActiveExperimentIds?{}:e.getActiveExperimentIds().reduce((s,o)=>(s["rokt.custom.optimizely.experiment."+o+".variationId"]=e.getVariationMap()[o].id,s),{})}}catch(e){console.error("Error fetching Optimizely attributes:",e)}return{}}isKitReady(){return!!(this.isInitialized&&this.launcher)}isPartnerInLocalLauncherTestGroup(){return!!(a().config&&a().config.isLocalLauncherEnabled&&this.isAssignedToSampleGroup())}isAssignedToSampleGroup(){return Math.random()>.5}captureTiming(t){window&&a()&&a().captureTiming&&t&&a().captureTiming(t)}init(t,e,i,r,s){const o=t,c=o.accountId;this.userAttributes=R(s),this._onboardingExpProvider=o.onboardingExpProvider;const u=S(o.placementEventMapping);this.placementEventMappingLookup=F(u);const l=S(o.placementEventAttributeMapping);this.placementEventAttributeMappingLookup=H(l),o.hashedEmailUserIdentityType&&(this._mappedEmailSha256Key=o.hashedEmailUserIdentityType.toLowerCase()),this._workspaceIdSyncApiKey=g(o.workspaceIdSyncApiKey)?o.workspaceIdSyncApiKey:void 0;const h=a().Rokt?.domain,{roktExtensionsQueryParams:U,legacyRoktExtensions:w,loadThankYouElement:b}=j(o.roktExtensions),f={...a().Rokt?.launcherOptions||{}};this.integrationName=ut(f.integrationName),f.integrationName=this.integrationName,this.domain=h;const k={loggingUrl:o.loggingUrl,errorUrl:o.errorUrl,integrationDomain:h,isLoggingEnabled:a().config?.isLoggingEnabled===!0},I=new q(k,this.integrationName,window.__rokt_li_guid__,o.accountId),L=new B(k,I,this.integrationName,window.__rokt_li_guid__,o.accountId);return this.errorReportingService=I,this.loggingService=L,a()._registerErrorReportingService&&a()._registerErrorReportingService(I),a()._registerLoggingService&&a()._registerLoggingService(L),i?(this.testHelpers={generateLauncherScript:M,generateThankYouElementScript:D,extractRoktExtensionConfig:j,hashEventMessage:W,parseSettingsString:S,generateMappedEventLookup:F,generateMappedEventAttributeLookup:H,sendAdBlockMeasurementSignals:z,createAutoRemovedIframe:P,djb2:G,setAllowedOriginHashes:m=>{p._allowedOriginHashes=m},ReportingTransport:C,ErrorReportingService:q,LoggingService:B,RateLimiter:V,ErrorCodes:T,WSDKErrorSeverity:_},this.attachLauncher(c,f),"Successfully initialized: "+d):(b&&(a().Rokt.flushOnShoppableAdsReadyMessageQueue?.(this),x(it,D(h),{onLoad:()=>{this._isThankYouElementLoaded=!0,this._thankYouElementOnLoadCallback&&this._thankYouElementOnLoadCallback()},onError:m=>{console.error("Error loading Rokt Thank You Element script:",m)}})),this.isLauncherReadyToAttach()?this.attachLauncher(c,f,w):(x(et,M(h,U),{onLoad:()=>{this.isLauncherReadyToAttach()?this.attachLauncher(c,f,w):console.error("Rokt object is not available after script load.")},onError:m=>{console.error("Error loading Rokt launcher script:",m)}}),this.captureTiming(p.PERFORMANCE_MARKS.RoktScriptAppended)),"Successfully initialized: "+d)}process(t){if(!this.isKitReady())return"Kit not ready for forwarder: "+d;if(typeof a().Rokt?.setLocalSessionAttribute=="function"&&(y(this.placementEventAttributeMappingLookup)||this.applyPlacementEventAttributeMapping(t),!y(this.placementEventMappingLookup))){const e=W(t.EventDataType,t.EventCategory,t.EventName??"");this.placementEventMappingLookup[String(e)]&&a().Rokt.setLocalSessionAttribute?.(this.placementEventMappingLookup[String(e)],!0)}return"Successfully sent to forwarder: "+d}setExtensionData(t){if(!this.isKitReady()){console.error("Rokt Kit: Not initialized");return}window.Rokt.setExtensionData(t)}setUserAttribute(t,e){return K(t)||(this.userAttributes[t]=e),"Successfully set user attribute for forwarder: "+d}removeUserAttribute(t){return delete this.userAttributes[t],"Successfully removed user attribute for forwarder: "+d}handleIdentityComplete(t,e){return this.userAttributes=R(t.getAllUserAttributes()),"Successfully called "+e+" for forwarder: "+d}onUserIdentified(t){const e=t;return this.filters.filteredUser=e,this._workspaceSearchInFlightPromise=this.search(e),this.handleIdentityComplete(t,"onUserIdentified")}search(t){const e=this._workspaceIdSyncApiKey;if(!e)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=t.getUserIdentities?t.getUserIdentities().userIdentities:null,s={};if(r)for(const u of Object.keys(r)){const l=r[u];g(l)&&l.length>0&&(s[u]=l)}const o=Object.keys(s);if(o.length===0)return this.userIdentifiedInWorkspace=!1,this._workspaceLastSearchedIdentitiesKey=void 0,Promise.resolve();const c=o.sort().map(u=>`${u}=${s[u]}`).join("&");return c===this._workspaceLastSearchedIdentitiesKey?this._workspaceSearchInFlightPromise||Promise.resolve():(this.userIdentifiedInWorkspace=!1,this._workspaceLastSearchedIdentitiesKey=c,new Promise(u=>{try{i(e,s,l=>{l?.httpCode===200&&(this.userIdentifiedInWorkspace=!0),u()})}catch(l){console.error("Rokt Kit: Workspace IDSync search failed",l),this._workspaceLastSearchedIdentitiesKey=void 0,u()}}))}onLoginComplete(t,e){return this.handleIdentityComplete(t,"onLoginComplete")}onLogoutComplete(t,e){return this.userIdentifiedInWorkspace=!1,this._workspaceSearchInFlightPromise=null,this._workspaceLastSearchedIdentitiesKey=void 0,this.handleIdentityComplete(t,"onLogoutComplete")}onModifyComplete(t,e){return this.handleIdentityComplete(t,"onModifyComplete")}selectPlacements(t){if(this._workspaceSearchInFlightPromise){const e=this._workspaceSearchInFlightPromise;return Promise.race([e,new Promise(i=>setTimeout(i,rt))]).then(()=>this._dispatchPlacements(t))}return this._dispatchPlacements(t)}_dispatchPlacements(t){const e=t&&t.attributes||{},r={...R(this.userAttributes),...e},s=this.filters||{},o=s.userAttributeFilters||[],c=s.filteredUser||null,u=c?c.getMPID():null;let l;s?s.filterUserAttributes?l=s.filterUserAttributes(r,o):l=r:(console.warn("Rokt Kit: No filters available, using user attributes"),l=r),this.userAttributes=R(l);const h=this._onboardingExpProvider==="Optimizely"?this.fetchOptimizely():{},U=this.returnUserIdentities(c),w=this.returnLocalSessionAttributes(),b={...U,...l,...h,...w,...this.userIdentifiedInWorkspace?{[nt]:!0}:{},mpid:u},f={...t,attributes:b},k=this.launcher.selectPlacements(f),I=()=>this.logSelectPlacementsEvent(b);return Promise.resolve(k).then(L=>L?.context?.sessionId?.then(m=>this.setRoktSessionId(m))).catch(()=>{}).finally(I),k}hashAttributes(t){return this.isKitReady()?this.launcher.hashAttributes(t):(console.error("Rokt Kit: Not initialized"),null)}use(t){return this.isKitReady()?!t||!g(t)?Promise.reject(new Error("Rokt Kit: Invalid extension name")):this.launcher.use(t):(console.error("Rokt Kit: Not initialized"),Promise.reject(new Error("Rokt Kit: Not initialized")))}onShoppableAdsReady(t){this._isThankYouElementLoaded?t():this._thankYouElementOnLoadCallback=t}};p._allowedOriginHashes=[-553112570,549508659],p.PERFORMANCE_MARKS={RoktScriptAppended:"mp:RoktScriptAppended"},p.EMAIL_SHA256_KEY="emailsha256";let E=p;function gt(){return A}function ft(n){if(!n){window.console.log("You must pass a config object to register the kit "+d);return}if(!N(n)){window.console.log("'config' must be an object. You passed in a "+typeof n);return}N(n.kits)?n.kits[d]={constructor:E}:(n.kits={},n.kits[d]={constructor:E}),window.console.log("Successfully registered "+d+" to your mParticle configuration")}return typeof window<"u"&&window.mParticle&&a().addForwarder&&a().addForwarder({name:d,constructor:E,getId:gt}),v.register=ft,Object.defineProperty(v,Symbol.toStringTag,{value:"Module"}),v})({});
|
|
1
|
+
var RoktKit=(function(b){"use strict";const $=["active_time_on_site_ms","billingaddress1","billingaddress2","billingcity","billingstate","billingzipcode","cartitems","ccbin","confirmationref","conversiontype","country","couponcode","currency","language","paymentserviceprovider","paymentserviceproviderattribute","paymenttype","shippingaddress1","shippingcity","shippingcountry","shippingmethod","shippingstate","shippingzipcode","totalprice"],Z=new Set($);function M(n){return Z.has(n.toLowerCase())}function I(n){const e={},t=n||{},i=Object.keys(t);for(let r=0;r<i.length;r++){const s=i[r];M(s)||(e[s]=t[s])}return e}const d="Rokt",S=181,ee="selectPlacements",te="apps.roktecommerce.com",ie=.1,ne="ThankYouPageJourney",re="rokt-launcher",se="rokt-thank-you-element",oe="userIdentifiedInWorkspace",ae=3,ce=2,L="mpPageViews",le=25,ue="page_events",de=500,T={UNKNOWN_ERROR:"UNKNOWN_ERROR",UNHANDLED_EXCEPTION:"UNHANDLED_EXCEPTION",IDENTITY_REQUEST:"IDENTITY_REQUEST",LOG_DELIVERY_FAILURE:"LOG_DELIVERY_FAILURE"},g={ERROR:"ERROR",INFO:"INFO",WARNING:"WARNING"},he="apps.rokt-api.com",pe="/v1/log",ge="/v1/errors",fe=10;function a(){return window.mParticle}function D(){try{const n=window.localStorage.getItem(L);if(n===null)return[];const e=JSON.parse(n);return Array.isArray(e)?e:[]}catch{return[]}}function me(n){window.localStorage.setItem(L,JSON.stringify(n))}function F(){window.localStorage.removeItem(L)}function Y(n,e){const i=[N(n),"/wsdk/integrations/launcher.js"].join("");return!e||e.length===0?i:i+"?extensions="+e.join(",")}function x(n){return[N(n),"/rokt-elements/rokt-element-thank-you.js"].join("")}function N(n){return["https://",typeof n<"u"?n:he].join("")}function G(n,e,t){return n?n.startsWith("http://")||n.startsWith("https://")?n:"https://"+n:N(e)+t}function W(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 k(n){if(!n)return[];try{return JSON.parse(n.replace(/"/g,'"'))}catch{console.error("Settings string contains invalid JSON")}return[]}function j(n){const e=n?k(n):[],t=[],i=[];let r=!1;for(let s=0;s<e.length;s++){const o=e[s].value;o==="thank-you-journey"?(r=!0,i.push(ne)):t.push(o)}return{roktExtensionsQueryParams:t,legacyRoktExtensions:i,loadThankYouElement:r}}async function Ee(n,e){const t=[];if(e)for(const i of n)t.push(e.use(i));return Promise.all(t)}function H(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 V(n){const e={};if(!Array.isArray(n))return e;for(let t=0;t<n.length;t++){const i=n[t];if(!i||!E(i.value)||!E(i.map))continue;const r=i.value,s=i.map;e[r]||(e[r]=[]),e[r].push({eventAttributeKey:s,conditions:Array.isArray(i.conditions)?i.conditions:[]})}return e}function z(n,e,t){return a().generateHash([n,e,t].join(""))}function P(n){return n==null?!0:typeof n=="object"?Object.keys(n).length===0:Array.isArray(n)?n.length===0:!1}function E(n){return typeof n=="string"}function _e(n){try{const e=new URL(n);return e.search="",e.toString()}catch{return n}}function ye(n){let i="mParticle_wsdkv_"+a().getVersion()+"_kitv_"+"1.30.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 C(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 q(n,e){const t=J(window.location.origin);if(_._allowedOriginHashes.indexOf(t)===-1||Math.random()>=ie)return;const r=window.__rokt_li_guid__;if(!r)return;const s=window.location.href.split("?")[0].split("#")[0],o="version="+encodeURIComponent(e??"")+"&launcherInstanceGuid="+encodeURIComponent(r)+"&pageUrl="+encodeURIComponent(s);C("https://"+(n||"apps.rokt.com")+"/v1/wsdk-init/index.html?"+o),C("https://"+te+"/v1/wsdk-init/index.html?"+o+"&isControl=true")}function Ie(){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 ke(){return typeof window<"u"?window.navigator?.userAgent:void 0}class B{constructor(){this._logCount={}}incrementAndCheck(e){const i=(this._logCount[e]||0)+1;return this._logCount[e]=i,i>fe}}class U{constructor(e,t,i,r,s){this._reporter="mp-wsdk";const o=e.isLoggingEnabled;this._integrationName=t||"",this._launcherInstanceGuid=i,this._accountId=r||null,this._rateLimiter=s||new B,this._isEnabled=Ie()||o}send(e,t,i,r,s,o){if(!(!this._isEnabled||this._rateLimiter.incrementAndCheck(t)))try{const c={additionalInformation:{message:i,version:this._integrationName},severity:t,code:r||T.UNKNOWN_ERROR,url:Se(),deviceInfo:ke(),stackTrace:s,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)}).then(l=>{if(!l.ok){const h=new Error("HTTP "+l.status+" from log endpoint");throw h.statusCode=l.status,h}}).catch(l=>{console.error("ReportingTransport: Failed to send log",l),o&&o(l)})}catch(c){console.error("ReportingTransport: Failed to send log",c),o&&o(c)}}}class Q{constructor(e,t,i,r,s){this._transport=new U(e,t,i,r,s),this._errorUrl=G(e?.errorUrl,e?.integrationDomain,ge)}report(e){if(!e)return;const t=e.severity||g.ERROR;this._transport.send(this._errorUrl,t,e.message,e.code,e.stackTrace)}}class X{constructor(e,t,i,r,s,o){this._transport=new U(e,i,r,s,o),this._loggingUrl=G(e?.loggingUrl,e?.integrationDomain,pe),this._errorReportingService=t}log(e){e&&this._transport.send(this._loggingUrl,g.INFO,e.message,e.code,void 0,t=>{if(this._errorReportingService){const i=typeof t.statusCode=="number";this._errorReportingService.report({message:"LoggingService: Failed to send log: "+t.message,code:T.LOG_DELIVERY_FAILURE,severity:i?g.ERROR:g.WARNING})}})}}const f=class f{constructor(){this.name=d,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.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||!E(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||!E(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 s=0;s<i.length;s++)if(!this.doesEventAttributeConditionMatch(i[s],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],s=this.placementEventAttributeMappingLookup[r];if(P(s))continue;let o=!0;for(let c=0;c<s.length;c++)if(!this.doesEventMatchRule(e,s[c])){o=!1;break}o&&a().Rokt.setLocalSessionAttribute?.(r,!0)}}capturePageView(e){let t;try{t=_e(window.location.href);const i=D(),r={pageUrl:t,sourceMessageId:e.SourceMessageId,timestamp:e.Timestamp};for(Number.isFinite(e.ActiveTimeOnSite)&&(r.activeTimeOnSite=e.ActiveTimeOnSite),i.push(r);i.length>le;)i.shift();me(i)}catch(i){this.errorReportingService?.report({message:`Rokt Kit: Failed to capture page view for ${t}`,code:"PAGE_VIEW_CAPTURE_FAILED",severity:g.WARNING,stackTrace:i instanceof Error?i.stack:void 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"?{}:a().Rokt.getLocalSessionAttributes()}buildPageEvents(e){return e.map((t,i)=>{const r={pageUrl:t.pageUrl,sourceMessageId:t.sourceMessageId,timestamp:t.timestamp},s=t.activeTimeOnSite,o=s!==void 0&&Number.isFinite(s);o&&(r.activeTimeOnSite=s);const u=e[i+1]?.activeTimeOnSite,l=u!==void 0&&Number.isFinite(u);if(o&&l){const h=u-s;h>=0&&(r.timeOnPage=h)}return r})}replaceOtherIdentityWithEmailsha256(e){const t={...e||{}},i=this._mappedEmailSha256Key;return i&&e[i]&&(t[f.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(ee,t,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,s={accountId:e,...t||{},...r?{mpSessionId:r}:{}};let o;this.isPartnerInLocalLauncherTestGroup()?o=Promise.resolve(window.Rokt.createLocalLauncher(s)):o=window.Rokt.createLauncher(s),o.then(async c=>{await Ee(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,q(this.domain,this.integrationName),a().Rokt.attachKit(this)}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((s,o)=>(s["rokt.custom.optimizely.experiment."+o+".variationId"]=t.getVariationMap()[o].id,s),{})}}catch(t){console.error("Error fetching Optimizely attributes:",t)}return{}}isKitReady(){return!!(this.isInitialized&&this.launcher)}isTargetingDisabled(){return a().Rokt?.launcherOptions?.noTargeting===!0}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,s){const o=e,c=o.accountId;this.userAttributes=I(s),this._onboardingExpProvider=o.onboardingExpProvider;const u=k(o.placementEventMapping);this.placementEventMappingLookup=H(u);const l=k(o.placementEventAttributeMapping);this.placementEventAttributeMappingLookup=V(l),o.hashedEmailUserIdentityType&&(this._mappedEmailSha256Key=o.hashedEmailUserIdentityType.toLowerCase()),this._workspaceIdSyncApiKey=E(o.workspaceIdSyncApiKey)?o.workspaceIdSyncApiKey:void 0;const h=a().Rokt?.domain,{roktExtensionsQueryParams:K,legacyRoktExtensions:A,loadThankYouElement:R}=j(o.roktExtensions),m={...a().Rokt?.launcherOptions||{}};this.integrationName=ye(m.integrationName),m.integrationName=this.integrationName,this.domain=h;const w={loggingUrl:o.loggingUrl,errorUrl:o.errorUrl,integrationDomain:h,isLoggingEnabled:a().config?.isLoggingEnabled===!0},y=new Q(w,this.integrationName,window.__rokt_li_guid__,o.accountId),v=new X(w,y,this.integrationName,window.__rokt_li_guid__,o.accountId);if(this.errorReportingService=y,this.loggingService=v,this.isTargetingDisabled())try{F()}catch(p){this.errorReportingService?.report({message:"Rokt Kit: Failed to clear page views when targeting is disabled",code:"PAGE_VIEW_CAPTURE_FAILED",severity:g.WARNING,stackTrace:p instanceof Error?p.stack:void 0})}return a()._registerErrorReportingService&&a()._registerErrorReportingService(y),a()._registerLoggingService&&a()._registerLoggingService(v),i?(this.testHelpers={generateLauncherScript:Y,generateThankYouElementScript:x,extractRoktExtensionConfig:j,hashEventMessage:z,parseSettingsString:k,generateMappedEventLookup:H,generateMappedEventAttributeLookup:V,sendAdBlockMeasurementSignals:q,createAutoRemovedIframe:C,djb2:J,setAllowedOriginHashes:p=>{f._allowedOriginHashes=p},ReportingTransport:U,ErrorReportingService:Q,LoggingService:X,RateLimiter:B,ErrorCodes:T,WSDKErrorSeverity:g},this.attachLauncher(c,m),"Successfully initialized: "+d):(R&&(a().Rokt.flushOnShoppableAdsReadyMessageQueue?.(this),W(se,x(h),{onLoad:()=>{this._isThankYouElementLoaded=!0,this._thankYouElementOnLoadCallback&&this._thankYouElementOnLoadCallback()},onError:p=>{console.error("Error loading Rokt Thank You Element script:",p)}})),this.isLauncherReadyToAttach()?this.attachLauncher(c,m,A):(W(re,Y(h,K),{onLoad:()=>{this.isLauncherReadyToAttach()?this.attachLauncher(c,m,A):console.error("Rokt object is not available after script load.")},onError:p=>{console.error("Error loading Rokt launcher script:",p)}}),this.captureTiming(f.PERFORMANCE_MARKS.RoktScriptAppended)),"Successfully initialized: "+d)}process(e){if(!this.isTargetingDisabled()&&(e.EventDataType===ae&&this.capturePageView(e),e.EventDataType===ce))try{F()}catch(t){this.errorReportingService?.report({message:"Rokt Kit: Failed to clear page views on session end",code:"PAGE_VIEW_CAPTURE_FAILED",severity:g.WARNING,stackTrace:t instanceof Error?t.stack:void 0})}if(!this.isKitReady())return"Kit not ready for forwarder: "+d;if(typeof a().Rokt?.setLocalSessionAttribute=="function"&&(P(this.placementEventAttributeMappingLookup)||this.applyPlacementEventAttributeMapping(e),!P(this.placementEventMappingLookup))){const t=z(e.EventDataType,e.EventCategory,e.EventName??"");this.placementEventMappingLookup[String(t)]&&a().Rokt.setLocalSessionAttribute?.(this.placementEventMappingLookup[String(t)],!0)}return"Successfully sent to forwarder: "+d}setExtensionData(e){if(!this.isKitReady()){console.error("Rokt Kit: Not initialized");return}window.Rokt.setExtensionData(e)}setUserAttribute(e,t){return M(e)||(this.userAttributes[e]=t),"Successfully set user attribute for forwarder: "+d}removeUserAttribute(e){return delete this.userAttributes[e],"Successfully removed user attribute for forwarder: "+d}handleIdentityComplete(e,t){return this.userAttributes=I(e.getAllUserAttributes()),"Successfully called "+t+" for forwarder: "+d}onUserIdentified(e){const t=e;return this.filters.filteredUser=t,this._workspaceSearchInFlightPromise=this.search(t),this.handleIdentityComplete(e,"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,s={};if(r)for(const u of Object.keys(r)){const l=r[u];E(l)&&l.length>0&&(s[u]=l)}const o=Object.keys(s);if(o.length===0)return this.userIdentifiedInWorkspace=!1,this._workspaceLastSearchedIdentitiesKey=void 0,Promise.resolve();const c=o.sort().map(u=>`${u}=${s[u]}`).join("&");return c===this._workspaceLastSearchedIdentitiesKey?this._workspaceSearchInFlightPromise||Promise.resolve():(this.userIdentifiedInWorkspace=!1,this._workspaceLastSearchedIdentitiesKey=c,new Promise(u=>{try{i(t,s,l=>{l?.httpCode===200&&(this.userIdentifiedInWorkspace=!0),u()})}catch(l){console.error("Rokt Kit: Workspace IDSync search failed",l),this._workspaceLastSearchedIdentitiesKey=void 0,u()}}))}onLoginComplete(e,t){return this.handleIdentityComplete(e,"onLoginComplete")}onLogoutComplete(e,t){return this.userIdentifiedInWorkspace=!1,this._workspaceSearchInFlightPromise=null,this._workspaceLastSearchedIdentitiesKey=void 0,this.handleIdentityComplete(e,"onLogoutComplete")}onModifyComplete(e,t){return this.handleIdentityComplete(e,"onModifyComplete")}selectPlacements(e){if(this._workspaceSearchInFlightPromise){const t=this._workspaceSearchInFlightPromise;return Promise.race([t,new Promise(i=>setTimeout(i,de))]).then(()=>this._dispatchPlacements(e))}return this._dispatchPlacements(e)}_dispatchPlacements(e){const t=e&&e.attributes||{},r={...I(this.userAttributes),...t},s=this.filters||{},o=s.userAttributeFilters||[],c=s.filteredUser||null,u=c?c.getMPID():null;let l;s?s.filterUserAttributes?l=s.filterUserAttributes(r,o):l=r:(console.warn("Rokt Kit: No filters available, using user attributes"),l=r),this.userAttributes=I(l);const h=this._onboardingExpProvider==="Optimizely"?this.fetchOptimizely():{},K=this.returnUserIdentities(c),A=this.returnLocalSessionAttributes(),R=this.buildPageEvents(D()),m={...K,...l,...h,...A,...R.length?{[ue]:JSON.stringify(R)}:{},...this.userIdentifiedInWorkspace?{[oe]:!0}:{},mpid:u},w={...e,attributes:m},y=this.launcher.selectPlacements(w),v=()=>this.logSelectPlacementsEvent(m);return Promise.resolve(y).then(p=>p?.context?.sessionId?.then(we=>this.setRoktSessionId(we))).catch(()=>{}).finally(v),y}hashAttributes(e){return this.isKitReady()?this.launcher.hashAttributes(e):(console.error("Rokt Kit: Not initialized"),null)}use(e){return this.isKitReady()?!e||!E(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}};f._allowedOriginHashes=[-553112570,549508659],f.PERFORMANCE_MARKS={RoktScriptAppended:"mp:RoktScriptAppended"},f.EMAIL_SHA256_KEY="emailsha256";let _=f;function Ae(){return S}function Re(n){if(!n){window.console.log("You must pass a config object to register the kit "+d);return}if(!O(n)){window.console.log("'config' must be an object. You passed in a "+typeof n);return}O(n.kits)?n.kits[d]={constructor:_}:(n.kits={},n.kits[d]={constructor:_}),window.console.log("Successfully registered "+d+" to your mParticle configuration")}return typeof window<"u"&&window.mParticle&&a().addForwarder&&a().addForwarder({name:d,constructor:_,getId:Ae}),b.register=Re,Object.defineProperty(b,Symbol.toStringTag,{value:"Module"}),b})({});
|
|
2
2
|
//# sourceMappingURL=Rokt-Kit.iife.js.map
|