@deriv-com/analytics 1.37.0 → 1.38.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.
@@ -1,3 +1,3 @@
1
- export { P as Posthog } from '../../posthog-CY-D6TZM.mjs';
1
+ export { P as Posthog } from '../../posthog-DGiwrEsA.mjs';
2
2
  import '../../types-DoMejCXv.mjs';
3
3
  import 'posthog-js';
@@ -1,3 +1,3 @@
1
- export { P as Posthog } from '../../posthog-D--oI2Yn.js';
1
+ export { P as Posthog } from '../../posthog-D3QL9y8a.js';
2
2
  import '../../types-DoMejCXv.js';
3
3
  import 'posthog-js';
@@ -1,3 +1,3 @@
1
1
  'use strict';var chunkNOEKD4DT_js=require('../../chunk-NOEKD4DT.js'),o=require('posthog-js');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var o__default=/*#__PURE__*/_interopDefault(o);/* @deriv-com/analytics - NPM Package - Built with tsup */
2
- var e=class e{constructor(t){this.has_initialized=false;this.has_identified=false;this.init=async()=>{try{let{apiKey:t,config:s={}}=this.options;if(!t){console.warn("Posthog: No API key provided");return}let i={api_host:chunkNOEKD4DT_js.d,ui_host:chunkNOEKD4DT_js.e,autocapture:!0,session_recording:{recordCrossOriginIframes:!0,minimumDurationMilliseconds:3e4,...s.session_recording},before_send:r=>{if(typeof window>"u")return null;let n=window.location.host;return chunkNOEKD4DT_js.f.some(a=>n.endsWith(`.${a}`)||n===a)?r:null},...s};o__default.default.init(t,i),this.has_initialized=!0;}catch(t){console.error("Posthog: Failed to initialize",t);}};this.identifyEvent=(t,s)=>{if(!this.has_initialized){console.warn("Posthog: Cannot identify - not initialized");return}try{let i=o__default.default._isIdentified,r=typeof i=="function"?i():this.has_identified;if(t&&!r){let n=o__default.default.get_distinct_id();n&&n!==t&&o__default.default.alias(t,n);}o__default.default.identify(t,s),this.has_identified=!0;}catch(i){console.error("Posthog: Failed to identify user",i);}};this.reset=()=>{if(this.has_initialized)try{o__default.default.reset(),this.has_identified=!1;}catch(t){console.error("Posthog: Failed to reset",t);}};this.capture=(t,s)=>{if(this.has_initialized)try{o__default.default.capture(t,s);}catch(i){console.error("Posthog: Failed to capture event",i);}};this.options=t,this.init();}};e.getPosthogInstance=t=>(e._instance||(e._instance=new e(t)),e._instance);var f=e;exports.Posthog=f;//# sourceMappingURL=index.js.map
2
+ var e=class e{constructor(t){this.has_initialized=false;this.has_identified=false;this.init=async()=>{try{let{apiKey:t,api_host:s,config:i={}}=this.options;if(!t){console.warn("Posthog: No API key provided");return}let r={api_host:s||chunkNOEKD4DT_js.d,ui_host:chunkNOEKD4DT_js.e,autocapture:!0,session_recording:{recordCrossOriginIframes:!0,minimumDurationMilliseconds:3e4,...i.session_recording},before_send:n=>{if(typeof window>"u")return null;let a=window.location.host;return chunkNOEKD4DT_js.f.some(d=>a.endsWith(`.${d}`)||a===d)?n:null},...i};o__default.default.init(t,r),this.has_initialized=!0;}catch(t){console.error("Posthog: Failed to initialize",t);}};this.identifyEvent=(t,s)=>{if(!this.has_initialized){console.warn("Posthog: Cannot identify - not initialized");return}try{let i=o__default.default._isIdentified,r=typeof i=="function"?i():this.has_identified;if(t&&!r){let n=o__default.default.get_distinct_id();n&&n!==t&&o__default.default.alias(t,n);}o__default.default.identify(t,s),this.has_identified=!0;}catch(i){console.error("Posthog: Failed to identify user",i);}};this.reset=()=>{if(this.has_initialized)try{o__default.default.reset(),this.has_identified=!1;}catch(t){console.error("Posthog: Failed to reset",t);}};this.capture=(t,s)=>{if(this.has_initialized)try{o__default.default.capture(t,s);}catch(i){console.error("Posthog: Failed to capture event",i);}};this.options=t,this.init();}};e.getPosthogInstance=t=>(e._instance||(e._instance=new e(t)),e._instance);var l=e;exports.Posthog=l;//# sourceMappingURL=index.js.map
3
3
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/providers/posthog.ts"],"names":["_Posthog","options","apiKey","config","posthogConfig","posthogApiHost","posthogUiHost","event","currentHost","allowedDomains","domain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AAM,kCAAA,CAAoCA,CAAK,EAC3D,CACJ,CAAA,CAzHI,IAAA,CAAK,OAAA,CAAUX,CAAAA,CACf,IAAA,CAAK,IAAA,GACT,CAwHJ,CAAA,CAjIaD,CAAAA,CAgBK,kBAAA,CAAsBC,CAAAA,GAC3BD,CAAAA,CAAQ,SAAA,GACTA,CAAAA,CAAQ,SAAA,CAAY,IAAIA,CAAAA,CAAQC,CAAO,CAAA,CAAA,CAEpCD,CAAAA,CAAQ,SAAA,CAAA,CApBhB,IAAMoB,CAAAA,CAANpB","file":"index.js","sourcesContent":["import posthog from 'posthog-js'\nimport type { TPosthogConfig, TPosthogIdentifyTraits, TPosthogOptions } from './posthogTypes'\nimport type { TCoreAttributes } from '../types'\nimport { allowedDomains, posthogApiHost, posthogUiHost } from '../utils/urls'\n\n/**\n * PostHog analytics wrapper with singleton pattern.\n * Provides optional PostHog integration for event tracking and session recording.\n *\n * Features:\n * - Dynamically loads PostHog SDK on demand\n * - Domain allowlisting for security\n * - Automatic user identification and aliasing\n * - Custom event tracking with property sanitization\n * - Built-in caching and retry mechanisms (handled by posthog-js library)\n *\n * Note: PostHog handles its own event queuing, caching, and retry logic internally.\n * No additional caching is needed at the wrapper level.\n */\nexport class Posthog {\n has_initialized = false\n has_identified = false\n private static _instance: Posthog\n private options: TPosthogOptions\n\n constructor(options: TPosthogOptions) {\n this.options = options\n this.init()\n }\n\n /**\n * Get or create the singleton instance of Posthog\n * @param options - PostHog configuration options including API key\n * @returns The Posthog singleton instance\n */\n public static getPosthogInstance = (options: TPosthogOptions): Posthog => {\n if (!Posthog._instance) {\n Posthog._instance = new Posthog(options)\n }\n return Posthog._instance\n }\n\n /**\n * Initialize PostHog with configuration\n * Configures PostHog instance with provided options\n */\n init = async (): Promise<void> => {\n try {\n const { apiKey, config = {} } = this.options\n\n if (!apiKey) {\n console.warn('Posthog: No API key provided')\n return\n }\n\n const posthogConfig: TPosthogConfig = {\n api_host: posthogApiHost,\n ui_host: posthogUiHost,\n autocapture: true,\n session_recording: {\n recordCrossOriginIframes: true,\n minimumDurationMilliseconds: 30000,\n ...config.session_recording,\n },\n before_send: event => {\n if (typeof window === 'undefined') return null\n\n const currentHost = window.location.host\n const isAllowed = allowedDomains.some(\n domain => currentHost.endsWith(`.${domain}`) || currentHost === domain\n )\n return isAllowed ? event : null\n },\n ...config,\n }\n\n // Initialize PostHog\n posthog.init(apiKey, posthogConfig)\n this.has_initialized = true\n } catch (error) {\n console.error('Posthog: Failed to initialize', error)\n }\n }\n\n /**\n * Identify a user with PostHog\n * Creates an alias between anonymous ID and user ID, then identifies with traits\n *\n * @param user_id - The user ID to identify\n * @param traits - User properties (language, country_of_residence, etc.)\n */\n identifyEvent = (user_id: string, traits?: TPosthogIdentifyTraits): void => {\n if (!this.has_initialized) {\n console.warn('Posthog: Cannot identify - not initialized')\n return\n }\n\n try {\n // Only alias if not already identified\n const isIdentifiedFn = posthog._isIdentified\n const isIdentified = typeof isIdentifiedFn === 'function' ? isIdentifiedFn() : this.has_identified\n\n if (user_id && !isIdentified) {\n const anonId = posthog.get_distinct_id()\n if (anonId && anonId !== user_id) {\n posthog.alias(user_id, anonId)\n }\n }\n\n // Identify with traits\n posthog.identify(user_id, traits)\n this.has_identified = true\n } catch (error) {\n console.error('Posthog: Failed to identify user', error)\n }\n }\n\n /**\n * Reset PostHog state\n * Clears user identification and resets the instance\n */\n reset = (): void => {\n if (!this.has_initialized) return\n\n try {\n posthog.reset()\n this.has_identified = false\n } catch (error) {\n console.error('Posthog: Failed to reset', error)\n }\n }\n\n /**\n * Capture a custom event with properties\n * Properties are pre-flattened and cleaned by analytics.ts before being passed here\n *\n * @param event_name - The name of the event to track\n * @param properties - Event properties including core attributes (already flattened and cleaned)\n */\n capture = (event_name: string, properties?: Record<string, any> & Partial<TCoreAttributes>): void => {\n if (!this.has_initialized) return\n\n try {\n posthog.capture(event_name, properties)\n } catch (error) {\n console.error('Posthog: Failed to capture event', error)\n }\n }\n}\n"]}
1
+ {"version":3,"sources":["../../../src/providers/posthog.ts"],"names":["_Posthog","options","apiKey","api_host","config","posthogConfig","posthogApiHost","posthogUiHost","event","currentHost","allowedDomains","domain","posthog","error","user_id","traits","isIdentifiedFn","isIdentified","anonId","event_name","properties","Posthog"],"mappings":";AAmBO,IAAMA,CAAAA,CAAN,MAAMA,CAAQ,CAMjB,WAAA,CAAYC,CAAAA,CAA0B,CALtC,IAAA,CAAA,eAAA,CAAkB,KAAA,CAClB,IAAA,CAAA,cAAA,CAAiB,KAAA,CAyBjB,IAAA,CAAA,IAAA,CAAO,SAA2B,CAC9B,GAAI,CACA,GAAM,CAAE,MAAA,CAAAC,CAAAA,CAAQ,QAAA,CAAAC,CAAAA,CAAU,MAAA,CAAAC,CAAAA,CAAS,EAAG,CAAA,CAAI,IAAA,CAAK,OAAA,CAE/C,GAAI,CAACF,CAAAA,CAAQ,CACT,OAAA,CAAQ,IAAA,CAAK,8BAA8B,CAAA,CAC3C,MACJ,CAEA,IAAMG,CAAAA,CAAgC,CAClC,QAAA,CAAUF,CAAAA,EAAYG,kBAAAA,CACtB,OAAA,CAASC,kBAAAA,CACT,WAAA,CAAa,CAAA,CAAA,CACb,iBAAA,CAAmB,CACf,wBAAA,CAA0B,CAAA,CAAA,CAC1B,2BAAA,CAA6B,GAAA,CAC7B,GAAGH,CAAAA,CAAO,iBACd,CAAA,CACA,WAAA,CAAaI,CAAAA,EAAS,CAClB,GAAI,OAAO,MAAA,CAAW,GAAA,CAAa,OAAO,IAAA,CAE1C,IAAMC,CAAAA,CAAc,MAAA,CAAO,QAAA,CAAS,IAAA,CAIpC,OAHkBC,kBAAAA,CAAe,IAAA,CAC7BC,CAAAA,EAAUF,CAAAA,CAAY,QAAA,CAAS,CAAA,CAAA,EAAIE,CAAM,CAAA,CAAE,CAAA,EAAKF,CAAAA,GAAgBE,CACpE,CAAA,CACmBH,CAAAA,CAAQ,IAC/B,CAAA,CACA,GAAGJ,CACP,CAAA,CAGAQ,kBAAAA,CAAQ,IAAA,CAAK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K,IAAA,CAAK,eAAA,CAEV,GAAI,CACAR,kBAAAA,CAAQ,OAAA,CAAQO,CAAAA,CAAYC,CAAU,EAC1C,CAAA,MAASP,CAAAA,CAAO,CACZ,OAAA,CAAQ,KAAA,CAAM,kCAAA,CAAoCA,CAAK,EAC3D,CACJ,CAAA,CAzHI,IAAA,CAAK,OAAA,CAAUZ,CAAAA,CACf,IAAA,CAAK,IAAA,GACT,CAwHJ,CAAA,CAjIaD,CAAAA,CAgBK,kBAAA,CAAsBC,CAAAA,GAC3BD,CAAAA,CAAQ,SAAA,GACTA,CAAAA,CAAQ,SAAA,CAAY,IAAIA,CAAAA,CAAQC,CAAO,CAAA,CAAA,CAEpCD,CAAAA,CAAQ,SAAA,CAAA,CApBhB,IAAMqB,CAAAA,CAANrB","file":"index.js","sourcesContent":["import posthog from 'posthog-js'\nimport type { TPosthogConfig, TPosthogIdentifyTraits, TPosthogOptions } from './posthogTypes'\nimport type { TCoreAttributes } from '../types'\nimport { allowedDomains, posthogApiHost, posthogUiHost } from '../utils/urls'\n\n/**\n * PostHog analytics wrapper with singleton pattern.\n * Provides optional PostHog integration for event tracking and session recording.\n *\n * Features:\n * - Dynamically loads PostHog SDK on demand\n * - Domain allowlisting for security\n * - Automatic user identification and aliasing\n * - Custom event tracking with property sanitization\n * - Built-in caching and retry mechanisms (handled by posthog-js library)\n *\n * Note: PostHog handles its own event queuing, caching, and retry logic internally.\n * No additional caching is needed at the wrapper level.\n */\nexport class Posthog {\n has_initialized = false\n has_identified = false\n private static _instance: Posthog\n private options: TPosthogOptions\n\n constructor(options: TPosthogOptions) {\n this.options = options\n this.init()\n }\n\n /**\n * Get or create the singleton instance of Posthog\n * @param options - PostHog configuration options including API key\n * @returns The Posthog singleton instance\n */\n public static getPosthogInstance = (options: TPosthogOptions): Posthog => {\n if (!Posthog._instance) {\n Posthog._instance = new Posthog(options)\n }\n return Posthog._instance\n }\n\n /**\n * Initialize PostHog with configuration\n * Configures PostHog instance with provided options\n */\n init = async (): Promise<void> => {\n try {\n const { apiKey, api_host, config = {} } = this.options\n\n if (!apiKey) {\n console.warn('Posthog: No API key provided')\n return\n }\n\n const posthogConfig: TPosthogConfig = {\n api_host: api_host || posthogApiHost,\n ui_host: posthogUiHost,\n autocapture: true,\n session_recording: {\n recordCrossOriginIframes: true,\n minimumDurationMilliseconds: 30000,\n ...config.session_recording,\n },\n before_send: event => {\n if (typeof window === 'undefined') return null\n\n const currentHost = window.location.host\n const isAllowed = allowedDomains.some(\n domain => currentHost.endsWith(`.${domain}`) || currentHost === domain\n )\n return isAllowed ? event : null\n },\n ...config,\n }\n\n // Initialize PostHog\n posthog.init(apiKey, posthogConfig)\n this.has_initialized = true\n } catch (error) {\n console.error('Posthog: Failed to initialize', error)\n }\n }\n\n /**\n * Identify a user with PostHog\n * Creates an alias between anonymous ID and user ID, then identifies with traits\n *\n * @param user_id - The user ID to identify\n * @param traits - User properties (language, country_of_residence, etc.)\n */\n identifyEvent = (user_id: string, traits?: TPosthogIdentifyTraits): void => {\n if (!this.has_initialized) {\n console.warn('Posthog: Cannot identify - not initialized')\n return\n }\n\n try {\n // Only alias if not already identified\n const isIdentifiedFn = posthog._isIdentified\n const isIdentified = typeof isIdentifiedFn === 'function' ? isIdentifiedFn() : this.has_identified\n\n if (user_id && !isIdentified) {\n const anonId = posthog.get_distinct_id()\n if (anonId && anonId !== user_id) {\n posthog.alias(user_id, anonId)\n }\n }\n\n // Identify with traits\n posthog.identify(user_id, traits)\n this.has_identified = true\n } catch (error) {\n console.error('Posthog: Failed to identify user', error)\n }\n }\n\n /**\n * Reset PostHog state\n * Clears user identification and resets the instance\n */\n reset = (): void => {\n if (!this.has_initialized) return\n\n try {\n posthog.reset()\n this.has_identified = false\n } catch (error) {\n console.error('Posthog: Failed to reset', error)\n }\n }\n\n /**\n * Capture a custom event with properties\n * Properties are pre-flattened and cleaned by analytics.ts before being passed here\n *\n * @param event_name - The name of the event to track\n * @param properties - Event properties including core attributes (already flattened and cleaned)\n */\n capture = (event_name: string, properties?: Record<string, any> & Partial<TCoreAttributes>): void => {\n if (!this.has_initialized) return\n\n try {\n posthog.capture(event_name, properties)\n } catch (error) {\n console.error('Posthog: Failed to capture event', error)\n }\n }\n}\n"]}
@@ -1,3 +1,3 @@
1
- import {f as f$1,e as e$1,d}from'../../chunk-DNCZM4KN.mjs';import o from'posthog-js';/* @deriv-com/analytics - NPM Package - Built with tsup */
2
- var e=class e{constructor(t){this.has_initialized=false;this.has_identified=false;this.init=async()=>{try{let{apiKey:t,config:s={}}=this.options;if(!t){console.warn("Posthog: No API key provided");return}let i={api_host:d,ui_host:e$1,autocapture:!0,session_recording:{recordCrossOriginIframes:!0,minimumDurationMilliseconds:3e4,...s.session_recording},before_send:r=>{if(typeof window>"u")return null;let n=window.location.host;return f$1.some(a=>n.endsWith(`.${a}`)||n===a)?r:null},...s};o.init(t,i),this.has_initialized=!0;}catch(t){console.error("Posthog: Failed to initialize",t);}};this.identifyEvent=(t,s)=>{if(!this.has_initialized){console.warn("Posthog: Cannot identify - not initialized");return}try{let i=o._isIdentified,r=typeof i=="function"?i():this.has_identified;if(t&&!r){let n=o.get_distinct_id();n&&n!==t&&o.alias(t,n);}o.identify(t,s),this.has_identified=!0;}catch(i){console.error("Posthog: Failed to identify user",i);}};this.reset=()=>{if(this.has_initialized)try{o.reset(),this.has_identified=!1;}catch(t){console.error("Posthog: Failed to reset",t);}};this.capture=(t,s)=>{if(this.has_initialized)try{o.capture(t,s);}catch(i){console.error("Posthog: Failed to capture event",i);}};this.options=t,this.init();}};e.getPosthogInstance=t=>(e._instance||(e._instance=new e(t)),e._instance);var f=e;export{f as Posthog};//# sourceMappingURL=index.mjs.map
1
+ import {f,e as e$1,d}from'../../chunk-DNCZM4KN.mjs';import o from'posthog-js';/* @deriv-com/analytics - NPM Package - Built with tsup */
2
+ var e=class e{constructor(t){this.has_initialized=false;this.has_identified=false;this.init=async()=>{try{let{apiKey:t,api_host:s,config:i={}}=this.options;if(!t){console.warn("Posthog: No API key provided");return}let r={api_host:s||d,ui_host:e$1,autocapture:!0,session_recording:{recordCrossOriginIframes:!0,minimumDurationMilliseconds:3e4,...i.session_recording},before_send:n=>{if(typeof window>"u")return null;let a=window.location.host;return f.some(d=>a.endsWith(`.${d}`)||a===d)?n:null},...i};o.init(t,r),this.has_initialized=!0;}catch(t){console.error("Posthog: Failed to initialize",t);}};this.identifyEvent=(t,s)=>{if(!this.has_initialized){console.warn("Posthog: Cannot identify - not initialized");return}try{let i=o._isIdentified,r=typeof i=="function"?i():this.has_identified;if(t&&!r){let n=o.get_distinct_id();n&&n!==t&&o.alias(t,n);}o.identify(t,s),this.has_identified=!0;}catch(i){console.error("Posthog: Failed to identify user",i);}};this.reset=()=>{if(this.has_initialized)try{o.reset(),this.has_identified=!1;}catch(t){console.error("Posthog: Failed to reset",t);}};this.capture=(t,s)=>{if(this.has_initialized)try{o.capture(t,s);}catch(i){console.error("Posthog: Failed to capture event",i);}};this.options=t,this.init();}};e.getPosthogInstance=t=>(e._instance||(e._instance=new e(t)),e._instance);var l=e;export{l as Posthog};//# sourceMappingURL=index.mjs.map
3
3
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/providers/posthog.ts"],"names":["_Posthog","options","apiKey","config","posthogConfig","posthogApiHost","posthogUiHost","event","currentHost","allowedDomains","domain","posthog","error","user_id","traits","isIdentifiedFn","isIdentified","anonId","event_name","properties","Posthog"],"mappings":";AAmBO,IAAMA,CAAAA,CAAN,MAAMA,CAAQ,CAMjB,WAAA,CAAYC,CAAAA,CAA0B,CALtC,IAAA,CAAA,eAAA,CAAkB,KAAA,CAClB,IAAA,CAAA,cAAA,CAAiB,KAAA,CAyBjB,IAAA,CAAA,IAAA,CAAO,SAA2B,CAC9B,GAAI,CACA,GAAM,CAAE,MAAA,CAAAC,CAAAA,CAAQ,MAAA,CAAAC,CAAAA,CAAS,EAAG,CAAA,CAAI,IAAA,CAAK,OAAA,CAErC,GAAI,CAACD,CAAAA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PosthogOptions } from './posthogTypes'\nimport type { TCoreAttributes } from '../types'\nimport { allowedDomains, posthogApiHost, posthogUiHost } from '../utils/urls'\n\n/**\n * PostHog analytics wrapper with singleton pattern.\n * Provides optional PostHog integration for event tracking and session recording.\n *\n * Features:\n * - Dynamically loads PostHog SDK on demand\n * - Domain allowlisting for security\n * - Automatic user identification and aliasing\n * - Custom event tracking with property sanitization\n * - Built-in caching and retry mechanisms (handled by posthog-js library)\n *\n * Note: PostHog handles its own event queuing, caching, and retry logic internally.\n * No additional caching is needed at the wrapper level.\n */\nexport class Posthog {\n has_initialized = false\n has_identified = false\n private static _instance: Posthog\n private options: TPosthogOptions\n\n constructor(options: TPosthogOptions) {\n this.options = options\n this.init()\n }\n\n /**\n * Get or create the singleton instance of Posthog\n * @param options - PostHog configuration options including API key\n * @returns The Posthog singleton instance\n */\n public static getPosthogInstance = (options: TPosthogOptions): Posthog => {\n if (!Posthog._instance) {\n Posthog._instance = new Posthog(options)\n }\n return Posthog._instance\n }\n\n /**\n * Initialize PostHog with configuration\n * Configures PostHog instance with provided options\n */\n init = async (): Promise<void> => {\n try {\n const { apiKey, config = {} } = this.options\n\n if (!apiKey) {\n console.warn('Posthog: No API key provided')\n return\n }\n\n const posthogConfig: TPosthogConfig = {\n api_host: posthogApiHost,\n ui_host: posthogUiHost,\n autocapture: true,\n session_recording: {\n recordCrossOriginIframes: true,\n minimumDurationMilliseconds: 30000,\n ...config.session_recording,\n },\n before_send: event => {\n if (typeof window === 'undefined') return null\n\n const currentHost = window.location.host\n const isAllowed = allowedDomains.some(\n domain => currentHost.endsWith(`.${domain}`) || currentHost === domain\n )\n return isAllowed ? event : null\n },\n ...config,\n }\n\n // Initialize PostHog\n posthog.init(apiKey, posthogConfig)\n this.has_initialized = true\n } catch (error) {\n console.error('Posthog: Failed to initialize', error)\n }\n }\n\n /**\n * Identify a user with PostHog\n * Creates an alias between anonymous ID and user ID, then identifies with traits\n *\n * @param user_id - The user ID to identify\n * @param traits - User properties (language, country_of_residence, etc.)\n */\n identifyEvent = (user_id: string, traits?: TPosthogIdentifyTraits): void => {\n if (!this.has_initialized) {\n console.warn('Posthog: Cannot identify - not initialized')\n return\n }\n\n try {\n // Only alias if not already identified\n const isIdentifiedFn = posthog._isIdentified\n const isIdentified = typeof isIdentifiedFn === 'function' ? isIdentifiedFn() : this.has_identified\n\n if (user_id && !isIdentified) {\n const anonId = posthog.get_distinct_id()\n if (anonId && anonId !== user_id) {\n posthog.alias(user_id, anonId)\n }\n }\n\n // Identify with traits\n posthog.identify(user_id, traits)\n this.has_identified = true\n } catch (error) {\n console.error('Posthog: Failed to identify user', error)\n }\n }\n\n /**\n * Reset PostHog state\n * Clears user identification and resets the instance\n */\n reset = (): void => {\n if (!this.has_initialized) return\n\n try {\n posthog.reset()\n this.has_identified = false\n } catch (error) {\n console.error('Posthog: Failed to reset', error)\n }\n }\n\n /**\n * Capture a custom event with properties\n * Properties are pre-flattened and cleaned by analytics.ts before being passed here\n *\n * @param event_name - The name of the event to track\n * @param properties - Event properties including core attributes (already flattened and cleaned)\n */\n capture = (event_name: string, properties?: Record<string, any> & Partial<TCoreAttributes>): void => {\n if (!this.has_initialized) return\n\n try {\n posthog.capture(event_name, properties)\n } catch (error) {\n console.error('Posthog: Failed to capture event', error)\n }\n }\n}\n"]}
1
+ {"version":3,"sources":["../../../src/providers/posthog.ts"],"names":["_Posthog","options","apiKey","api_host","config","posthogConfig","posthogApiHost","posthogUiHost","event","currentHost","allowedDomains","domain","posthog","error","user_id","traits","isIdentifiedFn","isIdentified","anonId","event_name","properties","Posthog"],"mappings":";AAmBO,IAAMA,CAAAA,CAAN,MAAMA,CAAQ,CAMjB,WAAA,CAAYC,CAAAA,CAA0B,CALtC,IAAA,CAAA,eAAA,CAAkB,KAAA,CAClB,IAAA,CAAA,cAAA,CAAiB,KAAA,CAyBjB,IAAA,CAAA,IAAA,CAAO,SAA2B,CAC9B,GAAI,CACA,GAAM,CAAE,MAAA,CAAAC,CAAAA,CAAQ,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,CAEpCD,CAAAA,CAAQ,SAAA,CAAA,CApBhB,IAAMqB,CAAAA,CAANrB","file":"index.mjs","sourcesContent":["import posthog from 'posthog-js'\nimport type { TPosthogConfig, TPosthogIdentifyTraits, TPosthogOptions } from './posthogTypes'\nimport type { TCoreAttributes } from '../types'\nimport { allowedDomains, posthogApiHost, posthogUiHost } from '../utils/urls'\n\n/**\n * PostHog analytics wrapper with singleton pattern.\n * Provides optional PostHog integration for event tracking and session recording.\n *\n * Features:\n * - Dynamically loads PostHog SDK on demand\n * - Domain allowlisting for security\n * - Automatic user identification and aliasing\n * - Custom event tracking with property sanitization\n * - Built-in caching and retry mechanisms (handled by posthog-js library)\n *\n * Note: PostHog handles its own event queuing, caching, and retry logic internally.\n * No additional caching is needed at the wrapper level.\n */\nexport class Posthog {\n has_initialized = false\n has_identified = false\n private static _instance: Posthog\n private options: TPosthogOptions\n\n constructor(options: TPosthogOptions) {\n this.options = options\n this.init()\n }\n\n /**\n * Get or create the singleton instance of Posthog\n * @param options - PostHog configuration options including API key\n * @returns The Posthog singleton instance\n */\n public static getPosthogInstance = (options: TPosthogOptions): Posthog => {\n if (!Posthog._instance) {\n Posthog._instance = new Posthog(options)\n }\n return Posthog._instance\n }\n\n /**\n * Initialize PostHog with configuration\n * Configures PostHog instance with provided options\n */\n init = async (): Promise<void> => {\n try {\n const { apiKey, api_host, config = {} } = this.options\n\n if (!apiKey) {\n console.warn('Posthog: No API key provided')\n return\n }\n\n const posthogConfig: TPosthogConfig = {\n api_host: api_host || posthogApiHost,\n ui_host: posthogUiHost,\n autocapture: true,\n session_recording: {\n recordCrossOriginIframes: true,\n minimumDurationMilliseconds: 30000,\n ...config.session_recording,\n },\n before_send: event => {\n if (typeof window === 'undefined') return null\n\n const currentHost = window.location.host\n const isAllowed = allowedDomains.some(\n domain => currentHost.endsWith(`.${domain}`) || currentHost === domain\n )\n return isAllowed ? event : null\n },\n ...config,\n }\n\n // Initialize PostHog\n posthog.init(apiKey, posthogConfig)\n this.has_initialized = true\n } catch (error) {\n console.error('Posthog: Failed to initialize', error)\n }\n }\n\n /**\n * Identify a user with PostHog\n * Creates an alias between anonymous ID and user ID, then identifies with traits\n *\n * @param user_id - The user ID to identify\n * @param traits - User properties (language, country_of_residence, etc.)\n */\n identifyEvent = (user_id: string, traits?: TPosthogIdentifyTraits): void => {\n if (!this.has_initialized) {\n console.warn('Posthog: Cannot identify - not initialized')\n return\n }\n\n try {\n // Only alias if not already identified\n const isIdentifiedFn = posthog._isIdentified\n const isIdentified = typeof isIdentifiedFn === 'function' ? isIdentifiedFn() : this.has_identified\n\n if (user_id && !isIdentified) {\n const anonId = posthog.get_distinct_id()\n if (anonId && anonId !== user_id) {\n posthog.alias(user_id, anonId)\n }\n }\n\n // Identify with traits\n posthog.identify(user_id, traits)\n this.has_identified = true\n } catch (error) {\n console.error('Posthog: Failed to identify user', error)\n }\n }\n\n /**\n * Reset PostHog state\n * Clears user identification and resets the instance\n */\n reset = (): void => {\n if (!this.has_initialized) return\n\n try {\n posthog.reset()\n this.has_identified = false\n } catch (error) {\n console.error('Posthog: Failed to reset', error)\n }\n }\n\n /**\n * Capture a custom event with properties\n * Properties are pre-flattened and cleaned by analytics.ts before being passed here\n *\n * @param event_name - The name of the event to track\n * @param properties - Event properties including core attributes (already flattened and cleaned)\n */\n capture = (event_name: string, properties?: Record<string, any> & Partial<TCoreAttributes>): void => {\n if (!this.has_initialized) return\n\n try {\n posthog.capture(event_name, properties)\n } catch (error) {\n console.error('Posthog: Failed to capture event', error)\n }\n }\n}\n"]}
@@ -1,2 +1,2 @@
1
- 'use strict';var chunkTLPR24DO_js=require('../../chunk-TLPR24DO.js');require('../../chunk-NOEKD4DT.js');Object.defineProperty(exports,"RudderStack",{enumerable:true,get:function(){return chunkTLPR24DO_js.a}});//# sourceMappingURL=index.js.map
1
+ 'use strict';var chunkNZ35MU4O_js=require('../../chunk-NZ35MU4O.js');require('../../chunk-NOEKD4DT.js');Object.defineProperty(exports,"RudderStack",{enumerable:true,get:function(){return chunkNZ35MU4O_js.a}});//# sourceMappingURL=index.js.map
2
2
  //# sourceMappingURL=index.js.map
@@ -1,2 +1,2 @@
1
- export{a as RudderStack}from'../../chunk-2P7RWD3W.mjs';import'../../chunk-DNCZM4KN.mjs';//# sourceMappingURL=index.mjs.map
1
+ export{a as RudderStack}from'../../chunk-KDJ46GSX.mjs';import'../../chunk-DNCZM4KN.mjs';//# sourceMappingURL=index.mjs.map
2
2
  //# sourceMappingURL=index.mjs.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deriv-com/analytics",
3
- "version": "1.37.0",
3
+ "version": "1.38.1",
4
4
  "description": "Comprehensive analytics package for Deriv applications. Provides unified event tracking, A/B testing, and user analytics through RudderStack, PostHog and GrowthBook integrations with built-in caching and offline support.",
5
5
  "keywords": [
6
6
  "rudderstack",
@@ -1,3 +0,0 @@
1
- import {c}from'./chunk-DNCZM4KN.mjs';import {RudderAnalytics}from'@rudderstack/analytics-js';/* @deriv-com/analytics - NPM Package - Built with tsup */
2
- var h=2*365*24*60*60,i=class i{constructor(t,e){this.analytics=new RudderAnalytics;this.has_identified=false;this.has_initialized=false;this.current_page="";this.rudderstack_anonymous_cookie_key="rudder_anonymous_id";this.getAnonymousId=()=>document.cookie.match("(^|;)\\s*"+this.rudderstack_anonymous_cookie_key+"\\s*=\\s*([^;]+)")?.pop();this.setCookieIfNotExists=()=>{if(!this.getAnonymousId())try{let e=window.location.hostname,o=["webflow.io"].some(l=>e.endsWith(l))?e:e.split(".").slice(-2).join("."),d=crypto?.randomUUID?crypto.randomUUID():`${Date.now()}-${Math.random()}`,c=window.location.protocol==="https:"?"; Secure":"";document.cookie=`${this.rudderstack_anonymous_cookie_key}=${d}; path=/; Domain=${o}; max-age=${h}; SameSite=Lax${c}`;}catch(e){console.warn("RudderStack: Failed to set anonymous ID cookie",e);}};this.getUserId=()=>this.analytics.getUserId();this.init=t=>{if(!t){console.warn("RudderStack: Initialization skipped - no key provided");return}try{this.setCookieIfNotExists(),this.analytics.load(t,c,{externalAnonymousIdCookieName:this.rudderstack_anonymous_cookie_key,useBeacon:!0,lockIntegrationsVersion:!0,onLoaded:()=>{this.has_initialized=!0,this.has_identified=!!this.getUserId(),this.onLoadedCallback?.();}});}catch(e){console.error("RudderStack: Failed to initialize",e);}};this.identifyEvent=(t,e)=>{if(!this.has_initialized){console.warn("RudderStack: Cannot identify - not initialized");return}if(this.getUserId())this.has_identified=true;else try{this.analytics.identify(t,e||{}),this.has_identified=!0;}catch(s){console.error("RudderStack: Failed to identify user",s);}};this.pageView=(t,e="Deriv App",n,s)=>{if(!(!this.has_initialized||t===this.current_page))try{let o={...n&&{user_id:n},...s};this.analytics.page(e,t,o),this.current_page=t;}catch(o){console.error("RudderStack: Failed to track page view",o);}};this.reset=()=>{if(this.has_initialized)try{this.analytics.reset(),this.has_identified=!1;}catch(t){console.error("RudderStack: Failed to reset",t);}};this.track=(t,e)=>{if(this.has_initialized)try{this.analytics.track(t,e);}catch(n){console.warn("RudderStack: Failed to track event",n);}};this.onLoadedCallback=e,this.init(t);}};i.getRudderStackInstance=(t,e)=>(i._instance||(i._instance=new i(t,e)),i._instance);var r=i;export{r as a};//# sourceMappingURL=chunk-2P7RWD3W.mjs.map
3
- //# sourceMappingURL=chunk-2P7RWD3W.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/providers/rudderstack.ts"],"names":["COOKIE_MAX_AGE_SECONDS","_RudderStack","RUDDERSTACK_KEY","onLoaded","RudderAnalytics","hostname","domain_name","domain","uuid","secureFlag","error","rudderstackDataplane","user_id","payload","current_page","platform","properties","pageProperties","event","err","RudderStack"],"mappings":";AAKA,IAAMA,CAAAA,CAAyB,CAAA,CAAI,IAAM,EAAA,CAAK,EAAA,CAAK,EAAA,CAMtCC,CAAAA,CAAN,MAAMA,CAAY,CASrB,YAAYC,CAAAA,CAAyBC,CAAAA,CAAuB,CAR5D,IAAA,CAAA,SAAA,CAAY,IAAIC,eAAAA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ACjE,IAAA,CAAK,YAAA,CAAeH,EACxB,CAAA,MAASJ,CAAAA,CAAO,CACZ,OAAA,CAAQ,KAAA,CAAM,yCAA0CA,CAAK,EACjE,CACJ,CAAA,CAMA,IAAA,CAAA,KAAA,CAAQ,IAAY,CAChB,GAAK,KAAK,eAAA,CAEV,GAAI,CACA,IAAA,CAAK,SAAA,CAAU,KAAA,EAAM,CACrB,KAAK,cAAA,CAAiB,CAAA,EAC1B,OAASA,CAAAA,CAAO,CACZ,QAAQ,KAAA,CAAM,8BAAA,CAAgCA,CAAK,EACvD,CACJ,EAQA,IAAA,CAAA,KAAA,CAAQ,CAA6BQ,EAAUL,CAAAA,GAA4D,CACvG,GAAK,IAAA,CAAK,eAAA,CAEV,GAAI,CAGA,KAAK,SAAA,CAAU,KAAA,CAAMK,EAAiBL,CAAc,EACxD,OAASM,CAAAA,CAAK,CACV,QAAQ,IAAA,CAAK,oCAAA,CAAsCA,CAAG,EAC1D,CACJ,EA5KI,IAAA,CAAK,gBAAA,CAAmBhB,EACxB,IAAA,CAAK,IAAA,CAAKD,CAAe,EAC7B,CA2KJ,CAAA,CAvLaD,CAAAA,CAoBK,uBAAyB,CAACC,CAAAA,CAAyBC,KACxDF,CAAAA,CAAY,SAAA,GACbA,EAAY,SAAA,CAAY,IAAIA,EAAYC,CAAAA,CAAiBC,CAAQ,GAE9DF,CAAAA,CAAY,SAAA,CAAA,KAxBdmB,CAAAA,CAANnB","file":"chunk-2P7RWD3W.mjs","sourcesContent":["import { RudderAnalytics } from '@rudderstack/analytics-js'\nimport type { TCoreAttributes, TAllEvents } from '../types'\nimport { rudderstackDataplane } from '../utils/urls'\n\n// Constants\nconst COOKIE_MAX_AGE_SECONDS = 2 * 365 * 24 * 60 * 60 // 2 years\n\n/**\n * RudderStack analytics wrapper with singleton pattern.\n * Handles user tracking, page views, and event analytics.\n */\nexport class RudderStack {\n analytics = new RudderAnalytics()\n has_identified = false\n has_initialized = false\n current_page = ''\n rudderstack_anonymous_cookie_key = 'rudder_anonymous_id'\n private static _instance: RudderStack\n private onLoadedCallback?: () => void\n\n constructor(RUDDERSTACK_KEY: string, onLoaded?: () => void) {\n this.onLoadedCallback = onLoaded\n this.init(RUDDERSTACK_KEY)\n }\n\n /**\n * Get or create the singleton instance of RudderStack\n * @param RUDDERSTACK_KEY - RudderStack write key\n * @param onLoaded - Optional callback when RudderStack is loaded\n * @returns The RudderStack singleton instance\n */\n public static getRudderStackInstance = (RUDDERSTACK_KEY: string, onLoaded?: () => void): RudderStack => {\n if (!RudderStack._instance) {\n RudderStack._instance = new RudderStack(RUDDERSTACK_KEY, onLoaded)\n }\n return RudderStack._instance\n }\n\n /**\n * Get the anonymous ID from cookies\n * @returns The anonymous ID or undefined if not found\n */\n getAnonymousId = (): string | undefined => {\n return document.cookie.match('(^|;)\\\\s*' + this.rudderstack_anonymous_cookie_key + '\\\\s*=\\\\s*([^;]+)')?.pop()\n }\n\n /**\n * Set anonymous ID cookie if it doesn't exist\n * Creates a secure cookie with proper domain and security attributes\n */\n setCookieIfNotExists = (): void => {\n const anonymous_id = this.getAnonymousId()\n\n if (!anonymous_id) {\n try {\n const hostname = window.location.hostname\n const external_domains = ['webflow.io']\n const is_external_domain = external_domains.some(domain => hostname.endsWith(domain))\n const domain_name = is_external_domain ? hostname : hostname.split('.').slice(-2).join('.')\n\n // Check if crypto.randomUUID is available\n const uuid = crypto?.randomUUID ? crypto.randomUUID() : `${Date.now()}-${Math.random()}`\n\n const isSecure = window.location.protocol === 'https:'\n const secureFlag = isSecure ? '; Secure' : ''\n\n document.cookie = `${this.rudderstack_anonymous_cookie_key}=${uuid}; path=/; Domain=${domain_name}; max-age=${COOKIE_MAX_AGE_SECONDS}; SameSite=Lax${secureFlag}`\n } catch (error) {\n console.warn('RudderStack: Failed to set anonymous ID cookie', error)\n }\n }\n }\n\n /**\n * Get the current user ID\n * @returns The user ID, null, or undefined if not identified\n */\n getUserId = () => this.analytics.getUserId()\n\n /**\n * Initialize RudderStack with the provided key\n * @param RUDDERSTACK_KEY - RudderStack write key\n */\n init = (RUDDERSTACK_KEY: string): void => {\n if (!RUDDERSTACK_KEY) {\n console.warn('RudderStack: Initialization skipped - no key provided')\n return\n }\n\n try {\n this.setCookieIfNotExists()\n\n this.analytics.load(RUDDERSTACK_KEY, rudderstackDataplane, {\n externalAnonymousIdCookieName: this.rudderstack_anonymous_cookie_key,\n // Performance optimizations\n useBeacon: true,\n lockIntegrationsVersion: true,\n onLoaded: () => {\n this.has_initialized = true\n this.has_identified = !!this.getUserId()\n this.onLoadedCallback?.()\n },\n })\n } catch (error) {\n console.error('RudderStack: Failed to initialize', error)\n }\n }\n\n /**\n * Identify a user with RudderStack\n * Only identifies if user hasn't been identified yet\n * @param user_id - The user ID to identify\n * @param payload - Optional user traits (e.g., language, custom properties)\n */\n identifyEvent = (user_id: string, payload?: Record<string, any>): void => {\n if (!this.has_initialized) {\n console.warn('RudderStack: Cannot identify - not initialized')\n return\n }\n\n const currentUserId = this.getUserId()\n if (!currentUserId) {\n try {\n this.analytics.identify(user_id, payload || {})\n this.has_identified = true\n } catch (error) {\n console.error('RudderStack: Failed to identify user', error)\n }\n } else {\n this.has_identified = true\n }\n }\n\n /**\n * Track a page view event\n * @param current_page - The page name/path\n * @param platform - The platform name (default: 'Deriv App')\n * @param user_id - The user ID\n * @param properties - Additional page properties\n */\n pageView = (\n current_page: string,\n platform = 'Deriv App',\n user_id: string,\n properties?: Record<string, unknown>\n ): void => {\n if (!this.has_initialized || current_page === this.current_page) return\n\n try {\n const pageProperties = {\n ...(user_id && { user_id }),\n ...properties,\n }\n\n // Type assertion needed due to RudderStack's type definitions\n this.analytics.page(platform, current_page, pageProperties as any)\n this.current_page = current_page\n } catch (error) {\n console.error('RudderStack: Failed to track page view', error)\n }\n }\n\n /**\n * Reset the RudderStack instance\n * Clears user identification and resets tracking state\n */\n reset = (): void => {\n if (!this.has_initialized) return\n\n try {\n this.analytics.reset()\n this.has_identified = false\n } catch (error) {\n console.error('RudderStack: Failed to reset', error)\n }\n }\n\n /**\n * Track a custom event with payload\n * Payload is pre-cleaned by analytics.ts using cleanObject before being passed here\n * @param event - The event name\n * @param payload - The event payload with core attributes\n */\n track = <T extends keyof TAllEvents>(event: T, payload: TAllEvents[T] & Partial<TCoreAttributes>): void => {\n if (!this.has_initialized) return\n\n try {\n // Type assertion needed to match RudderStack's ApiObject type\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n this.analytics.track(event as string, payload as any)\n } catch (err) {\n console.warn('RudderStack: Failed to track event', err)\n }\n }\n}\n"]}
@@ -1,3 +0,0 @@
1
- 'use strict';var chunkNOEKD4DT_js=require('./chunk-NOEKD4DT.js'),analyticsJs=require('@rudderstack/analytics-js');/* @deriv-com/analytics - NPM Package - Built with tsup */
2
- var h=2*365*24*60*60,i=class i{constructor(t,e){this.analytics=new analyticsJs.RudderAnalytics;this.has_identified=false;this.has_initialized=false;this.current_page="";this.rudderstack_anonymous_cookie_key="rudder_anonymous_id";this.getAnonymousId=()=>document.cookie.match("(^|;)\\s*"+this.rudderstack_anonymous_cookie_key+"\\s*=\\s*([^;]+)")?.pop();this.setCookieIfNotExists=()=>{if(!this.getAnonymousId())try{let e=window.location.hostname,o=["webflow.io"].some(l=>e.endsWith(l))?e:e.split(".").slice(-2).join("."),d=crypto?.randomUUID?crypto.randomUUID():`${Date.now()}-${Math.random()}`,c=window.location.protocol==="https:"?"; Secure":"";document.cookie=`${this.rudderstack_anonymous_cookie_key}=${d}; path=/; Domain=${o}; max-age=${h}; SameSite=Lax${c}`;}catch(e){console.warn("RudderStack: Failed to set anonymous ID cookie",e);}};this.getUserId=()=>this.analytics.getUserId();this.init=t=>{if(!t){console.warn("RudderStack: Initialization skipped - no key provided");return}try{this.setCookieIfNotExists(),this.analytics.load(t,chunkNOEKD4DT_js.c,{externalAnonymousIdCookieName:this.rudderstack_anonymous_cookie_key,useBeacon:!0,lockIntegrationsVersion:!0,onLoaded:()=>{this.has_initialized=!0,this.has_identified=!!this.getUserId(),this.onLoadedCallback?.();}});}catch(e){console.error("RudderStack: Failed to initialize",e);}};this.identifyEvent=(t,e)=>{if(!this.has_initialized){console.warn("RudderStack: Cannot identify - not initialized");return}if(this.getUserId())this.has_identified=true;else try{this.analytics.identify(t,e||{}),this.has_identified=!0;}catch(s){console.error("RudderStack: Failed to identify user",s);}};this.pageView=(t,e="Deriv App",n,s)=>{if(!(!this.has_initialized||t===this.current_page))try{let o={...n&&{user_id:n},...s};this.analytics.page(e,t,o),this.current_page=t;}catch(o){console.error("RudderStack: Failed to track page view",o);}};this.reset=()=>{if(this.has_initialized)try{this.analytics.reset(),this.has_identified=!1;}catch(t){console.error("RudderStack: Failed to reset",t);}};this.track=(t,e)=>{if(this.has_initialized)try{this.analytics.track(t,e);}catch(n){console.warn("RudderStack: Failed to track event",n);}};this.onLoadedCallback=e,this.init(t);}};i.getRudderStackInstance=(t,e)=>(i._instance||(i._instance=new i(t,e)),i._instance);var r=i;exports.a=r;//# sourceMappingURL=chunk-TLPR24DO.js.map
3
- //# sourceMappingURL=chunk-TLPR24DO.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/providers/rudderstack.ts"],"names":["COOKIE_MAX_AGE_SECONDS","_RudderStack","RUDDERSTACK_KEY","onLoaded","RudderAnalytics","hostname","domain_name","domain","uuid","secureFlag","error","rudderstackDataplane","user_id","payload","current_page","platform","properties","pageProperties","event","err","RudderStack"],"mappings":";AAKA,IAAMA,CAAAA,CAAyB,CAAA,CAAI,IAAM,EAAA,CAAK,EAAA,CAAK,EAAA,CAMtCC,CAAAA,CAAN,MAAMA,CAAY,CASrB,YAAYC,CAAAA,CAAyBC,CAAAA,CAAuB,CAR5D,IAAA,CAAA,SAAA,CAAY,IAAIC,2BAAAA,CAChB,IAAA,CAAA,cAAA,CAAiB,MACjB,IAAA,CAAA,eAAA,CAAkB,KAAA,CAClB,kBAAe,EAAA,CACf,IAAA,CAAA,gCAAA,CAAmC,sBA0BnC,IAAA,CAAA,cAAA,CAAiB,IAC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,IAAY,CAChB,GAAK,KAAK,eAAA,CAEV,GAAI,CACA,IAAA,CAAK,SAAA,CAAU,KAAA,EAAM,CACrB,KAAK,cAAA,CAAiB,CAAA,EAC1B,OAASA,CAAAA,CAAO,CACZ,QAAQ,KAAA,CAAM,8BAAA,CAAgCA,CAAK,EACvD,CACJ,EAQA,IAAA,CAAA,KAAA,CAAQ,CAA6BQ,EAAUL,CAAAA,GAA4D,CACvG,GAAK,IAAA,CAAK,eAAA,CAEV,GAAI,CAGA,KAAK,SAAA,CAAU,KAAA,CAAMK,EAAiBL,CAAc,EACxD,OAASM,CAAAA,CAAK,CACV,QAAQ,IAAA,CAAK,oCAAA,CAAsCA,CAAG,EAC1D,CACJ,EA5KI,IAAA,CAAK,gBAAA,CAAmBhB,EACxB,IAAA,CAAK,IAAA,CAAKD,CAAe,EAC7B,CA2KJ,CAAA,CAvLaD,CAAAA,CAoBK,uBAAyB,CAACC,CAAAA,CAAyBC,KACxDF,CAAAA,CAAY,SAAA,GACbA,EAAY,SAAA,CAAY,IAAIA,EAAYC,CAAAA,CAAiBC,CAAQ,GAE9DF,CAAAA,CAAY,SAAA,CAAA,KAxBdmB,CAAAA,CAANnB","file":"chunk-TLPR24DO.js","sourcesContent":["import { RudderAnalytics } from '@rudderstack/analytics-js'\nimport type { TCoreAttributes, TAllEvents } from '../types'\nimport { rudderstackDataplane } from '../utils/urls'\n\n// Constants\nconst COOKIE_MAX_AGE_SECONDS = 2 * 365 * 24 * 60 * 60 // 2 years\n\n/**\n * RudderStack analytics wrapper with singleton pattern.\n * Handles user tracking, page views, and event analytics.\n */\nexport class RudderStack {\n analytics = new RudderAnalytics()\n has_identified = false\n has_initialized = false\n current_page = ''\n rudderstack_anonymous_cookie_key = 'rudder_anonymous_id'\n private static _instance: RudderStack\n private onLoadedCallback?: () => void\n\n constructor(RUDDERSTACK_KEY: string, onLoaded?: () => void) {\n this.onLoadedCallback = onLoaded\n this.init(RUDDERSTACK_KEY)\n }\n\n /**\n * Get or create the singleton instance of RudderStack\n * @param RUDDERSTACK_KEY - RudderStack write key\n * @param onLoaded - Optional callback when RudderStack is loaded\n * @returns The RudderStack singleton instance\n */\n public static getRudderStackInstance = (RUDDERSTACK_KEY: string, onLoaded?: () => void): RudderStack => {\n if (!RudderStack._instance) {\n RudderStack._instance = new RudderStack(RUDDERSTACK_KEY, onLoaded)\n }\n return RudderStack._instance\n }\n\n /**\n * Get the anonymous ID from cookies\n * @returns The anonymous ID or undefined if not found\n */\n getAnonymousId = (): string | undefined => {\n return document.cookie.match('(^|;)\\\\s*' + this.rudderstack_anonymous_cookie_key + '\\\\s*=\\\\s*([^;]+)')?.pop()\n }\n\n /**\n * Set anonymous ID cookie if it doesn't exist\n * Creates a secure cookie with proper domain and security attributes\n */\n setCookieIfNotExists = (): void => {\n const anonymous_id = this.getAnonymousId()\n\n if (!anonymous_id) {\n try {\n const hostname = window.location.hostname\n const external_domains = ['webflow.io']\n const is_external_domain = external_domains.some(domain => hostname.endsWith(domain))\n const domain_name = is_external_domain ? hostname : hostname.split('.').slice(-2).join('.')\n\n // Check if crypto.randomUUID is available\n const uuid = crypto?.randomUUID ? crypto.randomUUID() : `${Date.now()}-${Math.random()}`\n\n const isSecure = window.location.protocol === 'https:'\n const secureFlag = isSecure ? '; Secure' : ''\n\n document.cookie = `${this.rudderstack_anonymous_cookie_key}=${uuid}; path=/; Domain=${domain_name}; max-age=${COOKIE_MAX_AGE_SECONDS}; SameSite=Lax${secureFlag}`\n } catch (error) {\n console.warn('RudderStack: Failed to set anonymous ID cookie', error)\n }\n }\n }\n\n /**\n * Get the current user ID\n * @returns The user ID, null, or undefined if not identified\n */\n getUserId = () => this.analytics.getUserId()\n\n /**\n * Initialize RudderStack with the provided key\n * @param RUDDERSTACK_KEY - RudderStack write key\n */\n init = (RUDDERSTACK_KEY: string): void => {\n if (!RUDDERSTACK_KEY) {\n console.warn('RudderStack: Initialization skipped - no key provided')\n return\n }\n\n try {\n this.setCookieIfNotExists()\n\n this.analytics.load(RUDDERSTACK_KEY, rudderstackDataplane, {\n externalAnonymousIdCookieName: this.rudderstack_anonymous_cookie_key,\n // Performance optimizations\n useBeacon: true,\n lockIntegrationsVersion: true,\n onLoaded: () => {\n this.has_initialized = true\n this.has_identified = !!this.getUserId()\n this.onLoadedCallback?.()\n },\n })\n } catch (error) {\n console.error('RudderStack: Failed to initialize', error)\n }\n }\n\n /**\n * Identify a user with RudderStack\n * Only identifies if user hasn't been identified yet\n * @param user_id - The user ID to identify\n * @param payload - Optional user traits (e.g., language, custom properties)\n */\n identifyEvent = (user_id: string, payload?: Record<string, any>): void => {\n if (!this.has_initialized) {\n console.warn('RudderStack: Cannot identify - not initialized')\n return\n }\n\n const currentUserId = this.getUserId()\n if (!currentUserId) {\n try {\n this.analytics.identify(user_id, payload || {})\n this.has_identified = true\n } catch (error) {\n console.error('RudderStack: Failed to identify user', error)\n }\n } else {\n this.has_identified = true\n }\n }\n\n /**\n * Track a page view event\n * @param current_page - The page name/path\n * @param platform - The platform name (default: 'Deriv App')\n * @param user_id - The user ID\n * @param properties - Additional page properties\n */\n pageView = (\n current_page: string,\n platform = 'Deriv App',\n user_id: string,\n properties?: Record<string, unknown>\n ): void => {\n if (!this.has_initialized || current_page === this.current_page) return\n\n try {\n const pageProperties = {\n ...(user_id && { user_id }),\n ...properties,\n }\n\n // Type assertion needed due to RudderStack's type definitions\n this.analytics.page(platform, current_page, pageProperties as any)\n this.current_page = current_page\n } catch (error) {\n console.error('RudderStack: Failed to track page view', error)\n }\n }\n\n /**\n * Reset the RudderStack instance\n * Clears user identification and resets tracking state\n */\n reset = (): void => {\n if (!this.has_initialized) return\n\n try {\n this.analytics.reset()\n this.has_identified = false\n } catch (error) {\n console.error('RudderStack: Failed to reset', error)\n }\n }\n\n /**\n * Track a custom event with payload\n * Payload is pre-cleaned by analytics.ts using cleanObject before being passed here\n * @param event - The event name\n * @param payload - The event payload with core attributes\n */\n track = <T extends keyof TAllEvents>(event: T, payload: TAllEvents[T] & Partial<TCoreAttributes>): void => {\n if (!this.has_initialized) return\n\n try {\n // Type assertion needed to match RudderStack's ApiObject type\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n this.analytics.track(event as string, payload as any)\n } catch (err) {\n console.warn('RudderStack: Failed to track event', err)\n }\n }\n}\n"]}