@customerio/cdp-analytics-browser 0.3.15 → 0.3.17
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/cjs/generated/version.js +1 -1
- package/dist/pkg/generated/version.js +1 -1
- package/dist/types/core/buffer/index.d.ts +1 -1
- package/dist/types/generated/version.d.ts +1 -1
- package/dist/umd/573.js +1 -0
- package/dist/umd/573.js.gz +0 -0
- package/dist/umd/inAppPlugin.js +1 -1
- package/dist/umd/inAppPlugin.js.gz +0 -0
- package/dist/umd/index.js +1 -1
- package/dist/umd/index.js.gz +0 -0
- package/dist/umd/standalone.js +1 -1
- package/dist/umd/standalone.js.gz +0 -0
- package/package.json +3 -3
- package/src/generated/version.ts +1 -1
- package/dist/umd/740.js +0 -1
- package/dist/umd/740.js.gz +0 -0
|
@@ -76,7 +76,7 @@ export declare class AnalyticsBuffered implements PromiseLike<[Analytics, Contex
|
|
|
76
76
|
deregister: (...args: string[]) => Promise<Context>;
|
|
77
77
|
user: () => Promise<import("../user").User>;
|
|
78
78
|
inbox(...topics: string[]): import('../../plugins/in-app-plugin').InboxAPI;
|
|
79
|
-
readonly VERSION = "0.3.
|
|
79
|
+
readonly VERSION = "0.3.17";
|
|
80
80
|
private _createMethod;
|
|
81
81
|
/**
|
|
82
82
|
* These are for methods that where determining when the method gets "flushed" is not important.
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const version = "0.3.
|
|
1
|
+
export declare const version = "0.3.17";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
package/dist/umd/573.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(self.webpackChunk_customerio_cdp_analytics_browser=self.webpackChunk_customerio_cdp_analytics_browser||[]).push([[573],{7573:function(e){var t;t=()=>(()=>{"use strict";var e={d:(t,s)=>{for(var n in s)e.o(s,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:s[n]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)},t={};e.d(t,{default:()=>Ke});class s{constructor(){this.callbacks={}}on(e,t){const s=this.callbacks[e];s?s.push(t):this.callbacks[e]=[t]}off(e,t){const s=this.callbacks[e];if(!s)return;if(!t)return void delete this.callbacks[e];const n=s.indexOf(t);-1!==n&&s.splice(n,1),0===s.length&&delete this.callbacks[e]}dispatch(e,t){const s=this.callbacks[e];s&&s.forEach((e=>e(t)))}}function n(e){Ke.config&&Ke.config.logging&&console.log(`Gist: ${e}`)}const i="gist.web.isPersistingSession";function a(e,t,s=null){let n=s;n||(n=new Date,n.setDate(n.getDate()+365));const i={value:t,expiry:n};u().setItem(e,JSON.stringify(i))}function o(e){return l(e)}function r(e){u().removeItem(e)}function c(){const e=sessionStorage.getItem(i);return null===e?(sessionStorage.setItem(i,"true"),!0):"true"===e}function u(){return c()?localStorage:sessionStorage}function l(e){if(!e)return null;try{const t=u().getItem(e);if(!t)return null;const s=JSON.parse(t);if(!s.expiry)return s.value;const n=new Date,i=new Date(s.expiry),a=e.startsWith("gist.web.message.broadcasts")&&!e.endsWith("shouldShow")&&!e.endsWith("numberOfTimesShown")||e.startsWith("gist.web.message.user")&&!e.endsWith("seen")&&!e.endsWith("state"),o=new Date(n.getTime()+366e4);return a&&i.getTime()>o.getTime()||n.getTime()>i.getTime()?(r(e),null):s.value}catch(t){n(`Error checking key ${e} for expiry: ${t}`)}return null}var d,g=new Uint8Array(16);function m(){if(!d&&!(d="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||"undefined"!=typeof msCrypto&&"function"==typeof msCrypto.getRandomValues&&msCrypto.getRandomValues.bind(msCrypto)))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return d(g)}const p=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;for(var f=[],h=0;h<256;++h)f.push((h+256).toString(16).substr(1));const w=function(e,t,s){var n=(e=e||{}).random||(e.rng||m)();if(n[6]=15&n[6]|64,n[8]=63&n[8]|128,t){s=s||0;for(var i=0;i<16;++i)t[s+i]=n[i];return t}return function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,s=(f[e[t+0]]+f[e[t+1]]+f[e[t+2]]+f[e[t+3]]+"-"+f[e[t+4]]+f[e[t+5]]+"-"+f[e[t+6]]+f[e[t+7]]+"-"+f[e[t+8]]+f[e[t+9]]+"-"+f[e[t+10]]+f[e[t+11]]+f[e[t+12]]+f[e[t+13]]+f[e[t+14]]+f[e[t+15]]).toLowerCase();if(!function(e){return"string"==typeof e&&p.test(e)}(s))throw TypeError("Stringified UUID is invalid");return s}(n)},y="gist.web.userQueueUseSSE",b="gist.web.activeSSEConnection";let v,S=30;const I={RENDERER_HOST:"https://code.gist.build",ENGINE_API_ENDPOINT:{prod:"https://engine.api.gist.build",dev:"https://engine.api.dev.gist.build",local:"http://engine.api.local.gist.build:82"},GIST_QUEUE_API_ENDPOINT:{prod:"https://consumer.cloud.gist.build",dev:"https://consumer.cloud.dev.gist.build",local:"http://api.local.gist.build:86"},GIST_QUEUE_REALTIME_API_ENDPOINT:{prod:"https://realtime.cloud.gist.build",dev:"https://realtime.cloud.dev.gist.build",local:"http://api.local.gist.build:3000"},GIST_VIEW_ENDPOINT:{prod:"https://renderer.gist.build/3.0",dev:"https://renderer.gist.build/3.0",local:"http://app.local.gist.build:8080/web"},getSdkId:()=>(v||(v=w()),v),useSSE:()=>o(y)??!1,setUseSSEFlag(e){a(y,e,new Date((new Date).getTime()+6e4)),n(`Set user uses SSE to "${e}"`)},removeActiveSSEConnection(){r(b)},setActiveSSEConnection(){a(b,I.getSdkId(),new Date((new Date).getTime()+I.getSSEHeartbeat()))},hasActiveSSEConnection:()=>o(b)??!1,isSSEConnectionManagedBySDK:()=>o(b)===I.getSdkId(),getSSEHeartbeat:()=>1e3*(S+5),setSSEHeartbeat(e){e&&e>0&&(S=e)}};function $(e){return null!==e&&"object"==typeof e&&"response"in e}function x(e){return $(e)?e.response:void 0}function E(){const e=I.GIST_QUEUE_API_ENDPOINT[Ke.config.env??"prod"],t={"X-CIO-Site-Id":Ke.config.siteId,"X-CIO-Client-Platform":"web"},s=_();async function n(s,n={}){const i=e+s,a=new AbortController,o=setTimeout((()=>a.abort()),5e3);try{const e=await fetch(i,{method:n.method||"GET",headers:{...t,...n.headers||{}},body:n.method&&"GET"!==n.method.toUpperCase()?n.body:void 0,signal:a.signal});clearTimeout(o);const s=e.headers.get("content-type")?.includes("application/json"),r=s?await e.json():await e.text(),c=Object.fromEntries(e.headers.entries());if(e.status<200||e.status>=400)throw function(e){return Object.assign(new Error,{response:e})}({status:e.status,data:r,headers:c});return{status:e.status,headers:c,data:r}}catch(e){if(clearTimeout(o),$(e))throw e;if(e instanceof Error)throw Object.assign(e,{response:{status:0,data:e.message||"Unknown error",headers:{}}});throw e}}return null!=s&&(t["X-Gist-Encoded-User-Token"]=s),n.post=(e,t={},s={})=>n(e,{method:"POST",body:JSON.stringify(t),headers:{"Content-Type":"application/json",...s.headers||{}}}),n}const k="gist.web.userLocale";function C(){const e=o(k);return null!==e?e:navigator.language}let D=600,T=!1;const M="gist.web.userQueueNextPullCheck",q="gist.web.sessionId";function R(){let e=o(q);return e||(e=w()),a(q,e,new Date((new Date).getTime()+18e5)),String(e)}const P="gist.web.userToken",L="gist.web.usingGuestUserToken",N="gist.web.guestUserToken";function W(){return null!==o(L)}function A(){return o(P)}function O(){if(null===A()){let e=o(N);null==e&&(e=w(),a(N,e),n(`Set guest user token "${e}" with expiry date set to 1 year from today`)),a(P,e),a(L,!0),n(`Using anonymous session with token: "${e}"`)}}async function U(){const e=A();return null===e?null:await async function(e){const t=(new TextEncoder).encode(e),s=await crypto.subtle.digest("SHA-256",t);return Array.from(new Uint8Array(s)).map((e=>e.toString(16).padStart(2,"0"))).join("")}(e)}function _(){const e=A();return null===e?null:btoa(e)}async function H(e){try{return await E().post(`/api/v1/logs/queue/${e}`)}catch(e){return x(e)}}function j(e){const t={isEmbedded:!1,elementId:"",hasRouteRule:!1,routeRule:"",position:"",hasPosition:!1,shouldScale:!1,campaignId:null,messageWidth:414,overlayColor:"#00000033",persistent:!1,exitClick:!1,hasCustomWidth:!1},s=e?.properties?.gist;return s?{isEmbedded:!!s.elementId,elementId:s.elementId||"",hasRouteRule:!!s.routeRuleWeb,routeRule:s.routeRuleWeb||"",position:s.position||"",hasPosition:!!s.position,shouldScale:!!s.scale,campaignId:s.campaignId??null,messageWidth:null!=s.messageWidth&&s.messageWidth>0?s.messageWidth:t.messageWidth,hasCustomWidth:(s.messageWidth??0)>0,overlayColor:s.overlayColor||t.overlayColor,persistent:!!s.persistent,exitClick:!!s.exitClick}:t}const z=["x-gist-top","x-gist-floating-top","x-gist-bottom","x-gist-floating-bottom","x-gist-floating-bottom-left","x-gist-floating-bottom-right","x-gist-floating-top-left","x-gist-floating-top-right"];function G(e){if(document.getElementById(e))return;const t=document.createElement("div");t.id=e,"x-gist-top"===e?document.body.insertBefore(t,document.body.firstChild):document.body.insertAdjacentElement("beforeend",t),n("Top & bottom elements injected into page")}const V=["x-gist-top","x-gist-bottom","x-gist-floating-top","x-gist-floating-bottom"];function F(e){return Ke.currentMessages.find((t=>t.instanceId===e))}function B(e){return!!e&&Ke.currentMessages.some((t=>t.queueId===e))}function J(e){return e?Ke.currentMessages.find((t=>t.elementId===e))??null:null}function Q(e){Ke.currentMessages=Ke.currentMessages.filter((t=>t.instanceId!==e))}function X(e,t){Q(e),Ke.currentMessages.push(t)}function K(e){const t={topLeft:"x-gist-floating-top-left",topCenter:"x-gist-floating-top",topRight:"x-gist-floating-top-right",bottomLeft:"x-gist-floating-bottom-left",bottomCenter:"x-gist-floating-bottom",bottomRight:"x-gist-floating-bottom-right"};return e&&t[e]?t[e]:(n(`Invalid overlay position "${e}", defaulting to "topCenter"`),t.topCenter)}function Y(e,t){if(e.properties||(e.properties={}),e.properties.gist||(e.properties.gist={}),"modal"===t.displayType)e.overlay=!0,e.elementId=null,e.properties.gist.elementId=null,e.position=t.modalPosition||"center",e.properties.gist.position=t.modalPosition||"center";else if("overlay"===t.displayType){e.overlay=!1;const s=K(t.overlayPosition);e.elementId=s,e.properties.gist.elementId=s,e.position=null,e.properties.gist.position=null}else"inline"===t.displayType&&(e.overlay=!1,e.elementId=t.elementSelector,e.properties.gist.elementId=t.elementSelector,e.position=null,e.properties.gist.position=null);e.elementId&&V.includes(e.elementId)?delete e.properties.gist.messageWidth:void 0!==t.maxWidth&&t.maxWidth>0?e.properties.gist.messageWidth=t.maxWidth:delete e.properties.gist.messageWidth,void 0!==t.overlayColor?e.properties.gist.overlayColor=t.overlayColor:delete e.properties.gist.overlayColor,void 0!==t.dismissOutsideClick?e.properties.gist.exitClick=t.dismissOutsideClick:delete e.properties.gist.exitClick}function Z(e){const t=ce(e);t&&(t.classList.remove("gist-visible"),Array.from(t.classList).filter((e=>e.startsWith("gist-"))).forEach((e=>t.classList.remove(e))),t.style.removeProperty("height"),t.style.removeProperty("width"),t.innerHTML="")}function ee(e){const t=ce(e);if(t)return!(!t.style||!t.style.height||"0px"===t.style.height)}function te(e,t,s=null){const n=document.getElementById(e);n&&(n.onload=()=>{!function(e,t,s=null){const n=document.getElementById(e);if(n?.contentWindow){const e={options:t,capabilities:se};s&&(t.stepId=s),n.contentWindow.postMessage(e,"*")}}(e,t,s)})}const se=["MultiStepDisplayTypes"];function ne(e){if(!e.displaySettings)return;const t=oe(e.instanceId??""),s=document.getElementById(t);s?.contentWindow&&s.contentWindow.postMessage({action:"updateDisplaySettings",displaySettings:e.displaySettings},"*")}async function ie(){const e=document.querySelector(".gist-message");e&&(e.classList.remove("gist-visible"),await new Promise((e=>setTimeout(e,300)))),ae()}function ae(){const e=document.querySelector("#gist-embed-message");e&&e.parentNode?.removeChild(e)}function oe(e){return`gist-${e}`}function re(){const e=document.querySelector(".gist-message");e&&e.classList.add("gist-visible")}function ce(e){try{const t=document.querySelector(`#${e}`);return t instanceof HTMLElement?t:null}catch{return null}}const ue="gist.web.customAttributes";let le=new Map;function de(){const e=Array.from(le.entries()),t=new Date;t.setDate(t.getDate()+30),a(ue,e,t),n(`Saved ${le.size} custom attributes to storage with TTL of 30 days`)}async function ge(e){const t=await he();if(!t)return;const s=new Date;s.setMinutes(s.getMinutes()+60),a(t,e.filter(pe),s)}async function me(e,t){return o(e)?.find((e=>e.queueId===t))}function pe(e){return!(!e.properties?.gist||!e.properties.gist.broadcast)}function fe(e){if(!pe(e))return!1;const t=e.properties.gist.broadcast;return 0===t.frequency.delay&&0===t.frequency.count}async function he(){const e=await U();return e?`gist.web.message.broadcasts.${e}`:null}function we(e,t){return`${e}.${t}.numberOfTimesShown`}function ye(e,t){return`${e}.${t}.shouldShow`}!function(){const e=o(ue);if(e)try{le=new Map(e)}catch{le=new Map}else le=new Map}();const be="gist.web.message.user";async function ve(e){const t=await Se();if(!t)return;const s=e.filter((e=>!(e.properties&&e.properties.gist&&e.properties.gist.broadcast))),n=new Date;n.setMinutes(n.getMinutes()+60),a(t,s,n)}async function Se(){const e=await U();return e?`${be}.${e}`:null}async function Ie(){const e=await U();return e?`${be}.${e}.seen`:null}async function $e(e){const t=await U();return t?`${be}.${t}.message.${e}.loading`:null}async function xe(e){const t=await U();return t?`${be}.${t}.message.${e}.state`:null}async function Ee(e){const t=await xe(e);t&&(r(t),n(`Cleared message state for queueId: ${e}`))}async function ke(e){if(Ke.isDocumentVisible){if(B(e.queueId))return n(`Message with queueId ${e.queueId} is already showing.`),null;if(Ke.overlayInstanceId)return n(`Message ${Ke.overlayInstanceId} already showing.`),null;{const t=j(e);return e.instanceId=w(),e.overlay=!0,e.firstLoad=!0,e.shouldResizeHeight=!0,e.shouldScale=t.shouldScale,e.renderStartTime=(new Date).getTime(),Ke.overlayInstanceId=e.instanceId,Ke.currentMessages.push(e),Pe(e,null,e.savedStepName||null)}}return n("Document hidden, not showing message now."),null}function Ce(e,t){return Ke.isDocumentVisible?B(e.queueId)?(n(`Message with queueId ${e.queueId} is already showing.`),null):J(t)?(n(`Message with elementId ${t} already has a message.`),null):(e.instanceId=w(),e.overlay=!1,e.firstLoad=!0,e.shouldScale=!1,e.elementId=t,e.shouldResizeHeight=!ee(t),e.renderStartTime=(new Date).getTime(),Ke.currentMessages.push(e),Pe(e,t,e.savedStepName||null)):(n("Document hidden, not showing message now."),null)}async function De(e){e?(Ke.messageDismissed(e),await Te(e)):n("Message not found")}async function Te(e){e.overlay?await Re(!0,e):qe(e)}async function Me(e){e?j(e).persistent&&(n("Persistent message dismissed, logging view"),await Ae(e),await Le(e),await Ee(e.queueId??"")):n("Message not found")}function qe(e){e.instanceId&&Q(e.instanceId),e.elementId&&Z(e.elementId)}async function Re(e,t){e?await ie():ae(),0===Ke.currentMessages.length&&(window.removeEventListener("message",We),window.removeEventListener("touchstart",Ne)),t.instanceId&&Q(t.instanceId),Ke.overlayInstanceId=null}function Pe(e,t=null,s=null){const i=Ke.config.env,a={endpoint:I.ENGINE_API_ENDPOINT[i],siteId:Ke.config.siteId,dataCenter:Ke.config.dataCenter,messageId:e.messageId,instanceId:e.instanceId??"",livePreview:!1,properties:e.properties,customAttributes:Object.fromEntries(new Map(le))},o=`${I.GIST_VIEW_ENDPOINT[i]}/index.html`;return window.addEventListener("message",We),window.addEventListener("touchstart",Ne),t?(z.includes(t)&&G(t),function(e,t,s,i,a=null){const o=ce(e);if(o){const n=oe(s.instanceId??"");o.classList.add(n);const r=j(s);let c=r.messageWidth+"px";V.includes(e)&&!r.hasCustomWidth&&(c="100%"),z.includes(e)&&(o.style.width=c),ee(e)||(o.style.height="0px"),o.innerHTML=function(e,t,s){return function(e,t,s){let n=800;return t.messageWidth>n&&(n=t.messageWidth),`\n <div id="gist-embed">\n <style>\n #x-gist-floating-top, #x-gist-floating-top-left, #x-gist-floating-top-right {\n position: fixed;\n top: 0px;\n z-index: 1000000;\n }\n #x-gist-floating-bottom, #x-gist-floating-bottom-left, #x-gist-floating-bottom-right {\n position: fixed;\n bottom: 0px;\n z-index: 1000000;\n }\n #x-gist-bottom, #x-gist-top, #x-gist-floating-top, #x-gist-floating-bottom {\n left: 50%;\n transform: translate(-50%, 0%);\n }\n #x-gist-floating-top-right, #x-gist-floating-bottom-right {\n right: 0px;\n }\n #gist-embed {\n position: relative;\n height: 100%;\n width: 100%;\n }\n #gist-embed-container {\n position: relative;\n height: 100%;\n width: 100%;\n }\n #gist-embed-container .gist-frame {\n height: 100%;\n width: 100%;\n border: none;\n }\n #x-gist-top.${e},\n #x-gist-bottom.${e},\n #x-gist-floating-top.${e},\n #x-gist-floating-bottom.${e},\n #x-gist-floating-top-left.${e},\n #x-gist-floating-top-right.${e},\n #x-gist-floating-bottom-left.${e},\n #x-gist-floating-bottom-right.${e} {\n transition: height 0.1s ease-in-out;\n }\n @media (max-width: ${n}px) {\n #x-gist-top.${e},\n #x-gist-bottom.${e},\n #x-gist-floating-top.${e},\n #x-gist-floating-bottom.${e},\n #x-gist-floating-top-left.${e},\n #x-gist-floating-top-right.${e},\n #x-gist-floating-bottom-left.${e},\n #x-gist-floating-bottom-right.${e} {\n width: 100% !important;\n }\n }\n </style>\n <div id="gist-embed-container">\n <iframe id="${e}" class="gist-frame" src="${s}"></iframe>\n </div>\n </div>`}(oe(t.instanceId??""),s,e)}(t,s,r),te(n,i,a)}else n(`Message could not be embedded, elementId ${e} not found.`)}(t,o,e,a,s)):function(e,t,s,n=null){document.querySelectorAll("#gist-embed-message").forEach((e=>{e.parentNode?.removeChild(e)})),document.body.insertAdjacentHTML("afterbegin",function(e,t){const s=j(t);return function(e,t,s){let n=600;return t.messageWidth>n&&(n=t.messageWidth),`\n <div id="gist-embed-message">\n <style>\n #gist-overlay.gist-background {\n position: fixed;\n z-index: 9999999998;\n left: 0;\n top: 0;\n width: 100%;\n height: 100%;\n background-color: ${t.overlayColor};\n visibility: hidden;\n }\n #gist-overlay.gist-background.gist-visible {\n visibility: visible;\n }\n .gist-message {\n width: ${t.messageWidth}px;\n position: absolute;\n border: none;\n opacity: 0;\n transition: opacity 0.3s ease-in-out, height 0.1s ease-in-out;\n z-index: 9999999999;\n left: 50%;\n transform: translateX(-50%);\n }\n .gist-message.gist-visible {\n opacity: 1;\n pointer-events: auto;\n }\n .gist-message.gist-center {\n transform: translate(-50%, -50%);\n top: 50%;\n }\n .gist-message.gist-bottom {\n bottom: 0;\n }\n .gist-message.gist-top {\n top: 0;\n }\n @media (max-width: ${n}px) {\n .gist-message {\n width: 100%;\n }\n }\n </style>\n <div id="gist-overlay" class="gist-background">\n <iframe id="${e}" class="gist-message" src="${s}"></iframe>\n </div>\n </div>`}(oe(t.instanceId??""),s,e)}(e,t)),te(oe(t.instanceId??""),s,n)}(o,e,a,s),e}async function Le(e){let t;n(`Message shown, logging view for: ${e.messageId}`),null!=e.queueId?(await Ae(e),t=await H(e.queueId)):t=await async function(e){try{return await E().post(`/api/v1/logs/message/${e}`)}catch(e){return x(e)}}(e.messageId),n(200===t?.status?"Message view logged":`Problem logging message: ${t?.status}`)}function Ne(){}async function We(e){const t=e.data;if(t.gist&&e.origin===I.RENDERER_HOST){const e=t.gist.instanceId,s=F(e);if(!s)return;const i=j(s);switch(t.gist.method){case"routeLoaded":{const a=.001*((new Date).getTime()-(s.renderStartTime??0));n(`Engine render for message: ${s.messageId} timer elapsed in ${a.toFixed(3)} seconds`),async function(e){const t=await $e(e);t&&r(t)}(s.queueId??""),s.currentRoute=t.gist.parameters.route,t.gist.parameters.fullDisplaySettings&&!s.displaySettings?s.displaySettings=t.gist.parameters.fullDisplaySettings:s.displaySettings&&(n("SDK already has display settings state, sending it to iframe"),ne(s)),(s.firstLoad||s.isDisplayChange)&&(s.overlay?function(e){const t=j(e),s=document.querySelector("#gist-overlay");if(s){s.classList.add("gist-visible");const n=document.querySelector(".gist-message");n&&(e.position?n.classList.add("gist-"+e.position):n.classList.add("gist-center")),setTimeout(re,100),t.exitClick&&setTimeout((()=>function(e){const t=document.querySelector("#gist-overlay");t&&t.addEventListener("click",(()=>{Ke.dismissMessage(e)}))}(e.instanceId??"")),1e3)}else ae()}(s):function(e){const t=ce(e);t&&t.classList.add("gist-visible")}(s.elementId),s.firstLoad&&!s.isDisplayChange&&(Ke.messageShown(s),i.persistent?n("Persistent message shown, skipping logging view"):await Le(s)),s.firstLoad=!1,s.isDisplayChange=!1),X(e,s);break}case"tap":{const e=t.gist.parameters.action,n=t.gist.parameters.name;if(Ke.messageAction(s,e,n),t.gist.parameters.system&&!i.persistent){await De(s);break}try{const t=new URL(e);if(t&&"gist:"===t.protocol)switch(t.href.replace("gist://","").split("?")[0]){case"close":await De(s),await Me(s),await Oe(s),await Be();break;case"showMessage":{const e=t.searchParams.get("messageId");let s=t.searchParams.get("properties");e&&(s&&(s=JSON.parse(atob(s))),await Ke.showMessage({messageId:e,properties:s}));break}case"loadPage":{const e=t.href.substring(t.href.indexOf("?url=")+5);e&&(e.startsWith("mailto:")||e.startsWith("https://")||e.startsWith("http://")||e.startsWith("/")?window.location.href=e:window.location.href=window.location+e);break}}}catch{}break}case"changeMessageStep":{const e=t.gist.parameters.displaySettings,r=t.gist.parameters.messageStepName;(i.persistent||fe(s))&&await async function(e,t,s){const i=await xe(e);if(!i)return;const r=o(i)||{},c={stepName:void 0!==t?t:r.stepName,displaySettings:void 0!==s?s:r.displaySettings},u=new Date;u.setDate(u.getDate()+30),a(i,c,u),n(`Saved message state for queueId: ${e}`)}(s.queueId??"",r,e),e&&function(e,t){const s=(n=e).overlay?"modal":n.elementId&&z.includes(n.elementId)?"overlay":n.elementId?"inline":"modal";var n;const i=t.displayType;if(void 0===i)return!1;if(s!==i)return!0;const a=j(e);switch(i){case"modal":if((e.position||"center")!==(t.modalPosition||"center"))return!0;if(void 0!==t.dismissOutsideClick&&a.exitClick!==t.dismissOutsideClick)return!0;if(void 0!==t.overlayColor&&a.overlayColor!==t.overlayColor)return!0;break;case"overlay":{const s=K(t.overlayPosition);if(e.elementId!==s)return!0;break}case"inline":if(e.elementId!==t.elementSelector)return!0}return void 0!==t.maxWidth&&a.messageWidth!==t.maxWidth}(s,e)&&(n("Display settings changed, reloading message"),await async function(e){e.overlay?await ie():e.elementId&&Z(e.elementId)}(s),Y(s,e),await async function(e,t){e.isDisplayChange=!0,e.renderStartTime=(new Date).getTime();const s=e.elementId||null;if(s){const t=J(s);t&&t.instanceId!==e.instanceId&&(n(`Dismissing existing message at ${s} to make room for multi-step message`),await De(t))}if(e.overlay){Ke.overlayInstanceId=e.instanceId??null;const t=j(e);e.shouldScale=t.shouldScale,e.shouldResizeHeight=!0}else Ke.overlayInstanceId=null,e.shouldScale=!1,e.shouldResizeHeight=!ee(s??"");s&&z.includes(s)&&G(s),Pe(e,s,t)}(s,r??null));break}case"routeChanged":s.currentRoute=t.gist.parameters.route,s.renderStartTime=(new Date).getTime(),X(e,s),n(`Route changed to: ${s.currentRoute}`);break;case"sizeChanged":n(`Size Changed Width: ${t.gist.parameters.width} - Height: ${t.gist.parameters.height}`),s.elementId&&!s.shouldResizeHeight||function(e,t){const s=ce(e.elementId?e.elementId:oe(e.instanceId??""));if(s){const n=s.style;if(t.height>0)if(t.height>window.innerHeight){const s=1-(t.height/window.innerHeight-1);e.shouldScale&&s>=.4?(n.height=`${t.height}px`,n.transform=`translateX(-50%) translateY(-50%) scale(${s})`):n.height=`${window.innerHeight}px`}else n.height=`${t.height}px`}}(s,t.gist.parameters);break;case"titleChanged":n(`Overlay title changed to: ${t.gist.parameters.title}`),function(e,t){const s=ce(oe(e));s&&(s.title=t)}(e,t.gist.parameters.title);break;case"eventDispatched":Ke.events.dispatch("eventDispatched",{name:t.gist.parameters.name,payload:t.gist.parameters.payload});break;case"error":case"routeError":Ke.messageError(s),Ke.overlayInstanceId?await Re(!1,s):qe(s)}}}async function Ae(e){n(`Logging user message view locally for: ${e.queueId}`),pe(e)?await async function(e){n(`Marking broadcast ${e} as seen.`);const t=await he();if(!t)return;const s=await me(t,e);if(!s)return;const i=s.properties.gist.broadcast,{frequency:r}=i,c=we(t,e),u=ye(t,e),l=o(c)||0;if(a(c,l+1),1===r.count)a(u,!1),n(`Marked broadcast ${e} as seen.`);else{const t=new Date;t.setSeconds(t.getSeconds()+r.delay),a(u,!1,t),n(`Marked broadcast ${e} as seen, broadcast was seen ${l+1} times, next show date is ${t}.`)}}(e.queueId??""):await async function(e){const t=await Ie();if(!t)return;const s=o(t)??[];s.push(e),a(t,s)}(e.queueId??"")}async function Oe(e){pe(e)&&(n(`Logging broadcast dismissed locally for: ${e.queueId}`),await async function(e){n(`Marking broadcast ${e} as dismissed.`);const t=await he();if(!t)return;const s=await me(t,e);s&&(!0!==s.properties.gist.broadcast.frequency.ignoreDismiss?(a(ye(t,e),!1),n(`Marked broadcast ${e} as dismissed and will not show again.`)):n(`Broadcast ${e} is set to ignore dismiss.`))}(e.queueId??""),await Ee(e.queueId??""))}const Ue="messageInboxUpdated";async function _e(e){const t=await je();if(!t)return;const s=new Date;s.setMinutes(s.getMinutes()+60),a(t,e,s),Ke.events.dispatch(Ue,e)}async function He(){const e=await je();if(!e)return[];const t=o(e)??[],s=new Date;return t.filter((e=>!e.expiry||new Date(e.expiry)>s))}async function je(){const e=await U();return e?`gist.web.inbox.messages.${e}`:null}const ze=(e,t)=>e().then((e=>new Promise((t=>setTimeout(t,e))))(t).then((()=>ze(e,t))));let Ge=!1,Ve=null;async function Fe(){Ge?await Be():A()?(n("Queue watcher started"),Ge=!0,ze((()=>new Promise((()=>{!async function(){if(I.hasActiveSSEConnection())return!I.isSSEConnectionManagedBySDK()&&Ve&&(n("Not the main instance, closing our SSE connection."),Xe()),void await Be();Ve&&(n("SSE connection not active, closing it."),Xe()),!I.useSSE()||W()?await Qe():await async function(){Xe();const e=function(){const e=_();return null===e?(n("No user token available for SSE endpoint."),null):I.GIST_QUEUE_REALTIME_API_ENDPOINT[Ke.config.env??"prod"]+`/api/v3/sse?userToken=${e}&siteId=${Ke.config.siteId}&sessionId=${R()}`}();if(null===e)return n("SSE endpoint not available, falling back to polling."),void await Qe();n(`Starting SSE queue listener on ${e}`),Ve=new EventSource(e),I.setActiveSSEConnection(),Ve.addEventListener("connected",(async e=>{try{n("SSE connection received"),I.setUseSSEFlag(!0);const t=JSON.parse(e.data);t.heartbeat&&(I.setSSEHeartbeat(t.heartbeat),n(`SSE heartbeat set to ${t.heartbeat} seconds`)),I.setActiveSSEConnection()}catch(e){n(`Failed to parse SSE settings: ${e}`)}r(M),await Qe()})),Ve.addEventListener("messages",(async e=>{try{const t=JSON.parse(e.data);n("SSE message received"),await ve(t),await ge(t),await Be()}catch(e){n(`Failed to parse SSE message: ${e}`),Xe()}})),Ve.addEventListener("inbox_messages",(async e=>{try{const t=JSON.parse(e.data);n("SSE inbox messages received"),await _e(t)}catch(e){n(`Failed to parse SSE inbox messages: ${e}`)}})),Ve.addEventListener("error",(async()=>{n("SSE error received"),Xe()})),Ve.addEventListener("heartbeat",(async()=>{n("SSE heartbeat received"),I.setActiveSSEConnection(),I.setUseSSEFlag(!0)}))}()}()}))),1e3)):n("User token not setup, queue not started.")}async function Be(){const e=await async function(){const e=await he();return e?(o(e)??[]).filter((t=>{const s=t.properties.gist.broadcast,{frequency:n}=s,i=o(ye(e,t.queueId))??!0,a=o(we(e,t.queueId))||0,r=0===n.count;return i&&(r||a<n.count)})):[]}(),t=await async function(){const e=await Se();if(!e)return[];const t=o(e)??[],s=await async function(){const e=await Ie();return e?o(e)??[]:[]}();return t.filter((e=>!s.includes(e.queueId??"")))}(),s=e.concat(t);n(`Messages in local queue: ${s.length}`);const i=s.sort(((e,t)=>e.priority-t.priority));for(const e of i)await Je(e)}async function Je(e){let t=j(e);if(t.hasRouteRule){let e=Ke.currentRoute;null==e&&(e=new URL(window.location.href).pathname);const s=t.routeRule;if(n(`Verifying route ${e} against rule: ${s}`),!new RegExp(s).test(e))return n(`Route ${e} does not match rule.`),!1}if(t.hasPosition&&(e.position=t.position),t.persistent||fe(e)){const s=await async function(e){const t=await xe(e);return t?o(t):null}(e.queueId??"");s&&(n(`Restoring saved state for queueId ${e.queueId}`),s.displaySettings&&(Y(e,s.displaySettings),t=j(e)),e.savedStepName=s.stepName??null)}if(t.persistent||fe(e)||!await async function(e){const t=await $e(e);return!!t&&null!==o(t)}(e.queueId??"")){let s=null;return s=t.isEmbedded?Ce(e,t.elementId):await ke(e),s&&async function(e){const t=await $e(e);t&&a(t,!0,new Date(Date.now()+5e3))}(e.queueId??""),null!==s}return n(`Not showing message with queueId ${e.queueId} because its already loading.`),!1}async function Qe(){if(A())if(Ke.isDocumentVisible)if(null===o(M)){const e=await async function(){const e=A();let t;try{if(!T){T=!0;const e={"X-Gist-User-Anonymous":String(W()),"Content-Language":String(C())};t=await E().post(`/api/v4/users?sessionId=${R()}`,{},{headers:e})}}catch(e){const s=x(e);s?t=s:n(`Error getting user queue: ${e}`)}finally{T=!1}return e!==A()?(n("User token changed, clearing queue next pull check."),void r(M)):(function(e){if(e?.headers){const t=e.headers["x-gist-queue-polling-interval"];t&&Number(t)>0&&(D=Number(t))}const t=new Date((new Date).getTime()+1e3*D);a(M,D,t)}(t),function(e){const t="true"===e?.headers?.["x-cio-use-sse"]?.toLowerCase();I.setUseSSEFlag(t)}(t),t)}();if(e){if(200===e.status||204===e.status){n("200 response, updating local store.");const t=e.data,s=t?.inAppMessages??[],i=t?.inboxMessages??[];ve(s),ge(s),_e(i)}else 304===e.status&&n("304 response, using local store.");await Be()}else n("No response object returned while checking message queue.")}else n("Next queue pull scheduled for later.");else n("Document not visible, skipping queue check.");else n("User token reset, skipping queue check.")}function Xe(e=!1){e&&I.removeActiveSSEConnection(),(e||I.isSSEConnectionManagedBySDK())&&I.setUseSSEFlag(!1),Ve&&(n("Stopping SSE queue listener..."),Ve.close(),Ve=null)}const Ke=class{static events;static config;static initialized;static currentMessages;static overlayInstanceId;static currentRoute;static isDocumentVisible;static async setup(e){this.initialized?n("Gist SDK already initialized, skipping setup."):(this.initialized=!0,this.events=new s,this.config={useAnonymousSession:void 0!==e.useAnonymousSession&&e.useAnonymousSession,siteId:e.siteId,dataCenter:e.dataCenter,env:void 0===e.env?"prod":e.env,logging:void 0!==e.logging&&e.logging,experiments:void 0!==e.experiments&&e.experiments},this.currentMessages=[],this.overlayInstanceId=null,this.currentRoute=null,this.isDocumentVisible=!0,this.config.isPreviewSession=function(){const e=new URLSearchParams(window.location.search).get("cioPreviewId");return e&&(sessionStorage.setItem(i,String(!1)),Ke.setUserToken(e),n(`Preview mode enabled with user token: ${e}`)),!c()}(),function(){const e=u();for(let t=e.length-1;t>=0;t--)l(e.key(t))}(),n(`Setup complete on ${this.config.env} environment.`),this.config.isPreviewSession||!this.config.useAnonymousSession||new URLSearchParams(location.search).has("ajs_uid")||O(),await Fe(),document.addEventListener("visibilitychange",(async()=>{"hidden"===document.visibilityState?this.isDocumentVisible=!1:(this.isDocumentVisible=!0,await Be())}),!1))}static async setCurrentRoute(e){this.currentRoute=e,n(`Current route set to: ${e}`),await async function(){if(0!==Ke.currentMessages.length)for(const e of[...Ke.currentMessages])null==document.querySelector(`#gist-${e.instanceId}`)&&(n(`Removing active message ${e.instanceId} that no longer exists after route change`),await Te(e))}(),await Be()}static async setUserToken(e,t){this.config.isPreviewSession||(function(e,t){void 0===t&&(t=new Date).setDate(t.getDate()+30),a(P,e,t),W()&&(r(M),r(L)),n(`Set user token "${e}" with expiry date set to ${t}`)}(e,t),Xe(!0),await Fe())}static setUserLocale(e){var t;a(k,t=e),n(`Set user locate to "${t}"`)}static setCustomAttribute(e,t){return function(e,t){return e&&"string"==typeof e?(le.set(e,t),de(),n(`Set custom attribute "${e}" to "${t}"`),!0):(n(`Invalid key for custom attribute: ${e}`),!1)}(e,t)}static clearCustomAttributes(){le.clear(),r(ue),n("Cleared all custom attributes")}static removeCustomAttribute(e){return function(e){if(!e||"string"!=typeof e)return n(`Invalid key for custom attribute: ${e}`),!1;const t=le.has(e);return le.delete(e),le.size>0?de():r(ue),n(`Removed custom attribute "${e}"`),t}(e)}static async clearUserToken(){this.config.isPreviewSession||(r(P),n("Cleared user token"),this.config.useAnonymousSession&&O(),Xe(!0),await Fe())}static async dismissMessage(e){var t=F(e);await De(t),await Me(t),await Oe(t),await Be()}static async embedMessage(e,t){var s=Ce(e,t);return s?s.instanceId:null}static async showMessage(e){var t=await ke(e);return t?t.instanceId:null}static updateMessageDisplaySettings(e,t){var s=F(e);return!!s&&(s.displaySettings=t,ne(s),!0)}static messageShown(e){n(`Message shown: ${e.messageId}`),this.events.dispatch("messageShown",e)}static messageDismissed(e){null!==e&&(n(`Message dismissed: ${e.messageId}`),this.events.dispatch("messageDismissed",e))}static messageError(e){n(`Message error: ${e.messageId}`),this.events.dispatch("messageError",e)}static messageAction(e,t,s){n(`Message action: ${e.currentRoute}, ${t} with name ${s} on ${e.instanceId}`),this.events.dispatch("messageAction",{message:e,action:t,name:s})}static async getInboxUnopenedCount(){return(await He()).filter((e=>!e.opened)).length}static async getInboxMessages(){return await He()}static async updateInboxMessageOpenState(e,t){return await async function(e,t){const s=await je();if(!s)return;const i=await async function(e,t){try{return await E()(`/api/v1/messages/${e}`,{method:"PATCH",body:JSON.stringify(t),headers:{"Content-Type":"application/json"}})}catch(e){return x(e)}}(e,{opened:t});if(!i||i.status<200||i.status>=300){const e=`Failed to mark inbox message opened: ${i?.status??"unknown error"}`;throw n(e),new Error(e)}const o=await He();let r=null;const c=o.map((s=>{if(s.queueId===e){const e={...s,opened:t};return r=e,e}return s})),u=new Date;if(u.setMinutes(u.getMinutes()+60),a(s,c,u),r){const e=t?"opened":"unopened";Ke.events.dispatch("inboxMessageAction",{message:r,action:e})}Ke.events.dispatch(Ue,await He())}(e,t)}static async removeInboxMessage(e){return await async function(e){const t=await je();if(!t)return;const s=await H(e);if(!s||s.status<200||s.status>=300){const e=`Failed to remove inbox message: ${s?.status??"unknown error"}`;throw n(e),new Error(e)}const i=(await He()).filter((t=>t.queueId!==e)),o=new Date;o.setMinutes(o.getMinutes()+60),a(t,i,o),Ke.events.dispatch(Ue,await He())}(e)}};return t.default})(),e.exports=t()}}]);
|
|
Binary file
|
package/dist/umd/inAppPlugin.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";(self.webpackChunk_customerio_cdp_analytics_browser=self.webpackChunk_customerio_cdp_analytics_browser||[]).push([[926],{599:function(e,n,t){t.d(n,{InAppPlugin:function(){return
|
|
1
|
+
"use strict";(self.webpackChunk_customerio_cdp_analytics_browser=self.webpackChunk_customerio_cdp_analytics_browser||[]).push([[926],{599:function(e,n,t){t.d(n,{InAppPlugin:function(){return f}});var i,s=t(5478);!function(e){e.MessageOpened="in-app:message-opened",e.MessageDismissed="in-app:message-dismissed",e.MessageError="in-app:message-error",e.MessageAction="in-app:message-action"}(i||(i={}));var o,r=Object.values(i);!function(e){e.Metric="Report Delivery Event",e.Content="Report Content Event",e.Opened="opened",e.Clicked="clicked",e.ViewedContent="viewed_content",e.ClickedContent="clicked_content"}(o||(o={}));var a="in_app_content";function u(e,n){return new CustomEvent(e,{detail:n})}var d=t(7573),c=t.n(d);function l(e,n,t){var i=this;return{sentAt:new Date(t.sentAt),expiresAt:t.expiry?new Date(t.expiry):void 0,messageId:t.queueId,opened:!0===(null==t?void 0:t.opened),properties:t.properties,type:t.type||"",topics:t.topics||[],trackClick:function(n){void 0!==t.deliveryId&&""!==t.deliveryId&&e.track(o.Metric,{deliveryId:t.deliveryId,metric:o.Clicked,actionName:n})},markOpened:function(){return(0,s.sH)(i,void 0,void 0,(function(){return(0,s.YH)(this,(function(e){switch(e.label){case 0:return[4,n.updateInboxMessageOpenState(t.queueId,!0)];case 1:return e.sent(),[2]}}))}))},markUnopened:function(){return(0,s.sH)(i,void 0,void 0,(function(){return(0,s.YH)(this,(function(e){switch(e.label){case 0:return[4,n.updateInboxMessageOpenState(t.queueId,!1)];case 1:return e.sent(),[2]}}))}))},markDeleted:function(){return(0,s.sH)(i,void 0,void 0,(function(){return(0,s.YH)(this,(function(e){switch(e.label){case 0:return[4,n.removeInboxMessage(t.queueId)];case 1:return e.sent(),[2]}}))}))}}}function v(e,n,t){return(0,s.sH)(this,void 0,Promise,(function(){var i;return(0,s.YH)(this,(function(s){switch(s.label){case 0:return(i=t)&&Array.isArray(i)?[3,2]:[4,e.getInboxMessages()];case 1:i=s.sent(),s.label=2;case 2:return i&&Array.isArray(i)?(i=i.slice().sort((function(e,n){return new Date(n.sentAt).getTime()-new Date(e.sentAt).getTime()})),0===n.length?[2,i]:[2,i.filter((function(e){var t=e.topics;return!(!t||0===t.length)&&t.some((function(e){return n.includes(e)}))}))]):[2,[]]}}))}))}function p(e,n,t){var i=this;return{total:function(){return(0,s.sH)(i,void 0,void 0,(function(){return(0,s.YH)(this,(function(e){switch(e.label){case 0:return[4,v(n,t,null)];case 1:return[2,e.sent().length]}}))}))},totalUnopened:function(){return(0,s.sH)(i,void 0,void 0,(function(){return(0,s.YH)(this,(function(e){switch(e.label){case 0:return[4,v(n,t,null)];case 1:return[2,e.sent().filter((function(e){return!0!==(null==e?void 0:e.opened)})).length]}}))}))},messages:function(){return(0,s.sH)(i,void 0,Promise,(function(){return(0,s.YH)(this,(function(i){switch(i.label){case 0:return[4,v(n,t,null)];case 1:return[2,i.sent().map((function(t){return l(e,n,t)}))]}}))}))},onUpdates:function(o){var r=function(r){return(0,s.sH)(i,void 0,void 0,(function(){var i,a,u;return(0,s.YH)(this,(function(s){switch(s.label){case 0:return s.trys.push([0,2,,3]),[4,v(n,t,r)];case 1:return i=s.sent(),a=i.map((function(t){return l(e,n,t)})),o(a),[3,3];case 2:return u=s.sent(),console.error("Error processing inbox updates:",u),[3,3];case 3:return[2]}}))}))};return n.events.on("messageInboxUpdated",r),function(){n.events.off("messageInboxUpdated",r)}}}}function f(e){var n,t=this,d=!1,l=!1,v=new EventTarget;function f(){return(0,s.sH)(this,void 0,void 0,(function(){var e;return(0,s.YH)(this,(function(t){switch(t.label){case 0:return(e=n.user().anonymousId())?[4,c().setCustomAttribute("cio_anonymous_id",e)]:[3,2];case 1:t.sent(),t.label=2;case 2:return[2]}}))}))}function m(){d&&!l&&(n.on("reset",g),e.events&&(r.forEach((function(n){v.addEventListener(n,null==e?void 0:e.events)})),["messageDismissed","messageError"].forEach((function(e){c().events.on(e,(function(n){var t,s;v.dispatchEvent(u(function(e){switch(e){case"messageShown":return i.MessageOpened;case"messageDismissed":return i.MessageDismissed;case"messageError":return i.MessageError;case"messageAction":return i.MessageAction;default:return""}}(e),{messageId:n.messageId,deliveryId:null===(s=null===(t=n.properties)||void 0===t?void 0:t.gist)||void 0===s?void 0:s.campaignId}))}))}))),c().events.on("messageShown",(function(t){var s,r,d,l,p,f,m,g,I,h,b,y=null===(r=null===(s=null==t?void 0:t.properties)||void 0===s?void 0:s.gist)||void 0===r?void 0:r.campaignId;if(e.events&&v.dispatchEvent(u(i.MessageOpened,{messageId:null==t?void 0:t.messageId,deliveryId:y,message:{dismiss:function(){c().dismissMessage(null==t?void 0:t.instanceId)}}})),void 0===y||""===y){var w=null===(p=null===(l=null===(d=null==t?void 0:t.properties)||void 0===d?void 0:d.gist)||void 0===l?void 0:l.broadcast)||void 0===p?void 0:p.broadcastIdInt;if(w||(w=null===(g=null===(m=null===(f=null==t?void 0:t.properties)||void 0===f?void 0:f.gist)||void 0===m?void 0:m.broadcast)||void 0===g?void 0:g.broadcastId),w){var k=null===(b=null===(h=null===(I=null==t?void 0:t.properties)||void 0===I?void 0:I.gist)||void 0===h?void 0:h.broadcast)||void 0===b?void 0:b.templateId;n.track(o.Content,{actionType:o.ViewedContent,contentId:w,templateId:k,contentType:a})}}else n.track(o.Metric,{deliveryId:y,metric:o.Opened})})),c().events.on("inboxMessageAction",(function(e){var t,i,s,r;(null==e?void 0:e.message)&&""!==(null==e?void 0:e.action)&&(t=n,i=e.message,s=e.action,r=null==i?void 0:i.deliveryId,"opened"===s&&void 0!==r&&""!==r&&t.track(o.Metric,{deliveryId:i.deliveryId,metric:o.Opened}))})),c().events.on("messageAction",(function(t){var s,r,d,l,p,f,m,g,I,h,b,y,w,k,C,H=null===(d=null===(r=null===(s=null==t?void 0:t.message)||void 0===s?void 0:s.properties)||void 0===r?void 0:r.gist)||void 0===d?void 0:d.campaignId;if(e.events&&v.dispatchEvent(u(i.MessageAction,{messageId:t.message.messageId,deliveryId:H,action:t.action,name:t.name,actionName:t.name,actionValue:t.action,message:{dismiss:function(){c().dismissMessage(t.message.instanceId)}}})),"gist://close"!==t.action)if(void 0===H||""===H){var A=null===(m=null===(f=null===(p=null===(l=null==t?void 0:t.message)||void 0===l?void 0:l.properties)||void 0===p?void 0:p.gist)||void 0===f?void 0:f.broadcast)||void 0===m?void 0:m.broadcastIdInt;if(A||(A=null===(b=null===(h=null===(I=null===(g=null==t?void 0:t.message)||void 0===g?void 0:g.properties)||void 0===I?void 0:I.gist)||void 0===h?void 0:h.broadcast)||void 0===b?void 0:b.broadcastId),A){var M=null===(C=null===(k=null===(w=null===(y=null==t?void 0:t.message)||void 0===y?void 0:y.properties)||void 0===w?void 0:w.gist)||void 0===k?void 0:k.broadcast)||void 0===C?void 0:C.templateId;n.track(o.Content,{actionType:o.ClickedContent,contentId:A,templateId:M,contentType:a,actionName:t.name,actionValue:t.action})}}else n.track(o.Metric,{deliveryId:H,metric:o.Clicked,actionName:t.name,actionValue:t.action})})),c().events.on("eventDispatched",(function(e){var t,i,s;if("analytics:track"===e.name){var o=null===(t=e.payload)||void 0===t?void 0:t.event;if(void 0===o||""===o)return;n.track(o,null===(i=e.payload)||void 0===i?void 0:i.properties,null===(s=e.payload)||void 0===s?void 0:s.options)}})))}function g(e){return(0,s.sH)(this,void 0,Promise,(function(){return(0,s.YH)(this,(function(n){switch(n.label){case 0:return[4,c().clearUserToken()];case 1:return n.sent(),[4,c().clearCustomAttributes()];case 2:return n.sent(),[4,f()];case 3:return n.sent(),[2,e]}}))}))}function I(e){return(0,s.sH)(this,void 0,Promise,(function(){var t;return(0,s.YH)(this,(function(i){switch(i.label){case 0:return d?"string"==typeof(t=n.user().id())&&t.length>0?[4,c().setUserToken(t)]:[3,2]:[2,e];case 1:return i.sent(),[3,4];case 2:return[4,c().clearUserToken()];case 3:i.sent(),i.label=4;case 4:return[2,e]}}))}))}var h={name:"Customer.io In-App Plugin",type:"before",version:"0.0.1",isLoaded:function(){return l},load:function(i,o){return(0,s.sH)(t,void 0,void 0,(function(){return(0,s.YH)(this,(function(t){switch(t.label){case 0:return n=o,null==e.siteId||""===e.siteId?(s="siteId is required. Can't initialize.",console.error("[Customer.io In-App Plugin] ".concat(s)),[2,i]):[4,f()];case 1:return t.sent(),[4,c().setup({siteId:e.siteId,env:e._env?e._env:"prod",logging:e._logging,useAnonymousSession:e.anonymousInApp})];case 2:return t.sent(),d=!0,[4,I(i)];case 3:return t.sent(),m(),o.inbox=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];if(!l)throw new Error("Customer.io In-App Plugin is not loaded yet. Ensure the plugin is initialized before calling inbox().");return p(o,c(),e)},l=!0,[2,Promise.resolve()]}var s}))}))},identify:I,page:function(e){var n,t,i,s,o;if(!l)return e;var r=null!==(i=null===(t=null===(n=e.event)||void 0===n?void 0:n.properties)||void 0===t?void 0:t.name)&&void 0!==i?i:null===(o=null===(s=e.event)||void 0===s?void 0:s.properties)||void 0===o?void 0:o.url;return"string"==typeof r&&r.length>0&&c().setCurrentRoute(r),e},unload:function(){e.events&&r.forEach((function(n){v.removeEventListener(n,null==e?void 0:e.events)}))}};return h}}}]);
|
|
Binary file
|