@mparticle/web-rokt-kit 1.28.0 → 1.28.1
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 +99 -162
- 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 V=["billingaddress1","billingaddress2","billingcity","billingstate","billingzipcode","cartitems","ccbin","confirmationref","conversiontype","country","couponcode","currency","language","paymentserviceprovider","paymentserviceproviderattribute","paymenttype","shippingaddress1","shippingcity","shippingcountry","shippingmethod","shippingstate","shippingzipcode","totalprice"],q=new Set(V);function z(n){return q.has(n.toLowerCase())}function A(n){const e={},t=n||{},i=Object.keys(t);for(let r=0;r<i.length;r++){const s=i[r];z(s)||(e[s]=t[s])}return e}const d="Rokt",w=181,J="selectPlacements",X="apps.roktecommerce.com",$=.1,v={LOGIN:"login",LOGOUT:"logout",MODIFY_USER:"modify_user",IDENTIFY:"identify"},Z="ThankYouPageJourney",ee="rokt-launcher",te="rokt-thank-you-element",ie="userIdentifiedInWorkspace",ne=500,P={UNKNOWN_ERROR:"UNKNOWN_ERROR",UNHANDLED_EXCEPTION:"UNHANDLED_EXCEPTION",IDENTITY_REQUEST:"IDENTITY_REQUEST"},L={ERROR:"ERROR",INFO:"INFO",WARNING:"WARNING"},re="apps.rokt-api.com/v1/log",se="apps.rokt-api.com/v1/errors",oe=10;function a(){return window.mParticle}function C(n,e){const i=[W(n),"/wsdk/integrations/launcher.js"].join("");return!e||e.length===0?i:i+"?extensions="+e.join(",")}function M(n){return[W(n),"/rokt-elements/rokt-element-thank-you.js"].join("")}function W(n){return["https://",typeof n<"u"?n:"apps.rokt-api.com"].join("")}function K(n,e,t){if(document.getElementById(n))return;const i=document.head||document.body,r=document.createElement("script");r.id=n,r.type="text/javascript",r.src=e,r.async=!0,r.crossOrigin="anonymous",r.fetchPriority="high",t?.onLoad&&(r.onload=t.onLoad),t?.onError&&(r.onerror=t.onError),i.appendChild(r)}function T(n){return n!=null&&typeof n=="object"&&Array.isArray(n)===!1}function b(n){if(!n)return[];try{return JSON.parse(n.replace(/"/g,'"'))}catch{console.error("Settings string contains invalid JSON")}return[]}function D(n){const e=n?b(n):[],t=[],i=[];let r=!1;for(let s=0;s<e.length;s++){const o=e[s].value;o==="thank-you-journey"?(r=!0,i.push(Z)):t.push(o)}return{roktExtensionsQueryParams:t,legacyRoktExtensions:i,loadThankYouElement:r}}async function ae(n,e){const t=[];if(e)for(const i of n)t.push(e.use(i));return Promise.all(t)}function Y(n){if(!n)return{};const e={};for(let t=0;t<n.length;t++){const i=n[t];e[i.jsmap]=i.value}return e}function x(n){const e={};if(!Array.isArray(n))return e;for(let t=0;t<n.length;t++){const i=n[t];if(!i||!f(i.value)||!f(i.map))continue;const r=i.value,s=i.map;e[r]||(e[r]=[]),e[r].push({eventAttributeKey:s,conditions:Array.isArray(i.conditions)?i.conditions:[]})}return e}function F(n,e,t){return a().generateHash([n,e,t].join(""))}function I(n){return n==null?!0:typeof n=="object"?Object.keys(n).length===0:Array.isArray(n)?n.length===0:!1}function f(n){return typeof n=="string"}function ce(n){let i="mParticle_wsdkv_"+a().getVersion()+"_kitv_"+"1.28.0";return n&&(i+="_"+n),i}function Q(n){let e=5381;for(let t=0;t<n.length;t++)e=(e<<5)+e+n.charCodeAt(t),e=e&e;return e}function N(n){const e=document.createElement("iframe");e.style.display="none",e.setAttribute("sandbox","allow-scripts allow-same-origin"),e.src=n,e.onload=function(){e.onload=null,e.parentNode&&e.parentNode.removeChild(e)};const t=document.body||document.head;t&&t.appendChild(e)}function j(n,e){const t=Q(window.location.origin);if(m._allowedOriginHashes.indexOf(t)===-1||Math.random()>=$)return;const r=window.__rokt_li_guid__;if(!r)return;const s=window.location.href.split("?")[0].split("#")[0],o="version="+encodeURIComponent(e??"")+"&launcherInstanceGuid="+encodeURIComponent(r)+"&pageUrl="+encodeURIComponent(s);N("https://"+(n||"apps.rokt.com")+"/v1/wsdk-init/index.html?"+o),N("https://"+X+"/v1/wsdk-init/index.html?"+o+"&isControl=true")}function ue(){return typeof window<"u"&&!!window.location?.search?.toLowerCase().includes("mp_enable_logging=true")}function le(){return typeof window<"u"?window.location?.href:void 0}function de(){return typeof window<"u"?window.navigator?.userAgent:void 0}class B{constructor(){this._logCount={}}incrementAndCheck(e){const i=(this._logCount[e]||0)+1;return this._logCount[e]=i,i>oe}}class U{constructor(e,t,i,r,s){this._reporter="mp-wsdk";const o=e.isLoggingEnabled;this._integrationName=t||"",this._launcherInstanceGuid=i,this._accountId=r||null,this._rateLimiter=s||new B,this._isEnabled=ue()||o}send(e,t,i,r,s,o){if(!(!this._isEnabled||this._rateLimiter.incrementAndCheck(t)))try{const c={additionalInformation:{message:i,version:this._integrationName},severity:t,code:r||P.UNKNOWN_ERROR,url:le(),deviceInfo:de(),stackTrace:s,reporter:this._reporter,integration:this._integrationName},l={Accept:"text/plain;charset=UTF-8","Content-Type":"application/json","rokt-launcher-version":this._integrationName,"rokt-wsdk-version":"joint"};this._launcherInstanceGuid&&(l["rokt-launcher-instance-guid"]=this._launcherInstanceGuid),this._accountId&&(l["rokt-account-id"]=this._accountId),fetch(e,{method:"POST",headers:l,body:JSON.stringify(c)}).catch(u=>{console.error("ReportingTransport: Failed to send log",u),o&&o(u)})}catch(c){console.error("ReportingTransport: Failed to send log",c),o&&o(c)}}}class H{constructor(e,t,i,r,s){this._transport=new U(e,t,i,r,s),this._errorUrl="https://"+(e?.errorUrl||se)}report(e){if(!e)return;const t=e.severity||L.ERROR;this._transport.send(this._errorUrl,t,e.message,e.code,e.stackTrace)}}class G{constructor(e,t,i,r,s,o){this._transport=new U(e,i,r,s,o),this._loggingUrl="https://"+(e?.loggingUrl||re),this._errorReportingService=t}log(e){e&&this._transport.send(this._loggingUrl,L.INFO,e.message,e.code,void 0,t=>{this._errorReportingService&&this._errorReportingService.report({message:"LoggingService: Failed to send log: "+t.message,code:P.UNKNOWN_ERROR,severity:L.ERROR})})}}const h=class h{constructor(){this.name=d,this.id=w,this.moduleId=w,this.isInitialized=!1,this.launcher=null,this.filters={},this.userAttributes={},this.userIdentifiedInWorkspace=!1,this.testHelpers=null,this.placementEventMappingLookup={},this.placementEventAttributeMappingLookup={},this.batchQueue=[],this.batchStreamQueue=[],this.pendingIdentityEvents=[],this.integrationName=null,this.errorReportingService=null,this.loggingService=null,this._thankYouElementOnLoadCallback=null,this._isThankYouElementLoaded=!1,this._workspaceSearchInFlightPromise=null}getEventAttributeValue(e,t){const i=e&&e.EventAttributes;return!i||typeof i[t]>"u"?null:i[t]}doesEventAttributeConditionMatch(e,t){if(!e||!f(e.operator))return!1;const i=e.operator.toLowerCase(),r=e.attributeValue;return i==="exists"?t!==null:t==null?!1:i==="equals"?String(t)===String(r):i==="contains"?String(t).indexOf(String(r))!==-1:!1}doesEventMatchRule(e,t){if(!t||!f(t.eventAttributeKey))return!1;const i=t.conditions;if(!Array.isArray(i))return!1;const r=this.getEventAttributeValue(e,t.eventAttributeKey);if(i.length===0)return r!==null;for(let s=0;s<i.length;s++)if(!this.doesEventAttributeConditionMatch(i[s],r))return!1;return!0}applyPlacementEventAttributeMapping(e){const t=Object.keys(this.placementEventAttributeMappingLookup);for(let i=0;i<t.length;i++){const r=t[i],s=this.placementEventAttributeMappingLookup[r];if(I(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)}}isLauncherReadyToAttach(){return!!window.Rokt&&typeof window.Rokt.createLauncher=="function"}returnUserIdentities(e){if(!e||!e.getUserIdentities)return{};const t=e.getUserIdentities().userIdentities;return this.replaceOtherIdentityWithEmailsha256(t)}returnLocalSessionAttributes(){return!a().Rokt||typeof a().Rokt.getLocalSessionAttributes!="function"?{}:I(this.placementEventMappingLookup)&&I(this.placementEventAttributeMappingLookup)?{}:a().Rokt.getLocalSessionAttributes()}replaceOtherIdentityWithEmailsha256(e){const t={...e||{}},i=this._mappedEmailSha256Key;return i&&e[i]&&(t[h.EMAIL_SHA256_KEY]=e[i]),i&&delete t[i],t}logSelectPlacementsEvent(e){if(!window.mParticle||typeof a().logEvent!="function"||!T(e))return;const t=a().EventType.Other;a().logEvent(J,t,e)}buildIdentityEvent(e,t){const i=t.getMPID(),r=a()&&a().sessionManager&&typeof a().sessionManager.getSession=="function"?a().sessionManager.getSession():void 0,s=this.returnUserIdentities(t);return{event_type:e,data:{timestamp_unixtime_ms:Date.now(),session_uuid:r??void 0,mpid:i,user_identities:s,user_attributes:this.userAttributes}}}mergePendingIdentityEvents(e){if(this.pendingIdentityEvents.length===0)return e;const t={...e,events:[...e.events??[],...this.pendingIdentityEvents]};return this.pendingIdentityEvents=[],t}drainBatchQueue(){this.batchQueue.forEach(e=>{this.processBatch(e)}),this.batchQueue=[]}processBatch(e){if(!this.isKitReady())return this.batchQueue.push(e),"Batch queued for forwarder: "+d;const t=this.enrichCommerceEventTypes(this.mergePendingIdentityEvents(e));return this.sendBatchStream(t),"Successfully sent batch to forwarder: "+d}enrichCommerceEventTypes(e){if(!e.events)return e;for(const t of e.events){if(t.event_type!=="commerce_event")continue;const{data:i}=t;if(!i)continue;const r=i.custom_flags?.["Rokt.CommerceEventType"];r&&T(i.product_action)&&(i.product_action.action=r)}return e}sendBatchStream(e){if(window.Rokt&&typeof window.Rokt.__batch_stream__=="function"){if(this.batchStreamQueue.length){const t=this.batchStreamQueue;this.batchStreamQueue=[];for(let i=0;i<t.length;i++)window.Rokt.__batch_stream__(t[i])}window.Rokt.__batch_stream__(e)}else this.batchStreamQueue.push(e)}setRoktSessionId(e){if(!(!e||typeof e!="string"))try{const t=a().getInstance();t&&typeof t.setIntegrationAttribute=="function"&&t.setIntegrationAttribute(w,{roktSessionId:e})}catch{}}attachLauncher(e,t,i=[]){const r=a()&&a().sessionManager&&typeof a().sessionManager.getSession=="function"?a().sessionManager.getSession():void 0,s={accountId:e,...t||{},...r?{mpSessionId:r}:{}};let o;this.isPartnerInLocalLauncherTestGroup()?o=Promise.resolve(window.Rokt.createLocalLauncher(s)):o=window.Rokt.createLauncher(s),o.then(async c=>{await ae(i,c),this.initRoktLauncher(c)}).catch(c=>{console.error("Error creating Rokt launcher:",c)})}initRoktLauncher(e){window.Rokt&&(window.Rokt.currentLauncher=e),this.launcher=e;const t=a().Rokt?.filters;t?(this.filters=t,t.filteredUser?this._workspaceSearchInFlightPromise=this.search(t.filteredUser):console.warn("Rokt Kit: No filtered user has been set.")):console.warn("Rokt Kit: No filters have been set."),this.isInitialized=!0,j(this.domain,this.integrationName),a().Rokt.attachKit(this),this.drainBatchQueue()}fetchOptimizely(){const e=a()._getActiveForwarders().filter(t=>t.name==="Optimizely");try{if(e.length>0&&window.optimizely){const t=window.optimizely.get("state");return!t||!t.getActiveExperimentIds?{}:t.getActiveExperimentIds().reduce((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)}isPartnerInLocalLauncherTestGroup(){return!!(a().config&&a().config.isLocalLauncherEnabled&&this.isAssignedToSampleGroup())}isAssignedToSampleGroup(){return Math.random()>.5}captureTiming(e){window&&a()&&a().captureTiming&&e&&a().captureTiming(e)}init(e,t,i,r,s){const o=e,c=o.accountId;this.userAttributes=A(s),this._onboardingExpProvider=o.onboardingExpProvider;const l=b(o.placementEventMapping);this.placementEventMappingLookup=Y(l);const u=b(o.placementEventAttributeMapping);this.placementEventAttributeMappingLookup=x(u),o.hashedEmailUserIdentityType&&(this._mappedEmailSha256Key=o.hashedEmailUserIdentityType.toLowerCase()),this._workspaceIdSyncApiKey=f(o.workspaceIdSyncApiKey)?o.workspaceIdSyncApiKey:void 0;const E=a().Rokt?.domain,{roktExtensionsQueryParams:O,legacyRoktExtensions:k,loadThankYouElement:R}=D(o.roktExtensions),p={...a().Rokt?.launcherOptions||{}};this.integrationName=ce(p.integrationName),p.integrationName=this.integrationName,this.domain=E;const _={loggingUrl:o.loggingUrl,errorUrl:o.errorUrl,isLoggingEnabled:a().config?.isLoggingEnabled===!0},y=new H(_,this.integrationName,window.__rokt_li_guid__,o.accountId),S=new G(_,y,this.integrationName,window.__rokt_li_guid__,o.accountId);return this.errorReportingService=y,this.loggingService=S,a()._registerErrorReportingService&&a()._registerErrorReportingService(y),a()._registerLoggingService&&a()._registerLoggingService(S),i?(this.testHelpers={generateLauncherScript:C,generateThankYouElementScript:M,extractRoktExtensionConfig:D,hashEventMessage:F,parseSettingsString:b,generateMappedEventLookup:Y,generateMappedEventAttributeLookup:x,sendAdBlockMeasurementSignals:j,createAutoRemovedIframe:N,djb2:Q,setAllowedOriginHashes:g=>{h._allowedOriginHashes=g},ReportingTransport:U,ErrorReportingService:H,LoggingService:G,RateLimiter:B,ErrorCodes:P,WSDKErrorSeverity:L},this.attachLauncher(c,p),"Successfully initialized: "+d):(R&&(a().Rokt.flushOnShoppableAdsReadyMessageQueue?.(this),K(te,M(E),{onLoad:()=>{this._isThankYouElementLoaded=!0,this._thankYouElementOnLoadCallback&&this._thankYouElementOnLoadCallback()},onError:g=>{console.error("Error loading Rokt Thank You Element script:",g)}})),this.isLauncherReadyToAttach()?this.attachLauncher(c,p,k):(K(ee,C(E,O),{onLoad:()=>{this.isLauncherReadyToAttach()?this.attachLauncher(c,p,k):console.error("Rokt object is not available after script load.")},onError:g=>{console.error("Error loading Rokt launcher script:",g)}}),this.captureTiming(h.PERFORMANCE_MARKS.RoktScriptAppended)),"Successfully initialized: "+d)}process(e){if(!this.isKitReady())return"Kit not ready for forwarder: "+d;if(typeof a().Rokt?.setLocalSessionAttribute=="function"&&(I(this.placementEventAttributeMappingLookup)||this.applyPlacementEventAttributeMapping(e),!I(this.placementEventMappingLookup))){const t=F(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 z(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,i){const r=e;return this.userAttributes=A(e.getAllUserAttributes()),this.pendingIdentityEvents.push(this.buildIdentityEvent(t,r)),"Successfully called "+i+" for forwarder: "+d}onUserIdentified(e){const t=e;return this.filters.filteredUser=t,this._workspaceSearchInFlightPromise=this.search(t),this.handleIdentityComplete(e,v.IDENTIFY,"onUserIdentified")}search(e){const t=this._workspaceIdSyncApiKey;if(!t)return this.userIdentifiedInWorkspace=!1,this._workspaceLastSearchedIdentitiesKey=void 0,Promise.resolve();const i=a().Identity?.search;if(typeof i!="function")return this.userIdentifiedInWorkspace=!1,this._workspaceLastSearchedIdentitiesKey=void 0,Promise.resolve();const r=e.getUserIdentities?e.getUserIdentities().userIdentities:null,s={};if(r)for(const l of Object.keys(r)){const u=r[l];f(u)&&u.length>0&&(s[l]=u)}const o=Object.keys(s);if(o.length===0)return this.userIdentifiedInWorkspace=!1,this._workspaceLastSearchedIdentitiesKey=void 0,Promise.resolve();const c=o.sort().map(l=>`${l}=${s[l]}`).join("&");return c===this._workspaceLastSearchedIdentitiesKey?this._workspaceSearchInFlightPromise||Promise.resolve():(this.userIdentifiedInWorkspace=!1,this._workspaceLastSearchedIdentitiesKey=c,new Promise(l=>{try{i(t,s,u=>{u?.httpCode===200&&(this.userIdentifiedInWorkspace=!0),l()})}catch(u){console.error("Rokt Kit: Workspace IDSync search failed",u),this._workspaceLastSearchedIdentitiesKey=void 0,l()}}))}onLoginComplete(e,t){return this.handleIdentityComplete(e,v.LOGIN,"onLoginComplete")}onLogoutComplete(e,t){return this.userIdentifiedInWorkspace=!1,this._workspaceSearchInFlightPromise=null,this._workspaceLastSearchedIdentitiesKey=void 0,this.handleIdentityComplete(e,v.LOGOUT,"onLogoutComplete")}onModifyComplete(e,t){return this.handleIdentityComplete(e,v.MODIFY_USER,"onModifyComplete")}selectPlacements(e){if(this._workspaceSearchInFlightPromise){const t=this._workspaceSearchInFlightPromise;return Promise.race([t,new Promise(i=>setTimeout(i,ne))]).then(()=>this._dispatchPlacements(e))}return this._dispatchPlacements(e)}_dispatchPlacements(e){const t=e&&e.attributes||{},r={...A(this.userAttributes),...t},s=this.filters||{},o=s.userAttributeFilters||[],c=s.filteredUser||null,l=c?c.getMPID():null;let u;s?s.filterUserAttributes?u=s.filterUserAttributes(r,o):u=r:(console.warn("Rokt Kit: No filters available, using user attributes"),u=r),this.userAttributes=A(u);const E=this._onboardingExpProvider==="Optimizely"?this.fetchOptimizely():{},O=this.returnUserIdentities(c),k=this.returnLocalSessionAttributes(),R={...O,...u,...E,...k,...this.userIdentifiedInWorkspace?{[ie]:!0}:{},mpid:l},p={...e,attributes:R},_=this.launcher.selectPlacements(p),y=()=>this.logSelectPlacementsEvent(R);return Promise.resolve(_).then(S=>S?.context?.sessionId?.then(g=>this.setRoktSessionId(g))).catch(()=>{}).finally(y),_}hashAttributes(e){return this.isKitReady()?this.launcher.hashAttributes(e):(console.error("Rokt Kit: Not initialized"),null)}use(e){return this.isKitReady()?!e||!f(e)?Promise.reject(new Error("Rokt Kit: Invalid extension name")):this.launcher.use(e):(console.error("Rokt Kit: Not initialized"),Promise.reject(new Error("Rokt Kit: Not initialized")))}onShoppableAdsReady(e){this._isThankYouElementLoaded?e():this._thankYouElementOnLoadCallback=e}};h._allowedOriginHashes=[-553112570,549508659],h.PERFORMANCE_MARKS={RoktScriptAppended:"mp:RoktScriptAppended"},h.EMAIL_SHA256_KEY="emailsha256";let m=h;function he(){return w}function pe(n){if(!n){window.console.log("You must pass a config object to register the kit "+d);return}if(!T(n)){window.console.log("'config' must be an object. You passed in a "+typeof n);return}T(n.kits)?n.kits[d]={constructor:m}:(n.kits={},n.kits[d]={constructor:m}),window.console.log("Successfully registered "+d+" to your mParticle configuration")}typeof window<"u"&&window.mParticle&&a().addForwarder&&a().addForwarder({name:d,constructor:m,getId:he});exports.register=pe;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const q=["billingaddress1","billingaddress2","billingcity","billingstate","billingzipcode","cartitems","ccbin","confirmationref","conversiontype","country","couponcode","currency","language","paymentserviceprovider","paymentserviceproviderattribute","paymenttype","shippingaddress1","shippingcity","shippingcountry","shippingmethod","shippingstate","shippingzipcode","totalprice"],B=new Set(q);function z(n){return B.has(n.toLowerCase())}function S(n){const e={},t=n||{},i=Object.keys(t);for(let r=0;r<i.length;r++){const s=i[r];z(s)||(e[s]=t[s])}return e}const d="Rokt",b=181,J="selectPlacements",Q="apps.roktecommerce.com",X=.1,$="ThankYouPageJourney",Z="rokt-launcher",ee="rokt-thank-you-element",te="userIdentifiedInWorkspace",ie=500,O={UNKNOWN_ERROR:"UNKNOWN_ERROR",UNHANDLED_EXCEPTION:"UNHANDLED_EXCEPTION",IDENTITY_REQUEST:"IDENTITY_REQUEST"},L={ERROR:"ERROR",INFO:"INFO",WARNING:"WARNING"},ne="apps.rokt-api.com/v1/log",re="apps.rokt-api.com/v1/errors",se=10;function a(){return window.mParticle}function C(n,e){const i=[W(n),"/wsdk/integrations/launcher.js"].join("");return!e||e.length===0?i:i+"?extensions="+e.join(",")}function U(n){return[W(n),"/rokt-elements/rokt-element-thank-you.js"].join("")}function W(n){return["https://",typeof n<"u"?n:"apps.rokt-api.com"].join("")}function K(n,e,t){if(document.getElementById(n))return;const i=document.head||document.body,r=document.createElement("script");r.id=n,r.type="text/javascript",r.src=e,r.async=!0,r.crossOrigin="anonymous",r.fetchPriority="high",t?.onLoad&&(r.onload=t.onLoad),t?.onError&&(r.onerror=t.onError),i.appendChild(r)}function T(n){return n!=null&&typeof n=="object"&&Array.isArray(n)===!1}function w(n){if(!n)return[];try{return JSON.parse(n.replace(/"/g,'"'))}catch{console.error("Settings string contains invalid JSON")}return[]}function M(n){const e=n?w(n):[],t=[],i=[];let r=!1;for(let s=0;s<e.length;s++){const o=e[s].value;o==="thank-you-journey"?(r=!0,i.push($)):t.push(o)}return{roktExtensionsQueryParams:t,legacyRoktExtensions:i,loadThankYouElement:r}}async function oe(n,e){const t=[];if(e)for(const i of n)t.push(e.use(i));return Promise.all(t)}function x(n){if(!n)return{};const e={};for(let t=0;t<n.length;t++){const i=n[t];e[i.jsmap]=i.value}return e}function D(n){const e={};if(!Array.isArray(n))return e;for(let t=0;t<n.length;t++){const i=n[t];if(!i||!f(i.value)||!f(i.map))continue;const r=i.value,s=i.map;e[r]||(e[r]=[]),e[r].push({eventAttributeKey:s,conditions:Array.isArray(i.conditions)?i.conditions:[]})}return e}function j(n,e,t){return a().generateHash([n,e,t].join(""))}function k(n){return n==null?!0:typeof n=="object"?Object.keys(n).length===0:Array.isArray(n)?n.length===0:!1}function f(n){return typeof n=="string"}function ae(n){let i="mParticle_wsdkv_"+a().getVersion()+"_kitv_"+"1.28.1";return n&&(i+="_"+n),i}function G(n){let e=5381;for(let t=0;t<n.length;t++)e=(e<<5)+e+n.charCodeAt(t),e=e&e;return e}function N(n){const e=document.createElement("iframe");e.style.display="none",e.setAttribute("sandbox","allow-scripts allow-same-origin"),e.src=n,e.onload=function(){e.onload=null,e.parentNode&&e.parentNode.removeChild(e)};const t=document.body||document.head;t&&t.appendChild(e)}function Y(n,e){const t=G(window.location.origin);if(m._allowedOriginHashes.indexOf(t)===-1||Math.random()>=X)return;const r=window.__rokt_li_guid__;if(!r)return;const s=window.location.href.split("?")[0].split("#")[0],o="version="+encodeURIComponent(e??"")+"&launcherInstanceGuid="+encodeURIComponent(r)+"&pageUrl="+encodeURIComponent(s);N("https://"+(n||"apps.rokt.com")+"/v1/wsdk-init/index.html?"+o),N("https://"+Q+"/v1/wsdk-init/index.html?"+o+"&isControl=true")}function ce(){return typeof window<"u"&&!!window.location?.search?.toLowerCase().includes("mp_enable_logging=true")}function le(){return typeof window<"u"?window.location?.href:void 0}function ue(){return typeof window<"u"?window.navigator?.userAgent:void 0}class V{constructor(){this._logCount={}}incrementAndCheck(e){const i=(this._logCount[e]||0)+1;return this._logCount[e]=i,i>se}}class P{constructor(e,t,i,r,s){this._reporter="mp-wsdk";const o=e.isLoggingEnabled;this._integrationName=t||"",this._launcherInstanceGuid=i,this._accountId=r||null,this._rateLimiter=s||new V,this._isEnabled=ce()||o}send(e,t,i,r,s,o){if(!(!this._isEnabled||this._rateLimiter.incrementAndCheck(t)))try{const c={additionalInformation:{message:i,version:this._integrationName},severity:t,code:r||O.UNKNOWN_ERROR,url:le(),deviceInfo:ue(),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)}).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 F{constructor(e,t,i,r,s){this._transport=new P(e,t,i,r,s),this._errorUrl="https://"+(e?.errorUrl||re)}report(e){if(!e)return;const t=e.severity||L.ERROR;this._transport.send(this._errorUrl,t,e.message,e.code,e.stackTrace)}}class H{constructor(e,t,i,r,s,o){this._transport=new P(e,i,r,s,o),this._loggingUrl="https://"+(e?.loggingUrl||ne),this._errorReportingService=t}log(e){e&&this._transport.send(this._loggingUrl,L.INFO,e.message,e.code,void 0,t=>{this._errorReportingService&&this._errorReportingService.report({message:"LoggingService: Failed to send log: "+t.message,code:O.UNKNOWN_ERROR,severity:L.ERROR})})}}const h=class h{constructor(){this.name=d,this.id=b,this.moduleId=b,this.isInitialized=!1,this.launcher=null,this.filters={},this.userAttributes={},this.userIdentifiedInWorkspace=!1,this.testHelpers=null,this.placementEventMappingLookup={},this.placementEventAttributeMappingLookup={},this.integrationName=null,this.errorReportingService=null,this.loggingService=null,this._thankYouElementOnLoadCallback=null,this._isThankYouElementLoaded=!1,this._workspaceSearchInFlightPromise=null}getEventAttributeValue(e,t){const i=e&&e.EventAttributes;return!i||typeof i[t]>"u"?null:i[t]}doesEventAttributeConditionMatch(e,t){if(!e||!f(e.operator))return!1;const i=e.operator.toLowerCase(),r=e.attributeValue;return i==="exists"?t!==null:t==null?!1:i==="equals"?String(t)===String(r):i==="contains"?String(t).indexOf(String(r))!==-1:!1}doesEventMatchRule(e,t){if(!t||!f(t.eventAttributeKey))return!1;const i=t.conditions;if(!Array.isArray(i))return!1;const r=this.getEventAttributeValue(e,t.eventAttributeKey);if(i.length===0)return r!==null;for(let s=0;s<i.length;s++)if(!this.doesEventAttributeConditionMatch(i[s],r))return!1;return!0}applyPlacementEventAttributeMapping(e){const t=Object.keys(this.placementEventAttributeMappingLookup);for(let i=0;i<t.length;i++){const r=t[i],s=this.placementEventAttributeMappingLookup[r];if(k(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)}}isLauncherReadyToAttach(){return!!window.Rokt&&typeof window.Rokt.createLauncher=="function"}returnUserIdentities(e){if(!e||!e.getUserIdentities)return{};const t=e.getUserIdentities().userIdentities;return this.replaceOtherIdentityWithEmailsha256(t)}returnLocalSessionAttributes(){return!a().Rokt||typeof a().Rokt.getLocalSessionAttributes!="function"?{}:k(this.placementEventMappingLookup)&&k(this.placementEventAttributeMappingLookup)?{}:a().Rokt.getLocalSessionAttributes()}replaceOtherIdentityWithEmailsha256(e){const t={...e||{}},i=this._mappedEmailSha256Key;return i&&e[i]&&(t[h.EMAIL_SHA256_KEY]=e[i]),i&&delete t[i],t}logSelectPlacementsEvent(e){if(!window.mParticle||typeof a().logEvent!="function"||!T(e))return;const t=a().EventType.Other;a().logEvent(J,t,e)}setRoktSessionId(e){if(!(!e||typeof e!="string"))try{const t=a().getInstance();t&&typeof t.setIntegrationAttribute=="function"&&t.setIntegrationAttribute(b,{roktSessionId:e})}catch{}}attachLauncher(e,t,i=[]){const r=a()&&a().sessionManager&&typeof a().sessionManager.getSession=="function"?a().sessionManager.getSession():void 0,s={accountId:e,...t||{},...r?{mpSessionId:r}:{}};let o;this.isPartnerInLocalLauncherTestGroup()?o=Promise.resolve(window.Rokt.createLocalLauncher(s)):o=window.Rokt.createLauncher(s),o.then(async c=>{await oe(i,c),this.initRoktLauncher(c)}).catch(c=>{console.error("Error creating Rokt launcher:",c)})}initRoktLauncher(e){window.Rokt&&(window.Rokt.currentLauncher=e),this.launcher=e;const t=a().Rokt?.filters;t?(this.filters=t,t.filteredUser?this._workspaceSearchInFlightPromise=this.search(t.filteredUser):console.warn("Rokt Kit: No filtered user has been set.")):console.warn("Rokt Kit: No filters have been set."),this.isInitialized=!0,Y(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)}isPartnerInLocalLauncherTestGroup(){return!!(a().config&&a().config.isLocalLauncherEnabled&&this.isAssignedToSampleGroup())}isAssignedToSampleGroup(){return Math.random()>.5}captureTiming(e){window&&a()&&a().captureTiming&&e&&a().captureTiming(e)}init(e,t,i,r,s){const o=e,c=o.accountId;this.userAttributes=S(s),this._onboardingExpProvider=o.onboardingExpProvider;const u=w(o.placementEventMapping);this.placementEventMappingLookup=x(u);const l=w(o.placementEventAttributeMapping);this.placementEventAttributeMappingLookup=D(l),o.hashedEmailUserIdentityType&&(this._mappedEmailSha256Key=o.hashedEmailUserIdentityType.toLowerCase()),this._workspaceIdSyncApiKey=f(o.workspaceIdSyncApiKey)?o.workspaceIdSyncApiKey:void 0;const E=a().Rokt?.domain,{roktExtensionsQueryParams:v,legacyRoktExtensions:I,loadThankYouElement:R}=M(o.roktExtensions),p={...a().Rokt?.launcherOptions||{}};this.integrationName=ae(p.integrationName),p.integrationName=this.integrationName,this.domain=E;const _={loggingUrl:o.loggingUrl,errorUrl:o.errorUrl,isLoggingEnabled:a().config?.isLoggingEnabled===!0},y=new F(_,this.integrationName,window.__rokt_li_guid__,o.accountId),A=new H(_,y,this.integrationName,window.__rokt_li_guid__,o.accountId);return this.errorReportingService=y,this.loggingService=A,a()._registerErrorReportingService&&a()._registerErrorReportingService(y),a()._registerLoggingService&&a()._registerLoggingService(A),i?(this.testHelpers={generateLauncherScript:C,generateThankYouElementScript:U,extractRoktExtensionConfig:M,hashEventMessage:j,parseSettingsString:w,generateMappedEventLookup:x,generateMappedEventAttributeLookup:D,sendAdBlockMeasurementSignals:Y,createAutoRemovedIframe:N,djb2:G,setAllowedOriginHashes:g=>{h._allowedOriginHashes=g},ReportingTransport:P,ErrorReportingService:F,LoggingService:H,RateLimiter:V,ErrorCodes:O,WSDKErrorSeverity:L},this.attachLauncher(c,p),"Successfully initialized: "+d):(R&&(a().Rokt.flushOnShoppableAdsReadyMessageQueue?.(this),K(ee,U(E),{onLoad:()=>{this._isThankYouElementLoaded=!0,this._thankYouElementOnLoadCallback&&this._thankYouElementOnLoadCallback()},onError:g=>{console.error("Error loading Rokt Thank You Element script:",g)}})),this.isLauncherReadyToAttach()?this.attachLauncher(c,p,I):(K(Z,C(E,v),{onLoad:()=>{this.isLauncherReadyToAttach()?this.attachLauncher(c,p,I):console.error("Rokt object is not available after script load.")},onError:g=>{console.error("Error loading Rokt launcher script:",g)}}),this.captureTiming(h.PERFORMANCE_MARKS.RoktScriptAppended)),"Successfully initialized: "+d)}process(e){if(!this.isKitReady())return"Kit not ready for forwarder: "+d;if(typeof a().Rokt?.setLocalSessionAttribute=="function"&&(k(this.placementEventAttributeMappingLookup)||this.applyPlacementEventAttributeMapping(e),!k(this.placementEventMappingLookup))){const t=j(e.EventDataType,e.EventCategory,e.EventName??"");this.placementEventMappingLookup[String(t)]&&a().Rokt.setLocalSessionAttribute?.(this.placementEventMappingLookup[String(t)],!0)}return"Successfully sent to forwarder: "+d}setExtensionData(e){if(!this.isKitReady()){console.error("Rokt Kit: Not initialized");return}window.Rokt.setExtensionData(e)}setUserAttribute(e,t){return z(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=S(e.getAllUserAttributes()),"Successfully called "+t+" for forwarder: "+d}onUserIdentified(e){const t=e;return this.filters.filteredUser=t,this._workspaceSearchInFlightPromise=this.search(t),this.handleIdentityComplete(e,"onUserIdentified")}search(e){const t=this._workspaceIdSyncApiKey;if(!t)return this.userIdentifiedInWorkspace=!1,this._workspaceLastSearchedIdentitiesKey=void 0,Promise.resolve();const i=a().Identity?.search;if(typeof i!="function")return this.userIdentifiedInWorkspace=!1,this._workspaceLastSearchedIdentitiesKey=void 0,Promise.resolve();const r=e.getUserIdentities?e.getUserIdentities().userIdentities:null,s={};if(r)for(const u of Object.keys(r)){const l=r[u];f(l)&&l.length>0&&(s[u]=l)}const o=Object.keys(s);if(o.length===0)return this.userIdentifiedInWorkspace=!1,this._workspaceLastSearchedIdentitiesKey=void 0,Promise.resolve();const c=o.sort().map(u=>`${u}=${s[u]}`).join("&");return c===this._workspaceLastSearchedIdentitiesKey?this._workspaceSearchInFlightPromise||Promise.resolve():(this.userIdentifiedInWorkspace=!1,this._workspaceLastSearchedIdentitiesKey=c,new Promise(u=>{try{i(t,s,l=>{l?.httpCode===200&&(this.userIdentifiedInWorkspace=!0),u()})}catch(l){console.error("Rokt Kit: Workspace IDSync search failed",l),this._workspaceLastSearchedIdentitiesKey=void 0,u()}}))}onLoginComplete(e,t){return this.handleIdentityComplete(e,"onLoginComplete")}onLogoutComplete(e,t){return this.userIdentifiedInWorkspace=!1,this._workspaceSearchInFlightPromise=null,this._workspaceLastSearchedIdentitiesKey=void 0,this.handleIdentityComplete(e,"onLogoutComplete")}onModifyComplete(e,t){return this.handleIdentityComplete(e,"onModifyComplete")}selectPlacements(e){if(this._workspaceSearchInFlightPromise){const t=this._workspaceSearchInFlightPromise;return Promise.race([t,new Promise(i=>setTimeout(i,ie))]).then(()=>this._dispatchPlacements(e))}return this._dispatchPlacements(e)}_dispatchPlacements(e){const t=e&&e.attributes||{},r={...S(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=S(l);const E=this._onboardingExpProvider==="Optimizely"?this.fetchOptimizely():{},v=this.returnUserIdentities(c),I=this.returnLocalSessionAttributes(),R={...v,...l,...E,...I,...this.userIdentifiedInWorkspace?{[te]:!0}:{},mpid:u},p={...e,attributes:R},_=this.launcher.selectPlacements(p),y=()=>this.logSelectPlacementsEvent(R);return Promise.resolve(_).then(A=>A?.context?.sessionId?.then(g=>this.setRoktSessionId(g))).catch(()=>{}).finally(y),_}hashAttributes(e){return this.isKitReady()?this.launcher.hashAttributes(e):(console.error("Rokt Kit: Not initialized"),null)}use(e){return this.isKitReady()?!e||!f(e)?Promise.reject(new Error("Rokt Kit: Invalid extension name")):this.launcher.use(e):(console.error("Rokt Kit: Not initialized"),Promise.reject(new Error("Rokt Kit: Not initialized")))}onShoppableAdsReady(e){this._isThankYouElementLoaded?e():this._thankYouElementOnLoadCallback=e}};h._allowedOriginHashes=[-553112570,549508659],h.PERFORMANCE_MARKS={RoktScriptAppended:"mp:RoktScriptAppended"},h.EMAIL_SHA256_KEY="emailsha256";let m=h;function de(){return b}function he(n){if(!n){window.console.log("You must pass a config object to register the kit "+d);return}if(!T(n)){window.console.log("'config' must be an object. You passed in a "+typeof n);return}T(n.kits)?n.kits[d]={constructor:m}:(n.kits={},n.kits[d]={constructor:m}),window.console.log("Successfully registered "+d+" to your mParticle configuration")}typeof window<"u"&&window.mParticle&&a().addForwarder&&a().addForwarder({name:d,constructor:m,getId:de});exports.register=he;
|
|
2
2
|
//# sourceMappingURL=Rokt-Kit.common.js.map
|
package/dist/Rokt-Kit.esm.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const
|
|
1
|
+
const q = [
|
|
2
2
|
"billingaddress1",
|
|
3
3
|
"billingaddress2",
|
|
4
4
|
"billingcity",
|
|
@@ -22,11 +22,11 @@ const V = [
|
|
|
22
22
|
"shippingstate",
|
|
23
23
|
"shippingzipcode",
|
|
24
24
|
"totalprice"
|
|
25
|
-
],
|
|
25
|
+
], B = new Set(q);
|
|
26
26
|
function z(n) {
|
|
27
|
-
return
|
|
27
|
+
return B.has(n.toLowerCase());
|
|
28
28
|
}
|
|
29
|
-
function
|
|
29
|
+
function S(n) {
|
|
30
30
|
const e = {}, t = n || {}, i = Object.keys(t);
|
|
31
31
|
for (let r = 0; r < i.length; r++) {
|
|
32
32
|
const s = i[r];
|
|
@@ -34,12 +34,7 @@ function A(n) {
|
|
|
34
34
|
}
|
|
35
35
|
return e;
|
|
36
36
|
}
|
|
37
|
-
const d = "Rokt", w = 181, J = "selectPlacements",
|
|
38
|
-
LOGIN: "login",
|
|
39
|
-
LOGOUT: "logout",
|
|
40
|
-
MODIFY_USER: "modify_user",
|
|
41
|
-
IDENTIFY: "identify"
|
|
42
|
-
}, Z = "ThankYouPageJourney", ee = "rokt-launcher", te = "rokt-thank-you-element", ie = "userIdentifiedInWorkspace", ne = 500, P = {
|
|
37
|
+
const d = "Rokt", w = 181, J = "selectPlacements", Q = "apps.roktecommerce.com", X = 0.1, $ = "ThankYouPageJourney", Z = "rokt-launcher", ee = "rokt-thank-you-element", te = "userIdentifiedInWorkspace", ie = 500, O = {
|
|
43
38
|
UNKNOWN_ERROR: "UNKNOWN_ERROR",
|
|
44
39
|
UNHANDLED_EXCEPTION: "UNHANDLED_EXCEPTION",
|
|
45
40
|
IDENTITY_REQUEST: "IDENTITY_REQUEST"
|
|
@@ -47,7 +42,7 @@ const d = "Rokt", w = 181, J = "selectPlacements", X = "apps.roktecommerce.com",
|
|
|
47
42
|
ERROR: "ERROR",
|
|
48
43
|
INFO: "INFO",
|
|
49
44
|
WARNING: "WARNING"
|
|
50
|
-
},
|
|
45
|
+
}, ne = "apps.rokt-api.com/v1/log", re = "apps.rokt-api.com/v1/errors", se = 10;
|
|
51
46
|
function a() {
|
|
52
47
|
return window.mParticle;
|
|
53
48
|
}
|
|
@@ -55,7 +50,7 @@ function C(n, e) {
|
|
|
55
50
|
const i = [W(n), "/wsdk/integrations/launcher.js"].join("");
|
|
56
51
|
return !e || e.length === 0 ? i : i + "?extensions=" + e.join(",");
|
|
57
52
|
}
|
|
58
|
-
function
|
|
53
|
+
function U(n) {
|
|
59
54
|
return [W(n), "/rokt-elements/rokt-element-thank-you.js"].join("");
|
|
60
55
|
}
|
|
61
56
|
function W(n) {
|
|
@@ -79,12 +74,12 @@ function b(n) {
|
|
|
79
74
|
}
|
|
80
75
|
return [];
|
|
81
76
|
}
|
|
82
|
-
function
|
|
77
|
+
function M(n) {
|
|
83
78
|
const e = n ? b(n) : [], t = [], i = [];
|
|
84
79
|
let r = !1;
|
|
85
80
|
for (let s = 0; s < e.length; s++) {
|
|
86
81
|
const o = e[s].value;
|
|
87
|
-
o === "thank-you-journey" ? (r = !0, i.push(
|
|
82
|
+
o === "thank-you-journey" ? (r = !0, i.push($)) : t.push(o);
|
|
88
83
|
}
|
|
89
84
|
return {
|
|
90
85
|
roktExtensionsQueryParams: t,
|
|
@@ -92,7 +87,7 @@ function D(n) {
|
|
|
92
87
|
loadThankYouElement: r
|
|
93
88
|
};
|
|
94
89
|
}
|
|
95
|
-
async function
|
|
90
|
+
async function oe(n, e) {
|
|
96
91
|
const t = [];
|
|
97
92
|
if (e)
|
|
98
93
|
for (const i of n)
|
|
@@ -109,7 +104,7 @@ function x(n) {
|
|
|
109
104
|
}
|
|
110
105
|
return e;
|
|
111
106
|
}
|
|
112
|
-
function
|
|
107
|
+
function D(n) {
|
|
113
108
|
const e = {};
|
|
114
109
|
if (!Array.isArray(n))
|
|
115
110
|
return e;
|
|
@@ -125,20 +120,20 @@ function Y(n) {
|
|
|
125
120
|
}
|
|
126
121
|
return e;
|
|
127
122
|
}
|
|
128
|
-
function
|
|
123
|
+
function j(n, e, t) {
|
|
129
124
|
return a().generateHash([n, e, t].join(""));
|
|
130
125
|
}
|
|
131
|
-
function
|
|
126
|
+
function k(n) {
|
|
132
127
|
return n == null ? !0 : typeof n == "object" ? Object.keys(n).length === 0 : Array.isArray(n) ? n.length === 0 : !1;
|
|
133
128
|
}
|
|
134
129
|
function f(n) {
|
|
135
130
|
return typeof n == "string";
|
|
136
131
|
}
|
|
137
|
-
function
|
|
138
|
-
let i = "mParticle_wsdkv_" + a().getVersion() + "_kitv_" + "1.28.
|
|
132
|
+
function ae(n) {
|
|
133
|
+
let i = "mParticle_wsdkv_" + a().getVersion() + "_kitv_" + "1.28.1";
|
|
139
134
|
return n && (i += "_" + n), i;
|
|
140
135
|
}
|
|
141
|
-
function
|
|
136
|
+
function G(n) {
|
|
142
137
|
let e = 5381;
|
|
143
138
|
for (let t = 0; t < n.length; t++)
|
|
144
139
|
e = (e << 5) + e + n.charCodeAt(t), e = e & e;
|
|
@@ -152,41 +147,41 @@ function N(n) {
|
|
|
152
147
|
const t = document.body || document.head;
|
|
153
148
|
t && t.appendChild(e);
|
|
154
149
|
}
|
|
155
|
-
function
|
|
156
|
-
const t =
|
|
157
|
-
if (m._allowedOriginHashes.indexOf(t) === -1 || Math.random() >=
|
|
150
|
+
function Y(n, e) {
|
|
151
|
+
const t = G(window.location.origin);
|
|
152
|
+
if (m._allowedOriginHashes.indexOf(t) === -1 || Math.random() >= X)
|
|
158
153
|
return;
|
|
159
154
|
const r = window.__rokt_li_guid__;
|
|
160
155
|
if (!r)
|
|
161
156
|
return;
|
|
162
157
|
const s = window.location.href.split("?")[0].split("#")[0], o = "version=" + encodeURIComponent(e ?? "") + "&launcherInstanceGuid=" + encodeURIComponent(r) + "&pageUrl=" + encodeURIComponent(s);
|
|
163
158
|
N("https://" + (n || "apps.rokt.com") + "/v1/wsdk-init/index.html?" + o), N(
|
|
164
|
-
"https://" +
|
|
159
|
+
"https://" + Q + "/v1/wsdk-init/index.html?" + o + "&isControl=true"
|
|
165
160
|
);
|
|
166
161
|
}
|
|
167
|
-
function
|
|
162
|
+
function ce() {
|
|
168
163
|
return typeof window < "u" && !!window.location?.search?.toLowerCase().includes("mp_enable_logging=true");
|
|
169
164
|
}
|
|
170
165
|
function le() {
|
|
171
166
|
return typeof window < "u" ? window.location?.href : void 0;
|
|
172
167
|
}
|
|
173
|
-
function
|
|
168
|
+
function ue() {
|
|
174
169
|
return typeof window < "u" ? window.navigator?.userAgent : void 0;
|
|
175
170
|
}
|
|
176
|
-
class
|
|
171
|
+
class V {
|
|
177
172
|
constructor() {
|
|
178
173
|
this._logCount = {};
|
|
179
174
|
}
|
|
180
175
|
incrementAndCheck(e) {
|
|
181
176
|
const i = (this._logCount[e] || 0) + 1;
|
|
182
|
-
return this._logCount[e] = i, i >
|
|
177
|
+
return this._logCount[e] = i, i > se;
|
|
183
178
|
}
|
|
184
179
|
}
|
|
185
|
-
class
|
|
180
|
+
class P {
|
|
186
181
|
constructor(e, t, i, r, s) {
|
|
187
182
|
this._reporter = "mp-wsdk";
|
|
188
183
|
const o = e.isLoggingEnabled;
|
|
189
|
-
this._integrationName = t || "", this._launcherInstanceGuid = i, this._accountId = r || null, this._rateLimiter = s || new
|
|
184
|
+
this._integrationName = t || "", this._launcherInstanceGuid = i, this._accountId = r || null, this._rateLimiter = s || new V(), this._isEnabled = ce() || o;
|
|
190
185
|
}
|
|
191
186
|
send(e, t, i, r, s, o) {
|
|
192
187
|
if (!(!this._isEnabled || this._rateLimiter.incrementAndCheck(t)))
|
|
@@ -197,33 +192,33 @@ class U {
|
|
|
197
192
|
version: this._integrationName
|
|
198
193
|
},
|
|
199
194
|
severity: t,
|
|
200
|
-
code: r ||
|
|
195
|
+
code: r || O.UNKNOWN_ERROR,
|
|
201
196
|
url: le(),
|
|
202
|
-
deviceInfo:
|
|
197
|
+
deviceInfo: ue(),
|
|
203
198
|
stackTrace: s,
|
|
204
199
|
reporter: this._reporter,
|
|
205
200
|
integration: this._integrationName
|
|
206
|
-
},
|
|
201
|
+
}, u = {
|
|
207
202
|
Accept: "text/plain;charset=UTF-8",
|
|
208
203
|
"Content-Type": "application/json",
|
|
209
204
|
"rokt-launcher-version": this._integrationName,
|
|
210
205
|
"rokt-wsdk-version": "joint"
|
|
211
206
|
};
|
|
212
|
-
this._launcherInstanceGuid && (
|
|
207
|
+
this._launcherInstanceGuid && (u["rokt-launcher-instance-guid"] = this._launcherInstanceGuid), this._accountId && (u["rokt-account-id"] = this._accountId), fetch(e, {
|
|
213
208
|
method: "POST",
|
|
214
|
-
headers:
|
|
209
|
+
headers: u,
|
|
215
210
|
body: JSON.stringify(c)
|
|
216
|
-
}).catch((
|
|
217
|
-
console.error("ReportingTransport: Failed to send log",
|
|
211
|
+
}).catch((l) => {
|
|
212
|
+
console.error("ReportingTransport: Failed to send log", l), o && o(l);
|
|
218
213
|
});
|
|
219
214
|
} catch (c) {
|
|
220
215
|
console.error("ReportingTransport: Failed to send log", c), o && o(c);
|
|
221
216
|
}
|
|
222
217
|
}
|
|
223
218
|
}
|
|
224
|
-
class
|
|
219
|
+
class F {
|
|
225
220
|
constructor(e, t, i, r, s) {
|
|
226
|
-
this._transport = new
|
|
221
|
+
this._transport = new P(e, t, i, r, s), this._errorUrl = "https://" + (e?.errorUrl || re);
|
|
227
222
|
}
|
|
228
223
|
report(e) {
|
|
229
224
|
if (!e) return;
|
|
@@ -231,9 +226,9 @@ class H {
|
|
|
231
226
|
this._transport.send(this._errorUrl, t, e.message, e.code, e.stackTrace);
|
|
232
227
|
}
|
|
233
228
|
}
|
|
234
|
-
class
|
|
229
|
+
class H {
|
|
235
230
|
constructor(e, t, i, r, s, o) {
|
|
236
|
-
this._transport = new
|
|
231
|
+
this._transport = new P(e, i, r, s, o), this._loggingUrl = "https://" + (e?.loggingUrl || ne), this._errorReportingService = t;
|
|
237
232
|
}
|
|
238
233
|
log(e) {
|
|
239
234
|
e && this._transport.send(
|
|
@@ -245,7 +240,7 @@ class G {
|
|
|
245
240
|
(t) => {
|
|
246
241
|
this._errorReportingService && this._errorReportingService.report({
|
|
247
242
|
message: "LoggingService: Failed to send log: " + t.message,
|
|
248
|
-
code:
|
|
243
|
+
code: O.UNKNOWN_ERROR,
|
|
249
244
|
severity: L.ERROR
|
|
250
245
|
});
|
|
251
246
|
}
|
|
@@ -254,7 +249,7 @@ class G {
|
|
|
254
249
|
}
|
|
255
250
|
const h = class h {
|
|
256
251
|
constructor() {
|
|
257
|
-
this.name = d, this.id = w, this.moduleId = w, this.isInitialized = !1, this.launcher = null, this.filters = {}, this.userAttributes = {}, this.userIdentifiedInWorkspace = !1, this.testHelpers = null, this.placementEventMappingLookup = {}, this.placementEventAttributeMappingLookup = {}, this.
|
|
252
|
+
this.name = d, this.id = w, this.moduleId = w, this.isInitialized = !1, this.launcher = null, this.filters = {}, this.userAttributes = {}, this.userIdentifiedInWorkspace = !1, this.testHelpers = null, this.placementEventMappingLookup = {}, this.placementEventAttributeMappingLookup = {}, this.integrationName = null, this.errorReportingService = null, this.loggingService = null, this._thankYouElementOnLoadCallback = null, this._isThankYouElementLoaded = !1, this._workspaceSearchInFlightPromise = null;
|
|
258
253
|
}
|
|
259
254
|
// ---- Private helpers ----
|
|
260
255
|
getEventAttributeValue(e, t) {
|
|
@@ -285,7 +280,7 @@ const h = class h {
|
|
|
285
280
|
const t = Object.keys(this.placementEventAttributeMappingLookup);
|
|
286
281
|
for (let i = 0; i < t.length; i++) {
|
|
287
282
|
const r = t[i], s = this.placementEventAttributeMappingLookup[r];
|
|
288
|
-
if (
|
|
283
|
+
if (k(s))
|
|
289
284
|
continue;
|
|
290
285
|
let o = !0;
|
|
291
286
|
for (let c = 0; c < s.length; c++)
|
|
@@ -309,7 +304,7 @@ const h = class h {
|
|
|
309
304
|
return this.replaceOtherIdentityWithEmailsha256(t);
|
|
310
305
|
}
|
|
311
306
|
returnLocalSessionAttributes() {
|
|
312
|
-
return !a().Rokt || typeof a().Rokt.getLocalSessionAttributes != "function" ? {} :
|
|
307
|
+
return !a().Rokt || typeof a().Rokt.getLocalSessionAttributes != "function" ? {} : k(this.placementEventMappingLookup) && k(this.placementEventAttributeMappingLookup) ? {} : a().Rokt.getLocalSessionAttributes();
|
|
313
308
|
}
|
|
314
309
|
replaceOtherIdentityWithEmailsha256(e) {
|
|
315
310
|
const t = { ...e || {} }, i = this._mappedEmailSha256Key;
|
|
@@ -321,63 +316,6 @@ const h = class h {
|
|
|
321
316
|
const t = a().EventType.Other;
|
|
322
317
|
a().logEvent(J, t, e);
|
|
323
318
|
}
|
|
324
|
-
buildIdentityEvent(e, t) {
|
|
325
|
-
const i = t.getMPID(), r = a() && a().sessionManager && typeof a().sessionManager.getSession == "function" ? a().sessionManager.getSession() : void 0, s = this.returnUserIdentities(t);
|
|
326
|
-
return {
|
|
327
|
-
event_type: e,
|
|
328
|
-
data: {
|
|
329
|
-
timestamp_unixtime_ms: Date.now(),
|
|
330
|
-
session_uuid: r ?? void 0,
|
|
331
|
-
mpid: i,
|
|
332
|
-
user_identities: s,
|
|
333
|
-
user_attributes: this.userAttributes
|
|
334
|
-
}
|
|
335
|
-
};
|
|
336
|
-
}
|
|
337
|
-
mergePendingIdentityEvents(e) {
|
|
338
|
-
if (this.pendingIdentityEvents.length === 0)
|
|
339
|
-
return e;
|
|
340
|
-
const t = {
|
|
341
|
-
...e,
|
|
342
|
-
events: [...e.events ?? [], ...this.pendingIdentityEvents]
|
|
343
|
-
};
|
|
344
|
-
return this.pendingIdentityEvents = [], t;
|
|
345
|
-
}
|
|
346
|
-
drainBatchQueue() {
|
|
347
|
-
this.batchQueue.forEach((e) => {
|
|
348
|
-
this.processBatch(e);
|
|
349
|
-
}), this.batchQueue = [];
|
|
350
|
-
}
|
|
351
|
-
processBatch(e) {
|
|
352
|
-
if (!this.isKitReady())
|
|
353
|
-
return this.batchQueue.push(e), "Batch queued for forwarder: " + d;
|
|
354
|
-
const t = this.enrichCommerceEventTypes(this.mergePendingIdentityEvents(e));
|
|
355
|
-
return this.sendBatchStream(t), "Successfully sent batch to forwarder: " + d;
|
|
356
|
-
}
|
|
357
|
-
enrichCommerceEventTypes(e) {
|
|
358
|
-
if (!e.events)
|
|
359
|
-
return e;
|
|
360
|
-
for (const t of e.events) {
|
|
361
|
-
if (t.event_type !== "commerce_event") continue;
|
|
362
|
-
const { data: i } = t;
|
|
363
|
-
if (!i) continue;
|
|
364
|
-
const r = i.custom_flags?.["Rokt.CommerceEventType"];
|
|
365
|
-
r && T(i.product_action) && (i.product_action.action = r);
|
|
366
|
-
}
|
|
367
|
-
return e;
|
|
368
|
-
}
|
|
369
|
-
sendBatchStream(e) {
|
|
370
|
-
if (window.Rokt && typeof window.Rokt.__batch_stream__ == "function") {
|
|
371
|
-
if (this.batchStreamQueue.length) {
|
|
372
|
-
const t = this.batchStreamQueue;
|
|
373
|
-
this.batchStreamQueue = [];
|
|
374
|
-
for (let i = 0; i < t.length; i++)
|
|
375
|
-
window.Rokt.__batch_stream__(t[i]);
|
|
376
|
-
}
|
|
377
|
-
window.Rokt.__batch_stream__(e);
|
|
378
|
-
} else
|
|
379
|
-
this.batchStreamQueue.push(e);
|
|
380
|
-
}
|
|
381
319
|
setRoktSessionId(e) {
|
|
382
320
|
if (!(!e || typeof e != "string"))
|
|
383
321
|
try {
|
|
@@ -396,7 +334,7 @@ const h = class h {
|
|
|
396
334
|
};
|
|
397
335
|
let o;
|
|
398
336
|
this.isPartnerInLocalLauncherTestGroup() ? o = Promise.resolve(window.Rokt.createLocalLauncher(s)) : o = window.Rokt.createLauncher(s), o.then(async (c) => {
|
|
399
|
-
await
|
|
337
|
+
await oe(i, c), this.initRoktLauncher(c);
|
|
400
338
|
}).catch((c) => {
|
|
401
339
|
console.error("Error creating Rokt launcher:", c);
|
|
402
340
|
});
|
|
@@ -404,7 +342,7 @@ const h = class h {
|
|
|
404
342
|
initRoktLauncher(e) {
|
|
405
343
|
window.Rokt && (window.Rokt.currentLauncher = e), this.launcher = e;
|
|
406
344
|
const t = a().Rokt?.filters;
|
|
407
|
-
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,
|
|
345
|
+
t ? (this.filters = t, t.filteredUser ? this._workspaceSearchInFlightPromise = this.search(t.filteredUser) : console.warn("Rokt Kit: No filtered user has been set.")) : console.warn("Rokt Kit: No filters have been set."), this.isInitialized = !0, Y(this.domain, this.integrationName), a().Rokt.attachKit(this);
|
|
408
346
|
}
|
|
409
347
|
fetchOptimizely() {
|
|
410
348
|
const e = a()._getActiveForwarders().filter((t) => t.name === "Optimizely");
|
|
@@ -436,65 +374,65 @@ const h = class h {
|
|
|
436
374
|
*/
|
|
437
375
|
init(e, t, i, r, s) {
|
|
438
376
|
const o = e, c = o.accountId;
|
|
439
|
-
this.userAttributes =
|
|
440
|
-
const
|
|
441
|
-
this.placementEventMappingLookup = x(
|
|
442
|
-
const
|
|
377
|
+
this.userAttributes = S(s), this._onboardingExpProvider = o.onboardingExpProvider;
|
|
378
|
+
const u = b(o.placementEventMapping);
|
|
379
|
+
this.placementEventMappingLookup = x(u);
|
|
380
|
+
const l = b(
|
|
443
381
|
o.placementEventAttributeMapping
|
|
444
382
|
);
|
|
445
|
-
this.placementEventAttributeMappingLookup =
|
|
446
|
-
const E = a().Rokt?.domain, { roktExtensionsQueryParams:
|
|
383
|
+
this.placementEventAttributeMappingLookup = D(l), o.hashedEmailUserIdentityType && (this._mappedEmailSha256Key = o.hashedEmailUserIdentityType.toLowerCase()), this._workspaceIdSyncApiKey = f(o.workspaceIdSyncApiKey) ? o.workspaceIdSyncApiKey : void 0;
|
|
384
|
+
const E = a().Rokt?.domain, { roktExtensionsQueryParams: v, legacyRoktExtensions: I, loadThankYouElement: R } = M(
|
|
447
385
|
o.roktExtensions
|
|
448
386
|
), p = {
|
|
449
387
|
...a().Rokt?.launcherOptions || {}
|
|
450
388
|
};
|
|
451
|
-
this.integrationName =
|
|
389
|
+
this.integrationName = ae(p.integrationName), p.integrationName = this.integrationName, this.domain = E;
|
|
452
390
|
const _ = {
|
|
453
391
|
loggingUrl: o.loggingUrl,
|
|
454
392
|
errorUrl: o.errorUrl,
|
|
455
393
|
isLoggingEnabled: a().config?.isLoggingEnabled === !0
|
|
456
|
-
}, y = new
|
|
394
|
+
}, y = new F(
|
|
457
395
|
_,
|
|
458
396
|
this.integrationName,
|
|
459
397
|
window.__rokt_li_guid__,
|
|
460
398
|
o.accountId
|
|
461
|
-
),
|
|
399
|
+
), A = new H(
|
|
462
400
|
_,
|
|
463
401
|
y,
|
|
464
402
|
this.integrationName,
|
|
465
403
|
window.__rokt_li_guid__,
|
|
466
404
|
o.accountId
|
|
467
405
|
);
|
|
468
|
-
return this.errorReportingService = y, this.loggingService =
|
|
406
|
+
return this.errorReportingService = y, this.loggingService = A, a()._registerErrorReportingService && a()._registerErrorReportingService(y), a()._registerLoggingService && a()._registerLoggingService(A), i ? (this.testHelpers = {
|
|
469
407
|
generateLauncherScript: C,
|
|
470
|
-
generateThankYouElementScript:
|
|
471
|
-
extractRoktExtensionConfig:
|
|
472
|
-
hashEventMessage:
|
|
408
|
+
generateThankYouElementScript: U,
|
|
409
|
+
extractRoktExtensionConfig: M,
|
|
410
|
+
hashEventMessage: j,
|
|
473
411
|
parseSettingsString: b,
|
|
474
412
|
generateMappedEventLookup: x,
|
|
475
|
-
generateMappedEventAttributeLookup:
|
|
476
|
-
sendAdBlockMeasurementSignals:
|
|
413
|
+
generateMappedEventAttributeLookup: D,
|
|
414
|
+
sendAdBlockMeasurementSignals: Y,
|
|
477
415
|
createAutoRemovedIframe: N,
|
|
478
|
-
djb2:
|
|
416
|
+
djb2: G,
|
|
479
417
|
setAllowedOriginHashes: (g) => {
|
|
480
418
|
h._allowedOriginHashes = g;
|
|
481
419
|
},
|
|
482
|
-
ReportingTransport:
|
|
483
|
-
ErrorReportingService:
|
|
484
|
-
LoggingService:
|
|
485
|
-
RateLimiter:
|
|
486
|
-
ErrorCodes:
|
|
420
|
+
ReportingTransport: P,
|
|
421
|
+
ErrorReportingService: F,
|
|
422
|
+
LoggingService: H,
|
|
423
|
+
RateLimiter: V,
|
|
424
|
+
ErrorCodes: O,
|
|
487
425
|
WSDKErrorSeverity: L
|
|
488
|
-
}, this.attachLauncher(c, p), "Successfully initialized: " + d) : (R && (a().Rokt.flushOnShoppableAdsReadyMessageQueue?.(this), K(
|
|
426
|
+
}, this.attachLauncher(c, p), "Successfully initialized: " + d) : (R && (a().Rokt.flushOnShoppableAdsReadyMessageQueue?.(this), K(ee, U(E), {
|
|
489
427
|
onLoad: () => {
|
|
490
428
|
this._isThankYouElementLoaded = !0, this._thankYouElementOnLoadCallback && this._thankYouElementOnLoadCallback();
|
|
491
429
|
},
|
|
492
430
|
onError: (g) => {
|
|
493
431
|
console.error("Error loading Rokt Thank You Element script:", g);
|
|
494
432
|
}
|
|
495
|
-
})), this.isLauncherReadyToAttach() ? this.attachLauncher(c, p,
|
|
433
|
+
})), this.isLauncherReadyToAttach() ? this.attachLauncher(c, p, I) : (K(Z, C(E, v), {
|
|
496
434
|
onLoad: () => {
|
|
497
|
-
this.isLauncherReadyToAttach() ? this.attachLauncher(c, p,
|
|
435
|
+
this.isLauncherReadyToAttach() ? this.attachLauncher(c, p, I) : console.error("Rokt object is not available after script load.");
|
|
498
436
|
},
|
|
499
437
|
onError: (g) => {
|
|
500
438
|
console.error("Error loading Rokt launcher script:", g);
|
|
@@ -504,8 +442,8 @@ const h = class h {
|
|
|
504
442
|
process(e) {
|
|
505
443
|
if (!this.isKitReady())
|
|
506
444
|
return "Kit not ready for forwarder: " + d;
|
|
507
|
-
if (typeof a().Rokt?.setLocalSessionAttribute == "function" && (
|
|
508
|
-
const t =
|
|
445
|
+
if (typeof a().Rokt?.setLocalSessionAttribute == "function" && (k(this.placementEventAttributeMappingLookup) || this.applyPlacementEventAttributeMapping(e), !k(this.placementEventMappingLookup))) {
|
|
446
|
+
const t = j(e.EventDataType, e.EventCategory, e.EventName ?? "");
|
|
509
447
|
this.placementEventMappingLookup[String(t)] && a().Rokt.setLocalSessionAttribute?.(this.placementEventMappingLookup[String(t)], !0);
|
|
510
448
|
}
|
|
511
449
|
return "Successfully sent to forwarder: " + d;
|
|
@@ -523,13 +461,12 @@ const h = class h {
|
|
|
523
461
|
removeUserAttribute(e) {
|
|
524
462
|
return delete this.userAttributes[e], "Successfully removed user attribute for forwarder: " + d;
|
|
525
463
|
}
|
|
526
|
-
handleIdentityComplete(e, t
|
|
527
|
-
|
|
528
|
-
return this.userAttributes = A(e.getAllUserAttributes()), this.pendingIdentityEvents.push(this.buildIdentityEvent(t, r)), "Successfully called " + i + " for forwarder: " + d;
|
|
464
|
+
handleIdentityComplete(e, t) {
|
|
465
|
+
return this.userAttributes = S(e.getAllUserAttributes()), "Successfully called " + t + " for forwarder: " + d;
|
|
529
466
|
}
|
|
530
467
|
onUserIdentified(e) {
|
|
531
468
|
const t = e;
|
|
532
|
-
return this.filters.filteredUser = t, this._workspaceSearchInFlightPromise = this.search(t), this.handleIdentityComplete(e,
|
|
469
|
+
return this.filters.filteredUser = t, this._workspaceSearchInFlightPromise = this.search(t), this.handleIdentityComplete(e, "onUserIdentified");
|
|
533
470
|
}
|
|
534
471
|
search(e) {
|
|
535
472
|
const t = this._workspaceIdSyncApiKey;
|
|
@@ -540,32 +477,32 @@ const h = class h {
|
|
|
540
477
|
return this.userIdentifiedInWorkspace = !1, this._workspaceLastSearchedIdentitiesKey = void 0, Promise.resolve();
|
|
541
478
|
const r = e.getUserIdentities ? e.getUserIdentities().userIdentities : null, s = {};
|
|
542
479
|
if (r)
|
|
543
|
-
for (const
|
|
544
|
-
const
|
|
545
|
-
f(
|
|
480
|
+
for (const u of Object.keys(r)) {
|
|
481
|
+
const l = r[u];
|
|
482
|
+
f(l) && l.length > 0 && (s[u] = l);
|
|
546
483
|
}
|
|
547
484
|
const o = Object.keys(s);
|
|
548
485
|
if (o.length === 0)
|
|
549
486
|
return this.userIdentifiedInWorkspace = !1, this._workspaceLastSearchedIdentitiesKey = void 0, Promise.resolve();
|
|
550
|
-
const c = o.sort().map((
|
|
551
|
-
return c === this._workspaceLastSearchedIdentitiesKey ? this._workspaceSearchInFlightPromise || Promise.resolve() : (this.userIdentifiedInWorkspace = !1, this._workspaceLastSearchedIdentitiesKey = c, new Promise((
|
|
487
|
+
const c = o.sort().map((u) => `${u}=${s[u]}`).join("&");
|
|
488
|
+
return c === this._workspaceLastSearchedIdentitiesKey ? this._workspaceSearchInFlightPromise || Promise.resolve() : (this.userIdentifiedInWorkspace = !1, this._workspaceLastSearchedIdentitiesKey = c, new Promise((u) => {
|
|
552
489
|
try {
|
|
553
|
-
i(t, s, (
|
|
554
|
-
|
|
490
|
+
i(t, s, (l) => {
|
|
491
|
+
l?.httpCode === 200 && (this.userIdentifiedInWorkspace = !0), u();
|
|
555
492
|
});
|
|
556
|
-
} catch (
|
|
557
|
-
console.error("Rokt Kit: Workspace IDSync search failed",
|
|
493
|
+
} catch (l) {
|
|
494
|
+
console.error("Rokt Kit: Workspace IDSync search failed", l), this._workspaceLastSearchedIdentitiesKey = void 0, u();
|
|
558
495
|
}
|
|
559
496
|
}));
|
|
560
497
|
}
|
|
561
498
|
onLoginComplete(e, t) {
|
|
562
|
-
return this.handleIdentityComplete(e,
|
|
499
|
+
return this.handleIdentityComplete(e, "onLoginComplete");
|
|
563
500
|
}
|
|
564
501
|
onLogoutComplete(e, t) {
|
|
565
|
-
return this.userIdentifiedInWorkspace = !1, this._workspaceSearchInFlightPromise = null, this._workspaceLastSearchedIdentitiesKey = void 0, this.handleIdentityComplete(e,
|
|
502
|
+
return this.userIdentifiedInWorkspace = !1, this._workspaceSearchInFlightPromise = null, this._workspaceLastSearchedIdentitiesKey = void 0, this.handleIdentityComplete(e, "onLogoutComplete");
|
|
566
503
|
}
|
|
567
504
|
onModifyComplete(e, t) {
|
|
568
|
-
return this.handleIdentityComplete(e,
|
|
505
|
+
return this.handleIdentityComplete(e, "onModifyComplete");
|
|
569
506
|
}
|
|
570
507
|
/**
|
|
571
508
|
* Selects placements for Rokt Web SDK with merged attributes, filters, and experimentation options.
|
|
@@ -595,24 +532,24 @@ const h = class h {
|
|
|
595
532
|
const t = this._workspaceSearchInFlightPromise;
|
|
596
533
|
return Promise.race([
|
|
597
534
|
t,
|
|
598
|
-
new Promise((i) => setTimeout(i,
|
|
535
|
+
new Promise((i) => setTimeout(i, ie))
|
|
599
536
|
]).then(() => this._dispatchPlacements(e));
|
|
600
537
|
}
|
|
601
538
|
return this._dispatchPlacements(e);
|
|
602
539
|
}
|
|
603
540
|
_dispatchPlacements(e) {
|
|
604
|
-
const t = e && e.attributes || {}, r = { ...
|
|
605
|
-
let
|
|
606
|
-
s ? s.filterUserAttributes ?
|
|
607
|
-
const E = this._onboardingExpProvider === "Optimizely" ? this.fetchOptimizely() : {},
|
|
608
|
-
...
|
|
609
|
-
...
|
|
541
|
+
const t = e && e.attributes || {}, r = { ...S(this.userAttributes), ...t }, s = this.filters || {}, o = s.userAttributeFilters || [], c = s.filteredUser || null, u = c ? c.getMPID() : null;
|
|
542
|
+
let l;
|
|
543
|
+
s ? s.filterUserAttributes ? l = s.filterUserAttributes(r, o) : l = r : (console.warn("Rokt Kit: No filters available, using user attributes"), l = r), this.userAttributes = S(l);
|
|
544
|
+
const E = this._onboardingExpProvider === "Optimizely" ? this.fetchOptimizely() : {}, v = this.returnUserIdentities(c), I = this.returnLocalSessionAttributes(), R = {
|
|
545
|
+
...v,
|
|
546
|
+
...l,
|
|
610
547
|
...E,
|
|
611
|
-
...
|
|
612
|
-
...this.userIdentifiedInWorkspace ? { [
|
|
613
|
-
mpid:
|
|
548
|
+
...I,
|
|
549
|
+
...this.userIdentifiedInWorkspace ? { [te]: !0 } : {},
|
|
550
|
+
mpid: u
|
|
614
551
|
}, p = { ...e, attributes: R }, _ = this.launcher.selectPlacements(p), y = () => this.logSelectPlacementsEvent(R);
|
|
615
|
-
return Promise.resolve(_).then((
|
|
552
|
+
return Promise.resolve(_).then((A) => A?.context?.sessionId?.then((g) => this.setRoktSessionId(g))).catch(() => {
|
|
616
553
|
}).finally(y), _;
|
|
617
554
|
}
|
|
618
555
|
/**
|
|
@@ -640,10 +577,10 @@ h._allowedOriginHashes = [-553112570, 549508659], h.PERFORMANCE_MARKS = {
|
|
|
640
577
|
RoktScriptAppended: "mp:RoktScriptAppended"
|
|
641
578
|
}, h.EMAIL_SHA256_KEY = "emailsha256";
|
|
642
579
|
let m = h;
|
|
643
|
-
function
|
|
580
|
+
function de() {
|
|
644
581
|
return w;
|
|
645
582
|
}
|
|
646
|
-
function
|
|
583
|
+
function he(n) {
|
|
647
584
|
if (!n) {
|
|
648
585
|
window.console.log("You must pass a config object to register the kit " + d);
|
|
649
586
|
return;
|
|
@@ -661,9 +598,9 @@ function pe(n) {
|
|
|
661
598
|
typeof window < "u" && window.mParticle && a().addForwarder && a().addForwarder({
|
|
662
599
|
name: d,
|
|
663
600
|
constructor: m,
|
|
664
|
-
getId:
|
|
601
|
+
getId: de
|
|
665
602
|
});
|
|
666
603
|
export {
|
|
667
|
-
|
|
604
|
+
he as register
|
|
668
605
|
};
|
|
669
606
|
//# sourceMappingURL=Rokt-Kit.esm.js.map
|
package/dist/Rokt-Kit.iife.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var RoktKit=(function(O){"use strict";const q=["billingaddress1","billingaddress2","billingcity","billingstate","billingzipcode","cartitems","ccbin","confirmationref","conversiontype","country","couponcode","currency","language","paymentserviceprovider","paymentserviceproviderattribute","paymenttype","shippingaddress1","shippingcity","shippingcountry","shippingmethod","shippingstate","shippingzipcode","totalprice"],J=new Set(q);function M(n){return J.has(n.toLowerCase())}function k(n){const e={},t=n||{},i=Object.keys(t);for(let r=0;r<i.length;r++){const s=i[r];M(s)||(e[s]=t[s])}return e}const d="Rokt",R=181,X="selectPlacements",$="apps.roktecommerce.com",Z=.1,S={LOGIN:"login",LOGOUT:"logout",MODIFY_USER:"modify_user",IDENTIFY:"identify"},ee="ThankYouPageJourney",te="rokt-launcher",ie="rokt-thank-you-element",ne="userIdentifiedInWorkspace",re=500,N={UNKNOWN_ERROR:"UNKNOWN_ERROR",UNHANDLED_EXCEPTION:"UNHANDLED_EXCEPTION",IDENTITY_REQUEST:"IDENTITY_REQUEST"},v={ERROR:"ERROR",INFO:"INFO",WARNING:"WARNING"},se="apps.rokt-api.com/v1/log",oe="apps.rokt-api.com/v1/errors",ae=10;function a(){return window.mParticle}function K(n,e){const i=[Y(n),"/wsdk/integrations/launcher.js"].join("");return!e||e.length===0?i:i+"?extensions="+e.join(",")}function D(n){return[Y(n),"/rokt-elements/rokt-element-thank-you.js"].join("")}function Y(n){return["https://",typeof n<"u"?n:"apps.rokt-api.com"].join("")}function x(n,e,t){if(document.getElementById(n))return;const i=document.head||document.body,r=document.createElement("script");r.id=n,r.type="text/javascript",r.src=e,r.async=!0,r.crossOrigin="anonymous",r.fetchPriority="high",t?.onLoad&&(r.onload=t.onLoad),t?.onError&&(r.onerror=t.onError),i.appendChild(r)}function A(n){return n!=null&&typeof n=="object"&&Array.isArray(n)===!1}function w(n){if(!n)return[];try{return JSON.parse(n.replace(/"/g,'"'))}catch{console.error("Settings string contains invalid JSON")}return[]}function F(n){const e=n?w(n):[],t=[],i=[];let r=!1;for(let s=0;s<e.length;s++){const o=e[s].value;o==="thank-you-journey"?(r=!0,i.push(ee)):t.push(o)}return{roktExtensionsQueryParams:t,legacyRoktExtensions:i,loadThankYouElement:r}}async function ce(n,e){const t=[];if(e)for(const i of n)t.push(e.use(i));return Promise.all(t)}function j(n){if(!n)return{};const e={};for(let t=0;t<n.length;t++){const i=n[t];e[i.jsmap]=i.value}return e}function H(n){const e={};if(!Array.isArray(n))return e;for(let t=0;t<n.length;t++){const i=n[t];if(!i||!p(i.value)||!p(i.map))continue;const r=i.value,s=i.map;e[r]||(e[r]=[]),e[r].push({eventAttributeKey:s,conditions:Array.isArray(i.conditions)?i.conditions:[]})}return e}function G(n,e,t){return a().generateHash([n,e,t].join(""))}function E(n){return n==null?!0:typeof n=="object"?Object.keys(n).length===0:Array.isArray(n)?n.length===0:!1}function p(n){return typeof n=="string"}function ue(n){let i="mParticle_wsdkv_"+a().getVersion()+"_kitv_"+"1.28.0";return n&&(i+="_"+n),i}function z(n){let e=5381;for(let t=0;t<n.length;t++)e=(e<<5)+e+n.charCodeAt(t),e=e&e;return e}function P(n){const e=document.createElement("iframe");e.style.display="none",e.setAttribute("sandbox","allow-scripts allow-same-origin"),e.src=n,e.onload=function(){e.onload=null,e.parentNode&&e.parentNode.removeChild(e)};const t=document.body||document.head;t&&t.appendChild(e)}function W(n,e){const t=z(window.location.origin);if(m._allowedOriginHashes.indexOf(t)===-1||Math.random()>=Z)return;const r=window.__rokt_li_guid__;if(!r)return;const s=window.location.href.split("?")[0].split("#")[0],o="version="+encodeURIComponent(e??"")+"&launcherInstanceGuid="+encodeURIComponent(r)+"&pageUrl="+encodeURIComponent(s);P("https://"+(n||"apps.rokt.com")+"/v1/wsdk-init/index.html?"+o),P("https://"+$+"/v1/wsdk-init/index.html?"+o+"&isControl=true")}function le(){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 he(){return typeof window<"u"?window.navigator?.userAgent:void 0}class Q{constructor(){this._logCount={}}incrementAndCheck(e){const i=(this._logCount[e]||0)+1;return this._logCount[e]=i,i>ae}}class U{constructor(e,t,i,r,s){this._reporter="mp-wsdk";const o=e.isLoggingEnabled;this._integrationName=t||"",this._launcherInstanceGuid=i,this._accountId=r||null,this._rateLimiter=s||new Q,this._isEnabled=le()||o}send(e,t,i,r,s,o){if(!(!this._isEnabled||this._rateLimiter.incrementAndCheck(t)))try{const c={additionalInformation:{message:i,version:this._integrationName},severity:t,code:r||N.UNKNOWN_ERROR,url:de(),deviceInfo:he(),stackTrace:s,reporter:this._reporter,integration:this._integrationName},l={Accept:"text/plain;charset=UTF-8","Content-Type":"application/json","rokt-launcher-version":this._integrationName,"rokt-wsdk-version":"joint"};this._launcherInstanceGuid&&(l["rokt-launcher-instance-guid"]=this._launcherInstanceGuid),this._accountId&&(l["rokt-account-id"]=this._accountId),fetch(e,{method:"POST",headers:l,body:JSON.stringify(c)}).catch(u=>{console.error("ReportingTransport: Failed to send log",u),o&&o(u)})}catch(c){console.error("ReportingTransport: Failed to send log",c),o&&o(c)}}}class B{constructor(e,t,i,r,s){this._transport=new U(e,t,i,r,s),this._errorUrl="https://"+(e?.errorUrl||oe)}report(e){if(!e)return;const t=e.severity||v.ERROR;this._transport.send(this._errorUrl,t,e.message,e.code,e.stackTrace)}}class V{constructor(e,t,i,r,s,o){this._transport=new U(e,i,r,s,o),this._loggingUrl="https://"+(e?.loggingUrl||se),this._errorReportingService=t}log(e){e&&this._transport.send(this._loggingUrl,v.INFO,e.message,e.code,void 0,t=>{this._errorReportingService&&this._errorReportingService.report({message:"LoggingService: Failed to send log: "+t.message,code:N.UNKNOWN_ERROR,severity:v.ERROR})})}}const h=class h{constructor(){this.name=d,this.id=R,this.moduleId=R,this.isInitialized=!1,this.launcher=null,this.filters={},this.userAttributes={},this.userIdentifiedInWorkspace=!1,this.testHelpers=null,this.placementEventMappingLookup={},this.placementEventAttributeMappingLookup={},this.batchQueue=[],this.batchStreamQueue=[],this.pendingIdentityEvents=[],this.integrationName=null,this.errorReportingService=null,this.loggingService=null,this._thankYouElementOnLoadCallback=null,this._isThankYouElementLoaded=!1,this._workspaceSearchInFlightPromise=null}getEventAttributeValue(e,t){const i=e&&e.EventAttributes;return!i||typeof i[t]>"u"?null:i[t]}doesEventAttributeConditionMatch(e,t){if(!e||!p(e.operator))return!1;const i=e.operator.toLowerCase(),r=e.attributeValue;return i==="exists"?t!==null:t==null?!1:i==="equals"?String(t)===String(r):i==="contains"?String(t).indexOf(String(r))!==-1:!1}doesEventMatchRule(e,t){if(!t||!p(t.eventAttributeKey))return!1;const i=t.conditions;if(!Array.isArray(i))return!1;const r=this.getEventAttributeValue(e,t.eventAttributeKey);if(i.length===0)return r!==null;for(let s=0;s<i.length;s++)if(!this.doesEventAttributeConditionMatch(i[s],r))return!1;return!0}applyPlacementEventAttributeMapping(e){const t=Object.keys(this.placementEventAttributeMappingLookup);for(let i=0;i<t.length;i++){const r=t[i],s=this.placementEventAttributeMappingLookup[r];if(E(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)}}isLauncherReadyToAttach(){return!!window.Rokt&&typeof window.Rokt.createLauncher=="function"}returnUserIdentities(e){if(!e||!e.getUserIdentities)return{};const t=e.getUserIdentities().userIdentities;return this.replaceOtherIdentityWithEmailsha256(t)}returnLocalSessionAttributes(){return!a().Rokt||typeof a().Rokt.getLocalSessionAttributes!="function"?{}:E(this.placementEventMappingLookup)&&E(this.placementEventAttributeMappingLookup)?{}:a().Rokt.getLocalSessionAttributes()}replaceOtherIdentityWithEmailsha256(e){const t={...e||{}},i=this._mappedEmailSha256Key;return i&&e[i]&&(t[h.EMAIL_SHA256_KEY]=e[i]),i&&delete t[i],t}logSelectPlacementsEvent(e){if(!window.mParticle||typeof a().logEvent!="function"||!A(e))return;const t=a().EventType.Other;a().logEvent(X,t,e)}buildIdentityEvent(e,t){const i=t.getMPID(),r=a()&&a().sessionManager&&typeof a().sessionManager.getSession=="function"?a().sessionManager.getSession():void 0,s=this.returnUserIdentities(t);return{event_type:e,data:{timestamp_unixtime_ms:Date.now(),session_uuid:r??void 0,mpid:i,user_identities:s,user_attributes:this.userAttributes}}}mergePendingIdentityEvents(e){if(this.pendingIdentityEvents.length===0)return e;const t={...e,events:[...e.events??[],...this.pendingIdentityEvents]};return this.pendingIdentityEvents=[],t}drainBatchQueue(){this.batchQueue.forEach(e=>{this.processBatch(e)}),this.batchQueue=[]}processBatch(e){if(!this.isKitReady())return this.batchQueue.push(e),"Batch queued for forwarder: "+d;const t=this.enrichCommerceEventTypes(this.mergePendingIdentityEvents(e));return this.sendBatchStream(t),"Successfully sent batch to forwarder: "+d}enrichCommerceEventTypes(e){if(!e.events)return e;for(const t of e.events){if(t.event_type!=="commerce_event")continue;const{data:i}=t;if(!i)continue;const r=i.custom_flags?.["Rokt.CommerceEventType"];r&&A(i.product_action)&&(i.product_action.action=r)}return e}sendBatchStream(e){if(window.Rokt&&typeof window.Rokt.__batch_stream__=="function"){if(this.batchStreamQueue.length){const t=this.batchStreamQueue;this.batchStreamQueue=[];for(let i=0;i<t.length;i++)window.Rokt.__batch_stream__(t[i])}window.Rokt.__batch_stream__(e)}else this.batchStreamQueue.push(e)}setRoktSessionId(e){if(!(!e||typeof e!="string"))try{const t=a().getInstance();t&&typeof t.setIntegrationAttribute=="function"&&t.setIntegrationAttribute(R,{roktSessionId:e})}catch{}}attachLauncher(e,t,i=[]){const r=a()&&a().sessionManager&&typeof a().sessionManager.getSession=="function"?a().sessionManager.getSession():void 0,s={accountId:e,...t||{},...r?{mpSessionId:r}:{}};let o;this.isPartnerInLocalLauncherTestGroup()?o=Promise.resolve(window.Rokt.createLocalLauncher(s)):o=window.Rokt.createLauncher(s),o.then(async c=>{await ce(i,c),this.initRoktLauncher(c)}).catch(c=>{console.error("Error creating Rokt launcher:",c)})}initRoktLauncher(e){window.Rokt&&(window.Rokt.currentLauncher=e),this.launcher=e;const t=a().Rokt?.filters;t?(this.filters=t,t.filteredUser?this._workspaceSearchInFlightPromise=this.search(t.filteredUser):console.warn("Rokt Kit: No filtered user has been set.")):console.warn("Rokt Kit: No filters have been set."),this.isInitialized=!0,W(this.domain,this.integrationName),a().Rokt.attachKit(this),this.drainBatchQueue()}fetchOptimizely(){const e=a()._getActiveForwarders().filter(t=>t.name==="Optimizely");try{if(e.length>0&&window.optimizely){const t=window.optimizely.get("state");return!t||!t.getActiveExperimentIds?{}:t.getActiveExperimentIds().reduce((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)}isPartnerInLocalLauncherTestGroup(){return!!(a().config&&a().config.isLocalLauncherEnabled&&this.isAssignedToSampleGroup())}isAssignedToSampleGroup(){return Math.random()>.5}captureTiming(e){window&&a()&&a().captureTiming&&e&&a().captureTiming(e)}init(e,t,i,r,s){const o=e,c=o.accountId;this.userAttributes=k(s),this._onboardingExpProvider=o.onboardingExpProvider;const l=w(o.placementEventMapping);this.placementEventMappingLookup=j(l);const u=w(o.placementEventAttributeMapping);this.placementEventAttributeMappingLookup=H(u),o.hashedEmailUserIdentityType&&(this._mappedEmailSha256Key=o.hashedEmailUserIdentityType.toLowerCase()),this._workspaceIdSyncApiKey=p(o.workspaceIdSyncApiKey)?o.workspaceIdSyncApiKey:void 0;const _=a().Rokt?.domain,{roktExtensionsQueryParams:C,legacyRoktExtensions:b,loadThankYouElement:L}=F(o.roktExtensions),g={...a().Rokt?.launcherOptions||{}};this.integrationName=ue(g.integrationName),g.integrationName=this.integrationName,this.domain=_;const y={loggingUrl:o.loggingUrl,errorUrl:o.errorUrl,isLoggingEnabled:a().config?.isLoggingEnabled===!0},I=new B(y,this.integrationName,window.__rokt_li_guid__,o.accountId),T=new V(y,I,this.integrationName,window.__rokt_li_guid__,o.accountId);return this.errorReportingService=I,this.loggingService=T,a()._registerErrorReportingService&&a()._registerErrorReportingService(I),a()._registerLoggingService&&a()._registerLoggingService(T),i?(this.testHelpers={generateLauncherScript:K,generateThankYouElementScript:D,extractRoktExtensionConfig:F,hashEventMessage:G,parseSettingsString:w,generateMappedEventLookup:j,generateMappedEventAttributeLookup:H,sendAdBlockMeasurementSignals:W,createAutoRemovedIframe:P,djb2:z,setAllowedOriginHashes:f=>{h._allowedOriginHashes=f},ReportingTransport:U,ErrorReportingService:B,LoggingService:V,RateLimiter:Q,ErrorCodes:N,WSDKErrorSeverity:v},this.attachLauncher(c,g),"Successfully initialized: "+d):(L&&(a().Rokt.flushOnShoppableAdsReadyMessageQueue?.(this),x(ie,D(_),{onLoad:()=>{this._isThankYouElementLoaded=!0,this._thankYouElementOnLoadCallback&&this._thankYouElementOnLoadCallback()},onError:f=>{console.error("Error loading Rokt Thank You Element script:",f)}})),this.isLauncherReadyToAttach()?this.attachLauncher(c,g,b):(x(te,K(_,C),{onLoad:()=>{this.isLauncherReadyToAttach()?this.attachLauncher(c,g,b):console.error("Rokt object is not available after script load.")},onError:f=>{console.error("Error loading Rokt launcher script:",f)}}),this.captureTiming(h.PERFORMANCE_MARKS.RoktScriptAppended)),"Successfully initialized: "+d)}process(e){if(!this.isKitReady())return"Kit not ready for forwarder: "+d;if(typeof a().Rokt?.setLocalSessionAttribute=="function"&&(E(this.placementEventAttributeMappingLookup)||this.applyPlacementEventAttributeMapping(e),!E(this.placementEventMappingLookup))){const t=G(e.EventDataType,e.EventCategory,e.EventName??"");this.placementEventMappingLookup[String(t)]&&a().Rokt.setLocalSessionAttribute?.(this.placementEventMappingLookup[String(t)],!0)}return"Successfully sent to forwarder: "+d}setExtensionData(e){if(!this.isKitReady()){console.error("Rokt Kit: Not initialized");return}window.Rokt.setExtensionData(e)}setUserAttribute(e,t){return M(e)||(this.userAttributes[e]=t),"Successfully set user attribute for forwarder: "+d}removeUserAttribute(e){return delete this.userAttributes[e],"Successfully removed user attribute for forwarder: "+d}handleIdentityComplete(e,t,i){const r=e;return this.userAttributes=k(e.getAllUserAttributes()),this.pendingIdentityEvents.push(this.buildIdentityEvent(t,r)),"Successfully called "+i+" for forwarder: "+d}onUserIdentified(e){const t=e;return this.filters.filteredUser=t,this._workspaceSearchInFlightPromise=this.search(t),this.handleIdentityComplete(e,S.IDENTIFY,"onUserIdentified")}search(e){const t=this._workspaceIdSyncApiKey;if(!t)return this.userIdentifiedInWorkspace=!1,this._workspaceLastSearchedIdentitiesKey=void 0,Promise.resolve();const i=a().Identity?.search;if(typeof i!="function")return this.userIdentifiedInWorkspace=!1,this._workspaceLastSearchedIdentitiesKey=void 0,Promise.resolve();const r=e.getUserIdentities?e.getUserIdentities().userIdentities:null,s={};if(r)for(const l of Object.keys(r)){const u=r[l];p(u)&&u.length>0&&(s[l]=u)}const o=Object.keys(s);if(o.length===0)return this.userIdentifiedInWorkspace=!1,this._workspaceLastSearchedIdentitiesKey=void 0,Promise.resolve();const c=o.sort().map(l=>`${l}=${s[l]}`).join("&");return c===this._workspaceLastSearchedIdentitiesKey?this._workspaceSearchInFlightPromise||Promise.resolve():(this.userIdentifiedInWorkspace=!1,this._workspaceLastSearchedIdentitiesKey=c,new Promise(l=>{try{i(t,s,u=>{u?.httpCode===200&&(this.userIdentifiedInWorkspace=!0),l()})}catch(u){console.error("Rokt Kit: Workspace IDSync search failed",u),this._workspaceLastSearchedIdentitiesKey=void 0,l()}}))}onLoginComplete(e,t){return this.handleIdentityComplete(e,S.LOGIN,"onLoginComplete")}onLogoutComplete(e,t){return this.userIdentifiedInWorkspace=!1,this._workspaceSearchInFlightPromise=null,this._workspaceLastSearchedIdentitiesKey=void 0,this.handleIdentityComplete(e,S.LOGOUT,"onLogoutComplete")}onModifyComplete(e,t){return this.handleIdentityComplete(e,S.MODIFY_USER,"onModifyComplete")}selectPlacements(e){if(this._workspaceSearchInFlightPromise){const t=this._workspaceSearchInFlightPromise;return Promise.race([t,new Promise(i=>setTimeout(i,re))]).then(()=>this._dispatchPlacements(e))}return this._dispatchPlacements(e)}_dispatchPlacements(e){const t=e&&e.attributes||{},r={...k(this.userAttributes),...t},s=this.filters||{},o=s.userAttributeFilters||[],c=s.filteredUser||null,l=c?c.getMPID():null;let u;s?s.filterUserAttributes?u=s.filterUserAttributes(r,o):u=r:(console.warn("Rokt Kit: No filters available, using user attributes"),u=r),this.userAttributes=k(u);const _=this._onboardingExpProvider==="Optimizely"?this.fetchOptimizely():{},C=this.returnUserIdentities(c),b=this.returnLocalSessionAttributes(),L={...C,...u,..._,...b,...this.userIdentifiedInWorkspace?{[ne]:!0}:{},mpid:l},g={...e,attributes:L},y=this.launcher.selectPlacements(g),I=()=>this.logSelectPlacementsEvent(L);return Promise.resolve(y).then(T=>T?.context?.sessionId?.then(f=>this.setRoktSessionId(f))).catch(()=>{}).finally(I),y}hashAttributes(e){return this.isKitReady()?this.launcher.hashAttributes(e):(console.error("Rokt Kit: Not initialized"),null)}use(e){return this.isKitReady()?!e||!p(e)?Promise.reject(new Error("Rokt Kit: Invalid extension name")):this.launcher.use(e):(console.error("Rokt Kit: Not initialized"),Promise.reject(new Error("Rokt Kit: Not initialized")))}onShoppableAdsReady(e){this._isThankYouElementLoaded?e():this._thankYouElementOnLoadCallback=e}};h._allowedOriginHashes=[-553112570,549508659],h.PERFORMANCE_MARKS={RoktScriptAppended:"mp:RoktScriptAppended"},h.EMAIL_SHA256_KEY="emailsha256";let m=h;function pe(){return R}function ge(n){if(!n){window.console.log("You must pass a config object to register the kit "+d);return}if(!A(n)){window.console.log("'config' must be an object. You passed in a "+typeof n);return}A(n.kits)?n.kits[d]={constructor:m}:(n.kits={},n.kits[d]={constructor:m}),window.console.log("Successfully registered "+d+" to your mParticle configuration")}return typeof window<"u"&&window.mParticle&&a().addForwarder&&a().addForwarder({name:d,constructor:m,getId:pe}),O.register=ge,Object.defineProperty(O,Symbol.toStringTag,{value:"Module"}),O})({});
|
|
1
|
+
var RoktKit=(function(v){"use strict";const B=["billingaddress1","billingaddress2","billingcity","billingstate","billingzipcode","cartitems","ccbin","confirmationref","conversiontype","country","couponcode","currency","language","paymentserviceprovider","paymentserviceproviderattribute","paymenttype","shippingaddress1","shippingcity","shippingcountry","shippingmethod","shippingstate","shippingzipcode","totalprice"],J=new Set(B);function U(n){return J.has(n.toLowerCase())}function I(n){const e={},t=n||{},i=Object.keys(t);for(let r=0;r<i.length;r++){const o=i[r];U(o)||(e[o]=t[o])}return e}const d="Rokt",R=181,Q="selectPlacements",X="apps.roktecommerce.com",$=.1,Z="ThankYouPageJourney",ee="rokt-launcher",te="rokt-thank-you-element",ie="userIdentifiedInWorkspace",ne=500,T={UNKNOWN_ERROR:"UNKNOWN_ERROR",UNHANDLED_EXCEPTION:"UNHANDLED_EXCEPTION",IDENTITY_REQUEST:"IDENTITY_REQUEST"},A={ERROR:"ERROR",INFO:"INFO",WARNING:"WARNING"},re="apps.rokt-api.com/v1/log",oe="apps.rokt-api.com/v1/errors",se=10;function a(){return window.mParticle}function K(n,e){const i=[D(n),"/wsdk/integrations/launcher.js"].join("");return!e||e.length===0?i:i+"?extensions="+e.join(",")}function M(n){return[D(n),"/rokt-elements/rokt-element-thank-you.js"].join("")}function D(n){return["https://",typeof n<"u"?n:"apps.rokt-api.com"].join("")}function x(n,e,t){if(document.getElementById(n))return;const i=document.head||document.body,r=document.createElement("script");r.id=n,r.type="text/javascript",r.src=e,r.async=!0,r.crossOrigin="anonymous",r.fetchPriority="high",t?.onLoad&&(r.onload=t.onLoad),t?.onError&&(r.onerror=t.onError),i.appendChild(r)}function N(n){return n!=null&&typeof n=="object"&&Array.isArray(n)===!1}function S(n){if(!n)return[];try{return JSON.parse(n.replace(/"/g,'"'))}catch{console.error("Settings string contains invalid JSON")}return[]}function j(n){const e=n?S(n):[],t=[],i=[];let r=!1;for(let o=0;o<e.length;o++){const s=e[o].value;s==="thank-you-journey"?(r=!0,i.push(Z)):t.push(s)}return{roktExtensionsQueryParams:t,legacyRoktExtensions:i,loadThankYouElement:r}}async function ae(n,e){const t=[];if(e)for(const i of n)t.push(e.use(i));return Promise.all(t)}function Y(n){if(!n)return{};const e={};for(let t=0;t<n.length;t++){const i=n[t];e[i.jsmap]=i.value}return e}function F(n){const e={};if(!Array.isArray(n))return e;for(let t=0;t<n.length;t++){const i=n[t];if(!i||!p(i.value)||!p(i.map))continue;const r=i.value,o=i.map;e[r]||(e[r]=[]),e[r].push({eventAttributeKey:o,conditions:Array.isArray(i.conditions)?i.conditions:[]})}return e}function H(n,e,t){return a().generateHash([n,e,t].join(""))}function E(n){return n==null?!0:typeof n=="object"?Object.keys(n).length===0:Array.isArray(n)?n.length===0:!1}function p(n){return typeof n=="string"}function ce(n){let i="mParticle_wsdkv_"+a().getVersion()+"_kitv_"+"1.28.1";return n&&(i+="_"+n),i}function z(n){let e=5381;for(let t=0;t<n.length;t++)e=(e<<5)+e+n.charCodeAt(t),e=e&e;return e}function O(n){const e=document.createElement("iframe");e.style.display="none",e.setAttribute("sandbox","allow-scripts allow-same-origin"),e.src=n,e.onload=function(){e.onload=null,e.parentNode&&e.parentNode.removeChild(e)};const t=document.body||document.head;t&&t.appendChild(e)}function W(n,e){const t=z(window.location.origin);if(m._allowedOriginHashes.indexOf(t)===-1||Math.random()>=$)return;const r=window.__rokt_li_guid__;if(!r)return;const o=window.location.href.split("?")[0].split("#")[0],s="version="+encodeURIComponent(e??"")+"&launcherInstanceGuid="+encodeURIComponent(r)+"&pageUrl="+encodeURIComponent(o);O("https://"+(n||"apps.rokt.com")+"/v1/wsdk-init/index.html?"+s),O("https://"+X+"/v1/wsdk-init/index.html?"+s+"&isControl=true")}function le(){return typeof window<"u"&&!!window.location?.search?.toLowerCase().includes("mp_enable_logging=true")}function ue(){return typeof window<"u"?window.location?.href:void 0}function de(){return typeof window<"u"?window.navigator?.userAgent:void 0}class G{constructor(){this._logCount={}}incrementAndCheck(e){const i=(this._logCount[e]||0)+1;return this._logCount[e]=i,i>se}}class P{constructor(e,t,i,r,o){this._reporter="mp-wsdk";const s=e.isLoggingEnabled;this._integrationName=t||"",this._launcherInstanceGuid=i,this._accountId=r||null,this._rateLimiter=o||new G,this._isEnabled=le()||s}send(e,t,i,r,o,s){if(!(!this._isEnabled||this._rateLimiter.incrementAndCheck(t)))try{const c={additionalInformation:{message:i,version:this._integrationName},severity:t,code:r||T.UNKNOWN_ERROR,url:ue(),deviceInfo:de(),stackTrace:o,reporter:this._reporter,integration:this._integrationName},u={Accept:"text/plain;charset=UTF-8","Content-Type":"application/json","rokt-launcher-version":this._integrationName,"rokt-wsdk-version":"joint"};this._launcherInstanceGuid&&(u["rokt-launcher-instance-guid"]=this._launcherInstanceGuid),this._accountId&&(u["rokt-account-id"]=this._accountId),fetch(e,{method:"POST",headers:u,body:JSON.stringify(c)}).catch(l=>{console.error("ReportingTransport: Failed to send log",l),s&&s(l)})}catch(c){console.error("ReportingTransport: Failed to send log",c),s&&s(c)}}}class V{constructor(e,t,i,r,o){this._transport=new P(e,t,i,r,o),this._errorUrl="https://"+(e?.errorUrl||oe)}report(e){if(!e)return;const t=e.severity||A.ERROR;this._transport.send(this._errorUrl,t,e.message,e.code,e.stackTrace)}}class q{constructor(e,t,i,r,o,s){this._transport=new P(e,i,r,o,s),this._loggingUrl="https://"+(e?.loggingUrl||re),this._errorReportingService=t}log(e){e&&this._transport.send(this._loggingUrl,A.INFO,e.message,e.code,void 0,t=>{this._errorReportingService&&this._errorReportingService.report({message:"LoggingService: Failed to send log: "+t.message,code:T.UNKNOWN_ERROR,severity:A.ERROR})})}}const h=class h{constructor(){this.name=d,this.id=R,this.moduleId=R,this.isInitialized=!1,this.launcher=null,this.filters={},this.userAttributes={},this.userIdentifiedInWorkspace=!1,this.testHelpers=null,this.placementEventMappingLookup={},this.placementEventAttributeMappingLookup={},this.integrationName=null,this.errorReportingService=null,this.loggingService=null,this._thankYouElementOnLoadCallback=null,this._isThankYouElementLoaded=!1,this._workspaceSearchInFlightPromise=null}getEventAttributeValue(e,t){const i=e&&e.EventAttributes;return!i||typeof i[t]>"u"?null:i[t]}doesEventAttributeConditionMatch(e,t){if(!e||!p(e.operator))return!1;const i=e.operator.toLowerCase(),r=e.attributeValue;return i==="exists"?t!==null:t==null?!1:i==="equals"?String(t)===String(r):i==="contains"?String(t).indexOf(String(r))!==-1:!1}doesEventMatchRule(e,t){if(!t||!p(t.eventAttributeKey))return!1;const i=t.conditions;if(!Array.isArray(i))return!1;const r=this.getEventAttributeValue(e,t.eventAttributeKey);if(i.length===0)return r!==null;for(let o=0;o<i.length;o++)if(!this.doesEventAttributeConditionMatch(i[o],r))return!1;return!0}applyPlacementEventAttributeMapping(e){const t=Object.keys(this.placementEventAttributeMappingLookup);for(let i=0;i<t.length;i++){const r=t[i],o=this.placementEventAttributeMappingLookup[r];if(E(o))continue;let s=!0;for(let c=0;c<o.length;c++)if(!this.doesEventMatchRule(e,o[c])){s=!1;break}s&&a().Rokt.setLocalSessionAttribute?.(r,!0)}}isLauncherReadyToAttach(){return!!window.Rokt&&typeof window.Rokt.createLauncher=="function"}returnUserIdentities(e){if(!e||!e.getUserIdentities)return{};const t=e.getUserIdentities().userIdentities;return this.replaceOtherIdentityWithEmailsha256(t)}returnLocalSessionAttributes(){return!a().Rokt||typeof a().Rokt.getLocalSessionAttributes!="function"?{}:E(this.placementEventMappingLookup)&&E(this.placementEventAttributeMappingLookup)?{}:a().Rokt.getLocalSessionAttributes()}replaceOtherIdentityWithEmailsha256(e){const t={...e||{}},i=this._mappedEmailSha256Key;return i&&e[i]&&(t[h.EMAIL_SHA256_KEY]=e[i]),i&&delete t[i],t}logSelectPlacementsEvent(e){if(!window.mParticle||typeof a().logEvent!="function"||!N(e))return;const t=a().EventType.Other;a().logEvent(Q,t,e)}setRoktSessionId(e){if(!(!e||typeof e!="string"))try{const t=a().getInstance();t&&typeof t.setIntegrationAttribute=="function"&&t.setIntegrationAttribute(R,{roktSessionId:e})}catch{}}attachLauncher(e,t,i=[]){const r=a()&&a().sessionManager&&typeof a().sessionManager.getSession=="function"?a().sessionManager.getSession():void 0,o={accountId:e,...t||{},...r?{mpSessionId:r}:{}};let s;this.isPartnerInLocalLauncherTestGroup()?s=Promise.resolve(window.Rokt.createLocalLauncher(o)):s=window.Rokt.createLauncher(o),s.then(async c=>{await ae(i,c),this.initRoktLauncher(c)}).catch(c=>{console.error("Error creating Rokt launcher:",c)})}initRoktLauncher(e){window.Rokt&&(window.Rokt.currentLauncher=e),this.launcher=e;const t=a().Rokt?.filters;t?(this.filters=t,t.filteredUser?this._workspaceSearchInFlightPromise=this.search(t.filteredUser):console.warn("Rokt Kit: No filtered user has been set.")):console.warn("Rokt Kit: No filters have been set."),this.isInitialized=!0,W(this.domain,this.integrationName),a().Rokt.attachKit(this)}fetchOptimizely(){const e=a()._getActiveForwarders().filter(t=>t.name==="Optimizely");try{if(e.length>0&&window.optimizely){const t=window.optimizely.get("state");return!t||!t.getActiveExperimentIds?{}:t.getActiveExperimentIds().reduce((o,s)=>(o["rokt.custom.optimizely.experiment."+s+".variationId"]=t.getVariationMap()[s].id,o),{})}}catch(t){console.error("Error fetching Optimizely attributes:",t)}return{}}isKitReady(){return!!(this.isInitialized&&this.launcher)}isPartnerInLocalLauncherTestGroup(){return!!(a().config&&a().config.isLocalLauncherEnabled&&this.isAssignedToSampleGroup())}isAssignedToSampleGroup(){return Math.random()>.5}captureTiming(e){window&&a()&&a().captureTiming&&e&&a().captureTiming(e)}init(e,t,i,r,o){const s=e,c=s.accountId;this.userAttributes=I(o),this._onboardingExpProvider=s.onboardingExpProvider;const u=S(s.placementEventMapping);this.placementEventMappingLookup=Y(u);const l=S(s.placementEventAttributeMapping);this.placementEventAttributeMappingLookup=F(l),s.hashedEmailUserIdentityType&&(this._mappedEmailSha256Key=s.hashedEmailUserIdentityType.toLowerCase()),this._workspaceIdSyncApiKey=p(s.workspaceIdSyncApiKey)?s.workspaceIdSyncApiKey:void 0;const _=a().Rokt?.domain,{roktExtensionsQueryParams:C,legacyRoktExtensions:b,loadThankYouElement:w}=j(s.roktExtensions),g={...a().Rokt?.launcherOptions||{}};this.integrationName=ce(g.integrationName),g.integrationName=this.integrationName,this.domain=_;const y={loggingUrl:s.loggingUrl,errorUrl:s.errorUrl,isLoggingEnabled:a().config?.isLoggingEnabled===!0},k=new V(y,this.integrationName,window.__rokt_li_guid__,s.accountId),L=new q(y,k,this.integrationName,window.__rokt_li_guid__,s.accountId);return this.errorReportingService=k,this.loggingService=L,a()._registerErrorReportingService&&a()._registerErrorReportingService(k),a()._registerLoggingService&&a()._registerLoggingService(L),i?(this.testHelpers={generateLauncherScript:K,generateThankYouElementScript:M,extractRoktExtensionConfig:j,hashEventMessage:H,parseSettingsString:S,generateMappedEventLookup:Y,generateMappedEventAttributeLookup:F,sendAdBlockMeasurementSignals:W,createAutoRemovedIframe:O,djb2:z,setAllowedOriginHashes:f=>{h._allowedOriginHashes=f},ReportingTransport:P,ErrorReportingService:V,LoggingService:q,RateLimiter:G,ErrorCodes:T,WSDKErrorSeverity:A},this.attachLauncher(c,g),"Successfully initialized: "+d):(w&&(a().Rokt.flushOnShoppableAdsReadyMessageQueue?.(this),x(te,M(_),{onLoad:()=>{this._isThankYouElementLoaded=!0,this._thankYouElementOnLoadCallback&&this._thankYouElementOnLoadCallback()},onError:f=>{console.error("Error loading Rokt Thank You Element script:",f)}})),this.isLauncherReadyToAttach()?this.attachLauncher(c,g,b):(x(ee,K(_,C),{onLoad:()=>{this.isLauncherReadyToAttach()?this.attachLauncher(c,g,b):console.error("Rokt object is not available after script load.")},onError:f=>{console.error("Error loading Rokt launcher script:",f)}}),this.captureTiming(h.PERFORMANCE_MARKS.RoktScriptAppended)),"Successfully initialized: "+d)}process(e){if(!this.isKitReady())return"Kit not ready for forwarder: "+d;if(typeof a().Rokt?.setLocalSessionAttribute=="function"&&(E(this.placementEventAttributeMappingLookup)||this.applyPlacementEventAttributeMapping(e),!E(this.placementEventMappingLookup))){const t=H(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 U(e)||(this.userAttributes[e]=t),"Successfully set user attribute for forwarder: "+d}removeUserAttribute(e){return delete this.userAttributes[e],"Successfully removed user attribute for forwarder: "+d}handleIdentityComplete(e,t){return this.userAttributes=I(e.getAllUserAttributes()),"Successfully called "+t+" for forwarder: "+d}onUserIdentified(e){const t=e;return this.filters.filteredUser=t,this._workspaceSearchInFlightPromise=this.search(t),this.handleIdentityComplete(e,"onUserIdentified")}search(e){const t=this._workspaceIdSyncApiKey;if(!t)return this.userIdentifiedInWorkspace=!1,this._workspaceLastSearchedIdentitiesKey=void 0,Promise.resolve();const i=a().Identity?.search;if(typeof i!="function")return this.userIdentifiedInWorkspace=!1,this._workspaceLastSearchedIdentitiesKey=void 0,Promise.resolve();const r=e.getUserIdentities?e.getUserIdentities().userIdentities:null,o={};if(r)for(const u of Object.keys(r)){const l=r[u];p(l)&&l.length>0&&(o[u]=l)}const s=Object.keys(o);if(s.length===0)return this.userIdentifiedInWorkspace=!1,this._workspaceLastSearchedIdentitiesKey=void 0,Promise.resolve();const c=s.sort().map(u=>`${u}=${o[u]}`).join("&");return c===this._workspaceLastSearchedIdentitiesKey?this._workspaceSearchInFlightPromise||Promise.resolve():(this.userIdentifiedInWorkspace=!1,this._workspaceLastSearchedIdentitiesKey=c,new Promise(u=>{try{i(t,o,l=>{l?.httpCode===200&&(this.userIdentifiedInWorkspace=!0),u()})}catch(l){console.error("Rokt Kit: Workspace IDSync search failed",l),this._workspaceLastSearchedIdentitiesKey=void 0,u()}}))}onLoginComplete(e,t){return this.handleIdentityComplete(e,"onLoginComplete")}onLogoutComplete(e,t){return this.userIdentifiedInWorkspace=!1,this._workspaceSearchInFlightPromise=null,this._workspaceLastSearchedIdentitiesKey=void 0,this.handleIdentityComplete(e,"onLogoutComplete")}onModifyComplete(e,t){return this.handleIdentityComplete(e,"onModifyComplete")}selectPlacements(e){if(this._workspaceSearchInFlightPromise){const t=this._workspaceSearchInFlightPromise;return Promise.race([t,new Promise(i=>setTimeout(i,ne))]).then(()=>this._dispatchPlacements(e))}return this._dispatchPlacements(e)}_dispatchPlacements(e){const t=e&&e.attributes||{},r={...I(this.userAttributes),...t},o=this.filters||{},s=o.userAttributeFilters||[],c=o.filteredUser||null,u=c?c.getMPID():null;let l;o?o.filterUserAttributes?l=o.filterUserAttributes(r,s):l=r:(console.warn("Rokt Kit: No filters available, using user attributes"),l=r),this.userAttributes=I(l);const _=this._onboardingExpProvider==="Optimizely"?this.fetchOptimizely():{},C=this.returnUserIdentities(c),b=this.returnLocalSessionAttributes(),w={...C,...l,..._,...b,...this.userIdentifiedInWorkspace?{[ie]:!0}:{},mpid:u},g={...e,attributes:w},y=this.launcher.selectPlacements(g),k=()=>this.logSelectPlacementsEvent(w);return Promise.resolve(y).then(L=>L?.context?.sessionId?.then(f=>this.setRoktSessionId(f))).catch(()=>{}).finally(k),y}hashAttributes(e){return this.isKitReady()?this.launcher.hashAttributes(e):(console.error("Rokt Kit: Not initialized"),null)}use(e){return this.isKitReady()?!e||!p(e)?Promise.reject(new Error("Rokt Kit: Invalid extension name")):this.launcher.use(e):(console.error("Rokt Kit: Not initialized"),Promise.reject(new Error("Rokt Kit: Not initialized")))}onShoppableAdsReady(e){this._isThankYouElementLoaded?e():this._thankYouElementOnLoadCallback=e}};h._allowedOriginHashes=[-553112570,549508659],h.PERFORMANCE_MARKS={RoktScriptAppended:"mp:RoktScriptAppended"},h.EMAIL_SHA256_KEY="emailsha256";let m=h;function he(){return R}function pe(n){if(!n){window.console.log("You must pass a config object to register the kit "+d);return}if(!N(n)){window.console.log("'config' must be an object. You passed in a "+typeof n);return}N(n.kits)?n.kits[d]={constructor:m}:(n.kits={},n.kits[d]={constructor:m}),window.console.log("Successfully registered "+d+" to your mParticle configuration")}return typeof window<"u"&&window.mParticle&&a().addForwarder&&a().addForwarder({name:d,constructor:m,getId:he}),v.register=pe,Object.defineProperty(v,Symbol.toStringTag,{value:"Module"}),v})({});
|
|
2
2
|
//# sourceMappingURL=Rokt-Kit.iife.js.map
|