@mparticle/web-rokt-kit 1.33.3 → 1.34.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Rokt-Kit.common.js +1 -1
- package/dist/Rokt-Kit.esm.js +108 -105
- 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 de=["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"],he=new Set(de);function ee(i){return he.has(i.toLowerCase())}function b(i){const e={},t=i||{},n=Object.keys(t);for(let r=0;r<n.length;r++){const s=n[r];ee(s)||(e[s]=t[s])}return e}function _(i){return typeof i=="object"&&i!==null&&!Array.isArray(i)}function m(i){return typeof i=="string"}function L(i){return typeof i=="function"}function C(i){return i==null?!0:typeof i=="object"?Object.keys(i).length===0:!1}function K(i){try{const e=new URL(i);return e.search="",e.toString()}catch{return i}}const Y="__rokt_ls_probe__";function x(){try{return window.localStorage.setItem(Y,"1"),window.localStorage.removeItem(Y),!0}catch{return!1}}function N(i){try{const e=window.localStorage.getItem(i);return e===null?null:JSON.parse(e)}catch{return null}}function te(i,e){try{return window.localStorage.setItem(i,JSON.stringify(e)),!0}catch{return!1}}function ie(i){try{window.localStorage.removeItem(i)}catch{}}function ne(i,e){const t=N(i);return _(t)?t[e]:void 0}function re(i,e,t){const n=N(i),r=_(n)?{...n}:{};return r[e]=t,te(i,r)}function pe(i,e){const t=N(i);if(!_(t)||!(e in t))return;const n={...t};delete n[e],Object.keys(n).length===0?ie(i):te(i,n)}const A="mp-rokt-kit",R="pageViews",G="mpPageViews";function se(i){const e=N(G);if(e===null)return;if(!(ne(A,R)!==void 0)&&Array.isArray(e)&&!re(A,R,e)){i?.log({message:"Rokt Kit: Failed to migrate legacy page-view storage; retaining legacy key for retry [reason: migration_retry]",code:"PAGE_VIEW_CAPTURE_FAILED"});return}ie(G)}function j(i){se(i);const e=ne(A,R);return Array.isArray(e)?e:[]}function ge(i){return re(A,R,i.slice(-25))}function W(){pe(A,R)}function fe(i){const e=i.slice(-25);return e.map((t,n)=>{const r=t.activeTimeOnSite,s=r!==void 0&&Number.isFinite(r),l=e[n+1]?.activeTimeOnSite,u=l!==void 0&&Number.isFinite(l),c=s&&u?l-r:void 0;return{pageUrl:t.pageUrl,sourceMessageId:t.sourceMessageId,timestamp:t.timestamp,...t.pageTitle!==void 0?{pageTitle:t.pageTitle}:{},...t.canonicalUrl!==void 0?{canonicalUrl:t.canonicalUrl}:{},...s?{activeTimeOnSite:r}:{},...c!==void 0&&c>=0?{activeTimeOnPage:c}:{}}})}function me(){const e=document.querySelector('link[rel="canonical"]')?.href;if(e)return K(e)}const d="Rokt",T=181,Ee="selectPlacements",_e="apps.roktecommerce.com",ye=.1,Ie="ThankYouPageJourney",Se="rokt-launcher",ke="rokt-thank-you-element",Ae="userIdentifiedInWorkspace",Re=3,ve=2,we="page_events",be="mparticle_session_id",Le=500,D={UNKNOWN_ERROR:"UNKNOWN_ERROR",UNHANDLED_EXCEPTION:"UNHANDLED_EXCEPTION",IDENTITY_REQUEST:"IDENTITY_REQUEST",LOG_DELIVERY_FAILURE:"LOG_DELIVERY_FAILURE"},E={ERROR:"ERROR",INFO:"INFO",WARNING:"WARNING"},Te="apps.rokt-api.com",Pe="/v1/log",Ne="/v1/errors",Oe=10;function a(){return window.mParticle}function H(i,e){const n=[O(i),"/wsdk/integrations/launcher.js"].join("");return!e||e.length===0?n:n+"?extensions="+e.join(",")}function V(i){return[O(i),"/rokt-elements/rokt-element-thank-you.js"].join("")}function O(i){const e=typeof i<"u"?i:Te;return e.includes("://")?e.replace(/\/+$/,""):["https://",e].join("")}function oe(i,e,t){if(i)return i.startsWith("http://")||i.startsWith("https://")?i:"https://"+i;const r=e?.includes("://")&&!/^https?:\/\//i.test(e)?void 0:e;return O(r)+t}function z(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 P(i){if(!i)return[];try{return JSON.parse(i.replace(/"/g,'"'))}catch{console.error("Settings string contains invalid JSON")}return[]}function J(i){const e=i?P(i):[],t=[],n=[];let r=!1;for(let s=0;s<e.length;s++){const o=e[s].value;o==="thank-you-journey"?(r=!0,n.push(Ie)):t.push(o)}return{roktExtensionsQueryParams:t,legacyRoktExtensions:n,loadThankYouElement:r}}async function Ue(i,e){const t=[];if(e)for(const n of i)t.push(e.use(n));return Promise.all(t)}function q(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 B(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,s=n.map;e[r]||(e[r]=[]),e[r].push({eventAttributeKey:s,conditions:Array.isArray(n.conditions)?n.conditions:[]})}return e}function $(i,e,t){return a().generateHash([i,e,t].join(""))}function Ce(i){let n="mParticle_wsdkv_"+a().getVersion()+"_kitv_"+"1.33.3";return i&&(n+="_"+i),n}function ae(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 M(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=ae(window.location.origin);if(y._allowedOriginHashes.indexOf(t)===-1||Math.random()>=ye)return;const r=window.__rokt_li_guid__;if(!r||i&&i.includes("://")&&!/^https:\/\//i.test(i))return;const s=window.location.href.split("?")[0].split("#")[0],o="version="+encodeURIComponent(e??"")+"&launcherInstanceGuid="+encodeURIComponent(r)+"&pageUrl="+encodeURIComponent(s),l=i?O(i):"https://apps.rokt.com";M(l+"/v1/wsdk-init/index.html?"+o),M("https://"+_e+"/v1/wsdk-init/index.html?"+o+"&isControl=true")}function Me(){return typeof window<"u"&&!!window.location?.search?.toLowerCase().includes("mp_enable_logging=true")}function Ke(){return typeof window<"u"?window.location?.href:void 0}function De(){return typeof window<"u"?window.navigator?.userAgent:void 0}class ce{constructor(){this._logCount={}}incrementAndCheck(e){const n=(this._logCount[e]||0)+1;return this._logCount[e]=n,n>Oe}}class F{constructor(e,t,n,r,s){this._reporter="mp-wsdk";const o=e.isLoggingEnabled;this._integrationName=t||"",this._launcherInstanceGuid=n,this._accountId=r||null,this._rateLimiter=s||new ce,this._isEnabled=Me()||o}send(e,t,n,r,s,o){if(!(!this._isEnabled||this._rateLimiter.incrementAndCheck(t)))try{const l={additionalInformation:{message:n,version:this._integrationName},severity:t,code:r||D.UNKNOWN_ERROR,url:Ke(),deviceInfo:De(),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(l)}).then(c=>{if(!c.ok){const p=new Error("HTTP "+c.status+" from log endpoint");throw p.statusCode=c.status,p}}).catch(c=>{console.error("ReportingTransport: Failed to send log",c),o&&o(c)})}catch(l){console.error("ReportingTransport: Failed to send log",l),o&&o(l)}}}class X{constructor(e,t,n,r,s){this._transport=new F(e,t,n,r,s),this._errorUrl=oe(e?.errorUrl,e?.integrationDomain,Ne)}report(e){if(!e)return;const t=e.severity||E.ERROR;this._transport.send(this._errorUrl,t,e.message,e.code,e.stackTrace)}}class Z{constructor(e,t,n,r,s,o){this._transport=new F(e,n,r,s,o),this._loggingUrl=oe(e?.loggingUrl,e?.integrationDomain,Pe),this._errorReportingService=t}log(e){e&&this._transport.send(this._loggingUrl,E.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:D.LOG_DELIVERY_FAILURE,severity:n?E.ERROR:E.WARNING})}})}}function Fe(i){const e=K(window.location.href),t=i.EventAttributes?.title||document.title,n=me(),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=T,this.moduleId=T,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 s=0;s<n.length;s++)if(!this.doesEventAttributeConditionMatch(n[s],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],s=this.placementEventAttributeMappingLookup[r];if(C(s))continue;let o=!0;for(let l=0;l<s.length;l++)if(!this.doesEventMatchRule(e,s[l])){o=!1;break}o&&a().Rokt.setLocalSessionAttribute?.(r,!0)}}capturePageView(e){let t;try{t=K(window.location.href);const n=j(this.loggingService),r=Fe(e);if(n.push(r),!ge(n)){const s=x()?"quota":"ls_unavailable";this.loggingService?.log({message:`Rokt Kit: Failed to persist page view for ${t} [reason: ${s}]`,code:"PAGE_VIEW_CAPTURE_FAILED"})}}catch(n){const r=x()?"exception":"ls_unavailable",s=n instanceof Error?n.message:String(n);this.loggingService?.log({message:`Rokt Kit: Failed to capture page view for ${t}: ${s} [reason: ${r}]`,code:"PAGE_VIEW_CAPTURE_FAILED"})}}isLauncherReadyToAttach(){return!!window.Rokt&&L(window.Rokt.createLauncher)}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"||!_(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&&L(t.setIntegrationAttribute)&&t.setIntegrationAttribute(T,{roktSessionId:e})}catch{}}readMpSessionId(){const e=a()?.sessionManager,t=e?.getSessionId??e?.getSession;if(L(t))return t.call(e)||void 0}attachLauncher(e,t,n=[]){const r={accountId:e,...t||{}};let s;this.isPartnerInLocalLauncherTestGroup()?s=Promise.resolve(window.Rokt.createLocalLauncher(r)):s=window.Rokt.createLauncher(r),s.then(async o=>{await Ue(n,o),this.initRoktLauncher(o)}).catch(o=>{console.error("Error creating Rokt launcher:",o)})}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,n,r,s){const o=e,l=o.accountId;this.userAttributes=b(s),this._onboardingExpProvider=o.onboardingExpProvider;const u=P(o.placementEventMapping);this.placementEventMappingLookup=q(u);const c=P(o.placementEventAttributeMapping);this.placementEventAttributeMappingLookup=B(c),o.hashedEmailUserIdentityType&&(this._mappedEmailSha256Key=o.hashedEmailUserIdentityType.toLowerCase()),this._workspaceIdSyncApiKey=m(o.workspaceIdSyncApiKey)?o.workspaceIdSyncApiKey:void 0;const p=a().Rokt?.domain,{roktExtensionsQueryParams:U,legacyRoktExtensions:v,loadThankYouElement:w}=J(o.roktExtensions),g={...a().Rokt?.launcherOptions||{}};this.integrationName=Ce(g.integrationName),g.integrationName=this.integrationName,this.domain=p;const I={loggingUrl:o.loggingUrl,errorUrl:o.errorUrl,integrationDomain:p,isLoggingEnabled:a().config?.isLoggingEnabled===!0},S=new X(I,this.integrationName,window.__rokt_li_guid__,o.accountId),k=new Z(I,S,this.integrationName,window.__rokt_li_guid__,o.accountId);if(this.errorReportingService=S,this.loggingService=k,this.isTargetingDisabled())try{W()}catch(h){this.errorReportingService?.report({message:"Rokt Kit: Failed to clear page views when targeting is disabled",code:"PAGE_VIEW_CAPTURE_FAILED",severity:E.INFO,stackTrace:h instanceof Error?h.stack:void 0})}return a()._registerErrorReportingService&&a()._registerErrorReportingService(S),a()._registerLoggingService&&a()._registerLoggingService(k),n?(this.testHelpers={generateLauncherScript:H,generateThankYouElementScript:V,extractRoktExtensionConfig:J,hashEventMessage:$,parseSettingsString:P,generateMappedEventLookup:q,generateMappedEventAttributeLookup:B,sendAdBlockMeasurementSignals:Q,createAutoRemovedIframe:M,djb2:ae,setAllowedOriginHashes:h=>{f._allowedOriginHashes=h},ReportingTransport:F,ErrorReportingService:X,LoggingService:Z,RateLimiter:ce,ErrorCodes:D,WSDKErrorSeverity:E},this.attachLauncher(l,g),"Successfully initialized: "+d):(w&&(a().Rokt.flushOnShoppableAdsReadyMessageQueue?.(this),z(ke,V(p),{onLoad:()=>{this._isThankYouElementLoaded=!0,this._thankYouElementOnLoadCallback&&this._thankYouElementOnLoadCallback()},onError:h=>{console.error("Error loading Rokt Thank You Element script:",h)}})),this.isLauncherReadyToAttach()?this.attachLauncher(l,g,v):(z(Se,H(p,U),{onLoad:()=>{this.isLauncherReadyToAttach()?this.attachLauncher(l,g,v):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===Re&&this.capturePageView(e),e.EventDataType===ve&&(se(this.loggingService),W())),!this.isKitReady())return"Kit not ready for forwarder: "+d;if(L(a().Rokt?.setLocalSessionAttribute)&&(C(this.placementEventAttributeMappingLookup)||this.applyPlacementEventAttributeMapping(e),!C(this.placementEventMappingLookup))){const t=$(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 ee(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,s={};if(r)for(const u of Object.keys(r)){const c=r[u];m(c)&&c.length>0&&(s[u]=c)}const o=Object.keys(s);if(o.length===0)return this.userIdentifiedInWorkspace=!1,this._workspaceLastSearchedIdentitiesKey=void 0,Promise.resolve();const l=o.sort().map(u=>`${u}=${s[u]}`).join("&");return l===this._workspaceLastSearchedIdentitiesKey?this._workspaceSearchInFlightPromise||Promise.resolve():(this.userIdentifiedInWorkspace=!1,this._workspaceLastSearchedIdentitiesKey=l,new Promise(u=>{try{n(t,s,c=>{c?.httpCode===200&&(this.userIdentifiedInWorkspace=!0),u()})}catch(c){console.error("Rokt Kit: Workspace IDSync search failed",c),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,Le))]).then(()=>this._dispatchPlacements(e))}return this._dispatchPlacements(e)}_dispatchPlacements(e){const t=e&&e.attributes||{},r={...b(this.userAttributes),...t},s=this.filters||{},o=s.userAttributeFilters||[],l=s.filteredUser||null,u=l?l.getMPID():null;let c;s?s.filterUserAttributes?c=s.filterUserAttributes(r,o):c=r:(console.warn("Rokt Kit: No filters available, using user attributes"),c=r),this.userAttributes=b(c);const p=this._onboardingExpProvider==="Optimizely"?this.fetchOptimizely():{},U=this.returnUserIdentities(l),v=this.returnLocalSessionAttributes(),w=fe(j(this.loggingService)),g=this.readMpSessionId(),I={...U,...c,...p,...v,...w.length?{[we]:JSON.stringify(w)}:{},...this.userIdentifiedInWorkspace?{[Ae]:!0}:{},...g?{[be]:g}:{},mpid:u},S={...e,attributes:I},k=this.launcher.selectPlacements(S),h=()=>this.logSelectPlacementsEvent(I);return Promise.resolve(k).then(le=>le?.context?.sessionId?.then(ue=>this.setRoktSessionId(ue))).catch(()=>{}).finally(h),k}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 y=f;function Ye(){return T}function xe(i){if(!i){window.console.log("You must pass a config object to register the kit "+d);return}if(!_(i)){window.console.log("'config' must be an object. You passed in a "+typeof i);return}_(i.kits)?i.kits[d]={constructor:y}:(i.kits={},i.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:Ye});exports.register=xe;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const he=["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"],pe=new Set(he);function ee(i){return pe.has(i.toLowerCase())}function b(i){const e={},t=i||{},n=Object.keys(t);for(let r=0;r<n.length;r++){const s=n[r];ee(s)||(e[s]=t[s])}return e}function I(i){return typeof i=="object"&&i!==null&&!Array.isArray(i)}function m(i){return typeof i=="string"}function L(i){return typeof i=="function"}function U(i){return i==null?!0:typeof i=="object"?Object.keys(i).length===0:!1}function K(i){try{const e=new URL(i);return e.search="",e.toString()}catch{return i}}const Y="__rokt_ls_probe__";function x(){try{return window.localStorage.setItem(Y,"1"),window.localStorage.removeItem(Y),!0}catch{return!1}}function N(i){try{const e=window.localStorage.getItem(i);return e===null?null:JSON.parse(e)}catch{return null}}function te(i,e){try{return window.localStorage.setItem(i,JSON.stringify(e)),!0}catch{return!1}}function ie(i){try{window.localStorage.removeItem(i)}catch{}}function ne(i,e){const t=N(i);return I(t)?t[e]:void 0}function re(i,e,t){const n=N(i),r=I(n)?{...n}:{};return r[e]=t,te(i,r)}function ge(i,e){const t=N(i);if(!I(t)||!(e in t))return;const n={...t};delete n[e],Object.keys(n).length===0?ie(i):te(i,n)}const A="mp-rokt-kit",k="pageViews",G="mpPageViews";function se(i){const e=N(G);if(e===null)return;!(ne(A,k)!==void 0)&&Array.isArray(e)&&(i?.log({message:"Rokt Kit: Migrating legacy page-view storage",code:"PAGE_VIEW_LEGACY_MIGRATION"}),re(A,k,e)||i?.log({message:"Rokt Kit: Failed to migrate legacy page-view storage [reason: migration_retry]",code:"PAGE_VIEW_CAPTURE_FAILED"})),ie(G)}function W(i){se(i);const e=ne(A,k);return Array.isArray(e)?e:[]}function fe(i){return re(A,k,i.slice(-25))}function j(){ge(A,k)}function me(i){const e=i.slice(-25);return e.map((t,n)=>{const r=t.activeTimeOnSite,s=r!==void 0&&Number.isFinite(r),l=e[n+1]?.activeTimeOnSite,u=l!==void 0&&Number.isFinite(l),c=s&&u?l-r:void 0;return{pageUrl:t.pageUrl,sourceMessageId:t.sourceMessageId,timestamp:t.timestamp,...t.pageTitle!==void 0?{pageTitle:t.pageTitle}:{},...t.canonicalUrl!==void 0?{canonicalUrl:t.canonicalUrl}:{},...s?{activeTimeOnSite:r}:{},...c!==void 0&&c>=0?{activeTimeOnPage:c}:{}}})}function Ee(){const e=document.querySelector('link[rel="canonical"]')?.href;if(e)return K(e)}const d="Rokt",T=181,_e="selectPlacements",Ie="apps.roktecommerce.com",Se=.1,ye="ThankYouPageJourney",Ae="rokt-launcher",ke="rokt-thank-you-element",ve="userIdentifiedInWorkspace",Re=3,we=2,be="page_events",Le="mparticle_session_id",Te="mparticle_device_id",Pe=500,D={UNKNOWN_ERROR:"UNKNOWN_ERROR",UNHANDLED_EXCEPTION:"UNHANDLED_EXCEPTION",IDENTITY_REQUEST:"IDENTITY_REQUEST",LOG_DELIVERY_FAILURE:"LOG_DELIVERY_FAILURE"},_={ERROR:"ERROR",INFO:"INFO",WARNING:"WARNING"},Ne="apps.rokt-api.com",Oe="/v1/log",Ce="/v1/errors",Ue=10;function a(){return window.mParticle}function V(i,e){const n=[O(i),"/wsdk/integrations/launcher.js"].join("");return!e||e.length===0?n:n+"?extensions="+e.join(",")}function H(i){return[O(i),"/rokt-elements/rokt-element-thank-you.js"].join("")}function O(i){const e=typeof i<"u"?i:Ne;return e.includes("://")?e.replace(/\/+$/,""):["https://",e].join("")}function oe(i,e,t){if(i)return i.startsWith("http://")||i.startsWith("https://")?i:"https://"+i;const r=e?.includes("://")&&!/^https?:\/\//i.test(e)?void 0:e;return O(r)+t}function z(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 P(i){if(!i)return[];try{return JSON.parse(i.replace(/"/g,'"'))}catch{console.error("Settings string contains invalid JSON")}return[]}function J(i){const e=i?P(i):[],t=[],n=[];let r=!1;for(let s=0;s<e.length;s++){const o=e[s].value;o==="thank-you-journey"?(r=!0,n.push(ye)):t.push(o)}return{roktExtensionsQueryParams:t,legacyRoktExtensions:n,loadThankYouElement:r}}async function Me(i,e){const t=[];if(e)for(const n of i)t.push(e.use(n));return Promise.all(t)}function q(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 B(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,s=n.map;e[r]||(e[r]=[]),e[r].push({eventAttributeKey:s,conditions:Array.isArray(n.conditions)?n.conditions:[]})}return e}function $(i,e,t){return a().generateHash([i,e,t].join(""))}function Ke(i){let n="mParticle_wsdkv_"+a().getVersion()+"_kitv_"+"1.34.0";return i&&(n+="_"+i),n}function ae(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 M(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=ae(window.location.origin);if(S._allowedOriginHashes.indexOf(t)===-1||Math.random()>=Se)return;const r=window.__rokt_li_guid__;if(!r||i&&i.includes("://")&&!/^https:\/\//i.test(i))return;const s=window.location.href.split("?")[0].split("#")[0],o="version="+encodeURIComponent(e??"")+"&launcherInstanceGuid="+encodeURIComponent(r)+"&pageUrl="+encodeURIComponent(s),l=i?O(i):"https://apps.rokt.com";M(l+"/v1/wsdk-init/index.html?"+o),M("https://"+Ie+"/v1/wsdk-init/index.html?"+o+"&isControl=true")}function De(){return typeof window<"u"&&!!window.location?.search?.toLowerCase().includes("mp_enable_logging=true")}function Fe(){return typeof window<"u"?window.location?.href:void 0}function Ye(){return typeof window<"u"?window.navigator?.userAgent:void 0}class ce{constructor(){this._logCount={}}incrementAndCheck(e){const n=(this._logCount[e]||0)+1;return this._logCount[e]=n,n>Ue}}class F{constructor(e,t,n,r,s){this._reporter="mp-wsdk";const o=e.isLoggingEnabled;this._integrationName=t||"",this._launcherInstanceGuid=n,this._accountId=r||null,this._rateLimiter=s||new ce,this._isEnabled=De()||o}send(e,t,n,r,s,o){if(!(!this._isEnabled||this._rateLimiter.incrementAndCheck(t)))try{const l={additionalInformation:{message:n,version:this._integrationName},severity:t,code:r||D.UNKNOWN_ERROR,url:Fe(),deviceInfo:Ye(),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(l)}).then(c=>{if(!c.ok){const p=new Error("HTTP "+c.status+" from log endpoint");throw p.statusCode=c.status,p}}).catch(c=>{console.error("ReportingTransport: Failed to send log",c),o&&o(c)})}catch(l){console.error("ReportingTransport: Failed to send log",l),o&&o(l)}}}class X{constructor(e,t,n,r,s){this._transport=new F(e,t,n,r,s),this._errorUrl=oe(e?.errorUrl,e?.integrationDomain,Ce)}report(e){if(!e)return;const t=e.severity||_.ERROR;this._transport.send(this._errorUrl,t,e.message,e.code,e.stackTrace)}}class Z{constructor(e,t,n,r,s,o){this._transport=new F(e,n,r,s,o),this._loggingUrl=oe(e?.loggingUrl,e?.integrationDomain,Oe),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:D.LOG_DELIVERY_FAILURE,severity:n?_.ERROR:_.WARNING})}})}}function xe(i){const e=K(window.location.href),t=i.EventAttributes?.title||document.title,n=Ee(),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=T,this.moduleId=T,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 s=0;s<n.length;s++)if(!this.doesEventAttributeConditionMatch(n[s],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],s=this.placementEventAttributeMappingLookup[r];if(U(s))continue;let o=!0;for(let l=0;l<s.length;l++)if(!this.doesEventMatchRule(e,s[l])){o=!1;break}o&&a().Rokt.setLocalSessionAttribute?.(r,!0)}}capturePageView(e){let t;try{t=K(window.location.href);const n=W(this.loggingService),r=xe(e);if(n.push(r),!fe(n)){const s=x()?"quota":"ls_unavailable";this.loggingService?.log({message:`Rokt Kit: Failed to persist page view for ${t} [reason: ${s}]`,code:"PAGE_VIEW_CAPTURE_FAILED"})}}catch(n){const r=x()?"exception":"ls_unavailable",s=n instanceof Error?n.message:String(n);this.loggingService?.log({message:`Rokt Kit: Failed to capture page view for ${t}: ${s} [reason: ${r}]`,code:"PAGE_VIEW_CAPTURE_FAILED"})}}isLauncherReadyToAttach(){return!!window.Rokt&&L(window.Rokt.createLauncher)}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"||!I(e))return;const t=a().EventType.Other;a().logEvent(_e,t,e)}setRoktSessionId(e){if(!(!e||typeof e!="string"))try{const t=a().getInstance();t&&L(t.setIntegrationAttribute)&&t.setIntegrationAttribute(T,{roktSessionId:e})}catch{}}readMpSessionId(){const e=a()?.sessionManager,t=e?.getSessionId??e?.getSession;if(L(t))return t.call(e)||void 0}readMpDeviceId(){return a()?.getDeviceId?.()||void 0}attachLauncher(e,t,n=[]){const r={accountId:e,...t||{}};let s;this.isPartnerInLocalLauncherTestGroup()?s=Promise.resolve(window.Rokt.createLocalLauncher(r)):s=window.Rokt.createLauncher(r),s.then(async o=>{await Me(n,o),this.initRoktLauncher(o)}).catch(o=>{console.error("Error creating Rokt launcher:",o)})}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,n,r,s){const o=e,l=o.accountId;this.userAttributes=b(s),this._onboardingExpProvider=o.onboardingExpProvider;const u=P(o.placementEventMapping);this.placementEventMappingLookup=q(u);const c=P(o.placementEventAttributeMapping);this.placementEventAttributeMappingLookup=B(c),o.hashedEmailUserIdentityType&&(this._mappedEmailSha256Key=o.hashedEmailUserIdentityType.toLowerCase()),this._workspaceIdSyncApiKey=m(o.workspaceIdSyncApiKey)?o.workspaceIdSyncApiKey:void 0;const p=a().Rokt?.domain,{roktExtensionsQueryParams:C,legacyRoktExtensions:v,loadThankYouElement:R}=J(o.roktExtensions),g={...a().Rokt?.launcherOptions||{}};this.integrationName=Ke(g.integrationName),g.integrationName=this.integrationName,this.domain=p;const y={loggingUrl:o.loggingUrl,errorUrl:o.errorUrl,integrationDomain:p,isLoggingEnabled:a().config?.isLoggingEnabled===!0},E=new X(y,this.integrationName,window.__rokt_li_guid__,o.accountId),w=new Z(y,E,this.integrationName,window.__rokt_li_guid__,o.accountId);if(this.errorReportingService=E,this.loggingService=w,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(E),a()._registerLoggingService&&a()._registerLoggingService(w),n?(this.testHelpers={generateLauncherScript:V,generateThankYouElementScript:H,extractRoktExtensionConfig:J,hashEventMessage:$,parseSettingsString:P,generateMappedEventLookup:q,generateMappedEventAttributeLookup:B,sendAdBlockMeasurementSignals:Q,createAutoRemovedIframe:M,djb2:ae,setAllowedOriginHashes:h=>{f._allowedOriginHashes=h},ReportingTransport:F,ErrorReportingService:X,LoggingService:Z,RateLimiter:ce,ErrorCodes:D,WSDKErrorSeverity:_},this.attachLauncher(l,g),"Successfully initialized: "+d):(R&&(a().Rokt.flushOnShoppableAdsReadyMessageQueue?.(this),z(ke,H(p),{onLoad:()=>{this._isThankYouElementLoaded=!0,this._thankYouElementOnLoadCallback&&this._thankYouElementOnLoadCallback()},onError:h=>{console.error("Error loading Rokt Thank You Element script:",h)}})),this.isLauncherReadyToAttach()?this.attachLauncher(l,g,v):(z(Ae,V(p,C),{onLoad:()=>{this.isLauncherReadyToAttach()?this.attachLauncher(l,g,v):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===Re&&this.capturePageView(e),e.EventDataType===we&&(se(this.loggingService),j())),!this.isKitReady())return"Kit not ready for forwarder: "+d;if(L(a().Rokt?.setLocalSessionAttribute)&&(U(this.placementEventAttributeMappingLookup)||this.applyPlacementEventAttributeMapping(e),!U(this.placementEventMappingLookup))){const t=$(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 ee(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,s={};if(r)for(const u of Object.keys(r)){const c=r[u];m(c)&&c.length>0&&(s[u]=c)}const o=Object.keys(s);if(o.length===0)return this.userIdentifiedInWorkspace=!1,this._workspaceLastSearchedIdentitiesKey=void 0,Promise.resolve();const l=o.sort().map(u=>`${u}=${s[u]}`).join("&");return l===this._workspaceLastSearchedIdentitiesKey?this._workspaceSearchInFlightPromise||Promise.resolve():(this.userIdentifiedInWorkspace=!1,this._workspaceLastSearchedIdentitiesKey=l,new Promise(u=>{try{n(t,s,c=>{c?.httpCode===200&&(this.userIdentifiedInWorkspace=!0),u()})}catch(c){console.error("Rokt Kit: Workspace IDSync search failed",c),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,Pe))]).then(()=>this._dispatchPlacements(e))}return this._dispatchPlacements(e)}_dispatchPlacements(e){const t=e&&e.attributes||{},r={...b(this.userAttributes),...t},s=this.filters||{},o=s.userAttributeFilters||[],l=s.filteredUser||null,u=l?l.getMPID():null;let c;s?s.filterUserAttributes?c=s.filterUserAttributes(r,o):c=r:(console.warn("Rokt Kit: No filters available, using user attributes"),c=r),this.userAttributes=b(c);const p=this._onboardingExpProvider==="Optimizely"?this.fetchOptimizely():{},C=this.returnUserIdentities(l),v=this.returnLocalSessionAttributes(),R=me(W(this.loggingService)),g=this.readMpSessionId(),y=this.readMpDeviceId(),E={...C,...c,...p,...v,...R.length?{[be]:JSON.stringify(R)}:{},...this.userIdentifiedInWorkspace?{[ve]:!0}:{},...g?{[Le]:g}:{},...y?{[Te]:y}:{},mpid:u},w={...e,attributes:E},h=this.launcher.selectPlacements(w),le=()=>this.logSelectPlacementsEvent(E);return Promise.resolve(h).then(ue=>ue?.context?.sessionId?.then(de=>this.setRoktSessionId(de))).catch(()=>{}).finally(le),h}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 S=f;function Ge(){return T}function We(i){if(!i){window.console.log("You must pass a config object to register the kit "+d);return}if(!I(i)){window.console.log("'config' must be an object. You passed in a "+typeof i);return}I(i.kits)?i.kits[d]={constructor:S}:(i.kits={},i.kits[d]={constructor:S}),window.console.log("Successfully registered "+d+" to your mParticle configuration")}typeof window<"u"&&window.mParticle&&a().addForwarder&&a().addForwarder({name:d,constructor:S,getId:Ge});exports.register=We;
|
|
2
2
|
//# sourceMappingURL=Rokt-Kit.common.js.map
|
package/dist/Rokt-Kit.esm.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const
|
|
1
|
+
const he = [
|
|
2
2
|
"active_time_on_site_ms",
|
|
3
3
|
"billingaddress1",
|
|
4
4
|
"billingaddress2",
|
|
@@ -23,9 +23,9 @@ const de = [
|
|
|
23
23
|
"shippingstate",
|
|
24
24
|
"shippingzipcode",
|
|
25
25
|
"totalprice"
|
|
26
|
-
],
|
|
26
|
+
], pe = new Set(he);
|
|
27
27
|
function ee(i) {
|
|
28
|
-
return
|
|
28
|
+
return pe.has(i.toLowerCase());
|
|
29
29
|
}
|
|
30
30
|
function b(i) {
|
|
31
31
|
const e = {}, t = i || {}, n = Object.keys(t);
|
|
@@ -35,7 +35,7 @@ function b(i) {
|
|
|
35
35
|
}
|
|
36
36
|
return e;
|
|
37
37
|
}
|
|
38
|
-
function
|
|
38
|
+
function I(i) {
|
|
39
39
|
return typeof i == "object" && i !== null && !Array.isArray(i);
|
|
40
40
|
}
|
|
41
41
|
function m(i) {
|
|
@@ -44,7 +44,7 @@ function m(i) {
|
|
|
44
44
|
function L(i) {
|
|
45
45
|
return typeof i == "function";
|
|
46
46
|
}
|
|
47
|
-
function
|
|
47
|
+
function U(i) {
|
|
48
48
|
return i == null ? !0 : typeof i == "object" ? Object.keys(i).length === 0 : !1;
|
|
49
49
|
}
|
|
50
50
|
function K(i) {
|
|
@@ -55,15 +55,15 @@ function K(i) {
|
|
|
55
55
|
return i;
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
|
-
const
|
|
59
|
-
function
|
|
58
|
+
const Y = "__rokt_ls_probe__";
|
|
59
|
+
function x() {
|
|
60
60
|
try {
|
|
61
|
-
return window.localStorage.setItem(
|
|
61
|
+
return window.localStorage.setItem(Y, "1"), window.localStorage.removeItem(Y), !0;
|
|
62
62
|
} catch {
|
|
63
63
|
return !1;
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
|
-
function
|
|
66
|
+
function N(i) {
|
|
67
67
|
try {
|
|
68
68
|
const e = window.localStorage.getItem(i);
|
|
69
69
|
return e === null ? null : JSON.parse(e);
|
|
@@ -85,46 +85,45 @@ function ie(i) {
|
|
|
85
85
|
}
|
|
86
86
|
}
|
|
87
87
|
function ne(i, e) {
|
|
88
|
-
const t =
|
|
89
|
-
return
|
|
88
|
+
const t = N(i);
|
|
89
|
+
return I(t) ? t[e] : void 0;
|
|
90
90
|
}
|
|
91
91
|
function re(i, e, t) {
|
|
92
|
-
const n =
|
|
92
|
+
const n = N(i), r = I(n) ? { ...n } : {};
|
|
93
93
|
return r[e] = t, te(i, r);
|
|
94
94
|
}
|
|
95
|
-
function
|
|
96
|
-
const t =
|
|
97
|
-
if (!
|
|
95
|
+
function ge(i, e) {
|
|
96
|
+
const t = N(i);
|
|
97
|
+
if (!I(t) || !(e in t))
|
|
98
98
|
return;
|
|
99
99
|
const n = { ...t };
|
|
100
100
|
delete n[e], Object.keys(n).length === 0 ? ie(i) : te(i, n);
|
|
101
101
|
}
|
|
102
|
-
const A = "mp-rokt-kit",
|
|
102
|
+
const A = "mp-rokt-kit", k = "pageViews", G = "mpPageViews";
|
|
103
103
|
function se(i) {
|
|
104
|
-
const e =
|
|
104
|
+
const e = N(G);
|
|
105
105
|
if (e === null)
|
|
106
106
|
return;
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
}
|
|
114
|
-
ie(G);
|
|
107
|
+
!(ne(A, k) !== void 0) && Array.isArray(e) && (i?.log({
|
|
108
|
+
message: "Rokt Kit: Migrating legacy page-view storage",
|
|
109
|
+
code: "PAGE_VIEW_LEGACY_MIGRATION"
|
|
110
|
+
}), re(A, k, e) || i?.log({
|
|
111
|
+
message: "Rokt Kit: Failed to migrate legacy page-view storage [reason: migration_retry]",
|
|
112
|
+
code: "PAGE_VIEW_CAPTURE_FAILED"
|
|
113
|
+
})), ie(G);
|
|
115
114
|
}
|
|
116
115
|
function W(i) {
|
|
117
116
|
se(i);
|
|
118
|
-
const e = ne(A,
|
|
117
|
+
const e = ne(A, k);
|
|
119
118
|
return Array.isArray(e) ? e : [];
|
|
120
119
|
}
|
|
121
|
-
function
|
|
122
|
-
return re(A,
|
|
120
|
+
function fe(i) {
|
|
121
|
+
return re(A, k, i.slice(-25));
|
|
123
122
|
}
|
|
124
123
|
function j() {
|
|
125
|
-
|
|
124
|
+
ge(A, k);
|
|
126
125
|
}
|
|
127
|
-
function
|
|
126
|
+
function me(i) {
|
|
128
127
|
const e = i.slice(-25);
|
|
129
128
|
return e.map((t, n) => {
|
|
130
129
|
const r = t.activeTimeOnSite, s = r !== void 0 && Number.isFinite(r), l = e[n + 1]?.activeTimeOnSite, u = l !== void 0 && Number.isFinite(l), c = s && u ? l - r : void 0;
|
|
@@ -139,33 +138,33 @@ function fe(i) {
|
|
|
139
138
|
};
|
|
140
139
|
});
|
|
141
140
|
}
|
|
142
|
-
function
|
|
141
|
+
function Ee() {
|
|
143
142
|
const e = document.querySelector('link[rel="canonical"]')?.href;
|
|
144
143
|
if (e)
|
|
145
144
|
return K(e);
|
|
146
145
|
}
|
|
147
|
-
const d = "Rokt", T = 181,
|
|
146
|
+
const d = "Rokt", T = 181, _e = "selectPlacements", Ie = "apps.roktecommerce.com", Se = 0.1, ye = "ThankYouPageJourney", Ae = "rokt-launcher", ke = "rokt-thank-you-element", Re = "userIdentifiedInWorkspace", ve = 3, we = 2, be = "page_events", Le = "mparticle_session_id", Te = "mparticle_device_id", Pe = 500, D = {
|
|
148
147
|
UNKNOWN_ERROR: "UNKNOWN_ERROR",
|
|
149
148
|
UNHANDLED_EXCEPTION: "UNHANDLED_EXCEPTION",
|
|
150
149
|
IDENTITY_REQUEST: "IDENTITY_REQUEST",
|
|
151
150
|
LOG_DELIVERY_FAILURE: "LOG_DELIVERY_FAILURE"
|
|
152
|
-
},
|
|
151
|
+
}, _ = {
|
|
153
152
|
ERROR: "ERROR",
|
|
154
153
|
INFO: "INFO",
|
|
155
154
|
WARNING: "WARNING"
|
|
156
|
-
},
|
|
155
|
+
}, Ne = "apps.rokt-api.com", Oe = "/v1/log", Ce = "/v1/errors", Ue = 10;
|
|
157
156
|
function a() {
|
|
158
157
|
return window.mParticle;
|
|
159
158
|
}
|
|
160
|
-
function
|
|
159
|
+
function V(i, e) {
|
|
161
160
|
const n = [O(i), "/wsdk/integrations/launcher.js"].join("");
|
|
162
161
|
return !e || e.length === 0 ? n : n + "?extensions=" + e.join(",");
|
|
163
162
|
}
|
|
164
|
-
function
|
|
163
|
+
function H(i) {
|
|
165
164
|
return [O(i), "/rokt-elements/rokt-element-thank-you.js"].join("");
|
|
166
165
|
}
|
|
167
166
|
function O(i) {
|
|
168
|
-
const e = typeof i < "u" ? i :
|
|
167
|
+
const e = typeof i < "u" ? i : Ne;
|
|
169
168
|
return e.includes("://") ? e.replace(/\/+$/, "") : ["https://", e].join("");
|
|
170
169
|
}
|
|
171
170
|
function oe(i, e, t) {
|
|
@@ -179,7 +178,7 @@ function z(i, e, t) {
|
|
|
179
178
|
const n = document.head || document.body, r = document.createElement("script");
|
|
180
179
|
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);
|
|
181
180
|
}
|
|
182
|
-
function
|
|
181
|
+
function P(i) {
|
|
183
182
|
if (!i)
|
|
184
183
|
return [];
|
|
185
184
|
try {
|
|
@@ -190,7 +189,7 @@ function N(i) {
|
|
|
190
189
|
return [];
|
|
191
190
|
}
|
|
192
191
|
function J(i) {
|
|
193
|
-
const e = i ?
|
|
192
|
+
const e = i ? P(i) : [], t = [], n = [];
|
|
194
193
|
let r = !1;
|
|
195
194
|
for (let s = 0; s < e.length; s++) {
|
|
196
195
|
const o = e[s].value;
|
|
@@ -202,7 +201,7 @@ function J(i) {
|
|
|
202
201
|
loadThankYouElement: r
|
|
203
202
|
};
|
|
204
203
|
}
|
|
205
|
-
async function
|
|
204
|
+
async function Me(i, e) {
|
|
206
205
|
const t = [];
|
|
207
206
|
if (e)
|
|
208
207
|
for (const n of i)
|
|
@@ -238,8 +237,8 @@ function B(i) {
|
|
|
238
237
|
function $(i, e, t) {
|
|
239
238
|
return a().generateHash([i, e, t].join(""));
|
|
240
239
|
}
|
|
241
|
-
function
|
|
242
|
-
let n = "mParticle_wsdkv_" + a().getVersion() + "_kitv_" + "1.
|
|
240
|
+
function Ke(i) {
|
|
241
|
+
let n = "mParticle_wsdkv_" + a().getVersion() + "_kitv_" + "1.34.0";
|
|
243
242
|
return i && (n += "_" + i), n;
|
|
244
243
|
}
|
|
245
244
|
function ae(i) {
|
|
@@ -258,23 +257,23 @@ function M(i) {
|
|
|
258
257
|
}
|
|
259
258
|
function Q(i, e) {
|
|
260
259
|
const t = ae(window.location.origin);
|
|
261
|
-
if (
|
|
260
|
+
if (S._allowedOriginHashes.indexOf(t) === -1 || Math.random() >= Se)
|
|
262
261
|
return;
|
|
263
262
|
const r = window.__rokt_li_guid__;
|
|
264
263
|
if (!r || i && i.includes("://") && !/^https:\/\//i.test(i))
|
|
265
264
|
return;
|
|
266
265
|
const s = window.location.href.split("?")[0].split("#")[0], o = "version=" + encodeURIComponent(e ?? "") + "&launcherInstanceGuid=" + encodeURIComponent(r) + "&pageUrl=" + encodeURIComponent(s), l = i ? O(i) : "https://apps.rokt.com";
|
|
267
266
|
M(l + "/v1/wsdk-init/index.html?" + o), M(
|
|
268
|
-
"https://" +
|
|
267
|
+
"https://" + Ie + "/v1/wsdk-init/index.html?" + o + "&isControl=true"
|
|
269
268
|
);
|
|
270
269
|
}
|
|
271
|
-
function
|
|
270
|
+
function De() {
|
|
272
271
|
return typeof window < "u" && !!window.location?.search?.toLowerCase().includes("mp_enable_logging=true");
|
|
273
272
|
}
|
|
274
|
-
function
|
|
273
|
+
function Fe() {
|
|
275
274
|
return typeof window < "u" ? window.location?.href : void 0;
|
|
276
275
|
}
|
|
277
|
-
function
|
|
276
|
+
function Ye() {
|
|
278
277
|
return typeof window < "u" ? window.navigator?.userAgent : void 0;
|
|
279
278
|
}
|
|
280
279
|
class ce {
|
|
@@ -283,14 +282,14 @@ class ce {
|
|
|
283
282
|
}
|
|
284
283
|
incrementAndCheck(e) {
|
|
285
284
|
const n = (this._logCount[e] || 0) + 1;
|
|
286
|
-
return this._logCount[e] = n, n >
|
|
285
|
+
return this._logCount[e] = n, n > Ue;
|
|
287
286
|
}
|
|
288
287
|
}
|
|
289
288
|
class F {
|
|
290
289
|
constructor(e, t, n, r, s) {
|
|
291
290
|
this._reporter = "mp-wsdk";
|
|
292
291
|
const o = e.isLoggingEnabled;
|
|
293
|
-
this._integrationName = t || "", this._launcherInstanceGuid = n, this._accountId = r || null, this._rateLimiter = s || new ce(), this._isEnabled =
|
|
292
|
+
this._integrationName = t || "", this._launcherInstanceGuid = n, this._accountId = r || null, this._rateLimiter = s || new ce(), this._isEnabled = De() || o;
|
|
294
293
|
}
|
|
295
294
|
send(e, t, n, r, s, o) {
|
|
296
295
|
if (!(!this._isEnabled || this._rateLimiter.incrementAndCheck(t)))
|
|
@@ -302,8 +301,8 @@ class F {
|
|
|
302
301
|
},
|
|
303
302
|
severity: t,
|
|
304
303
|
code: r || D.UNKNOWN_ERROR,
|
|
305
|
-
url:
|
|
306
|
-
deviceInfo:
|
|
304
|
+
url: Fe(),
|
|
305
|
+
deviceInfo: Ye(),
|
|
307
306
|
stackTrace: s,
|
|
308
307
|
reporter: this._reporter,
|
|
309
308
|
integration: this._integrationName
|
|
@@ -332,22 +331,22 @@ class F {
|
|
|
332
331
|
}
|
|
333
332
|
class X {
|
|
334
333
|
constructor(e, t, n, r, s) {
|
|
335
|
-
this._transport = new F(e, t, n, r, s), this._errorUrl = oe(e?.errorUrl, e?.integrationDomain,
|
|
334
|
+
this._transport = new F(e, t, n, r, s), this._errorUrl = oe(e?.errorUrl, e?.integrationDomain, Ce);
|
|
336
335
|
}
|
|
337
336
|
report(e) {
|
|
338
337
|
if (!e) return;
|
|
339
|
-
const t = e.severity ||
|
|
338
|
+
const t = e.severity || _.ERROR;
|
|
340
339
|
this._transport.send(this._errorUrl, t, e.message, e.code, e.stackTrace);
|
|
341
340
|
}
|
|
342
341
|
}
|
|
343
342
|
class Z {
|
|
344
343
|
constructor(e, t, n, r, s, o) {
|
|
345
|
-
this._transport = new F(e, n, r, s, o), this._loggingUrl = oe(e?.loggingUrl, e?.integrationDomain,
|
|
344
|
+
this._transport = new F(e, n, r, s, o), this._loggingUrl = oe(e?.loggingUrl, e?.integrationDomain, Oe), this._errorReportingService = t;
|
|
346
345
|
}
|
|
347
346
|
log(e) {
|
|
348
347
|
e && this._transport.send(
|
|
349
348
|
this._loggingUrl,
|
|
350
|
-
|
|
349
|
+
_.INFO,
|
|
351
350
|
e.message,
|
|
352
351
|
e.code,
|
|
353
352
|
void 0,
|
|
@@ -357,15 +356,15 @@ class Z {
|
|
|
357
356
|
this._errorReportingService.report({
|
|
358
357
|
message: "LoggingService: Failed to send log: " + t.message,
|
|
359
358
|
code: D.LOG_DELIVERY_FAILURE,
|
|
360
|
-
severity: n ?
|
|
359
|
+
severity: n ? _.ERROR : _.WARNING
|
|
361
360
|
});
|
|
362
361
|
}
|
|
363
362
|
}
|
|
364
363
|
);
|
|
365
364
|
}
|
|
366
365
|
}
|
|
367
|
-
function
|
|
368
|
-
const e = K(window.location.href), t = i.EventAttributes?.title || document.title, n =
|
|
366
|
+
function xe(i) {
|
|
367
|
+
const e = K(window.location.href), t = i.EventAttributes?.title || document.title, n = Ee(), r = i.ActiveTimeOnSite;
|
|
369
368
|
return {
|
|
370
369
|
pageUrl: e,
|
|
371
370
|
sourceMessageId: i.SourceMessageId,
|
|
@@ -408,7 +407,7 @@ const f = class f {
|
|
|
408
407
|
const t = Object.keys(this.placementEventAttributeMappingLookup);
|
|
409
408
|
for (let n = 0; n < t.length; n++) {
|
|
410
409
|
const r = t[n], s = this.placementEventAttributeMappingLookup[r];
|
|
411
|
-
if (
|
|
410
|
+
if (U(s))
|
|
412
411
|
continue;
|
|
413
412
|
let o = !0;
|
|
414
413
|
for (let l = 0; l < s.length; l++)
|
|
@@ -423,16 +422,16 @@ const f = class f {
|
|
|
423
422
|
let t;
|
|
424
423
|
try {
|
|
425
424
|
t = K(window.location.href);
|
|
426
|
-
const n = W(this.loggingService), r =
|
|
427
|
-
if (n.push(r), !
|
|
428
|
-
const s =
|
|
425
|
+
const n = W(this.loggingService), r = xe(e);
|
|
426
|
+
if (n.push(r), !fe(n)) {
|
|
427
|
+
const s = x() ? "quota" : "ls_unavailable";
|
|
429
428
|
this.loggingService?.log({
|
|
430
429
|
message: `Rokt Kit: Failed to persist page view for ${t} [reason: ${s}]`,
|
|
431
430
|
code: "PAGE_VIEW_CAPTURE_FAILED"
|
|
432
431
|
});
|
|
433
432
|
}
|
|
434
433
|
} catch (n) {
|
|
435
|
-
const r =
|
|
434
|
+
const r = x() ? "exception" : "ls_unavailable", s = n instanceof Error ? n.message : String(n);
|
|
436
435
|
this.loggingService?.log({
|
|
437
436
|
message: `Rokt Kit: Failed to capture page view for ${t}: ${s} [reason: ${r}]`,
|
|
438
437
|
code: "PAGE_VIEW_CAPTURE_FAILED"
|
|
@@ -459,10 +458,10 @@ const f = class f {
|
|
|
459
458
|
return n && e[n] && (t[f.EMAIL_SHA256_KEY] = e[n]), n && delete t[n], t;
|
|
460
459
|
}
|
|
461
460
|
logSelectPlacementsEvent(e) {
|
|
462
|
-
if (!window.mParticle || typeof a().logEvent != "function" || !
|
|
461
|
+
if (!window.mParticle || typeof a().logEvent != "function" || !I(e))
|
|
463
462
|
return;
|
|
464
463
|
const t = a().EventType.Other;
|
|
465
|
-
a().logEvent(
|
|
464
|
+
a().logEvent(_e, t, e);
|
|
466
465
|
}
|
|
467
466
|
setRoktSessionId(e) {
|
|
468
467
|
if (!(!e || typeof e != "string"))
|
|
@@ -479,6 +478,9 @@ const f = class f {
|
|
|
479
478
|
if (L(t))
|
|
480
479
|
return t.call(e) || void 0;
|
|
481
480
|
}
|
|
481
|
+
readMpDeviceId() {
|
|
482
|
+
return a()?.getDeviceId?.() || void 0;
|
|
483
|
+
}
|
|
482
484
|
attachLauncher(e, t, n = []) {
|
|
483
485
|
const r = {
|
|
484
486
|
accountId: e,
|
|
@@ -486,7 +488,7 @@ const f = class f {
|
|
|
486
488
|
};
|
|
487
489
|
let s;
|
|
488
490
|
this.isPartnerInLocalLauncherTestGroup() ? s = Promise.resolve(window.Rokt.createLocalLauncher(r)) : s = window.Rokt.createLauncher(r), s.then(async (o) => {
|
|
489
|
-
await
|
|
491
|
+
await Me(n, o), this.initRoktLauncher(o);
|
|
490
492
|
}).catch((o) => {
|
|
491
493
|
console.error("Error creating Rokt launcher:", o);
|
|
492
494
|
});
|
|
@@ -532,52 +534,52 @@ const f = class f {
|
|
|
532
534
|
init(e, t, n, r, s) {
|
|
533
535
|
const o = e, l = o.accountId;
|
|
534
536
|
this.userAttributes = b(s), this._onboardingExpProvider = o.onboardingExpProvider;
|
|
535
|
-
const u =
|
|
537
|
+
const u = P(o.placementEventMapping);
|
|
536
538
|
this.placementEventMappingLookup = q(u);
|
|
537
|
-
const c =
|
|
539
|
+
const c = P(
|
|
538
540
|
o.placementEventAttributeMapping
|
|
539
541
|
);
|
|
540
542
|
this.placementEventAttributeMappingLookup = B(c), o.hashedEmailUserIdentityType && (this._mappedEmailSha256Key = o.hashedEmailUserIdentityType.toLowerCase()), this._workspaceIdSyncApiKey = m(o.workspaceIdSyncApiKey) ? o.workspaceIdSyncApiKey : void 0;
|
|
541
|
-
const p = a().Rokt?.domain, { roktExtensionsQueryParams:
|
|
543
|
+
const p = a().Rokt?.domain, { roktExtensionsQueryParams: C, legacyRoktExtensions: R, loadThankYouElement: v } = J(
|
|
542
544
|
o.roktExtensions
|
|
543
545
|
), g = {
|
|
544
546
|
...a().Rokt?.launcherOptions || {}
|
|
545
547
|
};
|
|
546
|
-
this.integrationName =
|
|
548
|
+
this.integrationName = Ke(g.integrationName), g.integrationName = this.integrationName, this.domain = p;
|
|
547
549
|
const y = {
|
|
548
550
|
loggingUrl: o.loggingUrl,
|
|
549
551
|
errorUrl: o.errorUrl,
|
|
550
552
|
integrationDomain: p,
|
|
551
553
|
isLoggingEnabled: a().config?.isLoggingEnabled === !0
|
|
552
|
-
},
|
|
554
|
+
}, E = new X(
|
|
553
555
|
y,
|
|
554
556
|
this.integrationName,
|
|
555
557
|
window.__rokt_li_guid__,
|
|
556
558
|
o.accountId
|
|
557
|
-
),
|
|
559
|
+
), w = new Z(
|
|
558
560
|
y,
|
|
559
|
-
|
|
561
|
+
E,
|
|
560
562
|
this.integrationName,
|
|
561
563
|
window.__rokt_li_guid__,
|
|
562
564
|
o.accountId
|
|
563
565
|
);
|
|
564
|
-
if (this.errorReportingService =
|
|
566
|
+
if (this.errorReportingService = E, this.loggingService = w, this.isTargetingDisabled())
|
|
565
567
|
try {
|
|
566
568
|
j();
|
|
567
569
|
} catch (h) {
|
|
568
570
|
this.errorReportingService?.report({
|
|
569
571
|
message: "Rokt Kit: Failed to clear page views when targeting is disabled",
|
|
570
572
|
code: "PAGE_VIEW_CAPTURE_FAILED",
|
|
571
|
-
severity:
|
|
573
|
+
severity: _.INFO,
|
|
572
574
|
stackTrace: h instanceof Error ? h.stack : void 0
|
|
573
575
|
});
|
|
574
576
|
}
|
|
575
|
-
return a()._registerErrorReportingService && a()._registerErrorReportingService(
|
|
576
|
-
generateLauncherScript:
|
|
577
|
-
generateThankYouElementScript:
|
|
577
|
+
return a()._registerErrorReportingService && a()._registerErrorReportingService(E), a()._registerLoggingService && a()._registerLoggingService(w), n ? (this.testHelpers = {
|
|
578
|
+
generateLauncherScript: V,
|
|
579
|
+
generateThankYouElementScript: H,
|
|
578
580
|
extractRoktExtensionConfig: J,
|
|
579
581
|
hashEventMessage: $,
|
|
580
|
-
parseSettingsString:
|
|
582
|
+
parseSettingsString: P,
|
|
581
583
|
generateMappedEventLookup: q,
|
|
582
584
|
generateMappedEventAttributeLookup: B,
|
|
583
585
|
sendAdBlockMeasurementSignals: Q,
|
|
@@ -591,17 +593,17 @@ const f = class f {
|
|
|
591
593
|
LoggingService: Z,
|
|
592
594
|
RateLimiter: ce,
|
|
593
595
|
ErrorCodes: D,
|
|
594
|
-
WSDKErrorSeverity:
|
|
595
|
-
}, this.attachLauncher(l, g), "Successfully initialized: " + d) : (
|
|
596
|
+
WSDKErrorSeverity: _
|
|
597
|
+
}, this.attachLauncher(l, g), "Successfully initialized: " + d) : (v && (a().Rokt.flushOnShoppableAdsReadyMessageQueue?.(this), z(ke, H(p), {
|
|
596
598
|
onLoad: () => {
|
|
597
599
|
this._isThankYouElementLoaded = !0, this._thankYouElementOnLoadCallback && this._thankYouElementOnLoadCallback();
|
|
598
600
|
},
|
|
599
601
|
onError: (h) => {
|
|
600
602
|
console.error("Error loading Rokt Thank You Element script:", h);
|
|
601
603
|
}
|
|
602
|
-
})), this.isLauncherReadyToAttach() ? this.attachLauncher(l, g,
|
|
604
|
+
})), this.isLauncherReadyToAttach() ? this.attachLauncher(l, g, R) : (z(Ae, V(p, C), {
|
|
603
605
|
onLoad: () => {
|
|
604
|
-
this.isLauncherReadyToAttach() ? this.attachLauncher(l, g,
|
|
606
|
+
this.isLauncherReadyToAttach() ? this.attachLauncher(l, g, R) : console.error("Rokt object is not available after script load.");
|
|
605
607
|
},
|
|
606
608
|
onError: (h) => {
|
|
607
609
|
console.error("Error loading Rokt launcher script:", h);
|
|
@@ -609,9 +611,9 @@ const f = class f {
|
|
|
609
611
|
}), this.captureTiming(f.PERFORMANCE_MARKS.RoktScriptAppended)), "Successfully initialized: " + d);
|
|
610
612
|
}
|
|
611
613
|
process(e) {
|
|
612
|
-
if (this.isTargetingDisabled() || (e.EventDataType ===
|
|
614
|
+
if (this.isTargetingDisabled() || (e.EventDataType === ve && this.capturePageView(e), e.EventDataType === we && (se(this.loggingService), j())), !this.isKitReady())
|
|
613
615
|
return "Kit not ready for forwarder: " + d;
|
|
614
|
-
if (L(a().Rokt?.setLocalSessionAttribute) && (
|
|
616
|
+
if (L(a().Rokt?.setLocalSessionAttribute) && (U(this.placementEventAttributeMappingLookup) || this.applyPlacementEventAttributeMapping(e), !U(this.placementEventMappingLookup))) {
|
|
615
617
|
const t = $(e.EventDataType, e.EventCategory, e.EventName ?? "");
|
|
616
618
|
this.placementEventMappingLookup[String(t)] && a().Rokt.setLocalSessionAttribute?.(this.placementEventMappingLookup[String(t)], !0);
|
|
617
619
|
}
|
|
@@ -701,7 +703,7 @@ const f = class f {
|
|
|
701
703
|
const t = this._workspaceSearchInFlightPromise;
|
|
702
704
|
return Promise.race([
|
|
703
705
|
t,
|
|
704
|
-
new Promise((n) => setTimeout(n,
|
|
706
|
+
new Promise((n) => setTimeout(n, Pe))
|
|
705
707
|
]).then(() => this._dispatchPlacements(e));
|
|
706
708
|
}
|
|
707
709
|
return this._dispatchPlacements(e);
|
|
@@ -710,18 +712,19 @@ const f = class f {
|
|
|
710
712
|
const t = e && e.attributes || {}, r = { ...b(this.userAttributes), ...t }, s = this.filters || {}, o = s.userAttributeFilters || [], l = s.filteredUser || null, u = l ? l.getMPID() : null;
|
|
711
713
|
let c;
|
|
712
714
|
s ? s.filterUserAttributes ? c = s.filterUserAttributes(r, o) : c = r : (console.warn("Rokt Kit: No filters available, using user attributes"), c = r), this.userAttributes = b(c);
|
|
713
|
-
const p = this._onboardingExpProvider === "Optimizely" ? this.fetchOptimizely() : {},
|
|
714
|
-
...
|
|
715
|
+
const p = this._onboardingExpProvider === "Optimizely" ? this.fetchOptimizely() : {}, C = this.returnUserIdentities(l), R = this.returnLocalSessionAttributes(), v = me(W(this.loggingService)), g = this.readMpSessionId(), y = this.readMpDeviceId(), E = {
|
|
716
|
+
...C,
|
|
715
717
|
...c,
|
|
716
718
|
...p,
|
|
717
|
-
...
|
|
718
|
-
...
|
|
719
|
-
...this.userIdentifiedInWorkspace ? { [
|
|
720
|
-
...g ? { [
|
|
719
|
+
...R,
|
|
720
|
+
...v.length ? { [be]: JSON.stringify(v) } : {},
|
|
721
|
+
...this.userIdentifiedInWorkspace ? { [Re]: !0 } : {},
|
|
722
|
+
...g ? { [Le]: g } : {},
|
|
723
|
+
...y ? { [Te]: y } : {},
|
|
721
724
|
mpid: u
|
|
722
|
-
},
|
|
723
|
-
return Promise.resolve(
|
|
724
|
-
}).finally(
|
|
725
|
+
}, w = { ...e, attributes: E }, h = this.launcher.selectPlacements(w), le = () => this.logSelectPlacementsEvent(E);
|
|
726
|
+
return Promise.resolve(h).then((ue) => ue?.context?.sessionId?.then((de) => this.setRoktSessionId(de))).catch(() => {
|
|
727
|
+
}).finally(le), h;
|
|
725
728
|
}
|
|
726
729
|
/**
|
|
727
730
|
* Passes attributes to the Rokt Web SDK for client-side hashing.
|
|
@@ -747,31 +750,31 @@ const f = class f {
|
|
|
747
750
|
f._allowedOriginHashes = [-553112570, 549508659], f.PERFORMANCE_MARKS = {
|
|
748
751
|
RoktScriptAppended: "mp:RoktScriptAppended"
|
|
749
752
|
}, f.EMAIL_SHA256_KEY = "emailsha256";
|
|
750
|
-
let
|
|
751
|
-
function
|
|
753
|
+
let S = f;
|
|
754
|
+
function Ge() {
|
|
752
755
|
return T;
|
|
753
756
|
}
|
|
754
|
-
function
|
|
757
|
+
function We(i) {
|
|
755
758
|
if (!i) {
|
|
756
759
|
window.console.log("You must pass a config object to register the kit " + d);
|
|
757
760
|
return;
|
|
758
761
|
}
|
|
759
|
-
if (!
|
|
762
|
+
if (!I(i)) {
|
|
760
763
|
window.console.log("'config' must be an object. You passed in a " + typeof i);
|
|
761
764
|
return;
|
|
762
765
|
}
|
|
763
|
-
|
|
764
|
-
constructor:
|
|
766
|
+
I(i.kits) ? i.kits[d] = {
|
|
767
|
+
constructor: S
|
|
765
768
|
} : (i.kits = {}, i.kits[d] = {
|
|
766
|
-
constructor:
|
|
769
|
+
constructor: S
|
|
767
770
|
}), window.console.log("Successfully registered " + d + " to your mParticle configuration");
|
|
768
771
|
}
|
|
769
772
|
typeof window < "u" && window.mParticle && a().addForwarder && a().addForwarder({
|
|
770
773
|
name: d,
|
|
771
|
-
constructor:
|
|
772
|
-
getId:
|
|
774
|
+
constructor: S,
|
|
775
|
+
getId: Ge
|
|
773
776
|
});
|
|
774
777
|
export {
|
|
775
|
-
|
|
778
|
+
We as register
|
|
776
779
|
};
|
|
777
780
|
//# sourceMappingURL=Rokt-Kit.esm.js.map
|
package/dist/Rokt-Kit.iife.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var RoktKit=(function(U){"use strict";const ue=["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"],de=new Set(ue);function x(i){return de.has(i.toLowerCase())}function v(i){const e={},t=i||{},n=Object.keys(t);for(let r=0;r<n.length;r++){const s=n[r];x(s)||(e[s]=t[s])}return e}function E(i){return typeof i=="object"&&i!==null&&!Array.isArray(i)}function m(i){return typeof i=="string"}function w(i){return typeof i=="function"}function C(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}}const G="__rokt_ls_probe__";function j(){try{return window.localStorage.setItem(G,"1"),window.localStorage.removeItem(G),!0}catch{return!1}}function b(i){try{const e=window.localStorage.getItem(i);return e===null?null:JSON.parse(e)}catch{return null}}function W(i,e){try{return window.localStorage.setItem(i,JSON.stringify(e)),!0}catch{return!1}}function H(i){try{window.localStorage.removeItem(i)}catch{}}function V(i,e){const t=b(i);return E(t)?t[e]:void 0}function z(i,e,t){const n=b(i),r=E(n)?{...n}:{};return r[e]=t,W(i,r)}function he(i,e){const t=b(i);if(!E(t)||!(e in t))return;const n={...t};delete n[e],Object.keys(n).length===0?H(i):W(i,n)}const I="mp-rokt-kit",S="pageViews",J="mpPageViews";function q(i){const e=b(J);if(e===null)return;if(!(V(I,S)!==void 0)&&Array.isArray(e)&&!z(I,S,e)){i?.log({message:"Rokt Kit: Failed to migrate legacy page-view storage; retaining legacy key for retry [reason: migration_retry]",code:"PAGE_VIEW_CAPTURE_FAILED"});return}H(J)}function B(i){q(i);const e=V(I,S);return Array.isArray(e)?e:[]}function ge(i){return z(I,S,i.slice(-25))}function $(){he(I,S)}function pe(i){const e=i.slice(-25);return e.map((t,n)=>{const r=t.activeTimeOnSite,s=r!==void 0&&Number.isFinite(r),l=e[n+1]?.activeTimeOnSite,u=l!==void 0&&Number.isFinite(l),c=s&&u?l-r:void 0;return{pageUrl:t.pageUrl,sourceMessageId:t.sourceMessageId,timestamp:t.timestamp,...t.pageTitle!==void 0?{pageTitle:t.pageTitle}:{},...t.canonicalUrl!==void 0?{canonicalUrl:t.canonicalUrl}:{},...s?{activeTimeOnSite:r}:{},...c!==void 0&&c>=0?{activeTimeOnPage:c}:{}}})}function fe(){const e=document.querySelector('link[rel="canonical"]')?.href;if(e)return M(e)}const d="Rokt",L=181,me="selectPlacements",Ee="apps.roktecommerce.com",_e=.1,ye="ThankYouPageJourney",Ie="rokt-launcher",Se="rokt-thank-you-element",ke="userIdentifiedInWorkspace",Ae=3,Re=2,ve="page_events",we="mparticle_session_id",be=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"},Le="apps.rokt-api.com",Te="/v1/log",Pe="/v1/errors",Ne=10;function a(){return window.mParticle}function Q(i,e){const n=[T(i),"/wsdk/integrations/launcher.js"].join("");return!e||e.length===0?n:n+"?extensions="+e.join(",")}function X(i){return[T(i),"/rokt-elements/rokt-element-thank-you.js"].join("")}function T(i){const e=typeof i<"u"?i:Le;return e.includes("://")?e.replace(/\/+$/,""):["https://",e].join("")}function Z(i,e,t){if(i)return i.startsWith("http://")||i.startsWith("https://")?i:"https://"+i;const r=e?.includes("://")&&!/^https?:\/\//i.test(e)?void 0:e;return T(r)+t}function ee(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 P(i){if(!i)return[];try{return JSON.parse(i.replace(/"/g,'"'))}catch{console.error("Settings string contains invalid JSON")}return[]}function te(i){const e=i?P(i):[],t=[],n=[];let r=!1;for(let s=0;s<e.length;s++){const o=e[s].value;o==="thank-you-journey"?(r=!0,n.push(ye)):t.push(o)}return{roktExtensionsQueryParams:t,legacyRoktExtensions:n,loadThankYouElement:r}}async function Oe(i,e){const t=[];if(e)for(const n of i)t.push(e.use(n));return Promise.all(t)}function ie(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 ne(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,s=n.map;e[r]||(e[r]=[]),e[r].push({eventAttributeKey:s,conditions:Array.isArray(n.conditions)?n.conditions:[]})}return e}function re(i,e,t){return a().generateHash([i,e,t].join(""))}function Ue(i){let n="mParticle_wsdkv_"+a().getVersion()+"_kitv_"+"1.33.3";return i&&(n+="_"+i),n}function se(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 oe(i,e){const t=se(window.location.origin);if(y._allowedOriginHashes.indexOf(t)===-1||Math.random()>=_e)return;const r=window.__rokt_li_guid__;if(!r||i&&i.includes("://")&&!/^https:\/\//i.test(i))return;const s=window.location.href.split("?")[0].split("#")[0],o="version="+encodeURIComponent(e??"")+"&launcherInstanceGuid="+encodeURIComponent(r)+"&pageUrl="+encodeURIComponent(s),l=i?T(i):"https://apps.rokt.com";D(l+"/v1/wsdk-init/index.html?"+o),D("https://"+Ee+"/v1/wsdk-init/index.html?"+o+"&isControl=true")}function Ce(){return typeof window<"u"&&!!window.location?.search?.toLowerCase().includes("mp_enable_logging=true")}function Me(){return typeof window<"u"?window.location?.href:void 0}function Ke(){return typeof window<"u"?window.navigator?.userAgent:void 0}class ae{constructor(){this._logCount={}}incrementAndCheck(e){const n=(this._logCount[e]||0)+1;return this._logCount[e]=n,n>Ne}}class F{constructor(e,t,n,r,s){this._reporter="mp-wsdk";const o=e.isLoggingEnabled;this._integrationName=t||"",this._launcherInstanceGuid=n,this._accountId=r||null,this._rateLimiter=s||new ae,this._isEnabled=Ce()||o}send(e,t,n,r,s,o){if(!(!this._isEnabled||this._rateLimiter.incrementAndCheck(t)))try{const l={additionalInformation:{message:n,version:this._integrationName},severity:t,code:r||K.UNKNOWN_ERROR,url:Me(),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(l)}).then(c=>{if(!c.ok){const g=new Error("HTTP "+c.status+" from log endpoint");throw g.statusCode=c.status,g}}).catch(c=>{console.error("ReportingTransport: Failed to send log",c),o&&o(c)})}catch(l){console.error("ReportingTransport: Failed to send log",l),o&&o(l)}}}class ce{constructor(e,t,n,r,s){this._transport=new F(e,t,n,r,s),this._errorUrl=Z(e?.errorUrl,e?.integrationDomain,Pe)}report(e){if(!e)return;const t=e.severity||_.ERROR;this._transport.send(this._errorUrl,t,e.message,e.code,e.stackTrace)}}class le{constructor(e,t,n,r,s,o){this._transport=new F(e,n,r,s,o),this._loggingUrl=Z(e?.loggingUrl,e?.integrationDomain,Te),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 De(i){const e=M(window.location.href),t=i.EventAttributes?.title||document.title,n=fe(),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=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 s=0;s<n.length;s++)if(!this.doesEventAttributeConditionMatch(n[s],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],s=this.placementEventAttributeMappingLookup[r];if(C(s))continue;let o=!0;for(let l=0;l<s.length;l++)if(!this.doesEventMatchRule(e,s[l])){o=!1;break}o&&a().Rokt.setLocalSessionAttribute?.(r,!0)}}capturePageView(e){let t;try{t=M(window.location.href);const n=B(this.loggingService),r=De(e);if(n.push(r),!ge(n)){const s=j()?"quota":"ls_unavailable";this.loggingService?.log({message:`Rokt Kit: Failed to persist page view for ${t} [reason: ${s}]`,code:"PAGE_VIEW_CAPTURE_FAILED"})}}catch(n){const r=j()?"exception":"ls_unavailable",s=n instanceof Error?n.message:String(n);this.loggingService?.log({message:`Rokt Kit: Failed to capture page view for ${t}: ${s} [reason: ${r}]`,code:"PAGE_VIEW_CAPTURE_FAILED"})}}isLauncherReadyToAttach(){return!!window.Rokt&&w(window.Rokt.createLauncher)}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(me,t,e)}setRoktSessionId(e){if(!(!e||typeof e!="string"))try{const t=a().getInstance();t&&w(t.setIntegrationAttribute)&&t.setIntegrationAttribute(L,{roktSessionId:e})}catch{}}readMpSessionId(){const e=a()?.sessionManager,t=e?.getSessionId??e?.getSession;if(w(t))return t.call(e)||void 0}attachLauncher(e,t,n=[]){const r={accountId:e,...t||{}};let s;this.isPartnerInLocalLauncherTestGroup()?s=Promise.resolve(window.Rokt.createLocalLauncher(r)):s=window.Rokt.createLauncher(r),s.then(async o=>{await Oe(n,o),this.initRoktLauncher(o)}).catch(o=>{console.error("Error creating Rokt launcher:",o)})}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,oe(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,n,r,s){const o=e,l=o.accountId;this.userAttributes=v(s),this._onboardingExpProvider=o.onboardingExpProvider;const u=P(o.placementEventMapping);this.placementEventMappingLookup=ie(u);const c=P(o.placementEventAttributeMapping);this.placementEventAttributeMappingLookup=ne(c),o.hashedEmailUserIdentityType&&(this._mappedEmailSha256Key=o.hashedEmailUserIdentityType.toLowerCase()),this._workspaceIdSyncApiKey=m(o.workspaceIdSyncApiKey)?o.workspaceIdSyncApiKey:void 0;const g=a().Rokt?.domain,{roktExtensionsQueryParams:Y,legacyRoktExtensions:N,loadThankYouElement:O}=te(o.roktExtensions),f={...a().Rokt?.launcherOptions||{}};this.integrationName=Ue(f.integrationName),f.integrationName=this.integrationName,this.domain=g;const k={loggingUrl:o.loggingUrl,errorUrl:o.errorUrl,integrationDomain:g,isLoggingEnabled:a().config?.isLoggingEnabled===!0},A=new ce(k,this.integrationName,window.__rokt_li_guid__,o.accountId),R=new le(k,A,this.integrationName,window.__rokt_li_guid__,o.accountId);if(this.errorReportingService=A,this.loggingService=R,this.isTargetingDisabled())try{$()}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(A),a()._registerLoggingService&&a()._registerLoggingService(R),n?(this.testHelpers={generateLauncherScript:Q,generateThankYouElementScript:X,extractRoktExtensionConfig:te,hashEventMessage:re,parseSettingsString:P,generateMappedEventLookup:ie,generateMappedEventAttributeLookup:ne,sendAdBlockMeasurementSignals:oe,createAutoRemovedIframe:D,djb2:se,setAllowedOriginHashes:h=>{p._allowedOriginHashes=h},ReportingTransport:F,ErrorReportingService:ce,LoggingService:le,RateLimiter:ae,ErrorCodes:K,WSDKErrorSeverity:_},this.attachLauncher(l,f),"Successfully initialized: "+d):(O&&(a().Rokt.flushOnShoppableAdsReadyMessageQueue?.(this),ee(Se,X(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(l,f,N):(ee(Ie,Q(g,Y),{onLoad:()=>{this.isLauncherReadyToAttach()?this.attachLauncher(l,f,N):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===Ae&&this.capturePageView(e),e.EventDataType===Re&&(q(this.loggingService),$())),!this.isKitReady())return"Kit not ready for forwarder: "+d;if(w(a().Rokt?.setLocalSessionAttribute)&&(C(this.placementEventAttributeMappingLookup)||this.applyPlacementEventAttributeMapping(e),!C(this.placementEventMappingLookup))){const t=re(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=v(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,s={};if(r)for(const u of Object.keys(r)){const c=r[u];m(c)&&c.length>0&&(s[u]=c)}const o=Object.keys(s);if(o.length===0)return this.userIdentifiedInWorkspace=!1,this._workspaceLastSearchedIdentitiesKey=void 0,Promise.resolve();const l=o.sort().map(u=>`${u}=${s[u]}`).join("&");return l===this._workspaceLastSearchedIdentitiesKey?this._workspaceSearchInFlightPromise||Promise.resolve():(this.userIdentifiedInWorkspace=!1,this._workspaceLastSearchedIdentitiesKey=l,new Promise(u=>{try{n(t,s,c=>{c?.httpCode===200&&(this.userIdentifiedInWorkspace=!0),u()})}catch(c){console.error("Rokt Kit: Workspace IDSync search failed",c),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,be))]).then(()=>this._dispatchPlacements(e))}return this._dispatchPlacements(e)}_dispatchPlacements(e){const t=e&&e.attributes||{},r={...v(this.userAttributes),...t},s=this.filters||{},o=s.userAttributeFilters||[],l=s.filteredUser||null,u=l?l.getMPID():null;let c;s?s.filterUserAttributes?c=s.filterUserAttributes(r,o):c=r:(console.warn("Rokt Kit: No filters available, using user attributes"),c=r),this.userAttributes=v(c);const g=this._onboardingExpProvider==="Optimizely"?this.fetchOptimizely():{},Y=this.returnUserIdentities(l),N=this.returnLocalSessionAttributes(),O=pe(B(this.loggingService)),f=this.readMpSessionId(),k={...Y,...c,...g,...N,...O.length?{[ve]:JSON.stringify(O)}:{},...this.userIdentifiedInWorkspace?{[ke]:!0}:{},...f?{[we]:f}:{},mpid:u},A={...e,attributes:k},R=this.launcher.selectPlacements(A),h=()=>this.logSelectPlacementsEvent(k);return Promise.resolve(R).then(xe=>xe?.context?.sessionId?.then(Ge=>this.setRoktSessionId(Ge))).catch(()=>{}).finally(h),R}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 Fe(){return L}function Ye(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:Fe}),U.register=Ye,Object.defineProperty(U,Symbol.toStringTag,{value:"Module"}),U})({});
|
|
1
|
+
var RoktKit=(function(C){"use strict";const ue=["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"],de=new Set(ue);function x(i){return de.has(i.toLowerCase())}function v(i){const e={},t=i||{},n=Object.keys(t);for(let r=0;r<n.length;r++){const s=n[r];x(s)||(e[s]=t[s])}return e}function E(i){return typeof i=="object"&&i!==null&&!Array.isArray(i)}function m(i){return typeof i=="string"}function R(i){return typeof i=="function"}function U(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}}const G="__rokt_ls_probe__";function W(){try{return window.localStorage.setItem(G,"1"),window.localStorage.removeItem(G),!0}catch{return!1}}function w(i){try{const e=window.localStorage.getItem(i);return e===null?null:JSON.parse(e)}catch{return null}}function j(i,e){try{return window.localStorage.setItem(i,JSON.stringify(e)),!0}catch{return!1}}function V(i){try{window.localStorage.removeItem(i)}catch{}}function H(i,e){const t=w(i);return E(t)?t[e]:void 0}function z(i,e,t){const n=w(i),r=E(n)?{...n}:{};return r[e]=t,j(i,r)}function he(i,e){const t=w(i);if(!E(t)||!(e in t))return;const n={...t};delete n[e],Object.keys(n).length===0?V(i):j(i,n)}const y="mp-rokt-kit",A="pageViews",J="mpPageViews";function q(i){const e=w(J);if(e===null)return;!(H(y,A)!==void 0)&&Array.isArray(e)&&(i?.log({message:"Rokt Kit: Migrating legacy page-view storage",code:"PAGE_VIEW_LEGACY_MIGRATION"}),z(y,A,e)||i?.log({message:"Rokt Kit: Failed to migrate legacy page-view storage [reason: migration_retry]",code:"PAGE_VIEW_CAPTURE_FAILED"})),V(J)}function B(i){q(i);const e=H(y,A);return Array.isArray(e)?e:[]}function pe(i){return z(y,A,i.slice(-25))}function $(){he(y,A)}function ge(i){const e=i.slice(-25);return e.map((t,n)=>{const r=t.activeTimeOnSite,s=r!==void 0&&Number.isFinite(r),l=e[n+1]?.activeTimeOnSite,u=l!==void 0&&Number.isFinite(l),c=s&&u?l-r:void 0;return{pageUrl:t.pageUrl,sourceMessageId:t.sourceMessageId,timestamp:t.timestamp,...t.pageTitle!==void 0?{pageTitle:t.pageTitle}:{},...t.canonicalUrl!==void 0?{canonicalUrl:t.canonicalUrl}:{},...s?{activeTimeOnSite:r}:{},...c!==void 0&&c>=0?{activeTimeOnPage:c}:{}}})}function fe(){const e=document.querySelector('link[rel="canonical"]')?.href;if(e)return M(e)}const d="Rokt",b=181,me="selectPlacements",Ee="apps.roktecommerce.com",_e=.1,Ie="ThankYouPageJourney",Se="rokt-launcher",ye="rokt-thank-you-element",Ae="userIdentifiedInWorkspace",ke=3,ve=2,Re="page_events",we="mparticle_session_id",be="mparticle_device_id",Le=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"},Te="apps.rokt-api.com",Pe="/v1/log",Ne="/v1/errors",Oe=10;function a(){return window.mParticle}function Q(i,e){const n=[L(i),"/wsdk/integrations/launcher.js"].join("");return!e||e.length===0?n:n+"?extensions="+e.join(",")}function X(i){return[L(i),"/rokt-elements/rokt-element-thank-you.js"].join("")}function L(i){const e=typeof i<"u"?i:Te;return e.includes("://")?e.replace(/\/+$/,""):["https://",e].join("")}function Z(i,e,t){if(i)return i.startsWith("http://")||i.startsWith("https://")?i:"https://"+i;const r=e?.includes("://")&&!/^https?:\/\//i.test(e)?void 0:e;return L(r)+t}function ee(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 te(i){const e=i?T(i):[],t=[],n=[];let r=!1;for(let s=0;s<e.length;s++){const o=e[s].value;o==="thank-you-journey"?(r=!0,n.push(Ie)):t.push(o)}return{roktExtensionsQueryParams:t,legacyRoktExtensions:n,loadThankYouElement:r}}async function Ce(i,e){const t=[];if(e)for(const n of i)t.push(e.use(n));return Promise.all(t)}function ie(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 ne(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,s=n.map;e[r]||(e[r]=[]),e[r].push({eventAttributeKey:s,conditions:Array.isArray(n.conditions)?n.conditions:[]})}return e}function re(i,e,t){return a().generateHash([i,e,t].join(""))}function Ue(i){let n="mParticle_wsdkv_"+a().getVersion()+"_kitv_"+"1.34.0";return i&&(n+="_"+i),n}function se(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 oe(i,e){const t=se(window.location.origin);if(I._allowedOriginHashes.indexOf(t)===-1||Math.random()>=_e)return;const r=window.__rokt_li_guid__;if(!r||i&&i.includes("://")&&!/^https:\/\//i.test(i))return;const s=window.location.href.split("?")[0].split("#")[0],o="version="+encodeURIComponent(e??"")+"&launcherInstanceGuid="+encodeURIComponent(r)+"&pageUrl="+encodeURIComponent(s),l=i?L(i):"https://apps.rokt.com";D(l+"/v1/wsdk-init/index.html?"+o),D("https://"+Ee+"/v1/wsdk-init/index.html?"+o+"&isControl=true")}function Me(){return typeof window<"u"&&!!window.location?.search?.toLowerCase().includes("mp_enable_logging=true")}function Ke(){return typeof window<"u"?window.location?.href:void 0}function De(){return typeof window<"u"?window.navigator?.userAgent:void 0}class ae{constructor(){this._logCount={}}incrementAndCheck(e){const n=(this._logCount[e]||0)+1;return this._logCount[e]=n,n>Oe}}class F{constructor(e,t,n,r,s){this._reporter="mp-wsdk";const o=e.isLoggingEnabled;this._integrationName=t||"",this._launcherInstanceGuid=n,this._accountId=r||null,this._rateLimiter=s||new ae,this._isEnabled=Me()||o}send(e,t,n,r,s,o){if(!(!this._isEnabled||this._rateLimiter.incrementAndCheck(t)))try{const l={additionalInformation:{message:n,version:this._integrationName},severity:t,code:r||K.UNKNOWN_ERROR,url:Ke(),deviceInfo:De(),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(l)}).then(c=>{if(!c.ok){const p=new Error("HTTP "+c.status+" from log endpoint");throw p.statusCode=c.status,p}}).catch(c=>{console.error("ReportingTransport: Failed to send log",c),o&&o(c)})}catch(l){console.error("ReportingTransport: Failed to send log",l),o&&o(l)}}}class ce{constructor(e,t,n,r,s){this._transport=new F(e,t,n,r,s),this._errorUrl=Z(e?.errorUrl,e?.integrationDomain,Ne)}report(e){if(!e)return;const t=e.severity||_.ERROR;this._transport.send(this._errorUrl,t,e.message,e.code,e.stackTrace)}}class le{constructor(e,t,n,r,s,o){this._transport=new F(e,n,r,s,o),this._loggingUrl=Z(e?.loggingUrl,e?.integrationDomain,Pe),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 Fe(i){const e=M(window.location.href),t=i.EventAttributes?.title||document.title,n=fe(),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 g=class g{constructor(){this.name=d,this.id=b,this.moduleId=b,this.isInitialized=!1,this.launcher=null,this.filters={},this.userAttributes={},this.userIdentifiedInWorkspace=!1,this.testHelpers=null,this.placementEventMappingLookup={},this.placementEventAttributeMappingLookup={},this.integrationName=null,this.errorReportingService=null,this.loggingService=null,this._thankYouElementOnLoadCallback=null,this._isThankYouElementLoaded=!1,this._workspaceSearchInFlightPromise=null}getEventAttributeValue(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 s=0;s<n.length;s++)if(!this.doesEventAttributeConditionMatch(n[s],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],s=this.placementEventAttributeMappingLookup[r];if(U(s))continue;let o=!0;for(let l=0;l<s.length;l++)if(!this.doesEventMatchRule(e,s[l])){o=!1;break}o&&a().Rokt.setLocalSessionAttribute?.(r,!0)}}capturePageView(e){let t;try{t=M(window.location.href);const n=B(this.loggingService),r=Fe(e);if(n.push(r),!pe(n)){const s=W()?"quota":"ls_unavailable";this.loggingService?.log({message:`Rokt Kit: Failed to persist page view for ${t} [reason: ${s}]`,code:"PAGE_VIEW_CAPTURE_FAILED"})}}catch(n){const r=W()?"exception":"ls_unavailable",s=n instanceof Error?n.message:String(n);this.loggingService?.log({message:`Rokt Kit: Failed to capture page view for ${t}: ${s} [reason: ${r}]`,code:"PAGE_VIEW_CAPTURE_FAILED"})}}isLauncherReadyToAttach(){return!!window.Rokt&&R(window.Rokt.createLauncher)}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[g.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(me,t,e)}setRoktSessionId(e){if(!(!e||typeof e!="string"))try{const t=a().getInstance();t&&R(t.setIntegrationAttribute)&&t.setIntegrationAttribute(b,{roktSessionId:e})}catch{}}readMpSessionId(){const e=a()?.sessionManager,t=e?.getSessionId??e?.getSession;if(R(t))return t.call(e)||void 0}readMpDeviceId(){return a()?.getDeviceId?.()||void 0}attachLauncher(e,t,n=[]){const r={accountId:e,...t||{}};let s;this.isPartnerInLocalLauncherTestGroup()?s=Promise.resolve(window.Rokt.createLocalLauncher(r)):s=window.Rokt.createLauncher(r),s.then(async o=>{await Ce(n,o),this.initRoktLauncher(o)}).catch(o=>{console.error("Error creating Rokt launcher:",o)})}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,oe(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,n,r,s){const o=e,l=o.accountId;this.userAttributes=v(s),this._onboardingExpProvider=o.onboardingExpProvider;const u=T(o.placementEventMapping);this.placementEventMappingLookup=ie(u);const c=T(o.placementEventAttributeMapping);this.placementEventAttributeMappingLookup=ne(c),o.hashedEmailUserIdentityType&&(this._mappedEmailSha256Key=o.hashedEmailUserIdentityType.toLowerCase()),this._workspaceIdSyncApiKey=m(o.workspaceIdSyncApiKey)?o.workspaceIdSyncApiKey:void 0;const p=a().Rokt?.domain,{roktExtensionsQueryParams:Y,legacyRoktExtensions:P,loadThankYouElement:N}=te(o.roktExtensions),f={...a().Rokt?.launcherOptions||{}};this.integrationName=Ue(f.integrationName),f.integrationName=this.integrationName,this.domain=p;const k={loggingUrl:o.loggingUrl,errorUrl:o.errorUrl,integrationDomain:p,isLoggingEnabled:a().config?.isLoggingEnabled===!0},S=new ce(k,this.integrationName,window.__rokt_li_guid__,o.accountId),O=new le(k,S,this.integrationName,window.__rokt_li_guid__,o.accountId);if(this.errorReportingService=S,this.loggingService=O,this.isTargetingDisabled())try{$()}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(S),a()._registerLoggingService&&a()._registerLoggingService(O),n?(this.testHelpers={generateLauncherScript:Q,generateThankYouElementScript:X,extractRoktExtensionConfig:te,hashEventMessage:re,parseSettingsString:T,generateMappedEventLookup:ie,generateMappedEventAttributeLookup:ne,sendAdBlockMeasurementSignals:oe,createAutoRemovedIframe:D,djb2:se,setAllowedOriginHashes:h=>{g._allowedOriginHashes=h},ReportingTransport:F,ErrorReportingService:ce,LoggingService:le,RateLimiter:ae,ErrorCodes:K,WSDKErrorSeverity:_},this.attachLauncher(l,f),"Successfully initialized: "+d):(N&&(a().Rokt.flushOnShoppableAdsReadyMessageQueue?.(this),ee(ye,X(p),{onLoad:()=>{this._isThankYouElementLoaded=!0,this._thankYouElementOnLoadCallback&&this._thankYouElementOnLoadCallback()},onError:h=>{console.error("Error loading Rokt Thank You Element script:",h)}})),this.isLauncherReadyToAttach()?this.attachLauncher(l,f,P):(ee(Se,Q(p,Y),{onLoad:()=>{this.isLauncherReadyToAttach()?this.attachLauncher(l,f,P):console.error("Rokt object is not available after script load.")},onError:h=>{console.error("Error loading Rokt launcher script:",h)}}),this.captureTiming(g.PERFORMANCE_MARKS.RoktScriptAppended)),"Successfully initialized: "+d)}process(e){if(this.isTargetingDisabled()||(e.EventDataType===ke&&this.capturePageView(e),e.EventDataType===ve&&(q(this.loggingService),$())),!this.isKitReady())return"Kit not ready for forwarder: "+d;if(R(a().Rokt?.setLocalSessionAttribute)&&(U(this.placementEventAttributeMappingLookup)||this.applyPlacementEventAttributeMapping(e),!U(this.placementEventMappingLookup))){const t=re(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=v(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,s={};if(r)for(const u of Object.keys(r)){const c=r[u];m(c)&&c.length>0&&(s[u]=c)}const o=Object.keys(s);if(o.length===0)return this.userIdentifiedInWorkspace=!1,this._workspaceLastSearchedIdentitiesKey=void 0,Promise.resolve();const l=o.sort().map(u=>`${u}=${s[u]}`).join("&");return l===this._workspaceLastSearchedIdentitiesKey?this._workspaceSearchInFlightPromise||Promise.resolve():(this.userIdentifiedInWorkspace=!1,this._workspaceLastSearchedIdentitiesKey=l,new Promise(u=>{try{n(t,s,c=>{c?.httpCode===200&&(this.userIdentifiedInWorkspace=!0),u()})}catch(c){console.error("Rokt Kit: Workspace IDSync search failed",c),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,Le))]).then(()=>this._dispatchPlacements(e))}return this._dispatchPlacements(e)}_dispatchPlacements(e){const t=e&&e.attributes||{},r={...v(this.userAttributes),...t},s=this.filters||{},o=s.userAttributeFilters||[],l=s.filteredUser||null,u=l?l.getMPID():null;let c;s?s.filterUserAttributes?c=s.filterUserAttributes(r,o):c=r:(console.warn("Rokt Kit: No filters available, using user attributes"),c=r),this.userAttributes=v(c);const p=this._onboardingExpProvider==="Optimizely"?this.fetchOptimizely():{},Y=this.returnUserIdentities(l),P=this.returnLocalSessionAttributes(),N=ge(B(this.loggingService)),f=this.readMpSessionId(),k=this.readMpDeviceId(),S={...Y,...c,...p,...P,...N.length?{[Re]:JSON.stringify(N)}:{},...this.userIdentifiedInWorkspace?{[Ae]:!0}:{},...f?{[we]:f}:{},...k?{[be]:k}:{},mpid:u},O={...e,attributes:S},h=this.launcher.selectPlacements(O),Ge=()=>this.logSelectPlacementsEvent(S);return Promise.resolve(h).then(We=>We?.context?.sessionId?.then(je=>this.setRoktSessionId(je))).catch(()=>{}).finally(Ge),h}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}};g._allowedOriginHashes=[-553112570,549508659],g.PERFORMANCE_MARKS={RoktScriptAppended:"mp:RoktScriptAppended"},g.EMAIL_SHA256_KEY="emailsha256";let I=g;function Ye(){return b}function xe(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:I}:(i.kits={},i.kits[d]={constructor:I}),window.console.log("Successfully registered "+d+" to your mParticle configuration")}return typeof window<"u"&&window.mParticle&&a().addForwarder&&a().addForwarder({name:d,constructor:I,getId:Ye}),C.register=xe,Object.defineProperty(C,Symbol.toStringTag,{value:"Module"}),C})({});
|
|
2
2
|
//# sourceMappingURL=Rokt-Kit.iife.js.map
|