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