@mparticle/web-rokt-kit 1.33.2 → 1.33.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Rokt-Kit.common.js +1 -1
- package/dist/Rokt-Kit.esm.js +155 -164
- 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 te(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];te(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 D(i){try{const e=new URL(i);return e.search="",e.toString()}catch{return i}}const x="__rokt_ls_probe__";function G(){try{return window.localStorage.setItem(x,"1"),window.localStorage.removeItem(x),!0}catch{return!1}}function O(i){try{const e=window.localStorage.getItem(i);return e===null?null:JSON.parse(e)}catch{return null}}function ie(i,e){try{return window.localStorage.setItem(i,JSON.stringify(e)),!0}catch{return!1}}function ne(i){try{window.localStorage.removeItem(i)}catch{}}function re(i,e){const t=O(i);return _(t)?t[e]:void 0}function M(i,e,t){const n=O(i),r=_(n)?{...n}:{};return r[e]=t,ie(i,r)}function ge(i,e){const t=O(i);if(!_(t)||!(e in t))return;const n={...t};delete n[e],Object.keys(n).length===0?ne(i):ie(i,n)}function pe(i,e,t,n){const r=t.slice(),s=()=>r.length<=1?!1:(r.shift(),!0);let o=JSON.stringify(r).length>n;for(;o&&s();)o=JSON.stringify(r).length>n;let c=M(i,e,r);for(;!c&&s();)c=M(i,e,r);return c}const k="mp-rokt-kit",R="pageViews",W="mpPageViews",fe=100*1024;function se(i){const e=O(W);if(e===null)return;if(!(re(k,R)!==void 0)&&Array.isArray(e)&&!M(k,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}ne(W)}function j(i){se(i);const e=re(k,R);return Array.isArray(e)?e:[]}function me(i){return pe(k,R,i,fe)}function H(){ge(k,R)}function Ee(i){return i.map((e,t)=>{const n=e.activeTimeOnSite,r=n!==void 0&&Number.isFinite(n),o=i[t+1]?.activeTimeOnSite,c=o!==void 0&&Number.isFinite(o),u=r&&c?o-n:void 0;return{pageUrl:e.pageUrl,sourceMessageId:e.sourceMessageId,timestamp:e.timestamp,...e.pageTitle!==void 0?{pageTitle:e.pageTitle}:{},...e.canonicalUrl!==void 0?{canonicalUrl:e.canonicalUrl}:{},...r?{activeTimeOnSite:n}:{},...u!==void 0&&u>=0?{activeTimeOnPage:u}:{}}})}function _e(){const e=document.querySelector('link[rel="canonical"]')?.href;if(e)return D(e)}const d="Rokt",T=181,Se="selectPlacements",ye="apps.roktecommerce.com",Ie=.1,Ae="ThankYouPageJourney",ke="rokt-launcher",Re="rokt-thank-you-element",ve="userIdentifiedInWorkspace",we=3,be=2,Le="page_events",Te="mparticle_session_id",Ne=500,F={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"},Oe="apps.rokt-api.com",Pe="/v1/log",Ue="/v1/errors",Ce=10;function a(){return window.mParticle}function V(i,e){const n=[P(i),"/wsdk/integrations/launcher.js"].join("");return!e||e.length===0?n:n+"?extensions="+e.join(",")}function z(i){return[P(i),"/rokt-elements/rokt-element-thank-you.js"].join("")}function P(i){const e=typeof i<"u"?i:Oe;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 P(r)+t}function J(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 N(i){if(!i)return[];try{return JSON.parse(i.replace(/"/g,'"'))}catch{console.error("Settings string contains invalid JSON")}return[]}function B(i){const e=i?N(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(Ae)):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 $(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 Q(i,e,t){return a().generateHash([i,e,t].join(""))}function Ke(i){let n="mParticle_wsdkv_"+a().getVersion()+"_kitv_"+"1.33.2";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 K(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 X(i,e){const t=ae(window.location.origin);if(S._allowedOriginHashes.indexOf(t)===-1||Math.random()>=Ie)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),c=i?P(i):"https://apps.rokt.com";K(c+"/v1/wsdk-init/index.html?"+o),K("https://"+ye+"/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>Ce}}class Y{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 c={additionalInformation:{message:n,version:this._integrationName},severity:t,code:r||F.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(c)}).then(l=>{if(!l.ok){const g=new Error("HTTP "+l.status+" from log endpoint");throw g.statusCode=l.status,g}}).catch(l=>{console.error("ReportingTransport: Failed to send log",l),o&&o(l)})}catch(c){console.error("ReportingTransport: Failed to send log",c),o&&o(c)}}}class Z{constructor(e,t,n,r,s){this._transport=new Y(e,t,n,r,s),this._errorUrl=oe(e?.errorUrl,e?.integrationDomain,Ue)}report(e){if(!e)return;const t=e.severity||E.ERROR;this._transport.send(this._errorUrl,t,e.message,e.code,e.stackTrace)}}class ee{constructor(e,t,n,r,s,o){this._transport=new Y(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:F.LOG_DELIVERY_FAILURE,severity:n?E.ERROR:E.WARNING})}})}}function xe(i){const e=D(window.location.href),t=i.EventAttributes?.title||document.title,n=_e(),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 c=0;c<s.length;c++)if(!this.doesEventMatchRule(e,s[c])){o=!1;break}o&&a().Rokt.setLocalSessionAttribute?.(r,!0)}}capturePageView(e){let t;try{t=D(window.location.href);const n=j(this.loggingService),r=xe(e);if(n.push(r),!me(n)){const s=G()?"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=G()?"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(Se,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 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,X(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,c=o.accountId;this.userAttributes=b(s),this._onboardingExpProvider=o.onboardingExpProvider;const u=N(o.placementEventMapping);this.placementEventMappingLookup=q(u);const l=N(o.placementEventAttributeMapping);this.placementEventAttributeMappingLookup=$(l),o.hashedEmailUserIdentityType&&(this._mappedEmailSha256Key=o.hashedEmailUserIdentityType.toLowerCase()),this._workspaceIdSyncApiKey=m(o.workspaceIdSyncApiKey)?o.workspaceIdSyncApiKey:void 0;const g=a().Rokt?.domain,{roktExtensionsQueryParams:U,legacyRoktExtensions:v,loadThankYouElement:w}=B(o.roktExtensions),p={...a().Rokt?.launcherOptions||{}};this.integrationName=Ke(p.integrationName),p.integrationName=this.integrationName,this.domain=g;const y={loggingUrl:o.loggingUrl,errorUrl:o.errorUrl,integrationDomain:g,isLoggingEnabled:a().config?.isLoggingEnabled===!0},I=new Z(y,this.integrationName,window.__rokt_li_guid__,o.accountId),A=new ee(y,I,this.integrationName,window.__rokt_li_guid__,o.accountId);if(this.errorReportingService=I,this.loggingService=A,this.isTargetingDisabled())try{H()}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(I),a()._registerLoggingService&&a()._registerLoggingService(A),n?(this.testHelpers={generateLauncherScript:V,generateThankYouElementScript:z,extractRoktExtensionConfig:B,hashEventMessage:Q,parseSettingsString:N,generateMappedEventLookup:q,generateMappedEventAttributeLookup:$,sendAdBlockMeasurementSignals:X,createAutoRemovedIframe:K,djb2:ae,setAllowedOriginHashes:h=>{f._allowedOriginHashes=h},ReportingTransport:Y,ErrorReportingService:Z,LoggingService:ee,RateLimiter:ce,ErrorCodes:F,WSDKErrorSeverity:E},this.attachLauncher(c,p),"Successfully initialized: "+d):(w&&(a().Rokt.flushOnShoppableAdsReadyMessageQueue?.(this),J(Re,z(g),{onLoad:()=>{this._isThankYouElementLoaded=!0,this._thankYouElementOnLoadCallback&&this._thankYouElementOnLoadCallback()},onError:h=>{console.error("Error loading Rokt Thank You Element script:",h)}})),this.isLauncherReadyToAttach()?this.attachLauncher(c,p,v):(J(ke,V(g,U),{onLoad:()=>{this.isLauncherReadyToAttach()?this.attachLauncher(c,p,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===we&&this.capturePageView(e),e.EventDataType===be&&(se(this.loggingService),H())),!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=Q(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 te(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 l=r[u];m(l)&&l.length>0&&(s[u]=l)}const o=Object.keys(s);if(o.length===0)return this.userIdentifiedInWorkspace=!1,this._workspaceLastSearchedIdentitiesKey=void 0,Promise.resolve();const c=o.sort().map(u=>`${u}=${s[u]}`).join("&");return c===this._workspaceLastSearchedIdentitiesKey?this._workspaceSearchInFlightPromise||Promise.resolve():(this.userIdentifiedInWorkspace=!1,this._workspaceLastSearchedIdentitiesKey=c,new Promise(u=>{try{n(t,s,l=>{l?.httpCode===200&&(this.userIdentifiedInWorkspace=!0),u()})}catch(l){console.error("Rokt Kit: Workspace IDSync search failed",l),this._workspaceLastSearchedIdentitiesKey=void 0,u()}}))}onLoginComplete(e,t){return this.handleIdentityComplete(e,"onLoginComplete")}onLogoutComplete(e,t){return this.userIdentifiedInWorkspace=!1,this._workspaceSearchInFlightPromise=null,this._workspaceLastSearchedIdentitiesKey=void 0,this.handleIdentityComplete(e,"onLogoutComplete")}onModifyComplete(e,t){return this.handleIdentityComplete(e,"onModifyComplete")}selectPlacements(e){if(this._workspaceSearchInFlightPromise){const t=this._workspaceSearchInFlightPromise;return Promise.race([t,new Promise(n=>setTimeout(n,Ne))]).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||[],c=s.filteredUser||null,u=c?c.getMPID():null;let l;s?s.filterUserAttributes?l=s.filterUserAttributes(r,o):l=r:(console.warn("Rokt Kit: No filters available, using user attributes"),l=r),this.userAttributes=b(l);const g=this._onboardingExpProvider==="Optimizely"?this.fetchOptimizely():{},U=this.returnUserIdentities(c),v=this.returnLocalSessionAttributes(),w=Ee(j(this.loggingService)),p=this.readMpSessionId(),y={...U,...l,...g,...v,...w.length?{[Le]:JSON.stringify(w)}:{},...this.userIdentifiedInWorkspace?{[ve]:!0}:{},...p?{[Te]:p}:{},mpid:u},I={...e,attributes:y},A=this.launcher.selectPlacements(I),h=()=>this.logSelectPlacementsEvent(y);return Promise.resolve(A).then(le=>le?.context?.sessionId?.then(ue=>this.setRoktSessionId(ue))).catch(()=>{}).finally(h),A}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)){window.console.log("'config' must be an object. You passed in a "+typeof i);return}_(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;
|
|
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;
|
|
2
2
|
//# sourceMappingURL=Rokt-Kit.common.js.map
|
package/dist/Rokt-Kit.esm.js
CHANGED
|
@@ -24,14 +24,14 @@ const de = [
|
|
|
24
24
|
"shippingzipcode",
|
|
25
25
|
"totalprice"
|
|
26
26
|
], he = new Set(de);
|
|
27
|
-
function
|
|
27
|
+
function ee(i) {
|
|
28
28
|
return he.has(i.toLowerCase());
|
|
29
29
|
}
|
|
30
30
|
function b(i) {
|
|
31
31
|
const e = {}, t = i || {}, n = Object.keys(t);
|
|
32
32
|
for (let r = 0; r < n.length; r++) {
|
|
33
33
|
const s = n[r];
|
|
34
|
-
|
|
34
|
+
ee(s) || (e[s] = t[s]);
|
|
35
35
|
}
|
|
36
36
|
return e;
|
|
37
37
|
}
|
|
@@ -47,7 +47,7 @@ function L(i) {
|
|
|
47
47
|
function C(i) {
|
|
48
48
|
return i == null ? !0 : typeof i == "object" ? Object.keys(i).length === 0 : !1;
|
|
49
49
|
}
|
|
50
|
-
function
|
|
50
|
+
function K(i) {
|
|
51
51
|
try {
|
|
52
52
|
const e = new URL(i);
|
|
53
53
|
return e.search = "", e.toString();
|
|
@@ -56,14 +56,14 @@ function D(i) {
|
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
58
|
const x = "__rokt_ls_probe__";
|
|
59
|
-
function
|
|
59
|
+
function Y() {
|
|
60
60
|
try {
|
|
61
61
|
return window.localStorage.setItem(x, "1"), window.localStorage.removeItem(x), !0;
|
|
62
62
|
} catch {
|
|
63
63
|
return !1;
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
|
-
function
|
|
66
|
+
function P(i) {
|
|
67
67
|
try {
|
|
68
68
|
const e = window.localStorage.getItem(i);
|
|
69
69
|
return e === null ? null : JSON.parse(e);
|
|
@@ -71,89 +71,80 @@ function O(i) {
|
|
|
71
71
|
return null;
|
|
72
72
|
}
|
|
73
73
|
}
|
|
74
|
-
function
|
|
74
|
+
function te(i, e) {
|
|
75
75
|
try {
|
|
76
76
|
return window.localStorage.setItem(i, JSON.stringify(e)), !0;
|
|
77
77
|
} catch {
|
|
78
78
|
return !1;
|
|
79
79
|
}
|
|
80
80
|
}
|
|
81
|
-
function
|
|
81
|
+
function ie(i) {
|
|
82
82
|
try {
|
|
83
83
|
window.localStorage.removeItem(i);
|
|
84
84
|
} catch {
|
|
85
85
|
}
|
|
86
86
|
}
|
|
87
|
-
function
|
|
88
|
-
const t =
|
|
87
|
+
function ne(i, e) {
|
|
88
|
+
const t = P(i);
|
|
89
89
|
return _(t) ? t[e] : void 0;
|
|
90
90
|
}
|
|
91
|
-
function
|
|
92
|
-
const n =
|
|
93
|
-
return r[e] = t,
|
|
91
|
+
function re(i, e, t) {
|
|
92
|
+
const n = P(i), r = _(n) ? { ...n } : {};
|
|
93
|
+
return r[e] = t, te(i, r);
|
|
94
94
|
}
|
|
95
|
-
function
|
|
96
|
-
const t =
|
|
95
|
+
function pe(i, e) {
|
|
96
|
+
const t = P(i);
|
|
97
97
|
if (!_(t) || !(e in t))
|
|
98
98
|
return;
|
|
99
99
|
const n = { ...t };
|
|
100
|
-
delete n[e], Object.keys(n).length === 0 ?
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
const r = t.slice(), s = () => r.length <= 1 ? !1 : (r.shift(), !0);
|
|
104
|
-
let o = JSON.stringify(r).length > n;
|
|
105
|
-
for (; o && s(); )
|
|
106
|
-
o = JSON.stringify(r).length > n;
|
|
107
|
-
let c = M(i, e, r);
|
|
108
|
-
for (; !c && s(); )
|
|
109
|
-
c = M(i, e, r);
|
|
110
|
-
return c;
|
|
111
|
-
}
|
|
112
|
-
const k = "mp-rokt-kit", R = "pageViews", W = "mpPageViews", fe = 100 * 1024;
|
|
100
|
+
delete n[e], Object.keys(n).length === 0 ? ie(i) : te(i, n);
|
|
101
|
+
}
|
|
102
|
+
const A = "mp-rokt-kit", R = "pageViews", G = "mpPageViews";
|
|
113
103
|
function se(i) {
|
|
114
|
-
const e =
|
|
104
|
+
const e = P(G);
|
|
115
105
|
if (e === null)
|
|
116
106
|
return;
|
|
117
|
-
if (!(
|
|
107
|
+
if (!(ne(A, R) !== void 0) && Array.isArray(e) && !re(A, R, e)) {
|
|
118
108
|
i?.log({
|
|
119
109
|
message: "Rokt Kit: Failed to migrate legacy page-view storage; retaining legacy key for retry [reason: migration_retry]",
|
|
120
110
|
code: "PAGE_VIEW_CAPTURE_FAILED"
|
|
121
111
|
});
|
|
122
112
|
return;
|
|
123
113
|
}
|
|
124
|
-
|
|
114
|
+
ie(G);
|
|
125
115
|
}
|
|
126
|
-
function
|
|
116
|
+
function W(i) {
|
|
127
117
|
se(i);
|
|
128
|
-
const e =
|
|
118
|
+
const e = ne(A, R);
|
|
129
119
|
return Array.isArray(e) ? e : [];
|
|
130
120
|
}
|
|
131
|
-
function
|
|
132
|
-
return
|
|
121
|
+
function ge(i) {
|
|
122
|
+
return re(A, R, i.slice(-25));
|
|
133
123
|
}
|
|
134
|
-
function
|
|
135
|
-
|
|
124
|
+
function j() {
|
|
125
|
+
pe(A, R);
|
|
136
126
|
}
|
|
137
|
-
function
|
|
138
|
-
|
|
139
|
-
|
|
127
|
+
function fe(i) {
|
|
128
|
+
const e = i.slice(-25);
|
|
129
|
+
return e.map((t, n) => {
|
|
130
|
+
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;
|
|
140
131
|
return {
|
|
141
|
-
pageUrl:
|
|
142
|
-
sourceMessageId:
|
|
143
|
-
timestamp:
|
|
144
|
-
...
|
|
145
|
-
...
|
|
146
|
-
...
|
|
147
|
-
...
|
|
132
|
+
pageUrl: t.pageUrl,
|
|
133
|
+
sourceMessageId: t.sourceMessageId,
|
|
134
|
+
timestamp: t.timestamp,
|
|
135
|
+
...t.pageTitle !== void 0 ? { pageTitle: t.pageTitle } : {},
|
|
136
|
+
...t.canonicalUrl !== void 0 ? { canonicalUrl: t.canonicalUrl } : {},
|
|
137
|
+
...s ? { activeTimeOnSite: r } : {},
|
|
138
|
+
...c !== void 0 && c >= 0 ? { activeTimeOnPage: c } : {}
|
|
148
139
|
};
|
|
149
140
|
});
|
|
150
141
|
}
|
|
151
|
-
function
|
|
142
|
+
function me() {
|
|
152
143
|
const e = document.querySelector('link[rel="canonical"]')?.href;
|
|
153
144
|
if (e)
|
|
154
|
-
return
|
|
145
|
+
return K(e);
|
|
155
146
|
}
|
|
156
|
-
const d = "Rokt", T = 181,
|
|
147
|
+
const d = "Rokt", T = 181, Ee = "selectPlacements", _e = "apps.roktecommerce.com", Ie = 0.1, ye = "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 = {
|
|
157
148
|
UNKNOWN_ERROR: "UNKNOWN_ERROR",
|
|
158
149
|
UNHANDLED_EXCEPTION: "UNHANDLED_EXCEPTION",
|
|
159
150
|
IDENTITY_REQUEST: "IDENTITY_REQUEST",
|
|
@@ -162,28 +153,28 @@ const d = "Rokt", T = 181, Ie = "selectPlacements", Se = "apps.roktecommerce.com
|
|
|
162
153
|
ERROR: "ERROR",
|
|
163
154
|
INFO: "INFO",
|
|
164
155
|
WARNING: "WARNING"
|
|
165
|
-
},
|
|
156
|
+
}, Te = "apps.rokt-api.com", Ne = "/v1/log", Pe = "/v1/errors", Oe = 10;
|
|
166
157
|
function a() {
|
|
167
158
|
return window.mParticle;
|
|
168
159
|
}
|
|
169
|
-
function
|
|
170
|
-
const n = [
|
|
160
|
+
function H(i, e) {
|
|
161
|
+
const n = [O(i), "/wsdk/integrations/launcher.js"].join("");
|
|
171
162
|
return !e || e.length === 0 ? n : n + "?extensions=" + e.join(",");
|
|
172
163
|
}
|
|
173
|
-
function
|
|
174
|
-
return [
|
|
164
|
+
function V(i) {
|
|
165
|
+
return [O(i), "/rokt-elements/rokt-element-thank-you.js"].join("");
|
|
175
166
|
}
|
|
176
|
-
function
|
|
177
|
-
const e = typeof i < "u" ? i :
|
|
167
|
+
function O(i) {
|
|
168
|
+
const e = typeof i < "u" ? i : Te;
|
|
178
169
|
return e.includes("://") ? e.replace(/\/+$/, "") : ["https://", e].join("");
|
|
179
170
|
}
|
|
180
171
|
function oe(i, e, t) {
|
|
181
172
|
if (i)
|
|
182
173
|
return i.startsWith("http://") || i.startsWith("https://") ? i : "https://" + i;
|
|
183
174
|
const r = e?.includes("://") && !/^https?:\/\//i.test(e) ? void 0 : e;
|
|
184
|
-
return
|
|
175
|
+
return O(r) + t;
|
|
185
176
|
}
|
|
186
|
-
function
|
|
177
|
+
function z(i, e, t) {
|
|
187
178
|
if (document.getElementById(i)) return;
|
|
188
179
|
const n = document.head || document.body, r = document.createElement("script");
|
|
189
180
|
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);
|
|
@@ -198,12 +189,12 @@ function N(i) {
|
|
|
198
189
|
}
|
|
199
190
|
return [];
|
|
200
191
|
}
|
|
201
|
-
function
|
|
192
|
+
function J(i) {
|
|
202
193
|
const e = i ? N(i) : [], t = [], n = [];
|
|
203
194
|
let r = !1;
|
|
204
195
|
for (let s = 0; s < e.length; s++) {
|
|
205
196
|
const o = e[s].value;
|
|
206
|
-
o === "thank-you-journey" ? (r = !0, n.push(
|
|
197
|
+
o === "thank-you-journey" ? (r = !0, n.push(ye)) : t.push(o);
|
|
207
198
|
}
|
|
208
199
|
return {
|
|
209
200
|
roktExtensionsQueryParams: t,
|
|
@@ -211,7 +202,7 @@ function B(i) {
|
|
|
211
202
|
loadThankYouElement: r
|
|
212
203
|
};
|
|
213
204
|
}
|
|
214
|
-
async function
|
|
205
|
+
async function Ue(i, e) {
|
|
215
206
|
const t = [];
|
|
216
207
|
if (e)
|
|
217
208
|
for (const n of i)
|
|
@@ -228,7 +219,7 @@ function q(i) {
|
|
|
228
219
|
}
|
|
229
220
|
return e;
|
|
230
221
|
}
|
|
231
|
-
function
|
|
222
|
+
function B(i) {
|
|
232
223
|
const e = {};
|
|
233
224
|
if (!Array.isArray(i))
|
|
234
225
|
return e;
|
|
@@ -244,11 +235,11 @@ function $(i) {
|
|
|
244
235
|
}
|
|
245
236
|
return e;
|
|
246
237
|
}
|
|
247
|
-
function
|
|
238
|
+
function $(i, e, t) {
|
|
248
239
|
return a().generateHash([i, e, t].join(""));
|
|
249
240
|
}
|
|
250
|
-
function
|
|
251
|
-
let n = "mParticle_wsdkv_" + a().getVersion() + "_kitv_" + "1.33.
|
|
241
|
+
function Ce(i) {
|
|
242
|
+
let n = "mParticle_wsdkv_" + a().getVersion() + "_kitv_" + "1.33.3";
|
|
252
243
|
return i && (n += "_" + i), n;
|
|
253
244
|
}
|
|
254
245
|
function ae(i) {
|
|
@@ -257,7 +248,7 @@ function ae(i) {
|
|
|
257
248
|
e = (e << 5) + e + i.charCodeAt(t), e = e & e;
|
|
258
249
|
return e;
|
|
259
250
|
}
|
|
260
|
-
function
|
|
251
|
+
function M(i) {
|
|
261
252
|
const e = document.createElement("iframe");
|
|
262
253
|
e.style.display = "none", e.setAttribute("sandbox", "allow-scripts allow-same-origin"), e.src = i, e.onload = function() {
|
|
263
254
|
e.onload = null, e.parentNode && e.parentNode.removeChild(e);
|
|
@@ -265,25 +256,25 @@ function K(i) {
|
|
|
265
256
|
const t = document.body || document.head;
|
|
266
257
|
t && t.appendChild(e);
|
|
267
258
|
}
|
|
268
|
-
function
|
|
259
|
+
function Q(i, e) {
|
|
269
260
|
const t = ae(window.location.origin);
|
|
270
|
-
if (I._allowedOriginHashes.indexOf(t) === -1 || Math.random() >=
|
|
261
|
+
if (I._allowedOriginHashes.indexOf(t) === -1 || Math.random() >= Ie)
|
|
271
262
|
return;
|
|
272
263
|
const r = window.__rokt_li_guid__;
|
|
273
264
|
if (!r || i && i.includes("://") && !/^https:\/\//i.test(i))
|
|
274
265
|
return;
|
|
275
|
-
const s = window.location.href.split("?")[0].split("#")[0], o = "version=" + encodeURIComponent(e ?? "") + "&launcherInstanceGuid=" + encodeURIComponent(r) + "&pageUrl=" + encodeURIComponent(s),
|
|
276
|
-
|
|
277
|
-
"https://" +
|
|
266
|
+
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
|
+
M(l + "/v1/wsdk-init/index.html?" + o), M(
|
|
268
|
+
"https://" + _e + "/v1/wsdk-init/index.html?" + o + "&isControl=true"
|
|
278
269
|
);
|
|
279
270
|
}
|
|
280
|
-
function
|
|
271
|
+
function Me() {
|
|
281
272
|
return typeof window < "u" && !!window.location?.search?.toLowerCase().includes("mp_enable_logging=true");
|
|
282
273
|
}
|
|
283
|
-
function
|
|
274
|
+
function Ke() {
|
|
284
275
|
return typeof window < "u" ? window.location?.href : void 0;
|
|
285
276
|
}
|
|
286
|
-
function
|
|
277
|
+
function De() {
|
|
287
278
|
return typeof window < "u" ? window.navigator?.userAgent : void 0;
|
|
288
279
|
}
|
|
289
280
|
class ce {
|
|
@@ -292,27 +283,27 @@ class ce {
|
|
|
292
283
|
}
|
|
293
284
|
incrementAndCheck(e) {
|
|
294
285
|
const n = (this._logCount[e] || 0) + 1;
|
|
295
|
-
return this._logCount[e] = n, n >
|
|
286
|
+
return this._logCount[e] = n, n > Oe;
|
|
296
287
|
}
|
|
297
288
|
}
|
|
298
|
-
class
|
|
289
|
+
class F {
|
|
299
290
|
constructor(e, t, n, r, s) {
|
|
300
291
|
this._reporter = "mp-wsdk";
|
|
301
292
|
const o = e.isLoggingEnabled;
|
|
302
|
-
this._integrationName = t || "", this._launcherInstanceGuid = n, this._accountId = r || null, this._rateLimiter = s || new ce(), this._isEnabled =
|
|
293
|
+
this._integrationName = t || "", this._launcherInstanceGuid = n, this._accountId = r || null, this._rateLimiter = s || new ce(), this._isEnabled = Me() || o;
|
|
303
294
|
}
|
|
304
295
|
send(e, t, n, r, s, o) {
|
|
305
296
|
if (!(!this._isEnabled || this._rateLimiter.incrementAndCheck(t)))
|
|
306
297
|
try {
|
|
307
|
-
const
|
|
298
|
+
const l = {
|
|
308
299
|
additionalInformation: {
|
|
309
300
|
message: n,
|
|
310
301
|
version: this._integrationName
|
|
311
302
|
},
|
|
312
303
|
severity: t,
|
|
313
|
-
code: r ||
|
|
314
|
-
url:
|
|
315
|
-
deviceInfo:
|
|
304
|
+
code: r || D.UNKNOWN_ERROR,
|
|
305
|
+
url: Ke(),
|
|
306
|
+
deviceInfo: De(),
|
|
316
307
|
stackTrace: s,
|
|
317
308
|
reporter: this._reporter,
|
|
318
309
|
integration: this._integrationName
|
|
@@ -325,23 +316,23 @@ class Y {
|
|
|
325
316
|
this._launcherInstanceGuid && (u["rokt-launcher-instance-guid"] = this._launcherInstanceGuid), this._accountId && (u["rokt-account-id"] = this._accountId), fetch(e, {
|
|
326
317
|
method: "POST",
|
|
327
318
|
headers: u,
|
|
328
|
-
body: JSON.stringify(
|
|
329
|
-
}).then((
|
|
330
|
-
if (!
|
|
331
|
-
const
|
|
332
|
-
throw
|
|
319
|
+
body: JSON.stringify(l)
|
|
320
|
+
}).then((c) => {
|
|
321
|
+
if (!c.ok) {
|
|
322
|
+
const p = new Error("HTTP " + c.status + " from log endpoint");
|
|
323
|
+
throw p.statusCode = c.status, p;
|
|
333
324
|
}
|
|
334
|
-
}).catch((
|
|
335
|
-
console.error("ReportingTransport: Failed to send log",
|
|
325
|
+
}).catch((c) => {
|
|
326
|
+
console.error("ReportingTransport: Failed to send log", c), o && o(c);
|
|
336
327
|
});
|
|
337
|
-
} catch (
|
|
338
|
-
console.error("ReportingTransport: Failed to send log",
|
|
328
|
+
} catch (l) {
|
|
329
|
+
console.error("ReportingTransport: Failed to send log", l), o && o(l);
|
|
339
330
|
}
|
|
340
331
|
}
|
|
341
332
|
}
|
|
342
|
-
class
|
|
333
|
+
class X {
|
|
343
334
|
constructor(e, t, n, r, s) {
|
|
344
|
-
this._transport = new
|
|
335
|
+
this._transport = new F(e, t, n, r, s), this._errorUrl = oe(e?.errorUrl, e?.integrationDomain, Pe);
|
|
345
336
|
}
|
|
346
337
|
report(e) {
|
|
347
338
|
if (!e) return;
|
|
@@ -349,9 +340,9 @@ class Z {
|
|
|
349
340
|
this._transport.send(this._errorUrl, t, e.message, e.code, e.stackTrace);
|
|
350
341
|
}
|
|
351
342
|
}
|
|
352
|
-
class
|
|
343
|
+
class Z {
|
|
353
344
|
constructor(e, t, n, r, s, o) {
|
|
354
|
-
this._transport = new
|
|
345
|
+
this._transport = new F(e, n, r, s, o), this._loggingUrl = oe(e?.loggingUrl, e?.integrationDomain, Ne), this._errorReportingService = t;
|
|
355
346
|
}
|
|
356
347
|
log(e) {
|
|
357
348
|
e && this._transport.send(
|
|
@@ -365,7 +356,7 @@ class ee {
|
|
|
365
356
|
const n = typeof t.statusCode == "number";
|
|
366
357
|
this._errorReportingService.report({
|
|
367
358
|
message: "LoggingService: Failed to send log: " + t.message,
|
|
368
|
-
code:
|
|
359
|
+
code: D.LOG_DELIVERY_FAILURE,
|
|
369
360
|
severity: n ? E.ERROR : E.WARNING
|
|
370
361
|
});
|
|
371
362
|
}
|
|
@@ -373,8 +364,8 @@ class ee {
|
|
|
373
364
|
);
|
|
374
365
|
}
|
|
375
366
|
}
|
|
376
|
-
function
|
|
377
|
-
const e =
|
|
367
|
+
function Fe(i) {
|
|
368
|
+
const e = K(window.location.href), t = i.EventAttributes?.title || document.title, n = me(), r = i.ActiveTimeOnSite;
|
|
378
369
|
return {
|
|
379
370
|
pageUrl: e,
|
|
380
371
|
sourceMessageId: i.SourceMessageId,
|
|
@@ -420,8 +411,8 @@ const f = class f {
|
|
|
420
411
|
if (C(s))
|
|
421
412
|
continue;
|
|
422
413
|
let o = !0;
|
|
423
|
-
for (let
|
|
424
|
-
if (!this.doesEventMatchRule(e, s[
|
|
414
|
+
for (let l = 0; l < s.length; l++)
|
|
415
|
+
if (!this.doesEventMatchRule(e, s[l])) {
|
|
425
416
|
o = !1;
|
|
426
417
|
break;
|
|
427
418
|
}
|
|
@@ -431,17 +422,17 @@ const f = class f {
|
|
|
431
422
|
capturePageView(e) {
|
|
432
423
|
let t;
|
|
433
424
|
try {
|
|
434
|
-
t =
|
|
435
|
-
const n =
|
|
436
|
-
if (n.push(r), !
|
|
437
|
-
const s =
|
|
425
|
+
t = K(window.location.href);
|
|
426
|
+
const n = W(this.loggingService), r = Fe(e);
|
|
427
|
+
if (n.push(r), !ge(n)) {
|
|
428
|
+
const s = Y() ? "quota" : "ls_unavailable";
|
|
438
429
|
this.loggingService?.log({
|
|
439
430
|
message: `Rokt Kit: Failed to persist page view for ${t} [reason: ${s}]`,
|
|
440
431
|
code: "PAGE_VIEW_CAPTURE_FAILED"
|
|
441
432
|
});
|
|
442
433
|
}
|
|
443
434
|
} catch (n) {
|
|
444
|
-
const r =
|
|
435
|
+
const r = Y() ? "exception" : "ls_unavailable", s = n instanceof Error ? n.message : String(n);
|
|
445
436
|
this.loggingService?.log({
|
|
446
437
|
message: `Rokt Kit: Failed to capture page view for ${t}: ${s} [reason: ${r}]`,
|
|
447
438
|
code: "PAGE_VIEW_CAPTURE_FAILED"
|
|
@@ -471,7 +462,7 @@ const f = class f {
|
|
|
471
462
|
if (!window.mParticle || typeof a().logEvent != "function" || !_(e))
|
|
472
463
|
return;
|
|
473
464
|
const t = a().EventType.Other;
|
|
474
|
-
a().logEvent(
|
|
465
|
+
a().logEvent(Ee, t, e);
|
|
475
466
|
}
|
|
476
467
|
setRoktSessionId(e) {
|
|
477
468
|
if (!(!e || typeof e != "string"))
|
|
@@ -495,7 +486,7 @@ const f = class f {
|
|
|
495
486
|
};
|
|
496
487
|
let s;
|
|
497
488
|
this.isPartnerInLocalLauncherTestGroup() ? s = Promise.resolve(window.Rokt.createLocalLauncher(r)) : s = window.Rokt.createLauncher(r), s.then(async (o) => {
|
|
498
|
-
await
|
|
489
|
+
await Ue(n, o), this.initRoktLauncher(o);
|
|
499
490
|
}).catch((o) => {
|
|
500
491
|
console.error("Error creating Rokt launcher:", o);
|
|
501
492
|
});
|
|
@@ -503,7 +494,7 @@ const f = class f {
|
|
|
503
494
|
initRoktLauncher(e) {
|
|
504
495
|
window.Rokt && (window.Rokt.currentLauncher = e), this.launcher = e;
|
|
505
496
|
const t = a().Rokt?.filters;
|
|
506
|
-
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,
|
|
497
|
+
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);
|
|
507
498
|
}
|
|
508
499
|
fetchOptimizely() {
|
|
509
500
|
const e = a()._getActiveForwarders().filter((t) => t.name === "Optimizely");
|
|
@@ -539,40 +530,40 @@ const f = class f {
|
|
|
539
530
|
* Initializes the Rokt forwarder with settings from the mParticle server.
|
|
540
531
|
*/
|
|
541
532
|
init(e, t, n, r, s) {
|
|
542
|
-
const o = e,
|
|
533
|
+
const o = e, l = o.accountId;
|
|
543
534
|
this.userAttributes = b(s), this._onboardingExpProvider = o.onboardingExpProvider;
|
|
544
535
|
const u = N(o.placementEventMapping);
|
|
545
536
|
this.placementEventMappingLookup = q(u);
|
|
546
|
-
const
|
|
537
|
+
const c = N(
|
|
547
538
|
o.placementEventAttributeMapping
|
|
548
539
|
);
|
|
549
|
-
this.placementEventAttributeMappingLookup =
|
|
550
|
-
const
|
|
540
|
+
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: U, legacyRoktExtensions: v, loadThankYouElement: w } = J(
|
|
551
542
|
o.roktExtensions
|
|
552
|
-
),
|
|
543
|
+
), g = {
|
|
553
544
|
...a().Rokt?.launcherOptions || {}
|
|
554
545
|
};
|
|
555
|
-
this.integrationName =
|
|
556
|
-
const
|
|
546
|
+
this.integrationName = Ce(g.integrationName), g.integrationName = this.integrationName, this.domain = p;
|
|
547
|
+
const y = {
|
|
557
548
|
loggingUrl: o.loggingUrl,
|
|
558
549
|
errorUrl: o.errorUrl,
|
|
559
|
-
integrationDomain:
|
|
550
|
+
integrationDomain: p,
|
|
560
551
|
isLoggingEnabled: a().config?.isLoggingEnabled === !0
|
|
561
|
-
},
|
|
562
|
-
|
|
552
|
+
}, S = new X(
|
|
553
|
+
y,
|
|
563
554
|
this.integrationName,
|
|
564
555
|
window.__rokt_li_guid__,
|
|
565
556
|
o.accountId
|
|
566
|
-
),
|
|
567
|
-
S,
|
|
557
|
+
), k = new Z(
|
|
568
558
|
y,
|
|
559
|
+
S,
|
|
569
560
|
this.integrationName,
|
|
570
561
|
window.__rokt_li_guid__,
|
|
571
562
|
o.accountId
|
|
572
563
|
);
|
|
573
|
-
if (this.errorReportingService =
|
|
564
|
+
if (this.errorReportingService = S, this.loggingService = k, this.isTargetingDisabled())
|
|
574
565
|
try {
|
|
575
|
-
|
|
566
|
+
j();
|
|
576
567
|
} catch (h) {
|
|
577
568
|
this.errorReportingService?.report({
|
|
578
569
|
message: "Rokt Kit: Failed to clear page views when targeting is disabled",
|
|
@@ -581,36 +572,36 @@ const f = class f {
|
|
|
581
572
|
stackTrace: h instanceof Error ? h.stack : void 0
|
|
582
573
|
});
|
|
583
574
|
}
|
|
584
|
-
return a()._registerErrorReportingService && a()._registerErrorReportingService(
|
|
585
|
-
generateLauncherScript:
|
|
586
|
-
generateThankYouElementScript:
|
|
587
|
-
extractRoktExtensionConfig:
|
|
588
|
-
hashEventMessage:
|
|
575
|
+
return a()._registerErrorReportingService && a()._registerErrorReportingService(S), a()._registerLoggingService && a()._registerLoggingService(k), n ? (this.testHelpers = {
|
|
576
|
+
generateLauncherScript: H,
|
|
577
|
+
generateThankYouElementScript: V,
|
|
578
|
+
extractRoktExtensionConfig: J,
|
|
579
|
+
hashEventMessage: $,
|
|
589
580
|
parseSettingsString: N,
|
|
590
581
|
generateMappedEventLookup: q,
|
|
591
|
-
generateMappedEventAttributeLookup:
|
|
592
|
-
sendAdBlockMeasurementSignals:
|
|
593
|
-
createAutoRemovedIframe:
|
|
582
|
+
generateMappedEventAttributeLookup: B,
|
|
583
|
+
sendAdBlockMeasurementSignals: Q,
|
|
584
|
+
createAutoRemovedIframe: M,
|
|
594
585
|
djb2: ae,
|
|
595
586
|
setAllowedOriginHashes: (h) => {
|
|
596
587
|
f._allowedOriginHashes = h;
|
|
597
588
|
},
|
|
598
|
-
ReportingTransport:
|
|
599
|
-
ErrorReportingService:
|
|
600
|
-
LoggingService:
|
|
589
|
+
ReportingTransport: F,
|
|
590
|
+
ErrorReportingService: X,
|
|
591
|
+
LoggingService: Z,
|
|
601
592
|
RateLimiter: ce,
|
|
602
|
-
ErrorCodes:
|
|
593
|
+
ErrorCodes: D,
|
|
603
594
|
WSDKErrorSeverity: E
|
|
604
|
-
}, this.attachLauncher(
|
|
595
|
+
}, this.attachLauncher(l, g), "Successfully initialized: " + d) : (w && (a().Rokt.flushOnShoppableAdsReadyMessageQueue?.(this), z(ke, V(p), {
|
|
605
596
|
onLoad: () => {
|
|
606
597
|
this._isThankYouElementLoaded = !0, this._thankYouElementOnLoadCallback && this._thankYouElementOnLoadCallback();
|
|
607
598
|
},
|
|
608
599
|
onError: (h) => {
|
|
609
600
|
console.error("Error loading Rokt Thank You Element script:", h);
|
|
610
601
|
}
|
|
611
|
-
})), this.isLauncherReadyToAttach() ? this.attachLauncher(
|
|
602
|
+
})), this.isLauncherReadyToAttach() ? this.attachLauncher(l, g, v) : (z(Se, H(p, U), {
|
|
612
603
|
onLoad: () => {
|
|
613
|
-
this.isLauncherReadyToAttach() ? this.attachLauncher(
|
|
604
|
+
this.isLauncherReadyToAttach() ? this.attachLauncher(l, g, v) : console.error("Rokt object is not available after script load.");
|
|
614
605
|
},
|
|
615
606
|
onError: (h) => {
|
|
616
607
|
console.error("Error loading Rokt launcher script:", h);
|
|
@@ -618,10 +609,10 @@ const f = class f {
|
|
|
618
609
|
}), this.captureTiming(f.PERFORMANCE_MARKS.RoktScriptAppended)), "Successfully initialized: " + d);
|
|
619
610
|
}
|
|
620
611
|
process(e) {
|
|
621
|
-
if (this.isTargetingDisabled() || (e.EventDataType ===
|
|
612
|
+
if (this.isTargetingDisabled() || (e.EventDataType === Re && this.capturePageView(e), e.EventDataType === ve && (se(this.loggingService), j())), !this.isKitReady())
|
|
622
613
|
return "Kit not ready for forwarder: " + d;
|
|
623
614
|
if (L(a().Rokt?.setLocalSessionAttribute) && (C(this.placementEventAttributeMappingLookup) || this.applyPlacementEventAttributeMapping(e), !C(this.placementEventMappingLookup))) {
|
|
624
|
-
const t =
|
|
615
|
+
const t = $(e.EventDataType, e.EventCategory, e.EventName ?? "");
|
|
625
616
|
this.placementEventMappingLookup[String(t)] && a().Rokt.setLocalSessionAttribute?.(this.placementEventMappingLookup[String(t)], !0);
|
|
626
617
|
}
|
|
627
618
|
return "Successfully sent to forwarder: " + d;
|
|
@@ -634,7 +625,7 @@ const f = class f {
|
|
|
634
625
|
window.Rokt.setExtensionData(e);
|
|
635
626
|
}
|
|
636
627
|
setUserAttribute(e, t) {
|
|
637
|
-
return
|
|
628
|
+
return ee(e) || (this.userAttributes[e] = t), "Successfully set user attribute for forwarder: " + d;
|
|
638
629
|
}
|
|
639
630
|
removeUserAttribute(e) {
|
|
640
631
|
return delete this.userAttributes[e], "Successfully removed user attribute for forwarder: " + d;
|
|
@@ -656,20 +647,20 @@ const f = class f {
|
|
|
656
647
|
const r = e.getUserIdentities ? e.getUserIdentities().userIdentities : null, s = {};
|
|
657
648
|
if (r)
|
|
658
649
|
for (const u of Object.keys(r)) {
|
|
659
|
-
const
|
|
660
|
-
m(
|
|
650
|
+
const c = r[u];
|
|
651
|
+
m(c) && c.length > 0 && (s[u] = c);
|
|
661
652
|
}
|
|
662
653
|
const o = Object.keys(s);
|
|
663
654
|
if (o.length === 0)
|
|
664
655
|
return this.userIdentifiedInWorkspace = !1, this._workspaceLastSearchedIdentitiesKey = void 0, Promise.resolve();
|
|
665
|
-
const
|
|
666
|
-
return
|
|
656
|
+
const l = o.sort().map((u) => `${u}=${s[u]}`).join("&");
|
|
657
|
+
return l === this._workspaceLastSearchedIdentitiesKey ? this._workspaceSearchInFlightPromise || Promise.resolve() : (this.userIdentifiedInWorkspace = !1, this._workspaceLastSearchedIdentitiesKey = l, new Promise((u) => {
|
|
667
658
|
try {
|
|
668
|
-
n(t, s, (
|
|
669
|
-
|
|
659
|
+
n(t, s, (c) => {
|
|
660
|
+
c?.httpCode === 200 && (this.userIdentifiedInWorkspace = !0), u();
|
|
670
661
|
});
|
|
671
|
-
} catch (
|
|
672
|
-
console.error("Rokt Kit: Workspace IDSync search failed",
|
|
662
|
+
} catch (c) {
|
|
663
|
+
console.error("Rokt Kit: Workspace IDSync search failed", c), this._workspaceLastSearchedIdentitiesKey = void 0, u();
|
|
673
664
|
}
|
|
674
665
|
}));
|
|
675
666
|
}
|
|
@@ -710,27 +701,27 @@ const f = class f {
|
|
|
710
701
|
const t = this._workspaceSearchInFlightPromise;
|
|
711
702
|
return Promise.race([
|
|
712
703
|
t,
|
|
713
|
-
new Promise((n) => setTimeout(n,
|
|
704
|
+
new Promise((n) => setTimeout(n, Le))
|
|
714
705
|
]).then(() => this._dispatchPlacements(e));
|
|
715
706
|
}
|
|
716
707
|
return this._dispatchPlacements(e);
|
|
717
708
|
}
|
|
718
709
|
_dispatchPlacements(e) {
|
|
719
|
-
const t = e && e.attributes || {}, r = { ...b(this.userAttributes), ...t }, s = this.filters || {}, o = s.userAttributeFilters || [],
|
|
720
|
-
let
|
|
721
|
-
s ? s.filterUserAttributes ?
|
|
722
|
-
const
|
|
710
|
+
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
|
+
let c;
|
|
712
|
+
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() : {}, U = this.returnUserIdentities(l), v = this.returnLocalSessionAttributes(), w = fe(W(this.loggingService)), g = this.readMpSessionId(), y = {
|
|
723
714
|
...U,
|
|
724
|
-
...
|
|
725
|
-
...
|
|
715
|
+
...c,
|
|
716
|
+
...p,
|
|
726
717
|
...v,
|
|
727
|
-
...w.length ? { [
|
|
728
|
-
...this.userIdentifiedInWorkspace ? { [
|
|
729
|
-
...
|
|
718
|
+
...w.length ? { [we]: JSON.stringify(w) } : {},
|
|
719
|
+
...this.userIdentifiedInWorkspace ? { [Ae]: !0 } : {},
|
|
720
|
+
...g ? { [be]: g } : {},
|
|
730
721
|
mpid: u
|
|
731
|
-
},
|
|
732
|
-
return Promise.resolve(
|
|
733
|
-
}).finally(h),
|
|
722
|
+
}, S = { ...e, attributes: y }, k = this.launcher.selectPlacements(S), h = () => this.logSelectPlacementsEvent(y);
|
|
723
|
+
return Promise.resolve(k).then((le) => le?.context?.sessionId?.then((ue) => this.setRoktSessionId(ue))).catch(() => {
|
|
724
|
+
}).finally(h), k;
|
|
734
725
|
}
|
|
735
726
|
/**
|
|
736
727
|
* Passes attributes to the Rokt Web SDK for client-side hashing.
|
|
@@ -757,10 +748,10 @@ f._allowedOriginHashes = [-553112570, 549508659], f.PERFORMANCE_MARKS = {
|
|
|
757
748
|
RoktScriptAppended: "mp:RoktScriptAppended"
|
|
758
749
|
}, f.EMAIL_SHA256_KEY = "emailsha256";
|
|
759
750
|
let I = f;
|
|
760
|
-
function
|
|
751
|
+
function xe() {
|
|
761
752
|
return T;
|
|
762
753
|
}
|
|
763
|
-
function
|
|
754
|
+
function Ye(i) {
|
|
764
755
|
if (!i) {
|
|
765
756
|
window.console.log("You must pass a config object to register the kit " + d);
|
|
766
757
|
return;
|
|
@@ -778,9 +769,9 @@ function We(i) {
|
|
|
778
769
|
typeof window < "u" && window.mParticle && a().addForwarder && a().addForwarder({
|
|
779
770
|
name: d,
|
|
780
771
|
constructor: I,
|
|
781
|
-
getId:
|
|
772
|
+
getId: xe
|
|
782
773
|
});
|
|
783
774
|
export {
|
|
784
|
-
|
|
775
|
+
Ye as register
|
|
785
776
|
};
|
|
786
777
|
//# 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 G(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];G(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 W="__rokt_ls_probe__";function j(){try{return window.localStorage.setItem(W,"1"),window.localStorage.removeItem(W),!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 H(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 z(i,e){const t=b(i);return E(t)?t[e]:void 0}function K(i,e,t){const n=b(i),r=E(n)?{...n}:{};return r[e]=t,H(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?V(i):H(i,n)}function ge(i,e,t,n){const r=t.slice(),s=()=>r.length<=1?!1:(r.shift(),!0);let o=JSON.stringify(r).length>n;for(;o&&s();)o=JSON.stringify(r).length>n;let c=K(i,e,r);for(;!c&&s();)c=K(i,e,r);return c}const y="mp-rokt-kit",I="pageViews",J="mpPageViews",pe=100*1024;function B(i){const e=b(J);if(e===null)return;if(!(z(y,I)!==void 0)&&Array.isArray(e)&&!K(y,I,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}V(J)}function q(i){B(i);const e=z(y,I);return Array.isArray(e)?e:[]}function fe(i){return ge(y,I,i,pe)}function $(){he(y,I)}function me(i){return i.map((e,t)=>{const n=e.activeTimeOnSite,r=n!==void 0&&Number.isFinite(n),o=i[t+1]?.activeTimeOnSite,c=o!==void 0&&Number.isFinite(o),u=r&&c?o-n:void 0;return{pageUrl:e.pageUrl,sourceMessageId:e.sourceMessageId,timestamp:e.timestamp,...e.pageTitle!==void 0?{pageTitle:e.pageTitle}:{},...e.canonicalUrl!==void 0?{canonicalUrl:e.canonicalUrl}:{},...r?{activeTimeOnSite:n}:{},...u!==void 0&&u>=0?{activeTimeOnPage:u}:{}}})}function Ee(){const e=document.querySelector('link[rel="canonical"]')?.href;if(e)return M(e)}const d="Rokt",L=181,_e="selectPlacements",Se="apps.roktecommerce.com",ye=.1,Ie="ThankYouPageJourney",ke="rokt-launcher",Ae="rokt-thank-you-element",Re="userIdentifiedInWorkspace",ve=3,we=2,be="page_events",Le="mparticle_session_id",Te=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",Pe="/v1/errors",Ue=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:Ne;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 N(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?N(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 Me(i){let n="mParticle_wsdkv_"+a().getVersion()+"_kitv_"+"1.33.2";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 F(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(S._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),c=i?T(i):"https://apps.rokt.com";F(c+"/v1/wsdk-init/index.html?"+o),F("https://"+Se+"/v1/wsdk-init/index.html?"+o+"&isControl=true")}function Ke(){return typeof window<"u"&&!!window.location?.search?.toLowerCase().includes("mp_enable_logging=true")}function De(){return typeof window<"u"?window.location?.href:void 0}function Fe(){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>Ue}}class Y{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=Ke()||o}send(e,t,n,r,s,o){if(!(!this._isEnabled||this._rateLimiter.incrementAndCheck(t)))try{const c={additionalInformation:{message:n,version:this._integrationName},severity:t,code:r||D.UNKNOWN_ERROR,url:De(),deviceInfo:Fe(),stackTrace:s,reporter:this._reporter,integration:this._integrationName},u={Accept:"text/plain;charset=UTF-8","Content-Type":"application/json","rokt-launcher-version":this._integrationName,"rokt-wsdk-version":"joint"};this._launcherInstanceGuid&&(u["rokt-launcher-instance-guid"]=this._launcherInstanceGuid),this._accountId&&(u["rokt-account-id"]=this._accountId),fetch(e,{method:"POST",headers:u,body:JSON.stringify(c)}).then(l=>{if(!l.ok){const g=new Error("HTTP "+l.status+" from log endpoint");throw g.statusCode=l.status,g}}).catch(l=>{console.error("ReportingTransport: Failed to send log",l),o&&o(l)})}catch(c){console.error("ReportingTransport: Failed to send log",c),o&&o(c)}}}class ce{constructor(e,t,n,r,s){this._transport=new Y(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 Y(e,n,r,s,o),this._loggingUrl=Z(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 Ye(i){const e=M(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 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 c=0;c<s.length;c++)if(!this.doesEventMatchRule(e,s[c])){o=!1;break}o&&a().Rokt.setLocalSessionAttribute?.(r,!0)}}capturePageView(e){let t;try{t=M(window.location.href);const n=q(this.loggingService),r=Ye(e);if(n.push(r),!fe(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(_e,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 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,c=o.accountId;this.userAttributes=v(s),this._onboardingExpProvider=o.onboardingExpProvider;const u=N(o.placementEventMapping);this.placementEventMappingLookup=ie(u);const l=N(o.placementEventAttributeMapping);this.placementEventAttributeMappingLookup=ne(l),o.hashedEmailUserIdentityType&&(this._mappedEmailSha256Key=o.hashedEmailUserIdentityType.toLowerCase()),this._workspaceIdSyncApiKey=m(o.workspaceIdSyncApiKey)?o.workspaceIdSyncApiKey:void 0;const g=a().Rokt?.domain,{roktExtensionsQueryParams:x,legacyRoktExtensions:O,loadThankYouElement:P}=te(o.roktExtensions),f={...a().Rokt?.launcherOptions||{}};this.integrationName=Me(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:N,generateMappedEventLookup:ie,generateMappedEventAttributeLookup:ne,sendAdBlockMeasurementSignals:oe,createAutoRemovedIframe:F,djb2:se,setAllowedOriginHashes:h=>{p._allowedOriginHashes=h},ReportingTransport:Y,ErrorReportingService:ce,LoggingService:le,RateLimiter:ae,ErrorCodes:D,WSDKErrorSeverity:_},this.attachLauncher(c,f),"Successfully initialized: "+d):(P&&(a().Rokt.flushOnShoppableAdsReadyMessageQueue?.(this),ee(Ae,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(c,f,O):(ee(ke,Q(g,x),{onLoad:()=>{this.isLauncherReadyToAttach()?this.attachLauncher(c,f,O):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===ve&&this.capturePageView(e),e.EventDataType===we&&(B(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 G(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 l=r[u];m(l)&&l.length>0&&(s[u]=l)}const o=Object.keys(s);if(o.length===0)return this.userIdentifiedInWorkspace=!1,this._workspaceLastSearchedIdentitiesKey=void 0,Promise.resolve();const c=o.sort().map(u=>`${u}=${s[u]}`).join("&");return c===this._workspaceLastSearchedIdentitiesKey?this._workspaceSearchInFlightPromise||Promise.resolve():(this.userIdentifiedInWorkspace=!1,this._workspaceLastSearchedIdentitiesKey=c,new Promise(u=>{try{n(t,s,l=>{l?.httpCode===200&&(this.userIdentifiedInWorkspace=!0),u()})}catch(l){console.error("Rokt Kit: Workspace IDSync search failed",l),this._workspaceLastSearchedIdentitiesKey=void 0,u()}}))}onLoginComplete(e,t){return this.handleIdentityComplete(e,"onLoginComplete")}onLogoutComplete(e,t){return this.userIdentifiedInWorkspace=!1,this._workspaceSearchInFlightPromise=null,this._workspaceLastSearchedIdentitiesKey=void 0,this.handleIdentityComplete(e,"onLogoutComplete")}onModifyComplete(e,t){return this.handleIdentityComplete(e,"onModifyComplete")}selectPlacements(e){if(this._workspaceSearchInFlightPromise){const t=this._workspaceSearchInFlightPromise;return Promise.race([t,new Promise(n=>setTimeout(n,Te))]).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||[],c=s.filteredUser||null,u=c?c.getMPID():null;let l;s?s.filterUserAttributes?l=s.filterUserAttributes(r,o):l=r:(console.warn("Rokt Kit: No filters available, using user attributes"),l=r),this.userAttributes=v(l);const g=this._onboardingExpProvider==="Optimizely"?this.fetchOptimizely():{},x=this.returnUserIdentities(c),O=this.returnLocalSessionAttributes(),P=me(q(this.loggingService)),f=this.readMpSessionId(),k={...x,...l,...g,...O,...P.length?{[be]:JSON.stringify(P)}:{},...this.userIdentifiedInWorkspace?{[Re]:!0}:{},...f?{[Le]:f}:{},mpid:u},A={...e,attributes:k},R=this.launcher.selectPlacements(A),h=()=>this.logSelectPlacementsEvent(k);return Promise.resolve(R).then(We=>We?.context?.sessionId?.then(je=>this.setRoktSessionId(je))).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 S=p;function xe(){return L}function Ge(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:S}:(i.kits={},i.kits[d]={constructor:S}),window.console.log("Successfully registered "+d+" to your mParticle configuration")}return typeof window<"u"&&window.mParticle&&a().addForwarder&&a().addForwarder({name:d,constructor:S,getId:xe}),U.register=Ge,Object.defineProperty(U,Symbol.toStringTag,{value:"Module"}),U})({});
|
|
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})({});
|
|
2
2
|
//# sourceMappingURL=Rokt-Kit.iife.js.map
|