@sharadtech/infralytiqs-sdk 1.0.0 → 1.0.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/buildScripts/Jenkinsfile.deploy +317 -49
- package/clients/publicis/ps/README.md +84 -0
- package/clients/publicis/ps/package-lock.json +815 -0
- package/clients/publicis/ps/package.json +23 -0
- package/clients/publicis/ps/rollup.config.mjs +28 -0
- package/clients/publicis/ps/src/index.js +479 -0
- package/dist/infralytiqs.js +104 -1
- package/dist/infralytiqs.min.js +2 -2
- package/package.json +1 -1
- package/src/bootstrapLoader.ts +94 -0
- package/src/index.ts +15 -0
package/dist/infralytiqs.min.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/*! infralytiqs-sdk v1.0.
|
|
2
|
-
var Infralytiqs=function(t){"use strict";const e={ANALYTICS_API_BASE_URL:"",INGEST_PATH:"/il/analytics/:tenant_id/:site_id/events",BATCH_SIZE:20,FLUSH_INTERVAL_MS:5e3,SESSION_TIMEOUT_MS:18e5,STORAGE_PREFIX:"_il_",SDK_VERSION:"1.0.0",MAX_RETRIES:2,DEBUG:!1},n=`${e.STORAGE_PREFIX}anon_id`,i=`${e.STORAGE_PREFIX}session_id`,o=`${e.STORAGE_PREFIX}session_ts`;function s(){return"undefined"!=typeof crypto&&crypto.randomUUID?crypto.randomUUID():"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,t=>{const e=16*Math.random()|0;return("x"===t?e:3&e|8).toString(16)})}function r(t){try{return localStorage.getItem(t)}catch(t){return null}}function a(t,e){try{localStorage.setItem(t,e)}catch(t){}}function u(){let t=r(n);return t||(t=s(),a(n,t)),t}function c(t){const e=Date.now(),n=parseInt(r(o)||"0",10);let u=r(i);return(!u||e-n>t)&&(u=s(),a(i,u)),a(o,String(e)),u}let l="";function d(t){l=t;try{sessionStorage.setItem(`${e.STORAGE_PREFIX}user_id`,t)}catch(t){}}function f(){if(l)return l;try{l=sessionStorage.getItem(`${e.STORAGE_PREFIX}user_id`)||""}catch(t){}return l}function g(){const t=navigator.userAgent||"";return/tablet|ipad|playbook|silk/i.test(t)?"tablet":/mobile|iphone|ipod|android.*mobile|windows phone|blackberry/i.test(t)?"mobile":"desktop"}function h(){const t=navigator.userAgent||"",e=navigator.platform||"",n=navigator.maxTouchPoints||0;return/iPhone|iPod/i.test(t)||/iPad/i.test(t)||/Mac/.test(e)&&n>1?"iOS":/Android/i.test(t)?"Android":/CrOS/i.test(t)?"ChromeOS":/Windows/i.test(t)?"Windows":/Mac OS X|Macintosh/i.test(t)?"macOS":/Linux/i.test(t)?"Linux":"Other"}function m(){const t=(navigator.language||"").split("-");return t.length>1?t[1].toUpperCase():""}const p=["utm_source","utm_medium","utm_campaign","utm_term","utm_content"];function _(t){return`${t.serverUrl.replace(/\/+$/,"")}${e.INGEST_PATH.replace(":tenant_id",encodeURIComponent(t.tenantId)).replace(":site_id",encodeURIComponent(t.siteId))}`}function v(t,...e){t&&"undefined"!=typeof console&&console.log("[Infralytiqs]",...e)}function I(t,e){const n=[];if(!t.disableAutoPageView){e("page_view",null,{referrer:document.referrer||""},{});const t=()=>{e("page_view","spa_navigation",{referrer:document.referrer||""},{})};window.addEventListener("popstate",t),n.push(()=>window.removeEventListener("popstate",t));const i=history.pushState.bind(history);history.pushState=function(...t){i(...t),e("page_view","spa_navigation",{referrer:document.referrer||""},{})},n.push(()=>{history.pushState=i})}if(!t.disableAutoClick){const i=t.clickSelector||'a, button, [data-il-track], input[type="submit"]',o=n=>{const o=n.target;if(!o)return;const s=o.closest(i);if(!s)return;const r=Object.assign(Object.assign({},function(t){var e,n,i;const o={},s=(null===(e=t.tagName)||void 0===e?void 0:e.toLowerCase())||"";o.element_tag=s,t.id&&(o.element_id=t.id);const r=t.className;if("string"==typeof r&&r&&(o.element_class=r.split(/\s+/).slice(0,3).join(" ")),"a"===s){const e=t.href;e&&(o.link_url=e);const i=null===(n=t.textContent)||void 0===n?void 0:n.trim();i&&(o.link_text=i.substring(0,120))}else if("button"===s||"button"===t.getAttribute("role")){const e=null===(i=t.textContent)||void 0===i?void 0:i.trim();e&&(o.button_text=e.substring(0,120))}const a=t.getAttribute("data-il-track");return a&&(o.track_label=a),o}(s)),function(t,e){var n;const i={};if(!e)return i;for(const[o,s]of Object.entries(e))if("function"==typeof s)i[o]=s(t);else if("string"==typeof s){const e=t.closest(s)||t.querySelector(s);e&&(i[o]=e.getAttribute(`data-${o}`)||(null===(n=e.textContent)||void 0===n?void 0:n.trim())||"")}return i}(s,t.evarMap)),a=function(t,e){const n={};if(!e)return n;for(const[i,o]of Object.entries(e))n[i]=o(t);return n}(s,t.propMap);e("click",null,r,a)};document.addEventListener("click",o,{capture:!0,passive:!0}),n.push(()=>document.removeEventListener("click",o,!0))}if(!t.disableAutoPageLeave){let t=Date.now();const i=()=>{if("hidden"===document.visibilityState){const n=Math.round((Date.now()-t)/1e3);e("page_leave",null,{},{time_on_page_sec:n})}else t=Date.now()};document.addEventListener("visibilitychange",i),n.push(()=>document.removeEventListener("visibilitychange",i));const o=()=>{const n=Math.round((Date.now()-t)/1e3);e("page_leave","unload",{},{time_on_page_sec:n})};window.addEventListener("beforeunload",o),n.push(()=>window.removeEventListener("beforeunload",o))}return()=>n.forEach(t=>t())}const y="il_geo_v1",S="il_geo_deny_v1",b=8e3,w=()=>{try{if("undefined"!=typeof window&&window.localStorage){const t="__il_geo_probe__";return window.localStorage.setItem(t,"1"),window.localStorage.removeItem(t),window.localStorage}}catch(t){}return null};let E=null,T=null;const x=()=>{if(E)return;const t=(()=>{const t=w();if(!t)return null;try{const e=t.getItem(y);if(!e)return null;const n=JSON.parse(e);if("number"==typeof n.latitude&&"number"==typeof n.longitude&&"number"==typeof n.capturedAt&&Date.now()-n.capturedAt<6048e5)return n;t.removeItem(y)}catch(e){try{t.removeItem(y)}catch(t){}}return null})();t&&(E=t)},A=t=>{var n;return"undefined"==typeof window||"undefined"==typeof navigator?Promise.resolve(null):(x(),E?Promise.resolve(E):(()=>{const t=w();if(!t)return!1;try{const e=t.getItem(S);if(!e)return!1;const n=Number(e);if(Number.isFinite(n)&&Date.now()-n<864e5)return!0;t.removeItem(S)}catch(t){}return!1})()?(t&&console.log("[Infralytiqs] geolocation previously denied — skipping prompt"),Promise.resolve(null)):"geolocation"in navigator&&"function"==typeof(null===(n=navigator.geolocation)||void 0===n?void 0:n.getCurrentPosition)?T||(T=new Promise(n=>{let i=!1;const o=t=>{i||(i=!0,T=null,n(t))},s=window.setTimeout(()=>{t&&console.log("[Infralytiqs] geolocation prompt timed out after 8000ms"),o(null)},9e3);try{navigator.geolocation.getCurrentPosition(n=>{window.clearTimeout(s);const i={latitude:n.coords.latitude,longitude:n.coords.longitude,accuracy:n.coords.accuracy,capturedAt:Date.now()};E=i,(t=>{const e=w();if(e)try{e.setItem(y,JSON.stringify(t))}catch(t){}})(i),t&&console.log(`[Infralytiqs] geolocation granted (sdk=${e.SDK_VERSION}, acc=${Math.round(i.accuracy)}m)`),o(i)},e=>{window.clearTimeout(s),e&&1===e.code?((()=>{const t=w();if(t)try{t.setItem(S,String(Date.now()))}catch(t){}})(),t&&console.log("[Infralytiqs] geolocation permission denied")):t&&console.log(`[Infralytiqs] geolocation error (code=${null==e?void 0:e.code}): ${null==e?void 0:e.message}`),o(null)},{enableHighAccuracy:!1,timeout:b,maximumAge:36e5})}catch(t){window.clearTimeout(s),o(null)}}),T):Promise.resolve(null))};function O(){try{const t=window.location,e=t.hash||"";if(!e.startsWith("#/"))return t.href;const n=e.slice(1),i=n.indexOf("?"),o=i>=0?n.slice(0,i):n,s=i>=0?n.slice(i+1):"",r=[(t.search||"").replace(/^\?/,""),s].filter(Boolean).join("&");return t.origin+o+(r?"?"+r:"")}catch(t){return"undefined"!=typeof window&&window.location?window.location.href:""}}const R=new class{constructor(){this.queue=[],this.flushTimer=null,this.teardownAutoCapture=null,this.initialized=!1,this.preInitBuffer=[],this.preInitUserId=null}init(t){var n,i;if(this.initialized)return void this.log("Already initialized — ignoring duplicate init()");if(!t.serverUrl||!t.tenantId||!t.siteId)return void console.error("[Infralytiqs] init() requires serverUrl, tenantId, and siteId");const o=Object.assign(Object.assign({},t.dbName?{ch_db_name:t.dbName}:{}),null!==(n=t.globalDimensions)&&void 0!==n?n:{});if(this.config=Object.assign(Object.assign({batchSize:e.BATCH_SIZE,flushIntervalMs:e.FLUSH_INTERVAL_MS,sessionTimeoutMs:e.SESSION_TIMEOUT_MS,debug:e.DEBUG,clickSelector:'a, button, [data-il-track], input[type="submit"]'},t),{globalDimensions:o}),this.transportCfg={serverUrl:this.config.serverUrl,tenantId:this.config.tenantId,siteId:this.config.siteId,debug:null!==(i=this.config.debug)&&void 0!==i&&i},this.preInitUserId&&(d(this.preInitUserId),this.preInitUserId=null),this.config.userId&&d(this.config.userId),this.startFlushTimer(),this.teardownAutoCapture=I(this.config,(t,e,n,i)=>{this.trackRaw(t,e,n,i)}),this.initialized=!0,this.config.captureLocation&&A(this.config.debug).catch(()=>{}),this.preInitBuffer.length>0){const t=this.preInitBuffer.splice(0);this.log(`Draining pre-init buffer (${t.length} event(s))`);for(const e of t)this.trackRaw(e.eventType,e.eventSubtype,e.dims,e.metrics)}this.log("Initialized",{tenantId:t.tenantId,siteId:t.siteId,dbName:t.dbName,captureLocation:!!t.captureLocation})}track(t,e,n,i){if(!this.initialized)return this.preInitBuffer.length>=100&&this.preInitBuffer.shift(),void this.preInitBuffer.push({eventType:t,eventSubtype:null!=i?i:null,dims:null!=e?e:{},metrics:null!=n?n:{}});this.trackRaw(t,null!=i?i:null,null!=e?e:{},null!=n?n:{})}identify(t){this.initialized?(d(t),this.log("User identified",t)):this.preInitUserId=t}async flush(){await this.flushQueue(!1)}destroy(){this.flushQueue(!0),this.flushTimer&&(clearInterval(this.flushTimer),this.flushTimer=null),this.teardownAutoCapture&&(this.teardownAutoCapture(),this.teardownAutoCapture=null),this.initialized=!1,this.log("Destroyed")}trackRaw(t,n,i,o){var s,r,a,l;const d=function(){const t={},e="_il_utm_";try{const n=new URLSearchParams(window.location.search);let i=!1;for(const o of p){const s=n.get(o);s&&(t[o]=s,sessionStorage.setItem(`${e}${o}`,s),i=!0)}if(!i)for(const n of p){const i=sessionStorage.getItem(`${e}${n}`);i&&(t[n]=i)}}catch(t){}return t}(),_={language_iso_code:navigator.language||navigator.userLanguage||"",user_id:f(),anonymous_id:u(),session_id:c(null!==(s=this.config.sessionTimeoutMs)&&void 0!==s?s:e.SESSION_TIMEOUT_MS),event_type:t,event_subtype:n,custom_dimensions:Object.assign(Object.assign(Object.assign({},null!==(r=this.config.globalDimensions)&&void 0!==r?r:{}),i),{sdk_version:e.SDK_VERSION}),custom_metrics:o,page_url:O(),country_code:m(),device_type:g(),device_os:h(),utm_source:null!==(a=d.utm_source)&&void 0!==a?a:null};if(d.utm_medium&&(_.custom_dimensions.utm_medium=d.utm_medium),d.utm_campaign&&(_.custom_dimensions.utm_campaign=d.utm_campaign),d.utm_term&&(_.custom_dimensions.utm_term=d.utm_term),d.utm_content&&(_.custom_dimensions.utm_content=d.utm_content),this.config.captureLocation){const t=E||(x(),E);t&&(_.latitude=t.latitude,_.longitude=t.longitude,_.location_accuracy=t.accuracy)}this.queue.push(_),this.log("Queued",t,n,`(${this.queue.length}/${this.config.batchSize})`),this.queue.length>=(null!==(l=this.config.batchSize)&&void 0!==l?l:e.BATCH_SIZE)&&this.flushQueue(!1)}startFlushTimer(){var t;const n=null!==(t=this.config.flushIntervalMs)&&void 0!==t?t:e.FLUSH_INTERVAL_MS;this.flushTimer=setInterval(()=>this.flushQueue(!1),n)}async flushQueue(t){if(0===this.queue.length)return;const n=this.queue.splice(0,this.queue.length);if(t)return void function(t,e){if("undefined"==typeof navigator||!navigator.sendBeacon)return!1;const n=_(t),i=JSON.stringify(1===e.length?e[0]:e),o=new Blob([i],{type:"application/json"}),s=navigator.sendBeacon(n,o);v(t.debug,`Beacon ${s?"accepted":"rejected"} ${e.length} event(s)`)}(this.transportCfg,n);await async function(t,n,i=e.MAX_RETRIES){const o=_(t),s=JSON.stringify(1===n.length?n[0]:n);for(let e=0;e<=i;e++)try{const i=await fetch(o,{method:"POST",headers:{"Content-Type":"application/json"},body:s,keepalive:!0});if(i.ok)return v(t.debug,`Flushed ${n.length} event(s) — HTTP ${i.status}`),!0;v(t.debug,`Flush attempt ${e+1} failed — HTTP ${i.status}`)}catch(n){v(t.debug,`Flush attempt ${e+1} error`,n)}return!1}(this.transportCfg,n)||this.log("Flush failed — events dropped",n.length)}log(...t){var e;(null===(e=this.config)||void 0===e?void 0:e.debug)&&"undefined"!=typeof console&&console.log("[Infralytiqs]",...t)}},U={init(t){R.init(t)},track(t,e,n,i){R.track(t,e,n,i)},identify(t){R.identify(t)},flush:()=>R.flush(),destroy(){R.destroy()}};return t.LICENSE_MODULE_ID="infralytiqs.com",t.default=U,Object.defineProperty(t,"__esModule",{value:!0}),t}({});
|
|
1
|
+
/*! infralytiqs-sdk v1.0.1 | (c) 2026 sharadtech | License: See LICENSE | Built: 2026-05-27T12:40:33.717Z */
|
|
2
|
+
var Infralytiqs=function(t){"use strict";const e={ANALYTICS_API_BASE_URL:"",INGEST_PATH:"/il/analytics/:tenant_id/:site_id/events",BATCH_SIZE:20,FLUSH_INTERVAL_MS:5e3,SESSION_TIMEOUT_MS:18e5,STORAGE_PREFIX:"_il_",SDK_VERSION:"1.0.0",MAX_RETRIES:2,DEBUG:!1},n=`${e.STORAGE_PREFIX}anon_id`,i=`${e.STORAGE_PREFIX}session_id`,o=`${e.STORAGE_PREFIX}session_ts`;function r(){return"undefined"!=typeof crypto&&crypto.randomUUID?crypto.randomUUID():"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,t=>{const e=16*Math.random()|0;return("x"===t?e:3&e|8).toString(16)})}function s(t){try{return localStorage.getItem(t)}catch(t){return null}}function a(t,e){try{localStorage.setItem(t,e)}catch(t){}}function u(){let t=s(n);return t||(t=r(),a(n,t)),t}function c(t){const e=Date.now(),n=parseInt(s(o)||"0",10);let u=s(i);return(!u||e-n>t)&&(u=r(),a(i,u)),a(o,String(e)),u}let l="";function d(t){l=t;try{sessionStorage.setItem(`${e.STORAGE_PREFIX}user_id`,t)}catch(t){}}function f(){if(l)return l;try{l=sessionStorage.getItem(`${e.STORAGE_PREFIX}user_id`)||""}catch(t){}return l}function g(){const t=navigator.userAgent||"";return/tablet|ipad|playbook|silk/i.test(t)?"tablet":/mobile|iphone|ipod|android.*mobile|windows phone|blackberry/i.test(t)?"mobile":"desktop"}function h(){const t=navigator.userAgent||"",e=navigator.platform||"",n=navigator.maxTouchPoints||0;return/iPhone|iPod/i.test(t)||/iPad/i.test(t)||/Mac/.test(e)&&n>1?"iOS":/Android/i.test(t)?"Android":/CrOS/i.test(t)?"ChromeOS":/Windows/i.test(t)?"Windows":/Mac OS X|Macintosh/i.test(t)?"macOS":/Linux/i.test(t)?"Linux":"Other"}function m(){const t=(navigator.language||"").split("-");return t.length>1?t[1].toUpperCase():""}const p=["utm_source","utm_medium","utm_campaign","utm_term","utm_content"];function _(t){return`${t.serverUrl.replace(/\/+$/,"")}${e.INGEST_PATH.replace(":tenant_id",encodeURIComponent(t.tenantId)).replace(":site_id",encodeURIComponent(t.siteId))}`}function v(t,...e){t&&"undefined"!=typeof console&&console.log("[Infralytiqs]",...e)}function y(t,e){const n=[];if(!t.disableAutoPageView){e("page_view",null,{referrer:document.referrer||""},{});const t=()=>{e("page_view","spa_navigation",{referrer:document.referrer||""},{})};window.addEventListener("popstate",t),n.push(()=>window.removeEventListener("popstate",t));const i=history.pushState.bind(history);history.pushState=function(...t){i(...t),e("page_view","spa_navigation",{referrer:document.referrer||""},{})},n.push(()=>{history.pushState=i})}if(!t.disableAutoClick){const i=t.clickSelector||'a, button, [data-il-track], input[type="submit"]',o=n=>{const o=n.target;if(!o)return;const r=o.closest(i);if(!r)return;const s=Object.assign(Object.assign({},function(t){var e,n,i;const o={},r=(null===(e=t.tagName)||void 0===e?void 0:e.toLowerCase())||"";o.element_tag=r,t.id&&(o.element_id=t.id);const s=t.className;if("string"==typeof s&&s&&(o.element_class=s.split(/\s+/).slice(0,3).join(" ")),"a"===r){const e=t.href;e&&(o.link_url=e);const i=null===(n=t.textContent)||void 0===n?void 0:n.trim();i&&(o.link_text=i.substring(0,120))}else if("button"===r||"button"===t.getAttribute("role")){const e=null===(i=t.textContent)||void 0===i?void 0:i.trim();e&&(o.button_text=e.substring(0,120))}const a=t.getAttribute("data-il-track");return a&&(o.track_label=a),o}(r)),function(t,e){var n;const i={};if(!e)return i;for(const[o,r]of Object.entries(e))if("function"==typeof r)i[o]=r(t);else if("string"==typeof r){const e=t.closest(r)||t.querySelector(r);e&&(i[o]=e.getAttribute(`data-${o}`)||(null===(n=e.textContent)||void 0===n?void 0:n.trim())||"")}return i}(r,t.evarMap)),a=function(t,e){const n={};if(!e)return n;for(const[i,o]of Object.entries(e))n[i]=o(t);return n}(r,t.propMap);e("click",null,s,a)};document.addEventListener("click",o,{capture:!0,passive:!0}),n.push(()=>document.removeEventListener("click",o,!0))}if(!t.disableAutoPageLeave){let t=Date.now();const i=()=>{if("hidden"===document.visibilityState){const n=Math.round((Date.now()-t)/1e3);e("page_leave",null,{},{time_on_page_sec:n})}else t=Date.now()};document.addEventListener("visibilitychange",i),n.push(()=>document.removeEventListener("visibilitychange",i));const o=()=>{const n=Math.round((Date.now()-t)/1e3);e("page_leave","unload",{},{time_on_page_sec:n})};window.addEventListener("beforeunload",o),n.push(()=>window.removeEventListener("beforeunload",o))}return()=>n.forEach(t=>t())}const I="il_geo_v1",b="il_geo_deny_v1",S=8e3,w=()=>{try{if("undefined"!=typeof window&&window.localStorage){const t="__il_geo_probe__";return window.localStorage.setItem(t,"1"),window.localStorage.removeItem(t),window.localStorage}}catch(t){}return null};let E=null,T=null;const A=()=>{if(E)return;const t=(()=>{const t=w();if(!t)return null;try{const e=t.getItem(I);if(!e)return null;const n=JSON.parse(e);if("number"==typeof n.latitude&&"number"==typeof n.longitude&&"number"==typeof n.capturedAt&&Date.now()-n.capturedAt<6048e5)return n;t.removeItem(I)}catch(e){try{t.removeItem(I)}catch(t){}}return null})();t&&(E=t)},x=t=>{var n;return"undefined"==typeof window||"undefined"==typeof navigator?Promise.resolve(null):(A(),E?Promise.resolve(E):(()=>{const t=w();if(!t)return!1;try{const e=t.getItem(b);if(!e)return!1;const n=Number(e);if(Number.isFinite(n)&&Date.now()-n<864e5)return!0;t.removeItem(b)}catch(t){}return!1})()?(t&&console.log("[Infralytiqs] geolocation previously denied — skipping prompt"),Promise.resolve(null)):"geolocation"in navigator&&"function"==typeof(null===(n=navigator.geolocation)||void 0===n?void 0:n.getCurrentPosition)?T||(T=new Promise(n=>{let i=!1;const o=t=>{i||(i=!0,T=null,n(t))},r=window.setTimeout(()=>{t&&console.log("[Infralytiqs] geolocation prompt timed out after 8000ms"),o(null)},9e3);try{navigator.geolocation.getCurrentPosition(n=>{window.clearTimeout(r);const i={latitude:n.coords.latitude,longitude:n.coords.longitude,accuracy:n.coords.accuracy,capturedAt:Date.now()};E=i,(t=>{const e=w();if(e)try{e.setItem(I,JSON.stringify(t))}catch(t){}})(i),t&&console.log(`[Infralytiqs] geolocation granted (sdk=${e.SDK_VERSION}, acc=${Math.round(i.accuracy)}m)`),o(i)},e=>{window.clearTimeout(r),e&&1===e.code?((()=>{const t=w();if(t)try{t.setItem(b,String(Date.now()))}catch(t){}})(),t&&console.log("[Infralytiqs] geolocation permission denied")):t&&console.log(`[Infralytiqs] geolocation error (code=${null==e?void 0:e.code}): ${null==e?void 0:e.message}`),o(null)},{enableHighAccuracy:!1,timeout:S,maximumAge:36e5})}catch(t){window.clearTimeout(r),o(null)}}),T):Promise.resolve(null))};function O(){try{const t=window.location,e=t.hash||"";if(!e.startsWith("#/"))return t.href;const n=e.slice(1),i=n.indexOf("?"),o=i>=0?n.slice(0,i):n,r=i>=0?n.slice(i+1):"",s=[(t.search||"").replace(/^\?/,""),r].filter(Boolean).join("&");return t.origin+o+(s?"?"+s:"")}catch(t){return"undefined"!=typeof window&&window.location?window.location.href:""}}const L=(()=>{try{if("undefined"==typeof document)return"";const t=document.currentScript;if(t&&t.src)return t.src;const e=document.getElementsByTagName("script");for(let t=e.length-1;t>=0;t--){const n=e[t].src;if(n&&/infralytiqs(\.min)?\.js(\?.*)?$/.test(n))return n}}catch(t){}return""})(),R="__il_bootstrap_loaded__";const U=new class{constructor(){this.queue=[],this.flushTimer=null,this.teardownAutoCapture=null,this.initialized=!1,this.preInitBuffer=[],this.preInitUserId=null}init(t){var n,i;if(this.initialized)return void this.log("Already initialized — ignoring duplicate init()");if(!t.serverUrl||!t.tenantId||!t.siteId)return void console.error("[Infralytiqs] init() requires serverUrl, tenantId, and siteId");const o=Object.assign(Object.assign({},t.dbName?{ch_db_name:t.dbName}:{}),null!==(n=t.globalDimensions)&&void 0!==n?n:{});if(this.config=Object.assign(Object.assign({batchSize:e.BATCH_SIZE,flushIntervalMs:e.FLUSH_INTERVAL_MS,sessionTimeoutMs:e.SESSION_TIMEOUT_MS,debug:e.DEBUG,clickSelector:'a, button, [data-il-track], input[type="submit"]'},t),{globalDimensions:o}),this.transportCfg={serverUrl:this.config.serverUrl,tenantId:this.config.tenantId,siteId:this.config.siteId,debug:null!==(i=this.config.debug)&&void 0!==i&&i},this.preInitUserId&&(d(this.preInitUserId),this.preInitUserId=null),this.config.userId&&d(this.config.userId),this.startFlushTimer(),this.teardownAutoCapture=y(this.config,(t,e,n,i)=>{this.trackRaw(t,e,n,i)}),this.initialized=!0,this.config.captureLocation&&x(this.config.debug).catch(()=>{}),this.preInitBuffer.length>0){const t=this.preInitBuffer.splice(0);this.log(`Draining pre-init buffer (${t.length} event(s))`);for(const e of t)this.trackRaw(e.eventType,e.eventSubtype,e.dims,e.metrics)}this.log("Initialized",{tenantId:t.tenantId,siteId:t.siteId,dbName:t.dbName,captureLocation:!!t.captureLocation})}track(t,e,n,i){if(!this.initialized)return this.preInitBuffer.length>=100&&this.preInitBuffer.shift(),void this.preInitBuffer.push({eventType:t,eventSubtype:null!=i?i:null,dims:null!=e?e:{},metrics:null!=n?n:{}});this.trackRaw(t,null!=i?i:null,null!=e?e:{},null!=n?n:{})}identify(t){this.initialized?(d(t),this.log("User identified",t)):this.preInitUserId=t}async flush(){await this.flushQueue(!1)}destroy(){this.flushQueue(!0),this.flushTimer&&(clearInterval(this.flushTimer),this.flushTimer=null),this.teardownAutoCapture&&(this.teardownAutoCapture(),this.teardownAutoCapture=null),this.initialized=!1,this.log("Destroyed")}trackRaw(t,n,i,o){var r,s,a,l;const d=function(){const t={},e="_il_utm_";try{const n=new URLSearchParams(window.location.search);let i=!1;for(const o of p){const r=n.get(o);r&&(t[o]=r,sessionStorage.setItem(`${e}${o}`,r),i=!0)}if(!i)for(const n of p){const i=sessionStorage.getItem(`${e}${n}`);i&&(t[n]=i)}}catch(t){}return t}(),_={language_iso_code:navigator.language||navigator.userLanguage||"",user_id:f(),anonymous_id:u(),session_id:c(null!==(r=this.config.sessionTimeoutMs)&&void 0!==r?r:e.SESSION_TIMEOUT_MS),event_type:t,event_subtype:n,custom_dimensions:Object.assign(Object.assign(Object.assign({},null!==(s=this.config.globalDimensions)&&void 0!==s?s:{}),i),{sdk_version:e.SDK_VERSION}),custom_metrics:o,page_url:O(),country_code:m(),device_type:g(),device_os:h(),utm_source:null!==(a=d.utm_source)&&void 0!==a?a:null};if(d.utm_medium&&(_.custom_dimensions.utm_medium=d.utm_medium),d.utm_campaign&&(_.custom_dimensions.utm_campaign=d.utm_campaign),d.utm_term&&(_.custom_dimensions.utm_term=d.utm_term),d.utm_content&&(_.custom_dimensions.utm_content=d.utm_content),this.config.captureLocation){const t=E||(A(),E);t&&(_.latitude=t.latitude,_.longitude=t.longitude,_.location_accuracy=t.accuracy)}this.queue.push(_),this.log("Queued",t,n,`(${this.queue.length}/${this.config.batchSize})`),this.queue.length>=(null!==(l=this.config.batchSize)&&void 0!==l?l:e.BATCH_SIZE)&&this.flushQueue(!1)}startFlushTimer(){var t;const n=null!==(t=this.config.flushIntervalMs)&&void 0!==t?t:e.FLUSH_INTERVAL_MS;this.flushTimer=setInterval(()=>this.flushQueue(!1),n)}async flushQueue(t){if(0===this.queue.length)return;const n=this.queue.splice(0,this.queue.length);if(t)return void function(t,e){if("undefined"==typeof navigator||!navigator.sendBeacon)return!1;const n=_(t),i=JSON.stringify(1===e.length?e[0]:e),o=new Blob([i],{type:"application/json"}),r=navigator.sendBeacon(n,o);v(t.debug,`Beacon ${r?"accepted":"rejected"} ${e.length} event(s)`)}(this.transportCfg,n);await async function(t,n,i=e.MAX_RETRIES){const o=_(t),r=JSON.stringify(1===n.length?n[0]:n);for(let e=0;e<=i;e++)try{const i=await fetch(o,{method:"POST",headers:{"Content-Type":"application/json"},body:r,keepalive:!0});if(i.ok)return v(t.debug,`Flushed ${n.length} event(s) — HTTP ${i.status}`),!0;v(t.debug,`Flush attempt ${e+1} failed — HTTP ${i.status}`)}catch(n){v(t.debug,`Flush attempt ${e+1} error`,n)}return!1}(this.transportCfg,n)||this.log("Flush failed — events dropped",n.length)}log(...t){var e;(null===(e=this.config)||void 0===e?void 0:e.debug)&&"undefined"!=typeof console&&console.log("[Infralytiqs]",...t)}},k={init(t){U.init(t)},track(t,e,n,i){U.track(t,e,n,i)},identify(t){U.identify(t)},flush:()=>U.flush(),destroy(){U.destroy()}};try{!function(){if("undefined"==typeof window||"undefined"==typeof document)return;const t=window;if(t[R])return;const e=t.IL_CLIENT_BOOTSTRAP_LIB;if(!e||"string"!=typeof e)return;const n=function(t){if(/^https?:\/\//i.test(t))return t;if(!L)return t;try{return new URL(t,L).href}catch(e){return t}}(e);t[R]=!0;const i=document.createElement("script");i.src=n,i.async=!0,i.setAttribute("data-il-bootstrap","client"),i.onerror=()=>{"undefined"!=typeof console&&console.error("[Infralytiqs] failed to load client bootstrap from",n)};const o=document.head||document.documentElement;o&&o.appendChild(i)}()}catch(t){}return t.LICENSE_MODULE_ID="infralytiqs.com",t.default=k,Object.defineProperty(t,"__esModule",{value:!0}),t}({});
|
package/package.json
CHANGED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Client-bootstrap auto-loader.
|
|
3
|
+
*
|
|
4
|
+
* When the SDK script first executes on a host page, it looks for a
|
|
5
|
+
* `window.IL_CLIENT_BOOTSTRAP_LIB` global declared by the host (in AEM this
|
|
6
|
+
* is injected by the `Infralytiqs.html` Sightly fragment). If present, the
|
|
7
|
+
* SDK fetches that client-specific bootstrap JavaScript from the CDN and
|
|
8
|
+
* appends it to <head>. The bootstrap is then responsible for calling
|
|
9
|
+
* `Infralytiqs.init({...})` with tenant/site configuration and wiring any
|
|
10
|
+
* site-specific event hooks.
|
|
11
|
+
*
|
|
12
|
+
* Path resolution
|
|
13
|
+
* ---------------
|
|
14
|
+
* `IL_CLIENT_BOOTSTRAP_LIB` may be either:
|
|
15
|
+
* • A fully qualified URL ("https://…/bootstrap.min.js") — used as-is.
|
|
16
|
+
* • A path starting with "/" (e.g. "/cl/publicis/ps/bootstrap.min.js") —
|
|
17
|
+
* resolved against the SDK's own origin (the CDN host that served this
|
|
18
|
+
* script). This lets every client bootstrap live in the same S3 bucket
|
|
19
|
+
* as the SDK without the host page needing to know the CDN hostname.
|
|
20
|
+
* • A relative path — resolved against the SDK's own URL.
|
|
21
|
+
*
|
|
22
|
+
* The SDK script URL is captured at module-evaluation time via
|
|
23
|
+
* `document.currentScript`, which is only reliable during the SDK's
|
|
24
|
+
* synchronous IIFE execution. A defensive fallback scans existing <script>
|
|
25
|
+
* tags for one whose src matches the SDK bundle naming convention.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
const SDK_SCRIPT_URL: string = (() => {
|
|
29
|
+
try {
|
|
30
|
+
if (typeof document === 'undefined') return '';
|
|
31
|
+
const current = document.currentScript as HTMLScriptElement | null;
|
|
32
|
+
if (current && current.src) return current.src;
|
|
33
|
+
|
|
34
|
+
const scripts = document.getElementsByTagName('script');
|
|
35
|
+
for (let i = scripts.length - 1; i >= 0; i--) {
|
|
36
|
+
const src = scripts[i].src;
|
|
37
|
+
if (src && /infralytiqs(\.min)?\.js(\?.*)?$/.test(src)) return src;
|
|
38
|
+
}
|
|
39
|
+
} catch {
|
|
40
|
+
/* noop — fall through to empty */
|
|
41
|
+
}
|
|
42
|
+
return '';
|
|
43
|
+
})();
|
|
44
|
+
|
|
45
|
+
const BOOTSTRAP_FLAG = '__il_bootstrap_loaded__';
|
|
46
|
+
|
|
47
|
+
interface WindowWithBootstrap {
|
|
48
|
+
IL_CLIENT_BOOTSTRAP_LIB?: string;
|
|
49
|
+
[BOOTSTRAP_FLAG]?: boolean;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function resolveBootstrapUrl(rawPath: string): string {
|
|
53
|
+
if (/^https?:\/\//i.test(rawPath)) return rawPath;
|
|
54
|
+
if (!SDK_SCRIPT_URL) return rawPath;
|
|
55
|
+
try {
|
|
56
|
+
return new URL(rawPath, SDK_SCRIPT_URL).href;
|
|
57
|
+
} catch {
|
|
58
|
+
return rawPath;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Injects a <script src="…"> tag for the client bootstrap declared on the
|
|
64
|
+
* host page. Idempotent — a window sentinel guards against double injection
|
|
65
|
+
* if the SDK is somehow evaluated twice.
|
|
66
|
+
*/
|
|
67
|
+
export function loadClientBootstrap(): void {
|
|
68
|
+
if (typeof window === 'undefined' || typeof document === 'undefined') return;
|
|
69
|
+
|
|
70
|
+
const w = window as unknown as WindowWithBootstrap;
|
|
71
|
+
if (w[BOOTSTRAP_FLAG]) return;
|
|
72
|
+
|
|
73
|
+
const lib = w.IL_CLIENT_BOOTSTRAP_LIB;
|
|
74
|
+
if (!lib || typeof lib !== 'string') return;
|
|
75
|
+
|
|
76
|
+
const absoluteUrl = resolveBootstrapUrl(lib);
|
|
77
|
+
|
|
78
|
+
w[BOOTSTRAP_FLAG] = true;
|
|
79
|
+
|
|
80
|
+
const s = document.createElement('script');
|
|
81
|
+
s.src = absoluteUrl;
|
|
82
|
+
s.async = true;
|
|
83
|
+
s.setAttribute('data-il-bootstrap', 'client');
|
|
84
|
+
s.onerror = (): void => {
|
|
85
|
+
if (typeof console !== 'undefined') {
|
|
86
|
+
console.error('[Infralytiqs] failed to load client bootstrap from', absoluteUrl);
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
const parent = document.head || document.documentElement;
|
|
91
|
+
if (parent) {
|
|
92
|
+
parent.appendChild(s);
|
|
93
|
+
}
|
|
94
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -33,6 +33,7 @@
|
|
|
33
33
|
|
|
34
34
|
import { InfralytiqsTracker } from './tracker';
|
|
35
35
|
import type { InfralytiqsConfig } from './types';
|
|
36
|
+
import { loadClientBootstrap } from './bootstrapLoader';
|
|
36
37
|
|
|
37
38
|
export { LICENSE_MODULE_ID } from './licenseModuleId';
|
|
38
39
|
export type { InfralytiqsConfig };
|
|
@@ -89,3 +90,17 @@ const Infralytiqs = {
|
|
|
89
90
|
|
|
90
91
|
export default Infralytiqs;
|
|
91
92
|
|
|
93
|
+
// ─── Auto-load the client-specific bootstrap ────────────────────────────
|
|
94
|
+
// When the SDK script tag executes, look for `window.IL_CLIENT_BOOTSTRAP_LIB`
|
|
95
|
+
// declared by the host page (e.g. by the AEM Infralytiqs.html Sightly
|
|
96
|
+
// fragment) and inject a <script> tag for it. The bootstrap is then
|
|
97
|
+
// responsible for calling `Infralytiqs.init({...})` and wiring up any
|
|
98
|
+
// site-specific event hooks. Resolution against the SDK's own CDN origin
|
|
99
|
+
// is handled inside the loader, so host pages can use absolute-path
|
|
100
|
+
// shortcuts like "/cl/publicis/ps/infralytiqs-bootstrap.min.js".
|
|
101
|
+
try {
|
|
102
|
+
loadClientBootstrap();
|
|
103
|
+
} catch {
|
|
104
|
+
/* never throw out of SDK script-tag evaluation */
|
|
105
|
+
}
|
|
106
|
+
|