@vrplatform/log 2.0.0-alpha.2 → 2.0.0-alpha.4
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/build/main/tracking/index.d.ts +6 -8
- package/build/main/tracking/index.js +43 -17
- package/build/main/tracking/index.js.map +1 -1
- package/build/module/tracking/index.d.ts +6 -8
- package/build/module/tracking/index.js +43 -17
- package/build/module/tracking/index.js.map +1 -1
- package/package.json +1 -1
- package/src/tracking/index.ts +47 -19
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { type IntercomAPI, useIntercom } from './intercom';
|
|
2
1
|
export type TrackingProps = {
|
|
3
2
|
name: string;
|
|
4
3
|
dataset: string;
|
|
@@ -9,7 +8,6 @@ export type TrackingProps = {
|
|
|
9
8
|
};
|
|
10
9
|
};
|
|
11
10
|
export type Tracking = ReturnType<typeof useTracking>;
|
|
12
|
-
export type Intercom = ReturnType<typeof useIntercom>;
|
|
13
11
|
type OptionalUser<T> = T & ({
|
|
14
12
|
userId: string;
|
|
15
13
|
anonymousId?: string;
|
|
@@ -33,21 +31,21 @@ export declare const useTracking: ({ dataset, env, name }: TrackingProps, isDev?
|
|
|
33
31
|
groupId: string;
|
|
34
32
|
traits?: Record<string, any>;
|
|
35
33
|
}>) => void;
|
|
36
|
-
shutdown: () => Promise<[void, void, void]>;
|
|
37
|
-
alias: (data: {
|
|
34
|
+
shutdown: () => Promise<[void | undefined, void | undefined, void]>;
|
|
35
|
+
alias: ((data: {
|
|
38
36
|
distinctId: string;
|
|
39
37
|
alias: string;
|
|
40
38
|
disableGeoip?: boolean;
|
|
41
|
-
}) => void;
|
|
42
|
-
isFeatureEnabled: (key: string, distinctId: string, options?: {
|
|
39
|
+
}) => void) | undefined;
|
|
40
|
+
isFeatureEnabled: ((key: string, distinctId: string, options?: {
|
|
43
41
|
groups?: Record<string, string>;
|
|
44
42
|
personProperties?: Record<string, string>;
|
|
45
43
|
groupProperties?: Record<string, Record<string, string>>;
|
|
46
44
|
onlyEvaluateLocally?: boolean;
|
|
47
45
|
sendFeatureFlagEvents?: boolean;
|
|
48
46
|
disableGeoip?: boolean;
|
|
49
|
-
}) => Promise<boolean | undefined
|
|
50
|
-
intercom: IntercomAPI;
|
|
47
|
+
}) => Promise<boolean | undefined>) | undefined;
|
|
48
|
+
intercom: import("./intercom").IntercomAPI | undefined;
|
|
51
49
|
log: import("../log").WorkerLog;
|
|
52
50
|
};
|
|
53
51
|
export {};
|
|
@@ -5,19 +5,37 @@ const analytics_node_1 = require("@june-so/analytics-node");
|
|
|
5
5
|
const posthog_node_1 = require("posthog-node");
|
|
6
6
|
const log_1 = require("../log");
|
|
7
7
|
const intercom_1 = require("./intercom");
|
|
8
|
+
const E2E_TEST_USERS = [
|
|
9
|
+
'9e7dfc88-503c-4222-9905-9116169d2203', // lars+checkly@finalytic.co
|
|
10
|
+
'113d73d8-ee21-46b7-a12a-a74f632401ca', // e2e-invite-member@finalytic.io
|
|
11
|
+
'917b7c4e-cb03-491c-9e94-d33a5bdeca05', // e2e-invite-owner@finalytic.io
|
|
12
|
+
'ec8e5572-74d0-4ae6-af73-bca8db9a27e9', // e2e-sign-up@finalytic.io
|
|
13
|
+
];
|
|
14
|
+
const E2E_TEST_TEAMS = [
|
|
15
|
+
'c4fd21b4-8447-43a2-bdcb-f06a85a935ad', // VRP Automated Testing
|
|
16
|
+
'8f21060e-afe6-410a-b2f4-00a3caa20786', // test_company_xxxx
|
|
17
|
+
];
|
|
18
|
+
const isTest = (userId, groupId) => E2E_TEST_USERS.includes(userId) ||
|
|
19
|
+
(groupId && E2E_TEST_TEAMS.includes(groupId));
|
|
8
20
|
const useTracking = ({ dataset, env, name }, isDev) => {
|
|
9
21
|
const axiom = (0, log_1.useLog)({ name, dataset, env });
|
|
10
|
-
const intercom =
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
22
|
+
const intercom = env.INTERCOM_TOKEN
|
|
23
|
+
? (0, intercom_1.useIntercom)(env.INTERCOM_TOKEN, axiom)
|
|
24
|
+
: undefined;
|
|
25
|
+
const juneso = env.JUNESO_ANALYTICS_WRITE_KEY
|
|
26
|
+
? new analytics_node_1.Analytics(env.JUNESO_ANALYTICS_WRITE_KEY)
|
|
27
|
+
: undefined;
|
|
28
|
+
const posthog = env.POSTHOG_API_KEY
|
|
29
|
+
? new posthog_node_1.PostHog(env.POSTHOG_API_KEY, {
|
|
30
|
+
host: 'https://app.posthog.com',
|
|
31
|
+
})
|
|
32
|
+
: undefined;
|
|
15
33
|
return {
|
|
16
34
|
// General
|
|
17
35
|
track: async ({ userId, groupId, event, properties, }) => {
|
|
18
|
-
if (isDev)
|
|
36
|
+
if (isDev || isTest(userId, groupId))
|
|
19
37
|
return;
|
|
20
|
-
posthog
|
|
38
|
+
posthog?.capture({
|
|
21
39
|
distinctId: userId,
|
|
22
40
|
event,
|
|
23
41
|
groups: {
|
|
@@ -25,14 +43,14 @@ const useTracking = ({ dataset, env, name }, isDev) => {
|
|
|
25
43
|
},
|
|
26
44
|
properties,
|
|
27
45
|
});
|
|
28
|
-
juneso
|
|
46
|
+
juneso?.track({
|
|
29
47
|
userId,
|
|
30
48
|
event,
|
|
31
49
|
properties,
|
|
32
50
|
context: { groupId },
|
|
33
51
|
});
|
|
34
52
|
try {
|
|
35
|
-
await intercom
|
|
53
|
+
await intercom?.trackEvent({
|
|
36
54
|
user_id: userId,
|
|
37
55
|
event_name: event,
|
|
38
56
|
metadata: properties,
|
|
@@ -43,32 +61,40 @@ const useTracking = ({ dataset, env, name }, isDev) => {
|
|
|
43
61
|
}
|
|
44
62
|
},
|
|
45
63
|
identify: ({ traits, userId, disableGeoip, }) => {
|
|
46
|
-
|
|
64
|
+
if (isDev || isTest(userId))
|
|
65
|
+
return;
|
|
66
|
+
posthog?.identify({
|
|
47
67
|
distinctId: userId,
|
|
48
68
|
properties: traits,
|
|
49
69
|
disableGeoip,
|
|
50
70
|
});
|
|
51
|
-
juneso
|
|
71
|
+
juneso?.identify({
|
|
52
72
|
userId,
|
|
53
73
|
traits,
|
|
54
74
|
});
|
|
55
75
|
},
|
|
56
76
|
group: ({ traits, groupId, userId, anonymousId, }) => {
|
|
57
|
-
|
|
77
|
+
if (isDev || isTest(userId || anonymousId || '', groupId))
|
|
78
|
+
return;
|
|
79
|
+
posthog?.groupIdentify({
|
|
58
80
|
groupKey: groupId,
|
|
59
81
|
groupType: 'tenant',
|
|
60
82
|
properties: traits,
|
|
61
83
|
distinctId: userId,
|
|
62
84
|
});
|
|
63
85
|
if (anonymousId)
|
|
64
|
-
juneso
|
|
86
|
+
juneso?.group({ anonymousId, groupId, traits });
|
|
65
87
|
else if (userId)
|
|
66
|
-
juneso
|
|
88
|
+
juneso?.group({ userId, groupId, traits });
|
|
67
89
|
},
|
|
68
|
-
shutdown: async () => Promise.all([
|
|
90
|
+
shutdown: async () => Promise.all([
|
|
91
|
+
posthog?.shutdown(),
|
|
92
|
+
juneso?.closeAndFlush(),
|
|
93
|
+
axiom.flush(),
|
|
94
|
+
]),
|
|
69
95
|
// Posthog specific
|
|
70
|
-
alias: posthog
|
|
71
|
-
isFeatureEnabled: posthog
|
|
96
|
+
alias: posthog?.alias,
|
|
97
|
+
isFeatureEnabled: posthog?.isFeatureEnabled,
|
|
72
98
|
// export intercom and axiom
|
|
73
99
|
intercom,
|
|
74
100
|
log: axiom,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"src/","sources":["tracking/index.ts"],"names":[],"mappings":";;;AAAA,4DAAoD;AACpD,+CAAuC;AACvC,gCAAgC;AAChC,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"src/","sources":["tracking/index.ts"],"names":[],"mappings":";;;AAAA,4DAAoD;AACpD,+CAAuC;AACvC,gCAAgC;AAChC,yCAAyC;AAEzC,MAAM,cAAc,GAAG;IACrB,sCAAsC,EAAE,4BAA4B;IACpE,sCAAsC,EAAE,iCAAiC;IACzE,sCAAsC,EAAE,gCAA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AI,MAAM;gBAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,CAAC;QAC9D,CAAC;QACD,QAAQ,EAAE,KAAK,IAAI,EAAE,CACnB,OAAO,CAAC,GAAG,CAAC;YACV,OAAO,EAAE,QAAQ,EAAE;YACnB,MAAM,EAAE,aAAa,EAAE;YACvB,KAAK,CAAC,KAAK,EAAE;SACd,CAAC;QACJ,mBAAmB;QACnB,KAAK,EAAE,OAAO,EAAE,KAAK;QACrB,gBAAgB,EAAE,OAAO,EAAE,gBAAgB;QAC3C,4BAA4B;QAC5B,QAAQ;QACR,GAAG,EAAE,KAAK;KACX,CAAC;AACJ,CAAC,CAAC;AA/GW,QAAA,WAAW,eA+GtB"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { type IntercomAPI, useIntercom } from './intercom';
|
|
2
1
|
export type TrackingProps = {
|
|
3
2
|
name: string;
|
|
4
3
|
dataset: string;
|
|
@@ -9,7 +8,6 @@ export type TrackingProps = {
|
|
|
9
8
|
};
|
|
10
9
|
};
|
|
11
10
|
export type Tracking = ReturnType<typeof useTracking>;
|
|
12
|
-
export type Intercom = ReturnType<typeof useIntercom>;
|
|
13
11
|
type OptionalUser<T> = T & ({
|
|
14
12
|
userId: string;
|
|
15
13
|
anonymousId?: string;
|
|
@@ -33,21 +31,21 @@ export declare const useTracking: ({ dataset, env, name }: TrackingProps, isDev?
|
|
|
33
31
|
groupId: string;
|
|
34
32
|
traits?: Record<string, any>;
|
|
35
33
|
}>) => void;
|
|
36
|
-
shutdown: () => Promise<[void, void, void]>;
|
|
37
|
-
alias: (data: {
|
|
34
|
+
shutdown: () => Promise<[void | undefined, void | undefined, void]>;
|
|
35
|
+
alias: ((data: {
|
|
38
36
|
distinctId: string;
|
|
39
37
|
alias: string;
|
|
40
38
|
disableGeoip?: boolean;
|
|
41
|
-
}) => void;
|
|
42
|
-
isFeatureEnabled: (key: string, distinctId: string, options?: {
|
|
39
|
+
}) => void) | undefined;
|
|
40
|
+
isFeatureEnabled: ((key: string, distinctId: string, options?: {
|
|
43
41
|
groups?: Record<string, string>;
|
|
44
42
|
personProperties?: Record<string, string>;
|
|
45
43
|
groupProperties?: Record<string, Record<string, string>>;
|
|
46
44
|
onlyEvaluateLocally?: boolean;
|
|
47
45
|
sendFeatureFlagEvents?: boolean;
|
|
48
46
|
disableGeoip?: boolean;
|
|
49
|
-
}) => Promise<boolean | undefined
|
|
50
|
-
intercom: IntercomAPI;
|
|
47
|
+
}) => Promise<boolean | undefined>) | undefined;
|
|
48
|
+
intercom: import("./intercom").IntercomAPI | undefined;
|
|
51
49
|
log: import("../log").WorkerLog;
|
|
52
50
|
};
|
|
53
51
|
export {};
|
|
@@ -2,19 +2,37 @@ import { Analytics } from '@june-so/analytics-node';
|
|
|
2
2
|
import { PostHog } from 'posthog-node';
|
|
3
3
|
import { useLog } from '../log';
|
|
4
4
|
import { useIntercom } from './intercom';
|
|
5
|
+
const E2E_TEST_USERS = [
|
|
6
|
+
'9e7dfc88-503c-4222-9905-9116169d2203', // lars+checkly@finalytic.co
|
|
7
|
+
'113d73d8-ee21-46b7-a12a-a74f632401ca', // e2e-invite-member@finalytic.io
|
|
8
|
+
'917b7c4e-cb03-491c-9e94-d33a5bdeca05', // e2e-invite-owner@finalytic.io
|
|
9
|
+
'ec8e5572-74d0-4ae6-af73-bca8db9a27e9', // e2e-sign-up@finalytic.io
|
|
10
|
+
];
|
|
11
|
+
const E2E_TEST_TEAMS = [
|
|
12
|
+
'c4fd21b4-8447-43a2-bdcb-f06a85a935ad', // VRP Automated Testing
|
|
13
|
+
'8f21060e-afe6-410a-b2f4-00a3caa20786', // test_company_xxxx
|
|
14
|
+
];
|
|
15
|
+
const isTest = (userId, groupId) => E2E_TEST_USERS.includes(userId) ||
|
|
16
|
+
(groupId && E2E_TEST_TEAMS.includes(groupId));
|
|
5
17
|
export const useTracking = ({ dataset, env, name }, isDev) => {
|
|
6
18
|
const axiom = useLog({ name, dataset, env });
|
|
7
|
-
const intercom =
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
19
|
+
const intercom = env.INTERCOM_TOKEN
|
|
20
|
+
? useIntercom(env.INTERCOM_TOKEN, axiom)
|
|
21
|
+
: undefined;
|
|
22
|
+
const juneso = env.JUNESO_ANALYTICS_WRITE_KEY
|
|
23
|
+
? new Analytics(env.JUNESO_ANALYTICS_WRITE_KEY)
|
|
24
|
+
: undefined;
|
|
25
|
+
const posthog = env.POSTHOG_API_KEY
|
|
26
|
+
? new PostHog(env.POSTHOG_API_KEY, {
|
|
27
|
+
host: 'https://app.posthog.com',
|
|
28
|
+
})
|
|
29
|
+
: undefined;
|
|
12
30
|
return {
|
|
13
31
|
// General
|
|
14
32
|
track: async ({ userId, groupId, event, properties, }) => {
|
|
15
|
-
if (isDev)
|
|
33
|
+
if (isDev || isTest(userId, groupId))
|
|
16
34
|
return;
|
|
17
|
-
posthog
|
|
35
|
+
posthog?.capture({
|
|
18
36
|
distinctId: userId,
|
|
19
37
|
event,
|
|
20
38
|
groups: {
|
|
@@ -22,14 +40,14 @@ export const useTracking = ({ dataset, env, name }, isDev) => {
|
|
|
22
40
|
},
|
|
23
41
|
properties,
|
|
24
42
|
});
|
|
25
|
-
juneso
|
|
43
|
+
juneso?.track({
|
|
26
44
|
userId,
|
|
27
45
|
event,
|
|
28
46
|
properties,
|
|
29
47
|
context: { groupId },
|
|
30
48
|
});
|
|
31
49
|
try {
|
|
32
|
-
await intercom
|
|
50
|
+
await intercom?.trackEvent({
|
|
33
51
|
user_id: userId,
|
|
34
52
|
event_name: event,
|
|
35
53
|
metadata: properties,
|
|
@@ -40,32 +58,40 @@ export const useTracking = ({ dataset, env, name }, isDev) => {
|
|
|
40
58
|
}
|
|
41
59
|
},
|
|
42
60
|
identify: ({ traits, userId, disableGeoip, }) => {
|
|
43
|
-
|
|
61
|
+
if (isDev || isTest(userId))
|
|
62
|
+
return;
|
|
63
|
+
posthog?.identify({
|
|
44
64
|
distinctId: userId,
|
|
45
65
|
properties: traits,
|
|
46
66
|
disableGeoip,
|
|
47
67
|
});
|
|
48
|
-
juneso
|
|
68
|
+
juneso?.identify({
|
|
49
69
|
userId,
|
|
50
70
|
traits,
|
|
51
71
|
});
|
|
52
72
|
},
|
|
53
73
|
group: ({ traits, groupId, userId, anonymousId, }) => {
|
|
54
|
-
|
|
74
|
+
if (isDev || isTest(userId || anonymousId || '', groupId))
|
|
75
|
+
return;
|
|
76
|
+
posthog?.groupIdentify({
|
|
55
77
|
groupKey: groupId,
|
|
56
78
|
groupType: 'tenant',
|
|
57
79
|
properties: traits,
|
|
58
80
|
distinctId: userId,
|
|
59
81
|
});
|
|
60
82
|
if (anonymousId)
|
|
61
|
-
juneso
|
|
83
|
+
juneso?.group({ anonymousId, groupId, traits });
|
|
62
84
|
else if (userId)
|
|
63
|
-
juneso
|
|
85
|
+
juneso?.group({ userId, groupId, traits });
|
|
64
86
|
},
|
|
65
|
-
shutdown: async () => Promise.all([
|
|
87
|
+
shutdown: async () => Promise.all([
|
|
88
|
+
posthog?.shutdown(),
|
|
89
|
+
juneso?.closeAndFlush(),
|
|
90
|
+
axiom.flush(),
|
|
91
|
+
]),
|
|
66
92
|
// Posthog specific
|
|
67
|
-
alias: posthog
|
|
68
|
-
isFeatureEnabled: posthog
|
|
93
|
+
alias: posthog?.alias,
|
|
94
|
+
isFeatureEnabled: posthog?.isFeatureEnabled,
|
|
69
95
|
// export intercom and axiom
|
|
70
96
|
intercom,
|
|
71
97
|
log: axiom,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"src/","sources":["tracking/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACpD,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,
|
|
1
|
+
{"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,IAAI,KAAK,IAAI,MAAM,CAAC,MAAM,IAAI,WAAW,IAAI,EAAE,EAAE,OAAO,CAAC;gBAAE,OAAO;YAElE,OAAO,EAAE,aAAa,CAAC;gBACrB,QAAQ,EAAE,OAAO;gBACjB,SAAS,EAAE,QAAQ;gBACnB,UAAU,EAAE,MAAM;gBAClB,UAAU,EAAE,MAAM;aACnB,CAAC,CAAC;YACH,IAAI,WAAW;gBAAE,MAAM,EAAE,KAAK,CAAC,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,CAAC;iBAC5D,IAAI,MAAM;gBAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,CAAC;QAC9D,CAAC;QACD,QAAQ,EAAE,KAAK,IAAI,EAAE,CACnB,OAAO,CAAC,GAAG,CAAC;YACV,OAAO,EAAE,QAAQ,EAAE;YACnB,MAAM,EAAE,aAAa,EAAE;YACvB,KAAK,CAAC,KAAK,EAAE;SACd,CAAC;QACJ,mBAAmB;QACnB,KAAK,EAAE,OAAO,EAAE,KAAK;QACrB,gBAAgB,EAAE,OAAO,EAAE,gBAAgB;QAC3C,4BAA4B;QAC5B,QAAQ;QACR,GAAG,EAAE,KAAK;KACX,CAAC;AACJ,CAAC,CAAC"}
|
package/package.json
CHANGED
package/src/tracking/index.ts
CHANGED
|
@@ -1,7 +1,22 @@
|
|
|
1
1
|
import { Analytics } from '@june-so/analytics-node';
|
|
2
2
|
import { PostHog } from 'posthog-node';
|
|
3
3
|
import { useLog } from '../log';
|
|
4
|
-
import {
|
|
4
|
+
import { useIntercom } from './intercom';
|
|
5
|
+
|
|
6
|
+
const E2E_TEST_USERS = [
|
|
7
|
+
'9e7dfc88-503c-4222-9905-9116169d2203', // lars+checkly@finalytic.co
|
|
8
|
+
'113d73d8-ee21-46b7-a12a-a74f632401ca', // e2e-invite-member@finalytic.io
|
|
9
|
+
'917b7c4e-cb03-491c-9e94-d33a5bdeca05', // e2e-invite-owner@finalytic.io
|
|
10
|
+
'ec8e5572-74d0-4ae6-af73-bca8db9a27e9', // e2e-sign-up@finalytic.io
|
|
11
|
+
];
|
|
12
|
+
const E2E_TEST_TEAMS = [
|
|
13
|
+
'c4fd21b4-8447-43a2-bdcb-f06a85a935ad', // VRP Automated Testing
|
|
14
|
+
'8f21060e-afe6-410a-b2f4-00a3caa20786', // test_company_xxxx
|
|
15
|
+
];
|
|
16
|
+
|
|
17
|
+
const isTest = (userId: string, groupId?: string) =>
|
|
18
|
+
E2E_TEST_USERS.includes(userId) ||
|
|
19
|
+
(groupId && E2E_TEST_TEAMS.includes(groupId));
|
|
5
20
|
|
|
6
21
|
export type TrackingProps = {
|
|
7
22
|
name: string;
|
|
@@ -13,7 +28,6 @@ export type TrackingProps = {
|
|
|
13
28
|
};
|
|
14
29
|
};
|
|
15
30
|
export type Tracking = ReturnType<typeof useTracking>;
|
|
16
|
-
export type Intercom = ReturnType<typeof useIntercom>;
|
|
17
31
|
|
|
18
32
|
type OptionalUser<T> = T &
|
|
19
33
|
(
|
|
@@ -29,11 +43,17 @@ export const useTracking = (
|
|
|
29
43
|
isDev?: boolean
|
|
30
44
|
) => {
|
|
31
45
|
const axiom = useLog({ name, dataset, env });
|
|
32
|
-
const intercom =
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
46
|
+
const intercom = env.INTERCOM_TOKEN
|
|
47
|
+
? useIntercom(env.INTERCOM_TOKEN, axiom)
|
|
48
|
+
: undefined;
|
|
49
|
+
const juneso = env.JUNESO_ANALYTICS_WRITE_KEY
|
|
50
|
+
? new Analytics(env.JUNESO_ANALYTICS_WRITE_KEY)
|
|
51
|
+
: undefined;
|
|
52
|
+
const posthog = env.POSTHOG_API_KEY
|
|
53
|
+
? new PostHog(env.POSTHOG_API_KEY, {
|
|
54
|
+
host: 'https://app.posthog.com',
|
|
55
|
+
})
|
|
56
|
+
: undefined;
|
|
37
57
|
|
|
38
58
|
return {
|
|
39
59
|
// General
|
|
@@ -48,9 +68,9 @@ export const useTracking = (
|
|
|
48
68
|
event: string;
|
|
49
69
|
properties: Record<string, any>;
|
|
50
70
|
}) => {
|
|
51
|
-
if (isDev) return;
|
|
71
|
+
if (isDev || isTest(userId, groupId)) return;
|
|
52
72
|
|
|
53
|
-
posthog
|
|
73
|
+
posthog?.capture({
|
|
54
74
|
distinctId: userId,
|
|
55
75
|
event,
|
|
56
76
|
groups: {
|
|
@@ -58,7 +78,7 @@ export const useTracking = (
|
|
|
58
78
|
},
|
|
59
79
|
properties,
|
|
60
80
|
});
|
|
61
|
-
juneso
|
|
81
|
+
juneso?.track({
|
|
62
82
|
userId,
|
|
63
83
|
event,
|
|
64
84
|
properties,
|
|
@@ -66,7 +86,7 @@ export const useTracking = (
|
|
|
66
86
|
});
|
|
67
87
|
|
|
68
88
|
try {
|
|
69
|
-
await intercom
|
|
89
|
+
await intercom?.trackEvent({
|
|
70
90
|
user_id: userId,
|
|
71
91
|
event_name: event,
|
|
72
92
|
metadata: properties,
|
|
@@ -84,12 +104,14 @@ export const useTracking = (
|
|
|
84
104
|
traits: Record<string, any>;
|
|
85
105
|
disableGeoip?: boolean;
|
|
86
106
|
}) => {
|
|
87
|
-
|
|
107
|
+
if (isDev || isTest(userId)) return;
|
|
108
|
+
|
|
109
|
+
posthog?.identify({
|
|
88
110
|
distinctId: userId,
|
|
89
111
|
properties: traits,
|
|
90
112
|
disableGeoip,
|
|
91
113
|
});
|
|
92
|
-
juneso
|
|
114
|
+
juneso?.identify({
|
|
93
115
|
userId,
|
|
94
116
|
traits,
|
|
95
117
|
});
|
|
@@ -103,20 +125,26 @@ export const useTracking = (
|
|
|
103
125
|
groupId: string;
|
|
104
126
|
traits?: Record<string, any>;
|
|
105
127
|
}>) => {
|
|
106
|
-
|
|
128
|
+
if (isDev || isTest(userId || anonymousId || '', groupId)) return;
|
|
129
|
+
|
|
130
|
+
posthog?.groupIdentify({
|
|
107
131
|
groupKey: groupId,
|
|
108
132
|
groupType: 'tenant',
|
|
109
133
|
properties: traits,
|
|
110
134
|
distinctId: userId,
|
|
111
135
|
});
|
|
112
|
-
if (anonymousId) juneso
|
|
113
|
-
else if (userId) juneso
|
|
136
|
+
if (anonymousId) juneso?.group({ anonymousId, groupId, traits });
|
|
137
|
+
else if (userId) juneso?.group({ userId, groupId, traits });
|
|
114
138
|
},
|
|
115
139
|
shutdown: async () =>
|
|
116
|
-
Promise.all([
|
|
140
|
+
Promise.all([
|
|
141
|
+
posthog?.shutdown(),
|
|
142
|
+
juneso?.closeAndFlush(),
|
|
143
|
+
axiom.flush(),
|
|
144
|
+
]),
|
|
117
145
|
// Posthog specific
|
|
118
|
-
alias: posthog
|
|
119
|
-
isFeatureEnabled: posthog
|
|
146
|
+
alias: posthog?.alias,
|
|
147
|
+
isFeatureEnabled: posthog?.isFeatureEnabled,
|
|
120
148
|
// export intercom and axiom
|
|
121
149
|
intercom,
|
|
122
150
|
log: axiom,
|