@vrplatform/log 2.0.0-alpha.3 → 2.0.0-alpha.5
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 +8 -8
- package/build/main/tracking/index.js +24 -16
- package/build/main/tracking/index.js.map +1 -1
- package/build/module/tracking/index.d.ts +8 -8
- package/build/module/tracking/index.js +24 -16
- package/build/module/tracking/index.js.map +1 -1
- package/package.json +1 -1
- package/src/tracking/index.ts +26 -18
|
@@ -3,8 +3,8 @@ export type TrackingProps = {
|
|
|
3
3
|
dataset: string;
|
|
4
4
|
env: {
|
|
5
5
|
INTERCOM_TOKEN: string;
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
JUNESO_TOKEN: string;
|
|
7
|
+
POSTHOG_TOKEN: string;
|
|
8
8
|
};
|
|
9
9
|
};
|
|
10
10
|
export type Tracking = ReturnType<typeof useTracking>;
|
|
@@ -31,21 +31,21 @@ export declare const useTracking: ({ dataset, env, name }: TrackingProps, isDev?
|
|
|
31
31
|
groupId: string;
|
|
32
32
|
traits?: Record<string, any>;
|
|
33
33
|
}>) => void;
|
|
34
|
-
shutdown: () => Promise<[void, void, void]>;
|
|
35
|
-
alias: (data: {
|
|
34
|
+
shutdown: () => Promise<[void | undefined, void | undefined, void]>;
|
|
35
|
+
alias: ((data: {
|
|
36
36
|
distinctId: string;
|
|
37
37
|
alias: string;
|
|
38
38
|
disableGeoip?: boolean;
|
|
39
|
-
}) => void;
|
|
40
|
-
isFeatureEnabled: (key: string, distinctId: string, options?: {
|
|
39
|
+
}) => void) | undefined;
|
|
40
|
+
isFeatureEnabled: ((key: string, distinctId: string, options?: {
|
|
41
41
|
groups?: Record<string, string>;
|
|
42
42
|
personProperties?: Record<string, string>;
|
|
43
43
|
groupProperties?: Record<string, Record<string, string>>;
|
|
44
44
|
onlyEvaluateLocally?: boolean;
|
|
45
45
|
sendFeatureFlagEvents?: boolean;
|
|
46
46
|
disableGeoip?: boolean;
|
|
47
|
-
}) => Promise<boolean | undefined
|
|
48
|
-
intercom: import("./intercom").IntercomAPI;
|
|
47
|
+
}) => Promise<boolean | undefined>) | undefined;
|
|
48
|
+
intercom: import("./intercom").IntercomAPI | undefined;
|
|
49
49
|
log: import("../log").WorkerLog;
|
|
50
50
|
};
|
|
51
51
|
export {};
|
|
@@ -19,17 +19,21 @@ const isTest = (userId, groupId) => E2E_TEST_USERS.includes(userId) ||
|
|
|
19
19
|
(groupId && E2E_TEST_TEAMS.includes(groupId));
|
|
20
20
|
const useTracking = ({ dataset, env, name }, isDev) => {
|
|
21
21
|
const axiom = (0, log_1.useLog)({ name, dataset, env });
|
|
22
|
-
const intercom =
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
22
|
+
const intercom = env.INTERCOM_TOKEN
|
|
23
|
+
? (0, intercom_1.useIntercom)(env.INTERCOM_TOKEN, axiom)
|
|
24
|
+
: undefined;
|
|
25
|
+
const juneso = env.JUNESO_TOKEN ? new analytics_node_1.Analytics(env.JUNESO_TOKEN) : undefined;
|
|
26
|
+
const posthog = env.POSTHOG_TOKEN
|
|
27
|
+
? new posthog_node_1.PostHog(env.POSTHOG_TOKEN, {
|
|
28
|
+
host: 'https://app.posthog.com',
|
|
29
|
+
})
|
|
30
|
+
: undefined;
|
|
27
31
|
return {
|
|
28
32
|
// General
|
|
29
33
|
track: async ({ userId, groupId, event, properties, }) => {
|
|
30
34
|
if (isDev || isTest(userId, groupId))
|
|
31
35
|
return;
|
|
32
|
-
posthog
|
|
36
|
+
posthog?.capture({
|
|
33
37
|
distinctId: userId,
|
|
34
38
|
event,
|
|
35
39
|
groups: {
|
|
@@ -37,14 +41,14 @@ const useTracking = ({ dataset, env, name }, isDev) => {
|
|
|
37
41
|
},
|
|
38
42
|
properties,
|
|
39
43
|
});
|
|
40
|
-
juneso
|
|
44
|
+
juneso?.track({
|
|
41
45
|
userId,
|
|
42
46
|
event,
|
|
43
47
|
properties,
|
|
44
48
|
context: { groupId },
|
|
45
49
|
});
|
|
46
50
|
try {
|
|
47
|
-
await intercom
|
|
51
|
+
await intercom?.trackEvent({
|
|
48
52
|
user_id: userId,
|
|
49
53
|
event_name: event,
|
|
50
54
|
metadata: properties,
|
|
@@ -57,12 +61,12 @@ const useTracking = ({ dataset, env, name }, isDev) => {
|
|
|
57
61
|
identify: ({ traits, userId, disableGeoip, }) => {
|
|
58
62
|
if (isDev || isTest(userId))
|
|
59
63
|
return;
|
|
60
|
-
posthog
|
|
64
|
+
posthog?.identify({
|
|
61
65
|
distinctId: userId,
|
|
62
66
|
properties: traits,
|
|
63
67
|
disableGeoip,
|
|
64
68
|
});
|
|
65
|
-
juneso
|
|
69
|
+
juneso?.identify({
|
|
66
70
|
userId,
|
|
67
71
|
traits,
|
|
68
72
|
});
|
|
@@ -70,21 +74,25 @@ const useTracking = ({ dataset, env, name }, isDev) => {
|
|
|
70
74
|
group: ({ traits, groupId, userId, anonymousId, }) => {
|
|
71
75
|
if (isDev || isTest(userId || anonymousId || '', groupId))
|
|
72
76
|
return;
|
|
73
|
-
posthog
|
|
77
|
+
posthog?.groupIdentify({
|
|
74
78
|
groupKey: groupId,
|
|
75
79
|
groupType: 'tenant',
|
|
76
80
|
properties: traits,
|
|
77
81
|
distinctId: userId,
|
|
78
82
|
});
|
|
79
83
|
if (anonymousId)
|
|
80
|
-
juneso
|
|
84
|
+
juneso?.group({ anonymousId, groupId, traits });
|
|
81
85
|
else if (userId)
|
|
82
|
-
juneso
|
|
86
|
+
juneso?.group({ userId, groupId, traits });
|
|
83
87
|
},
|
|
84
|
-
shutdown: async () => Promise.all([
|
|
88
|
+
shutdown: async () => Promise.all([
|
|
89
|
+
posthog?.shutdown(),
|
|
90
|
+
juneso?.closeAndFlush(),
|
|
91
|
+
axiom.flush(),
|
|
92
|
+
]),
|
|
85
93
|
// Posthog specific
|
|
86
|
-
alias: posthog
|
|
87
|
-
isFeatureEnabled: posthog
|
|
94
|
+
alias: posthog?.alias,
|
|
95
|
+
isFeatureEnabled: posthog?.isFeatureEnabled,
|
|
88
96
|
// export intercom and axiom
|
|
89
97
|
intercom,
|
|
90
98
|
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,yCAAyC;AAEzC,MAAM,cAAc,GAAG;IACrB,sCAAsC,EAAE,4BAA4B;IACpE,sCAAsC,EAAE,iCAAiC;IACzE,sCAAsC,EAAE,gCAAgC;IACxE,sCAAsC,EAAE,2BAA2B;CACpE,CAAC;AACF,MAAM,cAAc,GAAG;IACrB,sCAAsC,EAAE,wBAAwB;IAChE,sCAAsC,EAAE,oBAAoB;CAC7D,CAAC;AAEF,MAAM,MAAM,GAAG,CAAC,MAAc,EAAE,OAAgB,EAAE,EAAE,CAClD,cAAc,CAAC,QAAQ,CAAC,MAAM,CAAC;IAC/B,CAAC,OAAO,IAAI,cAAc,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC;AAsBzC,MAAM,WAAW,GAAG,CACzB,EAAE,OAAO,EAAE,GAAG,EAAE,IAAI,EAAiB,EACrC,KAAe,EACf,EAAE;IACF,MAAM,KAAK,GAAG,IAAA,YAAM,EAAC,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,CAAC;IAC7C,MAAM,QAAQ,GAAG,IAAA,sBAAW,EAAC,GAAG,CAAC,cAAc,EAAE,KAAK,CAAC,CAAC;
|
|
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,gCAAgC;IACxE,sCAAsC,EAAE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E,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;AA7GW,QAAA,WAAW,eA6GtB"}
|
|
@@ -3,8 +3,8 @@ export type TrackingProps = {
|
|
|
3
3
|
dataset: string;
|
|
4
4
|
env: {
|
|
5
5
|
INTERCOM_TOKEN: string;
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
JUNESO_TOKEN: string;
|
|
7
|
+
POSTHOG_TOKEN: string;
|
|
8
8
|
};
|
|
9
9
|
};
|
|
10
10
|
export type Tracking = ReturnType<typeof useTracking>;
|
|
@@ -31,21 +31,21 @@ export declare const useTracking: ({ dataset, env, name }: TrackingProps, isDev?
|
|
|
31
31
|
groupId: string;
|
|
32
32
|
traits?: Record<string, any>;
|
|
33
33
|
}>) => void;
|
|
34
|
-
shutdown: () => Promise<[void, void, void]>;
|
|
35
|
-
alias: (data: {
|
|
34
|
+
shutdown: () => Promise<[void | undefined, void | undefined, void]>;
|
|
35
|
+
alias: ((data: {
|
|
36
36
|
distinctId: string;
|
|
37
37
|
alias: string;
|
|
38
38
|
disableGeoip?: boolean;
|
|
39
|
-
}) => void;
|
|
40
|
-
isFeatureEnabled: (key: string, distinctId: string, options?: {
|
|
39
|
+
}) => void) | undefined;
|
|
40
|
+
isFeatureEnabled: ((key: string, distinctId: string, options?: {
|
|
41
41
|
groups?: Record<string, string>;
|
|
42
42
|
personProperties?: Record<string, string>;
|
|
43
43
|
groupProperties?: Record<string, Record<string, string>>;
|
|
44
44
|
onlyEvaluateLocally?: boolean;
|
|
45
45
|
sendFeatureFlagEvents?: boolean;
|
|
46
46
|
disableGeoip?: boolean;
|
|
47
|
-
}) => Promise<boolean | undefined
|
|
48
|
-
intercom: import("./intercom").IntercomAPI;
|
|
47
|
+
}) => Promise<boolean | undefined>) | undefined;
|
|
48
|
+
intercom: import("./intercom").IntercomAPI | undefined;
|
|
49
49
|
log: import("../log").WorkerLog;
|
|
50
50
|
};
|
|
51
51
|
export {};
|
|
@@ -16,17 +16,21 @@ const isTest = (userId, groupId) => E2E_TEST_USERS.includes(userId) ||
|
|
|
16
16
|
(groupId && E2E_TEST_TEAMS.includes(groupId));
|
|
17
17
|
export const useTracking = ({ dataset, env, name }, isDev) => {
|
|
18
18
|
const axiom = useLog({ name, dataset, env });
|
|
19
|
-
const intercom =
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
19
|
+
const intercom = env.INTERCOM_TOKEN
|
|
20
|
+
? useIntercom(env.INTERCOM_TOKEN, axiom)
|
|
21
|
+
: undefined;
|
|
22
|
+
const juneso = env.JUNESO_TOKEN ? new Analytics(env.JUNESO_TOKEN) : undefined;
|
|
23
|
+
const posthog = env.POSTHOG_TOKEN
|
|
24
|
+
? new PostHog(env.POSTHOG_TOKEN, {
|
|
25
|
+
host: 'https://app.posthog.com',
|
|
26
|
+
})
|
|
27
|
+
: undefined;
|
|
24
28
|
return {
|
|
25
29
|
// General
|
|
26
30
|
track: async ({ userId, groupId, event, properties, }) => {
|
|
27
31
|
if (isDev || isTest(userId, groupId))
|
|
28
32
|
return;
|
|
29
|
-
posthog
|
|
33
|
+
posthog?.capture({
|
|
30
34
|
distinctId: userId,
|
|
31
35
|
event,
|
|
32
36
|
groups: {
|
|
@@ -34,14 +38,14 @@ export const useTracking = ({ dataset, env, name }, isDev) => {
|
|
|
34
38
|
},
|
|
35
39
|
properties,
|
|
36
40
|
});
|
|
37
|
-
juneso
|
|
41
|
+
juneso?.track({
|
|
38
42
|
userId,
|
|
39
43
|
event,
|
|
40
44
|
properties,
|
|
41
45
|
context: { groupId },
|
|
42
46
|
});
|
|
43
47
|
try {
|
|
44
|
-
await intercom
|
|
48
|
+
await intercom?.trackEvent({
|
|
45
49
|
user_id: userId,
|
|
46
50
|
event_name: event,
|
|
47
51
|
metadata: properties,
|
|
@@ -54,12 +58,12 @@ export const useTracking = ({ dataset, env, name }, isDev) => {
|
|
|
54
58
|
identify: ({ traits, userId, disableGeoip, }) => {
|
|
55
59
|
if (isDev || isTest(userId))
|
|
56
60
|
return;
|
|
57
|
-
posthog
|
|
61
|
+
posthog?.identify({
|
|
58
62
|
distinctId: userId,
|
|
59
63
|
properties: traits,
|
|
60
64
|
disableGeoip,
|
|
61
65
|
});
|
|
62
|
-
juneso
|
|
66
|
+
juneso?.identify({
|
|
63
67
|
userId,
|
|
64
68
|
traits,
|
|
65
69
|
});
|
|
@@ -67,21 +71,25 @@ export const useTracking = ({ dataset, env, name }, isDev) => {
|
|
|
67
71
|
group: ({ traits, groupId, userId, anonymousId, }) => {
|
|
68
72
|
if (isDev || isTest(userId || anonymousId || '', groupId))
|
|
69
73
|
return;
|
|
70
|
-
posthog
|
|
74
|
+
posthog?.groupIdentify({
|
|
71
75
|
groupKey: groupId,
|
|
72
76
|
groupType: 'tenant',
|
|
73
77
|
properties: traits,
|
|
74
78
|
distinctId: userId,
|
|
75
79
|
});
|
|
76
80
|
if (anonymousId)
|
|
77
|
-
juneso
|
|
81
|
+
juneso?.group({ anonymousId, groupId, traits });
|
|
78
82
|
else if (userId)
|
|
79
|
-
juneso
|
|
83
|
+
juneso?.group({ userId, groupId, traits });
|
|
80
84
|
},
|
|
81
|
-
shutdown: async () => Promise.all([
|
|
85
|
+
shutdown: async () => Promise.all([
|
|
86
|
+
posthog?.shutdown(),
|
|
87
|
+
juneso?.closeAndFlush(),
|
|
88
|
+
axiom.flush(),
|
|
89
|
+
]),
|
|
82
90
|
// Posthog specific
|
|
83
|
-
alias: posthog
|
|
84
|
-
isFeatureEnabled: posthog
|
|
91
|
+
alias: posthog?.alias,
|
|
92
|
+
isFeatureEnabled: posthog?.isFeatureEnabled,
|
|
85
93
|
// export intercom and axiom
|
|
86
94
|
intercom,
|
|
87
95
|
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,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAEzC,MAAM,cAAc,GAAG;IACrB,sCAAsC,EAAE,4BAA4B;IACpE,sCAAsC,EAAE,iCAAiC;IACzE,sCAAsC,EAAE,gCAAgC;IACxE,sCAAsC,EAAE,2BAA2B;CACpE,CAAC;AACF,MAAM,cAAc,GAAG;IACrB,sCAAsC,EAAE,wBAAwB;IAChE,sCAAsC,EAAE,oBAAoB;CAC7D,CAAC;AAEF,MAAM,MAAM,GAAG,CAAC,MAAc,EAAE,OAAgB,EAAE,EAAE,CAClD,cAAc,CAAC,QAAQ,CAAC,MAAM,CAAC;IAC/B,CAAC,OAAO,IAAI,cAAc,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC;AAsBhD,MAAM,CAAC,MAAM,WAAW,GAAG,CACzB,EAAE,OAAO,EAAE,GAAG,EAAE,IAAI,EAAiB,EACrC,KAAe,EACf,EAAE;IACF,MAAM,KAAK,GAAG,MAAM,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,CAAC;IAC7C,MAAM,QAAQ,GAAG,WAAW,CAAC,GAAG,CAAC,cAAc,EAAE,KAAK,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","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I,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
|
@@ -23,8 +23,8 @@ export type TrackingProps = {
|
|
|
23
23
|
dataset: string;
|
|
24
24
|
env: {
|
|
25
25
|
INTERCOM_TOKEN: string;
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
JUNESO_TOKEN: string;
|
|
27
|
+
POSTHOG_TOKEN: string;
|
|
28
28
|
};
|
|
29
29
|
};
|
|
30
30
|
export type Tracking = ReturnType<typeof useTracking>;
|
|
@@ -43,11 +43,15 @@ export const useTracking = (
|
|
|
43
43
|
isDev?: boolean
|
|
44
44
|
) => {
|
|
45
45
|
const axiom = useLog({ name, dataset, env });
|
|
46
|
-
const intercom =
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
46
|
+
const intercom = env.INTERCOM_TOKEN
|
|
47
|
+
? useIntercom(env.INTERCOM_TOKEN, axiom)
|
|
48
|
+
: undefined;
|
|
49
|
+
const juneso = env.JUNESO_TOKEN ? new Analytics(env.JUNESO_TOKEN) : undefined;
|
|
50
|
+
const posthog = env.POSTHOG_TOKEN
|
|
51
|
+
? new PostHog(env.POSTHOG_TOKEN, {
|
|
52
|
+
host: 'https://app.posthog.com',
|
|
53
|
+
})
|
|
54
|
+
: undefined;
|
|
51
55
|
|
|
52
56
|
return {
|
|
53
57
|
// General
|
|
@@ -64,7 +68,7 @@ export const useTracking = (
|
|
|
64
68
|
}) => {
|
|
65
69
|
if (isDev || isTest(userId, groupId)) return;
|
|
66
70
|
|
|
67
|
-
posthog
|
|
71
|
+
posthog?.capture({
|
|
68
72
|
distinctId: userId,
|
|
69
73
|
event,
|
|
70
74
|
groups: {
|
|
@@ -72,7 +76,7 @@ export const useTracking = (
|
|
|
72
76
|
},
|
|
73
77
|
properties,
|
|
74
78
|
});
|
|
75
|
-
juneso
|
|
79
|
+
juneso?.track({
|
|
76
80
|
userId,
|
|
77
81
|
event,
|
|
78
82
|
properties,
|
|
@@ -80,7 +84,7 @@ export const useTracking = (
|
|
|
80
84
|
});
|
|
81
85
|
|
|
82
86
|
try {
|
|
83
|
-
await intercom
|
|
87
|
+
await intercom?.trackEvent({
|
|
84
88
|
user_id: userId,
|
|
85
89
|
event_name: event,
|
|
86
90
|
metadata: properties,
|
|
@@ -100,12 +104,12 @@ export const useTracking = (
|
|
|
100
104
|
}) => {
|
|
101
105
|
if (isDev || isTest(userId)) return;
|
|
102
106
|
|
|
103
|
-
posthog
|
|
107
|
+
posthog?.identify({
|
|
104
108
|
distinctId: userId,
|
|
105
109
|
properties: traits,
|
|
106
110
|
disableGeoip,
|
|
107
111
|
});
|
|
108
|
-
juneso
|
|
112
|
+
juneso?.identify({
|
|
109
113
|
userId,
|
|
110
114
|
traits,
|
|
111
115
|
});
|
|
@@ -121,20 +125,24 @@ export const useTracking = (
|
|
|
121
125
|
}>) => {
|
|
122
126
|
if (isDev || isTest(userId || anonymousId || '', groupId)) return;
|
|
123
127
|
|
|
124
|
-
posthog
|
|
128
|
+
posthog?.groupIdentify({
|
|
125
129
|
groupKey: groupId,
|
|
126
130
|
groupType: 'tenant',
|
|
127
131
|
properties: traits,
|
|
128
132
|
distinctId: userId,
|
|
129
133
|
});
|
|
130
|
-
if (anonymousId) juneso
|
|
131
|
-
else if (userId) juneso
|
|
134
|
+
if (anonymousId) juneso?.group({ anonymousId, groupId, traits });
|
|
135
|
+
else if (userId) juneso?.group({ userId, groupId, traits });
|
|
132
136
|
},
|
|
133
137
|
shutdown: async () =>
|
|
134
|
-
Promise.all([
|
|
138
|
+
Promise.all([
|
|
139
|
+
posthog?.shutdown(),
|
|
140
|
+
juneso?.closeAndFlush(),
|
|
141
|
+
axiom.flush(),
|
|
142
|
+
]),
|
|
135
143
|
// Posthog specific
|
|
136
|
-
alias: posthog
|
|
137
|
-
isFeatureEnabled: posthog
|
|
144
|
+
alias: posthog?.alias,
|
|
145
|
+
isFeatureEnabled: posthog?.isFeatureEnabled,
|
|
138
146
|
// export intercom and axiom
|
|
139
147
|
intercom,
|
|
140
148
|
log: axiom,
|