@deriv-com/analytics 1.36.0 → 1.37.0
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/README.md +853 -72
- package/dist/browser/analytics.bundle.global.js +23 -0
- package/dist/browser/analytics.bundle.global.js.map +1 -0
- package/dist/browser/analytics.esm.mjs +9 -0
- package/dist/browser/analytics.esm.mjs.map +1 -0
- package/dist/chunk-2P7RWD3W.mjs +3 -0
- package/dist/chunk-2P7RWD3W.mjs.map +1 -0
- package/dist/chunk-3LFZFQL4.mjs +3 -0
- package/dist/chunk-3LFZFQL4.mjs.map +1 -0
- package/dist/chunk-DNCZM4KN.mjs +4 -0
- package/dist/chunk-DNCZM4KN.mjs.map +1 -0
- package/dist/chunk-EMF3RT6E.mjs +14 -0
- package/dist/chunk-EMF3RT6E.mjs.map +1 -0
- package/dist/chunk-HQX3Z7PF.mjs +3 -0
- package/dist/chunk-HQX3Z7PF.mjs.map +1 -0
- package/dist/chunk-LKLVBL24.js +3 -0
- package/dist/chunk-LKLVBL24.js.map +1 -0
- package/dist/chunk-NOEKD4DT.js +4 -0
- package/dist/chunk-NOEKD4DT.js.map +1 -0
- package/dist/chunk-TLPR24DO.js +3 -0
- package/dist/chunk-TLPR24DO.js.map +1 -0
- package/dist/growthbook-NJGOOJH4.mjs +3 -0
- package/dist/growthbook-NJGOOJH4.mjs.map +1 -0
- package/dist/index.d.mts +114 -0
- package/dist/index.d.ts +114 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +4 -0
- package/dist/index.mjs.map +1 -0
- package/dist/metafile-cjs.json +1 -0
- package/dist/metafile-esm.json +1 -0
- package/dist/metafile-iife.json +1 -0
- package/dist/posthog-CY-D6TZM.d.mts +90 -0
- package/dist/posthog-D--oI2Yn.d.ts +90 -0
- package/dist/posthog-OIC32FZG.mjs +6 -0
- package/dist/posthog-OIC32FZG.mjs.map +1 -0
- package/dist/providers/growthbook/index.d.mts +73 -0
- package/dist/providers/growthbook/index.d.ts +73 -0
- package/dist/providers/growthbook/index.js +3 -0
- package/dist/providers/growthbook/index.js.map +1 -0
- package/dist/providers/growthbook/index.mjs +3 -0
- package/dist/providers/growthbook/index.mjs.map +1 -0
- package/dist/providers/posthog/index.d.mts +3 -0
- package/dist/providers/posthog/index.d.ts +3 -0
- package/dist/providers/posthog/index.js +3 -0
- package/dist/providers/posthog/index.js.map +1 -0
- package/dist/providers/posthog/index.mjs +3 -0
- package/dist/providers/posthog/index.mjs.map +1 -0
- package/dist/providers/rudderstack/index.d.mts +73 -0
- package/dist/providers/rudderstack/index.d.ts +73 -0
- package/dist/providers/rudderstack/index.js +2 -0
- package/dist/providers/rudderstack/index.js.map +1 -0
- package/dist/providers/rudderstack/index.mjs +2 -0
- package/dist/providers/rudderstack/index.mjs.map +1 -0
- package/{lib/types.d.ts → dist/types-DoMejCXv.d.mts} +18 -29
- package/dist/types-DoMejCXv.d.ts +361 -0
- package/dist/utils/analytics-cache/index.d.mts +138 -0
- package/dist/utils/analytics-cache/index.d.ts +138 -0
- package/dist/utils/analytics-cache/index.js +2 -0
- package/dist/utils/analytics-cache/index.js.map +1 -0
- package/dist/utils/analytics-cache/index.mjs +2 -0
- package/dist/utils/analytics-cache/index.mjs.map +1 -0
- package/package.json +97 -68
- package/dist/analytics.bundle.js +0 -1
- package/lib/analytics.d.ts +0 -66
- package/lib/analytics.js +0 -418
- package/lib/growthbook.d.ts +0 -29
- package/lib/growthbook.js +0 -144
- package/lib/index.d.ts +0 -2
- package/lib/index.js +0 -5
- package/lib/posthog.d.ts +0 -28
- package/lib/posthog.js +0 -154
- package/lib/rudderstack.d.ts +0 -23
- package/lib/rudderstack.js +0 -100
- package/lib/types.js +0 -2
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import * as _growthbook_growthbook from '@growthbook/growthbook';
|
|
2
|
+
import { Context, GrowthBook, InitResponse } from '@growthbook/growthbook';
|
|
3
|
+
import { RudderAnalytics } from '@rudderstack/analytics-js';
|
|
4
|
+
|
|
5
|
+
type TGrowthbookAttributes = {
|
|
6
|
+
id?: string;
|
|
7
|
+
country?: string;
|
|
8
|
+
user_language?: string;
|
|
9
|
+
device_language?: string;
|
|
10
|
+
device_type?: string;
|
|
11
|
+
utm_source?: string;
|
|
12
|
+
utm_medium?: 'ppc-native' | 'affiliate' | 'common' | string;
|
|
13
|
+
utm_campaign?: string;
|
|
14
|
+
is_authorised?: boolean;
|
|
15
|
+
url?: string;
|
|
16
|
+
domain?: string;
|
|
17
|
+
utm_content?: string;
|
|
18
|
+
residence_country?: string;
|
|
19
|
+
loggedIn?: boolean;
|
|
20
|
+
network_type?: string;
|
|
21
|
+
network_downlink?: number;
|
|
22
|
+
user_id?: string;
|
|
23
|
+
anonymous_id?: string;
|
|
24
|
+
account_mode?: string;
|
|
25
|
+
};
|
|
26
|
+
type TGrowthbookOptions = Partial<Omit<Context, 'attributes'> & {
|
|
27
|
+
attributes: TGrowthbookCoreAttributes;
|
|
28
|
+
}>;
|
|
29
|
+
type TGrowthbookCoreAttributes = {
|
|
30
|
+
account_type?: string;
|
|
31
|
+
user_id?: string;
|
|
32
|
+
anonymous_id?: string;
|
|
33
|
+
app_id?: string;
|
|
34
|
+
user_identity?: string;
|
|
35
|
+
residence_country?: string;
|
|
36
|
+
geo_location?: string;
|
|
37
|
+
email_hash?: string;
|
|
38
|
+
network_type?: string;
|
|
39
|
+
network_rtt?: number;
|
|
40
|
+
network_downlink?: number;
|
|
41
|
+
account_currency?: string;
|
|
42
|
+
} & Partial<TGrowthbookAttributes>;
|
|
43
|
+
type GrowthbookConfigs = {
|
|
44
|
+
'tracking-buttons-config': Record<string, boolean>;
|
|
45
|
+
} & {
|
|
46
|
+
[key: string]: Record<string, boolean> | string | boolean | [];
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
declare class Growthbook {
|
|
50
|
+
analytics: RudderAnalytics;
|
|
51
|
+
GrowthBook: GrowthBook<GrowthbookConfigs>;
|
|
52
|
+
private static _instance;
|
|
53
|
+
isLoaded: boolean;
|
|
54
|
+
status: void | InitResponse;
|
|
55
|
+
constructor(clientKey: string, decryptionKey: string, growthbookOptions?: TGrowthbookOptions);
|
|
56
|
+
static getGrowthBookInstance: (clientKey: string, decryptionKey?: string, growthbookOptions?: TGrowthbookOptions) => Growthbook;
|
|
57
|
+
reapplyExperiment(url?: string): void;
|
|
58
|
+
private waitForIsLoaded;
|
|
59
|
+
setAttributes: ({ id, country, user_language, device_language, device_type, utm_source, utm_medium, utm_campaign, is_authorised, url, domain, utm_content, residence_country, loggedIn, network_type, network_downlink, user_id, anonymous_id, account_mode, }: TGrowthbookAttributes) => void;
|
|
60
|
+
getFeatureValue: <K extends keyof GrowthbookConfigs, V extends GrowthbookConfigs[K]>(key: K, defaultValue: V) => _growthbook_growthbook.WidenPrimitives<V>;
|
|
61
|
+
getStatus: () => Promise<{
|
|
62
|
+
isLoaded: boolean;
|
|
63
|
+
status: void | InitResponse;
|
|
64
|
+
}>;
|
|
65
|
+
getFeatureState: (id: string) => _growthbook_growthbook.FeatureResult<string | boolean | [] | Record<string, boolean> | null>;
|
|
66
|
+
setUrl: (href: string) => Promise<void>;
|
|
67
|
+
isOn: (key: string) => boolean;
|
|
68
|
+
init: () => Promise<void>;
|
|
69
|
+
destroy: () => void;
|
|
70
|
+
static resetInstance: () => void;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export { Growthbook, type GrowthbookConfigs, type TGrowthbookAttributes, type TGrowthbookCoreAttributes, type TGrowthbookOptions };
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import * as _growthbook_growthbook from '@growthbook/growthbook';
|
|
2
|
+
import { Context, GrowthBook, InitResponse } from '@growthbook/growthbook';
|
|
3
|
+
import { RudderAnalytics } from '@rudderstack/analytics-js';
|
|
4
|
+
|
|
5
|
+
type TGrowthbookAttributes = {
|
|
6
|
+
id?: string;
|
|
7
|
+
country?: string;
|
|
8
|
+
user_language?: string;
|
|
9
|
+
device_language?: string;
|
|
10
|
+
device_type?: string;
|
|
11
|
+
utm_source?: string;
|
|
12
|
+
utm_medium?: 'ppc-native' | 'affiliate' | 'common' | string;
|
|
13
|
+
utm_campaign?: string;
|
|
14
|
+
is_authorised?: boolean;
|
|
15
|
+
url?: string;
|
|
16
|
+
domain?: string;
|
|
17
|
+
utm_content?: string;
|
|
18
|
+
residence_country?: string;
|
|
19
|
+
loggedIn?: boolean;
|
|
20
|
+
network_type?: string;
|
|
21
|
+
network_downlink?: number;
|
|
22
|
+
user_id?: string;
|
|
23
|
+
anonymous_id?: string;
|
|
24
|
+
account_mode?: string;
|
|
25
|
+
};
|
|
26
|
+
type TGrowthbookOptions = Partial<Omit<Context, 'attributes'> & {
|
|
27
|
+
attributes: TGrowthbookCoreAttributes;
|
|
28
|
+
}>;
|
|
29
|
+
type TGrowthbookCoreAttributes = {
|
|
30
|
+
account_type?: string;
|
|
31
|
+
user_id?: string;
|
|
32
|
+
anonymous_id?: string;
|
|
33
|
+
app_id?: string;
|
|
34
|
+
user_identity?: string;
|
|
35
|
+
residence_country?: string;
|
|
36
|
+
geo_location?: string;
|
|
37
|
+
email_hash?: string;
|
|
38
|
+
network_type?: string;
|
|
39
|
+
network_rtt?: number;
|
|
40
|
+
network_downlink?: number;
|
|
41
|
+
account_currency?: string;
|
|
42
|
+
} & Partial<TGrowthbookAttributes>;
|
|
43
|
+
type GrowthbookConfigs = {
|
|
44
|
+
'tracking-buttons-config': Record<string, boolean>;
|
|
45
|
+
} & {
|
|
46
|
+
[key: string]: Record<string, boolean> | string | boolean | [];
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
declare class Growthbook {
|
|
50
|
+
analytics: RudderAnalytics;
|
|
51
|
+
GrowthBook: GrowthBook<GrowthbookConfigs>;
|
|
52
|
+
private static _instance;
|
|
53
|
+
isLoaded: boolean;
|
|
54
|
+
status: void | InitResponse;
|
|
55
|
+
constructor(clientKey: string, decryptionKey: string, growthbookOptions?: TGrowthbookOptions);
|
|
56
|
+
static getGrowthBookInstance: (clientKey: string, decryptionKey?: string, growthbookOptions?: TGrowthbookOptions) => Growthbook;
|
|
57
|
+
reapplyExperiment(url?: string): void;
|
|
58
|
+
private waitForIsLoaded;
|
|
59
|
+
setAttributes: ({ id, country, user_language, device_language, device_type, utm_source, utm_medium, utm_campaign, is_authorised, url, domain, utm_content, residence_country, loggedIn, network_type, network_downlink, user_id, anonymous_id, account_mode, }: TGrowthbookAttributes) => void;
|
|
60
|
+
getFeatureValue: <K extends keyof GrowthbookConfigs, V extends GrowthbookConfigs[K]>(key: K, defaultValue: V) => _growthbook_growthbook.WidenPrimitives<V>;
|
|
61
|
+
getStatus: () => Promise<{
|
|
62
|
+
isLoaded: boolean;
|
|
63
|
+
status: void | InitResponse;
|
|
64
|
+
}>;
|
|
65
|
+
getFeatureState: (id: string) => _growthbook_growthbook.FeatureResult<string | boolean | [] | Record<string, boolean> | null>;
|
|
66
|
+
setUrl: (href: string) => Promise<void>;
|
|
67
|
+
isOn: (key: string) => boolean;
|
|
68
|
+
init: () => Promise<void>;
|
|
69
|
+
destroy: () => void;
|
|
70
|
+
static resetInstance: () => void;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export { Growthbook, type GrowthbookConfigs, type TGrowthbookAttributes, type TGrowthbookCoreAttributes, type TGrowthbookOptions };
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
'use strict';var chunkNOEKD4DT_js=require('../../chunk-NOEKD4DT.js'),growthbook=require('@growthbook/growthbook'),analyticsJs=require('@rudderstack/analytics-js');/* @deriv-com/analytics - NPM Package - Built with tsup */
|
|
2
|
+
var o=class o{constructor(t,e,i={}){this.analytics=new analyticsJs.RudderAnalytics;this.isLoaded=false;this.status=void 0;this.setAttributes=({id:t,country:e,user_language:i,device_language:s,device_type:n,utm_source:r,utm_medium:a,utm_campaign:d,is_authorised:w,url:h,domain:u,utm_content:f,residence_country:c,loggedIn:k,network_type:l,network_downlink:b,user_id:p,anonymous_id:G,account_mode:g})=>{let B=this.GrowthBook.getAttributes();this.GrowthBook.setAttributes({...B,id:t,...p!==void 0&&{user_id:p},...G!==void 0&&{anonymous_id:G},...e!==void 0&&{country:e},...c!==void 0&&{residence_country:c},...i!==void 0&&{user_language:i},...s!==void 0&&{device_language:s},...n!==void 0&&{device_type:n},...r!==void 0&&{utm_source:r},...a!==void 0&&{utm_medium:a},...d!==void 0&&{utm_campaign:d},...w!==void 0&&{is_authorised:w},...h!==void 0&&{url:h},...u!==void 0&&{domain:u},...f!==void 0&&{utm_content:f},...k!==void 0&&{loggedIn:k},...l!==void 0&&{network_type:l},...b!==void 0&&{network_downlink:b},...g!==void 0&&{account_mode:g}});};this.getFeatureValue=(t,e)=>this.GrowthBook.getFeatureValue(t,e);this.getStatus=async()=>(await this.waitForIsLoaded(),{isLoaded:this.isLoaded,status:this.status});this.getFeatureState=t=>this.GrowthBook.evalFeature(t);this.setUrl=t=>this.GrowthBook.setURL(t);this.isOn=t=>this.GrowthBook.isOn(t);this.init=async()=>{let t=await this.GrowthBook.init({timeout:2e3,streaming:true}).catch(()=>{});this.status=t,this.isLoaded=true;};this.destroy=()=>{this.GrowthBook.destroy(),this.isLoaded=false,this.status=void 0;};let s=typeof window<"u"?window.location.hostname.includes("localhost"):false;this.GrowthBook=new growthbook.GrowthBook({apiHost:chunkNOEKD4DT_js.b,clientKey:t,decryptionKey:e,antiFlicker:false,navigateDelay:0,antiFlickerTimeout:3500,subscribeToChanges:true,enableDevMode:s,trackingCallback:(n,r)=>{typeof window<"u"&&window.dataLayer&&window.dataLayer.push({event:"experiment_viewed",event_category:"experiment",rudder_anonymous_id:this.analytics.getAnonymousId(),experiment_id:n.key,variation_id:r.variationId}),this.analytics.track("experiment_viewed",{experimentId:n.key,variationId:r.variationId});},...i}),this.init();}reapplyExperiment(t){let e=t??(typeof window<"u"?window.location.href:"");this.GrowthBook.setURL(e);}waitForIsLoaded(t=1e4){return new Promise((e,i)=>{let s=Date.now(),n=setInterval(()=>{this.isLoaded?(clearInterval(n),e()):Date.now()-s>=t&&(clearInterval(n),i(new Error("GrowthBook initialization timeout")));},100);})}};o.getGrowthBookInstance=(t,e,i)=>o._instance?(typeof window<"u"&&console.warn&&console.warn("GrowthBook instance already exists. Ignoring new initialization parameters."),o._instance):(o._instance=new o(t,e??"",i),o._instance),o.resetInstance=()=>{o._instance&&(o._instance.destroy(),o._instance=void 0);};var v=o;exports.Growthbook=v;//# sourceMappingURL=index.js.map
|
|
3
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/providers/growthbook.ts"],"names":["_Growthbook","clientKey","decryptionKey","growthbookOptions","RudderAnalytics","id","country","user_language","device_language","device_type","utm_source","utm_medium","utm_campaign","is_authorised","url","domain","utm_content","residence_country","loggedIn","network_type","network_downlink","user_id","anonymous_id","account_mode","currentAttributes","key","defaultValue","href","status","isLocalhost","GrowthBook","growthbookApi","experiment","result","currentUrl","timeout","resolve","reject","startTime","checkInterval","Growthbook"],"mappings":";AAUO,IAAMA,CAAAA,CAAN,MAAMA,CAAW,CAQpB,WAAA,CAAYC,CAAAA,CAAmBC,CAAAA,CAAuBC,CAAAA,CAAwC,EAAC,CAAG,CAPlG,IAAA,CAAA,SAAA,CAAY,IAAIC,2BAAAA,CAGhB,IAAA,CAAA,QAAA,CAAW,KAAA,CACX,IAAA,CAAA,MAAA,CAA8B,MAAA,CA2E9B,IAAA,CAAA,aAAA,CAAgB,CAAC,CACb,GAAAC,CAAAA,CACA,OAAA,CAAAC,CAAAA,CACA,aAAA,CAAAC,CAAAA,CACA,eAAA,CAAAC,CAAAA,CACA,WAAA,CAAAC,CAAAA,CACA,UAAA,CAAAC,CAAAA,CACA,UAAA,CAAAC,CAAAA,CACA,YAAA,CAAAC,CAAAA,CACA,aAAA,CAAAC,CAAAA,CACA,GAAA,CAAAC,CAAAA,CACA,MAAA,CAAAC,CAAAA,CACA,WAAA,CAAAC,CAAAA,CACA,iBAAA,CAAAC,CA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CAAO,EAAA,CAAA,CAClF,IAAA,CAAK,UAAA,CAAW,MAAA,CAAOoB,CAAU,EACrC,CAGQ,eAAA,CAAgBC,CAAAA,CAAU,GAAA,CAAsB,CACpD,OAAO,IAAI,OAAA,CAAQ,CAACC,CAAAA,CAASC,CAAAA,GAAW,CACpC,IAAMC,CAAAA,CAAY,IAAA,CAAK,GAAA,EAAI,CACrBC,CAAAA,CAAgB,WAAA,CAAY,IAAM,CAChC,IAAA,CAAK,QAAA,EACL,aAAA,CAAcA,CAAa,CAAA,CAC3BH,CAAAA,EAAQ,EACD,IAAA,CAAK,GAAA,EAAI,CAAIE,CAAAA,EAAaH,CAAAA,GACjC,cAAcI,CAAa,CAAA,CAC3BF,CAAAA,CAAO,IAAI,KAAA,CAAM,mCAAmC,CAAC,CAAA,EAE7D,CAAA,CAAG,GAAG,EACV,CAAC,CACL,CAqFJ,CAAA,CAnKarC,CAAAA,CAyCK,qBAAA,CAAwB,CAClCC,CAAAA,CACAC,CAAAA,CACAC,CAAAA,GAEKH,CAAAA,CAAW,SAAA,EAMZ,OAAO,MAAA,CAAW,GAAA,EAAe,OAAA,CAAQ,IAAA,EACzC,OAAA,CAAQ,IAAA,CAAK,6EAA6E,CAAA,CAGvFA,CAAAA,CAAW,SAAA,GATdA,CAAAA,CAAW,SAAA,CAAY,IAAIA,CAAAA,CAAWC,CAAAA,CAAWC,CAAAA,EAAiB,EAAA,CAAIC,CAAiB,CAAA,CAChFH,CAAAA,CAAW,SAAA,CAAA,CAhDjBA,CAAAA,CA6JK,aAAA,CAAgB,IAAM,CAC5BA,CAAAA,CAAW,SAAA,GACXA,CAAAA,CAAW,SAAA,CAAU,OAAA,EAAQ,CAC7BA,CAAAA,CAAW,SAAA,CAAY,MAAA,EAE/B,CAAA,CAlKG,IAAMwC,CAAAA,CAANxC","file":"index.js","sourcesContent":["import { GrowthBook, InitResponse } from '@growthbook/growthbook'\nimport { RudderAnalytics } from '@rudderstack/analytics-js'\nimport {\n TGrowthbookAttributes,\n TGrowthbookOptions,\n GrowthbookConfigs,\n TGrowthbookCoreAttributes,\n} from './growthbookTypes'\nimport { growthbookApi } from '../utils/urls'\n\nexport class Growthbook {\n analytics = new RudderAnalytics()\n GrowthBook: GrowthBook<GrowthbookConfigs>\n private static _instance: Growthbook\n isLoaded = false\n status: void | InitResponse = undefined\n\n // we have to pass settings due the specific framework implementation\n constructor(clientKey: string, decryptionKey: string, growthbookOptions: TGrowthbookOptions = {}) {\n const isLocalhost = typeof window !== 'undefined' ? window.location.hostname.includes('localhost') : false\n\n this.GrowthBook = new GrowthBook<GrowthbookConfigs>({\n apiHost: growthbookApi,\n clientKey,\n decryptionKey,\n antiFlicker: false,\n navigateDelay: 0,\n antiFlickerTimeout: 3500,\n subscribeToChanges: true,\n enableDevMode: isLocalhost,\n trackingCallback: (experiment, result) => {\n if (typeof window !== 'undefined' && window.dataLayer) {\n window.dataLayer.push({\n event: 'experiment_viewed',\n event_category: 'experiment',\n rudder_anonymous_id: this.analytics.getAnonymousId(),\n experiment_id: experiment.key,\n variation_id: result.variationId,\n })\n }\n this.analytics.track('experiment_viewed', {\n experimentId: experiment.key,\n variationId: result.variationId,\n })\n },\n ...growthbookOptions,\n })\n this.init()\n }\n\n // for make instance by singleton\n public static getGrowthBookInstance = (\n clientKey: string,\n decryptionKey?: string,\n growthbookOptions?: TGrowthbookOptions\n ) => {\n if (!Growthbook._instance) {\n Growthbook._instance = new Growthbook(clientKey, decryptionKey ?? '', growthbookOptions)\n return Growthbook._instance\n }\n\n // Warn if trying to reinitialize with different parameters\n if (typeof window !== 'undefined' && console.warn) {\n console.warn('GrowthBook instance already exists. Ignoring new initialization parameters.')\n }\n\n return Growthbook._instance\n }\n\n reapplyExperiment(url?: string) {\n const currentUrl = url ?? (typeof window !== 'undefined' ? window.location.href : '')\n this.GrowthBook.setURL(currentUrl)\n }\n\n // Utility function to wait for isLoaded to become true\n private waitForIsLoaded(timeout = 10000): Promise<void> {\n return new Promise((resolve, reject) => {\n const startTime = Date.now()\n const checkInterval = setInterval(() => {\n if (this.isLoaded) {\n clearInterval(checkInterval)\n resolve()\n } else if (Date.now() - startTime >= timeout) {\n clearInterval(checkInterval)\n reject(new Error('GrowthBook initialization timeout'))\n }\n }, 100)\n })\n }\n\n setAttributes = ({\n id,\n country,\n user_language,\n device_language,\n device_type,\n utm_source,\n utm_medium,\n utm_campaign,\n is_authorised,\n url,\n domain,\n utm_content,\n residence_country,\n loggedIn,\n network_type,\n network_downlink,\n user_id,\n anonymous_id,\n account_mode,\n }: TGrowthbookAttributes) => {\n const currentAttributes = this.GrowthBook.getAttributes()\n this.GrowthBook.setAttributes({\n ...currentAttributes,\n id,\n ...(user_id !== undefined && { user_id }),\n ...(anonymous_id !== undefined && { anonymous_id }),\n ...(country !== undefined && { country }),\n ...(residence_country !== undefined && { residence_country }),\n ...(user_language !== undefined && { user_language }),\n ...(device_language !== undefined && { device_language }),\n ...(device_type !== undefined && { device_type }),\n ...(utm_source !== undefined && { utm_source }),\n ...(utm_medium !== undefined && { utm_medium }),\n ...(utm_campaign !== undefined && { utm_campaign }),\n ...(is_authorised !== undefined && { is_authorised }),\n ...(url !== undefined && { url }),\n ...(domain !== undefined && { domain }),\n ...(utm_content !== undefined && { utm_content }),\n ...(loggedIn !== undefined && { loggedIn }),\n ...(network_type !== undefined && { network_type }),\n ...(network_downlink !== undefined && { network_downlink }),\n ...(account_mode !== undefined && { account_mode }),\n })\n }\n getFeatureValue = <K extends keyof GrowthbookConfigs, V extends GrowthbookConfigs[K]>(key: K, defaultValue: V) => {\n return this.GrowthBook.getFeatureValue(key as string, defaultValue)\n }\n getStatus = async (): Promise<{ isLoaded: boolean; status: void | InitResponse }> => {\n await this.waitForIsLoaded()\n\n return {\n isLoaded: this.isLoaded,\n status: this.status,\n }\n }\n getFeatureState = (id: string) => this.GrowthBook.evalFeature(id)\n setUrl = (href: string) => this.GrowthBook.setURL(href)\n isOn = (key: string) => this.GrowthBook.isOn(key)\n\n init = async () => {\n const status = await this.GrowthBook.init({ timeout: 2000, streaming: true }).catch(() => {\n // Silently handle initialization errors\n })\n\n this.status = status\n this.isLoaded = true\n }\n\n // Destroy the GrowthBook instance and reset singleton\n destroy = () => {\n this.GrowthBook.destroy()\n this.isLoaded = false\n this.status = undefined\n }\n\n // Reset the singleton instance (useful for testing)\n public static resetInstance = () => {\n if (Growthbook._instance) {\n Growthbook._instance.destroy()\n Growthbook._instance = undefined as any\n }\n }\n}\n\nexport type { GrowthbookConfigs, TGrowthbookAttributes, TGrowthbookOptions, TGrowthbookCoreAttributes }\n"]}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import {b}from'../../chunk-DNCZM4KN.mjs';import {GrowthBook}from'@growthbook/growthbook';import {RudderAnalytics}from'@rudderstack/analytics-js';/* @deriv-com/analytics - NPM Package - Built with tsup */
|
|
2
|
+
var o=class o{constructor(t,e,i={}){this.analytics=new RudderAnalytics;this.isLoaded=false;this.status=void 0;this.setAttributes=({id:t,country:e,user_language:i,device_language:s,device_type:n,utm_source:r,utm_medium:a,utm_campaign:d,is_authorised:w,url:h,domain:u,utm_content:f,residence_country:c,loggedIn:k,network_type:l,network_downlink:b,user_id:p,anonymous_id:G,account_mode:g})=>{let B=this.GrowthBook.getAttributes();this.GrowthBook.setAttributes({...B,id:t,...p!==void 0&&{user_id:p},...G!==void 0&&{anonymous_id:G},...e!==void 0&&{country:e},...c!==void 0&&{residence_country:c},...i!==void 0&&{user_language:i},...s!==void 0&&{device_language:s},...n!==void 0&&{device_type:n},...r!==void 0&&{utm_source:r},...a!==void 0&&{utm_medium:a},...d!==void 0&&{utm_campaign:d},...w!==void 0&&{is_authorised:w},...h!==void 0&&{url:h},...u!==void 0&&{domain:u},...f!==void 0&&{utm_content:f},...k!==void 0&&{loggedIn:k},...l!==void 0&&{network_type:l},...b!==void 0&&{network_downlink:b},...g!==void 0&&{account_mode:g}});};this.getFeatureValue=(t,e)=>this.GrowthBook.getFeatureValue(t,e);this.getStatus=async()=>(await this.waitForIsLoaded(),{isLoaded:this.isLoaded,status:this.status});this.getFeatureState=t=>this.GrowthBook.evalFeature(t);this.setUrl=t=>this.GrowthBook.setURL(t);this.isOn=t=>this.GrowthBook.isOn(t);this.init=async()=>{let t=await this.GrowthBook.init({timeout:2e3,streaming:true}).catch(()=>{});this.status=t,this.isLoaded=true;};this.destroy=()=>{this.GrowthBook.destroy(),this.isLoaded=false,this.status=void 0;};let s=typeof window<"u"?window.location.hostname.includes("localhost"):false;this.GrowthBook=new GrowthBook({apiHost:b,clientKey:t,decryptionKey:e,antiFlicker:false,navigateDelay:0,antiFlickerTimeout:3500,subscribeToChanges:true,enableDevMode:s,trackingCallback:(n,r)=>{typeof window<"u"&&window.dataLayer&&window.dataLayer.push({event:"experiment_viewed",event_category:"experiment",rudder_anonymous_id:this.analytics.getAnonymousId(),experiment_id:n.key,variation_id:r.variationId}),this.analytics.track("experiment_viewed",{experimentId:n.key,variationId:r.variationId});},...i}),this.init();}reapplyExperiment(t){let e=t??(typeof window<"u"?window.location.href:"");this.GrowthBook.setURL(e);}waitForIsLoaded(t=1e4){return new Promise((e,i)=>{let s=Date.now(),n=setInterval(()=>{this.isLoaded?(clearInterval(n),e()):Date.now()-s>=t&&(clearInterval(n),i(new Error("GrowthBook initialization timeout")));},100);})}};o.getGrowthBookInstance=(t,e,i)=>o._instance?(typeof window<"u"&&console.warn&&console.warn("GrowthBook instance already exists. Ignoring new initialization parameters."),o._instance):(o._instance=new o(t,e??"",i),o._instance),o.resetInstance=()=>{o._instance&&(o._instance.destroy(),o._instance=void 0);};var v=o;export{v as Growthbook};//# sourceMappingURL=index.mjs.map
|
|
3
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/providers/growthbook.ts"],"names":["_Growthbook","clientKey","decryptionKey","growthbookOptions","RudderAnalytics","id","country","user_language","device_language","device_type","utm_source","utm_medium","utm_campaign","is_authorised","url","domain","utm_content","residence_country","loggedIn","network_type","network_downlink","user_id","anonymous_id","account_mode","currentAttributes","key","defaultValue","href","status","isLocalhost","GrowthBook","growthbookApi","experiment","result","currentUrl","timeout","resolve","reject","startTime","checkInterval","Growthbook"],"mappings":";AAUO,IAAMA,CAAAA,CAAN,MAAMA,CAAW,CAQpB,WAAA,CAAYC,CAAAA,CAAmBC,CAAAA,CAAuBC,CAAAA,CAAwC,EAAC,CAAG,CAPlG,IAAA,CAAA,SAAA,CAAY,IAAIC,eAAAA,CAGhB,IAAA,CAAA,QAAA,CAAW,KAAA,CACX,IAAA,CAAA,MAAA,CAA8B,MAAA,CA2E9B,IAAA,CAAA,aAAA,CAAgB,CAAC,CACb,GAAAC,CAAAA,CACA,OAAA,CAAAC,CAAAA,CACA,aAAA,CAAAC,CAAAA,CACA,eAAA,CAAAC,CAAAA,CACA,WAAA,CAAAC,CAAAA,CACA,UAAA,CAAAC,CAAAA,CACA,UAAA,CAAAC,CAAAA,CACA,YAAA,CAAAC,CAAAA,CACA,aAAA,CAAAC,CAAAA,CACA,GAAA,CAAAC,CAAAA,CACA,MAAA,CAAAC,CAAAA,CACA,WAAA,CAAAC,CAAAA,CACA,iBAAA,CAAAC,CAAAA,CACA,QAAA,CAAAC,CAAAA,CACA,YAAA,CAAAC,CAAAA,CACA,gBAAA,CAAAC,EACA,OAAA,CAAAC,CAAAA,CACA,YAAA,CAAAC,CAAAA,CACA,YAAA,CAAAC,CACJ,CAAA,GAA6B,CACzB,IAAMC,CAAAA,CAAoB,IAAA,CAAK,UAAA,CAAW,aAAA,EAAc,CACxD,IAAA,CAAK,UAAA,CAAW,aAAA,CAAc,CAC1B,GAAGA,CAAAA,CACH,EAAA,CAAAnB,CAAAA,CACA,GAAIgB,CAAAA,GAAY,MAAA,EAAa,CAAE,OAAA,CAAAA,CAAQ,CAAA,CACvC,GAAIC,CAAAA,GAAiB,MAAA,EAAa,CAAE,YAAA,CAAAA,CAAa,CAAA,CACjD,GAAIhB,CAAAA,GAAY,MAAA,EAAa,CAAE,O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A,CAAG,GAAG,EACV,CAAC,CACL,CAqFJ,CAAA,CAnKarC,CAAAA,CAyCK,qBAAA,CAAwB,CAClCC,CAAAA,CACAC,CAAAA,CACAC,CAAAA,GAEKH,CAAAA,CAAW,SAAA,EAMZ,OAAO,MAAA,CAAW,GAAA,EAAe,OAAA,CAAQ,IAAA,EACzC,OAAA,CAAQ,IAAA,CAAK,6EAA6E,CAAA,CAGvFA,CAAAA,CAAW,SAAA,GATdA,CAAAA,CAAW,SAAA,CAAY,IAAIA,CAAAA,CAAWC,CAAAA,CAAWC,CAAAA,EAAiB,EAAA,CAAIC,CAAiB,CAAA,CAChFH,CAAAA,CAAW,SAAA,CAAA,CAhDjBA,CAAAA,CA6JK,aAAA,CAAgB,IAAM,CAC5BA,CAAAA,CAAW,SAAA,GACXA,CAAAA,CAAW,SAAA,CAAU,OAAA,EAAQ,CAC7BA,CAAAA,CAAW,SAAA,CAAY,MAAA,EAE/B,CAAA,CAlKG,IAAMwC,CAAAA,CAANxC","file":"index.mjs","sourcesContent":["import { GrowthBook, InitResponse } from '@growthbook/growthbook'\nimport { RudderAnalytics } from '@rudderstack/analytics-js'\nimport {\n TGrowthbookAttributes,\n TGrowthbookOptions,\n GrowthbookConfigs,\n TGrowthbookCoreAttributes,\n} from './growthbookTypes'\nimport { growthbookApi } from '../utils/urls'\n\nexport class Growthbook {\n analytics = new RudderAnalytics()\n GrowthBook: GrowthBook<GrowthbookConfigs>\n private static _instance: Growthbook\n isLoaded = false\n status: void | InitResponse = undefined\n\n // we have to pass settings due the specific framework implementation\n constructor(clientKey: string, decryptionKey: string, growthbookOptions: TGrowthbookOptions = {}) {\n const isLocalhost = typeof window !== 'undefined' ? window.location.hostname.includes('localhost') : false\n\n this.GrowthBook = new GrowthBook<GrowthbookConfigs>({\n apiHost: growthbookApi,\n clientKey,\n decryptionKey,\n antiFlicker: false,\n navigateDelay: 0,\n antiFlickerTimeout: 3500,\n subscribeToChanges: true,\n enableDevMode: isLocalhost,\n trackingCallback: (experiment, result) => {\n if (typeof window !== 'undefined' && window.dataLayer) {\n window.dataLayer.push({\n event: 'experiment_viewed',\n event_category: 'experiment',\n rudder_anonymous_id: this.analytics.getAnonymousId(),\n experiment_id: experiment.key,\n variation_id: result.variationId,\n })\n }\n this.analytics.track('experiment_viewed', {\n experimentId: experiment.key,\n variationId: result.variationId,\n })\n },\n ...growthbookOptions,\n })\n this.init()\n }\n\n // for make instance by singleton\n public static getGrowthBookInstance = (\n clientKey: string,\n decryptionKey?: string,\n growthbookOptions?: TGrowthbookOptions\n ) => {\n if (!Growthbook._instance) {\n Growthbook._instance = new Growthbook(clientKey, decryptionKey ?? '', growthbookOptions)\n return Growthbook._instance\n }\n\n // Warn if trying to reinitialize with different parameters\n if (typeof window !== 'undefined' && console.warn) {\n console.warn('GrowthBook instance already exists. Ignoring new initialization parameters.')\n }\n\n return Growthbook._instance\n }\n\n reapplyExperiment(url?: string) {\n const currentUrl = url ?? (typeof window !== 'undefined' ? window.location.href : '')\n this.GrowthBook.setURL(currentUrl)\n }\n\n // Utility function to wait for isLoaded to become true\n private waitForIsLoaded(timeout = 10000): Promise<void> {\n return new Promise((resolve, reject) => {\n const startTime = Date.now()\n const checkInterval = setInterval(() => {\n if (this.isLoaded) {\n clearInterval(checkInterval)\n resolve()\n } else if (Date.now() - startTime >= timeout) {\n clearInterval(checkInterval)\n reject(new Error('GrowthBook initialization timeout'))\n }\n }, 100)\n })\n }\n\n setAttributes = ({\n id,\n country,\n user_language,\n device_language,\n device_type,\n utm_source,\n utm_medium,\n utm_campaign,\n is_authorised,\n url,\n domain,\n utm_content,\n residence_country,\n loggedIn,\n network_type,\n network_downlink,\n user_id,\n anonymous_id,\n account_mode,\n }: TGrowthbookAttributes) => {\n const currentAttributes = this.GrowthBook.getAttributes()\n this.GrowthBook.setAttributes({\n ...currentAttributes,\n id,\n ...(user_id !== undefined && { user_id }),\n ...(anonymous_id !== undefined && { anonymous_id }),\n ...(country !== undefined && { country }),\n ...(residence_country !== undefined && { residence_country }),\n ...(user_language !== undefined && { user_language }),\n ...(device_language !== undefined && { device_language }),\n ...(device_type !== undefined && { device_type }),\n ...(utm_source !== undefined && { utm_source }),\n ...(utm_medium !== undefined && { utm_medium }),\n ...(utm_campaign !== undefined && { utm_campaign }),\n ...(is_authorised !== undefined && { is_authorised }),\n ...(url !== undefined && { url }),\n ...(domain !== undefined && { domain }),\n ...(utm_content !== undefined && { utm_content }),\n ...(loggedIn !== undefined && { loggedIn }),\n ...(network_type !== undefined && { network_type }),\n ...(network_downlink !== undefined && { network_downlink }),\n ...(account_mode !== undefined && { account_mode }),\n })\n }\n getFeatureValue = <K extends keyof GrowthbookConfigs, V extends GrowthbookConfigs[K]>(key: K, defaultValue: V) => {\n return this.GrowthBook.getFeatureValue(key as string, defaultValue)\n }\n getStatus = async (): Promise<{ isLoaded: boolean; status: void | InitResponse }> => {\n await this.waitForIsLoaded()\n\n return {\n isLoaded: this.isLoaded,\n status: this.status,\n }\n }\n getFeatureState = (id: string) => this.GrowthBook.evalFeature(id)\n setUrl = (href: string) => this.GrowthBook.setURL(href)\n isOn = (key: string) => this.GrowthBook.isOn(key)\n\n init = async () => {\n const status = await this.GrowthBook.init({ timeout: 2000, streaming: true }).catch(() => {\n // Silently handle initialization errors\n })\n\n this.status = status\n this.isLoaded = true\n }\n\n // Destroy the GrowthBook instance and reset singleton\n destroy = () => {\n this.GrowthBook.destroy()\n this.isLoaded = false\n this.status = undefined\n }\n\n // Reset the singleton instance (useful for testing)\n public static resetInstance = () => {\n if (Growthbook._instance) {\n Growthbook._instance.destroy()\n Growthbook._instance = undefined as any\n }\n }\n}\n\nexport type { GrowthbookConfigs, TGrowthbookAttributes, TGrowthbookOptions, TGrowthbookCoreAttributes }\n"]}
|
|
@@ -0,0 +1,3 @@
|
|
|
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
|
|
3
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +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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BAAA,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"]}
|
|
@@ -0,0 +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
|
|
3
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +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,CA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MoB,CAAAA,CAANpB","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, 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"]}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { RudderAnalytics } from '@rudderstack/analytics-js';
|
|
2
|
+
import { a as TAllEvents, T as TCoreAttributes } from '../../types-DoMejCXv.mjs';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* RudderStack analytics wrapper with singleton pattern.
|
|
6
|
+
* Handles user tracking, page views, and event analytics.
|
|
7
|
+
*/
|
|
8
|
+
declare class RudderStack {
|
|
9
|
+
analytics: RudderAnalytics;
|
|
10
|
+
has_identified: boolean;
|
|
11
|
+
has_initialized: boolean;
|
|
12
|
+
current_page: string;
|
|
13
|
+
rudderstack_anonymous_cookie_key: string;
|
|
14
|
+
private static _instance;
|
|
15
|
+
private onLoadedCallback?;
|
|
16
|
+
constructor(RUDDERSTACK_KEY: string, onLoaded?: () => void);
|
|
17
|
+
/**
|
|
18
|
+
* Get or create the singleton instance of RudderStack
|
|
19
|
+
* @param RUDDERSTACK_KEY - RudderStack write key
|
|
20
|
+
* @param onLoaded - Optional callback when RudderStack is loaded
|
|
21
|
+
* @returns The RudderStack singleton instance
|
|
22
|
+
*/
|
|
23
|
+
static getRudderStackInstance: (RUDDERSTACK_KEY: string, onLoaded?: () => void) => RudderStack;
|
|
24
|
+
/**
|
|
25
|
+
* Get the anonymous ID from cookies
|
|
26
|
+
* @returns The anonymous ID or undefined if not found
|
|
27
|
+
*/
|
|
28
|
+
getAnonymousId: () => string | undefined;
|
|
29
|
+
/**
|
|
30
|
+
* Set anonymous ID cookie if it doesn't exist
|
|
31
|
+
* Creates a secure cookie with proper domain and security attributes
|
|
32
|
+
*/
|
|
33
|
+
setCookieIfNotExists: () => void;
|
|
34
|
+
/**
|
|
35
|
+
* Get the current user ID
|
|
36
|
+
* @returns The user ID, null, or undefined if not identified
|
|
37
|
+
*/
|
|
38
|
+
getUserId: () => (string | null) | undefined;
|
|
39
|
+
/**
|
|
40
|
+
* Initialize RudderStack with the provided key
|
|
41
|
+
* @param RUDDERSTACK_KEY - RudderStack write key
|
|
42
|
+
*/
|
|
43
|
+
init: (RUDDERSTACK_KEY: string) => void;
|
|
44
|
+
/**
|
|
45
|
+
* Identify a user with RudderStack
|
|
46
|
+
* Only identifies if user hasn't been identified yet
|
|
47
|
+
* @param user_id - The user ID to identify
|
|
48
|
+
* @param payload - Optional user traits (e.g., language, custom properties)
|
|
49
|
+
*/
|
|
50
|
+
identifyEvent: (user_id: string, payload?: Record<string, any>) => void;
|
|
51
|
+
/**
|
|
52
|
+
* Track a page view event
|
|
53
|
+
* @param current_page - The page name/path
|
|
54
|
+
* @param platform - The platform name (default: 'Deriv App')
|
|
55
|
+
* @param user_id - The user ID
|
|
56
|
+
* @param properties - Additional page properties
|
|
57
|
+
*/
|
|
58
|
+
pageView: (current_page: string, platform: string | undefined, user_id: string, properties?: Record<string, unknown>) => void;
|
|
59
|
+
/**
|
|
60
|
+
* Reset the RudderStack instance
|
|
61
|
+
* Clears user identification and resets tracking state
|
|
62
|
+
*/
|
|
63
|
+
reset: () => void;
|
|
64
|
+
/**
|
|
65
|
+
* Track a custom event with payload
|
|
66
|
+
* Payload is pre-cleaned by analytics.ts using cleanObject before being passed here
|
|
67
|
+
* @param event - The event name
|
|
68
|
+
* @param payload - The event payload with core attributes
|
|
69
|
+
*/
|
|
70
|
+
track: <T extends keyof TAllEvents>(event: T, payload: TAllEvents[T] & Partial<TCoreAttributes>) => void;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export { RudderStack };
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { RudderAnalytics } from '@rudderstack/analytics-js';
|
|
2
|
+
import { a as TAllEvents, T as TCoreAttributes } from '../../types-DoMejCXv.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* RudderStack analytics wrapper with singleton pattern.
|
|
6
|
+
* Handles user tracking, page views, and event analytics.
|
|
7
|
+
*/
|
|
8
|
+
declare class RudderStack {
|
|
9
|
+
analytics: RudderAnalytics;
|
|
10
|
+
has_identified: boolean;
|
|
11
|
+
has_initialized: boolean;
|
|
12
|
+
current_page: string;
|
|
13
|
+
rudderstack_anonymous_cookie_key: string;
|
|
14
|
+
private static _instance;
|
|
15
|
+
private onLoadedCallback?;
|
|
16
|
+
constructor(RUDDERSTACK_KEY: string, onLoaded?: () => void);
|
|
17
|
+
/**
|
|
18
|
+
* Get or create the singleton instance of RudderStack
|
|
19
|
+
* @param RUDDERSTACK_KEY - RudderStack write key
|
|
20
|
+
* @param onLoaded - Optional callback when RudderStack is loaded
|
|
21
|
+
* @returns The RudderStack singleton instance
|
|
22
|
+
*/
|
|
23
|
+
static getRudderStackInstance: (RUDDERSTACK_KEY: string, onLoaded?: () => void) => RudderStack;
|
|
24
|
+
/**
|
|
25
|
+
* Get the anonymous ID from cookies
|
|
26
|
+
* @returns The anonymous ID or undefined if not found
|
|
27
|
+
*/
|
|
28
|
+
getAnonymousId: () => string | undefined;
|
|
29
|
+
/**
|
|
30
|
+
* Set anonymous ID cookie if it doesn't exist
|
|
31
|
+
* Creates a secure cookie with proper domain and security attributes
|
|
32
|
+
*/
|
|
33
|
+
setCookieIfNotExists: () => void;
|
|
34
|
+
/**
|
|
35
|
+
* Get the current user ID
|
|
36
|
+
* @returns The user ID, null, or undefined if not identified
|
|
37
|
+
*/
|
|
38
|
+
getUserId: () => (string | null) | undefined;
|
|
39
|
+
/**
|
|
40
|
+
* Initialize RudderStack with the provided key
|
|
41
|
+
* @param RUDDERSTACK_KEY - RudderStack write key
|
|
42
|
+
*/
|
|
43
|
+
init: (RUDDERSTACK_KEY: string) => void;
|
|
44
|
+
/**
|
|
45
|
+
* Identify a user with RudderStack
|
|
46
|
+
* Only identifies if user hasn't been identified yet
|
|
47
|
+
* @param user_id - The user ID to identify
|
|
48
|
+
* @param payload - Optional user traits (e.g., language, custom properties)
|
|
49
|
+
*/
|
|
50
|
+
identifyEvent: (user_id: string, payload?: Record<string, any>) => void;
|
|
51
|
+
/**
|
|
52
|
+
* Track a page view event
|
|
53
|
+
* @param current_page - The page name/path
|
|
54
|
+
* @param platform - The platform name (default: 'Deriv App')
|
|
55
|
+
* @param user_id - The user ID
|
|
56
|
+
* @param properties - Additional page properties
|
|
57
|
+
*/
|
|
58
|
+
pageView: (current_page: string, platform: string | undefined, user_id: string, properties?: Record<string, unknown>) => void;
|
|
59
|
+
/**
|
|
60
|
+
* Reset the RudderStack instance
|
|
61
|
+
* Clears user identification and resets tracking state
|
|
62
|
+
*/
|
|
63
|
+
reset: () => void;
|
|
64
|
+
/**
|
|
65
|
+
* Track a custom event with payload
|
|
66
|
+
* Payload is pre-cleaned by analytics.ts using cleanObject before being passed here
|
|
67
|
+
* @param event - The event name
|
|
68
|
+
* @param payload - The event payload with core attributes
|
|
69
|
+
*/
|
|
70
|
+
track: <T extends keyof TAllEvents>(event: T, payload: TAllEvents[T] & Partial<TCoreAttributes>) => void;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export { RudderStack };
|
|
@@ -0,0 +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
|
|
2
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"index.mjs"}
|
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
import type { Context } from '@growthbook/growthbook';
|
|
2
1
|
declare global {
|
|
3
2
|
interface Window {
|
|
4
3
|
define: any;
|
|
5
4
|
}
|
|
6
5
|
}
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
type TCoreAttributes = {
|
|
7
|
+
account_type?: string;
|
|
8
|
+
user_id?: string;
|
|
9
|
+
anonymous_id?: string;
|
|
10
|
+
app_id?: string;
|
|
11
|
+
user_identity?: string;
|
|
9
12
|
country?: string;
|
|
10
13
|
user_language?: string;
|
|
11
14
|
device_language?: string;
|
|
@@ -18,30 +21,15 @@ export type TGrowthbookAttributes = {
|
|
|
18
21
|
domain?: string;
|
|
19
22
|
utm_content?: string;
|
|
20
23
|
residence_country?: string;
|
|
21
|
-
loggedIn?: boolean;
|
|
22
|
-
network_type?: string;
|
|
23
|
-
network_downlink?: number;
|
|
24
|
-
user_id?: string;
|
|
25
|
-
anonymous_id?: string;
|
|
26
|
-
account_mode?: string;
|
|
27
|
-
};
|
|
28
|
-
export type TGrowthbookOptions = Partial<Omit<Context, 'attributes'> & {
|
|
29
|
-
attributes: TCoreAttributes;
|
|
30
|
-
}>;
|
|
31
|
-
export type TCoreAttributes = {
|
|
32
|
-
account_type?: string;
|
|
33
|
-
user_id?: string;
|
|
34
|
-
anonymous_id?: string;
|
|
35
|
-
app_id?: string;
|
|
36
|
-
user_identity?: string;
|
|
37
|
-
residence_country?: string;
|
|
38
24
|
geo_location?: string;
|
|
39
25
|
email_hash?: string;
|
|
40
26
|
network_type?: string;
|
|
41
27
|
network_rtt?: number;
|
|
42
28
|
network_downlink?: number;
|
|
43
29
|
account_currency?: string;
|
|
44
|
-
|
|
30
|
+
loggedIn?: boolean;
|
|
31
|
+
account_mode?: string;
|
|
32
|
+
};
|
|
45
33
|
type SignupProvider = 'email' | 'phone' | 'google' | 'facebook' | 'apple';
|
|
46
34
|
type VirtualSignupForm = {
|
|
47
35
|
action?: 'open' | 'started' | 'email_confirmation_sent' | 'email_confirmed' | 'country_selection_screen_opened' | 'password_screen_opened' | 'signup_done' | 'signup_flow_error' | 'go_to_login' | 'signup_modal_open' | 'signup_modal_close';
|
|
@@ -315,7 +303,7 @@ type TDtraderTradeForm = {
|
|
|
315
303
|
trade_type_count?: number;
|
|
316
304
|
contract_id?: number;
|
|
317
305
|
};
|
|
318
|
-
|
|
306
|
+
type TEvents = {
|
|
319
307
|
ce_virtual_signup_form: VirtualSignupForm;
|
|
320
308
|
ce_email_verification_form: EmailVerificationForm;
|
|
321
309
|
ce_real_account_signup_form: RealAccountSignupForm;
|
|
@@ -345,28 +333,29 @@ export type TEvents = {
|
|
|
345
333
|
ce_cashier_deposit_onboarding_form: TCashierDepositOnboardingFormAction;
|
|
346
334
|
ce_dtrader_trade_form: TDtraderTradeForm;
|
|
347
335
|
};
|
|
348
|
-
|
|
336
|
+
type TCtaInformation = {
|
|
349
337
|
cta_name: string;
|
|
350
338
|
section_name?: string;
|
|
351
339
|
container_name?: string;
|
|
352
340
|
};
|
|
353
|
-
|
|
341
|
+
type TErrorInformation = {
|
|
354
342
|
error_message: string;
|
|
355
343
|
error_code?: string;
|
|
356
344
|
};
|
|
357
|
-
|
|
345
|
+
type TV2EventMetadata = {
|
|
358
346
|
page_name?: string;
|
|
359
347
|
marketing_data?: Record<string, any>;
|
|
360
348
|
} & Partial<TCoreAttributes>;
|
|
361
|
-
|
|
349
|
+
type TV2EventPayload = {
|
|
362
350
|
action: string;
|
|
363
351
|
form_name?: string;
|
|
364
352
|
cta_information?: TCtaInformation | null;
|
|
365
353
|
error?: TErrorInformation | null;
|
|
366
354
|
event_metadata: TV2EventMetadata;
|
|
367
355
|
};
|
|
368
|
-
|
|
356
|
+
type TEventsV2 = {
|
|
369
357
|
ce_get_start_page: TV2EventPayload;
|
|
370
358
|
};
|
|
371
|
-
|
|
372
|
-
|
|
359
|
+
type TAllEvents = TEvents & TEventsV2;
|
|
360
|
+
|
|
361
|
+
export type { TCoreAttributes as T, TAllEvents as a, TEvents as b };
|