@vrplatform/log 2.0.28 → 2.0.29
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 +0 -6
- package/build/main/tracking/index.js +5 -82
- package/build/main/tracking/index.js.map +1 -1
- package/build/main/tracking/types.d.ts +0 -3
- package/build/module/tracking/index.d.ts +0 -6
- package/build/module/tracking/index.js +6 -83
- package/build/module/tracking/index.js.map +1 -1
- package/build/module/tracking/types.d.ts +0 -3
- package/package.json +1 -3
- package/src/tracking/index.ts +4 -110
- package/src/tracking/types.ts +0 -3
|
@@ -85,9 +85,7 @@ declare module 'intercom-client' {
|
|
|
85
85
|
}
|
|
86
86
|
}
|
|
87
87
|
}
|
|
88
|
-
import { Analytics } from '@june-so/analytics-node';
|
|
89
88
|
import { Intercom } from 'intercom-client';
|
|
90
|
-
import { PostHog } from 'posthog-node';
|
|
91
89
|
import { type LogBindings, type WorkerLog } from '../log';
|
|
92
90
|
import type { GroupProps, IdentifyProps, TrackProps, TrackingEvent } from './types';
|
|
93
91
|
export * from './types';
|
|
@@ -99,8 +97,6 @@ export type UseTracking = {
|
|
|
99
97
|
dataset: string;
|
|
100
98
|
env: {
|
|
101
99
|
INTERCOM_TOKEN?: string;
|
|
102
|
-
JUNESO_TOKEN?: string;
|
|
103
|
-
POSTHOG_TOKEN?: string;
|
|
104
100
|
HASURA_GRAPHQL_ADMIN_SECRET?: string;
|
|
105
101
|
HASURA_ADMIN_SECRET?: string;
|
|
106
102
|
} & LogBindings;
|
|
@@ -112,7 +108,5 @@ export declare const useTracking: ({ dataset, env, name }: UseTracking, isDev?:
|
|
|
112
108
|
group: (props: GroupProps) => Promise<void>;
|
|
113
109
|
shutdown: () => Promise<any>;
|
|
114
110
|
log: WorkerLog;
|
|
115
|
-
june?: Analytics;
|
|
116
111
|
intercom?: Intercom;
|
|
117
|
-
posthog?: PostHog;
|
|
118
112
|
};
|
|
@@ -16,9 +16,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
exports.useTracking = void 0;
|
|
18
18
|
const graphql_1 = require("@finalytic/graphql");
|
|
19
|
-
const analytics_node_1 = require("@june-so/analytics-node");
|
|
20
19
|
const intercom_client_1 = require("intercom-client");
|
|
21
|
-
const posthog_node_1 = require("posthog-node");
|
|
22
20
|
const log_1 = require("../log");
|
|
23
21
|
const utils_1 = require("../utils");
|
|
24
22
|
const convertValuesToString_1 = require("../utils/convertValuesToString");
|
|
@@ -42,12 +40,6 @@ const useTracking = ({ dataset, env, name }, isDev) => {
|
|
|
42
40
|
// }),
|
|
43
41
|
})
|
|
44
42
|
: undefined;
|
|
45
|
-
const june = env.JUNESO_TOKEN ? new analytics_node_1.Analytics(env.JUNESO_TOKEN) : undefined;
|
|
46
|
-
const posthog = env.POSTHOG_TOKEN
|
|
47
|
-
? new posthog_node_1.PostHog(env.POSTHOG_TOKEN, {
|
|
48
|
-
host: 'https://app.posthog.com',
|
|
49
|
-
})
|
|
50
|
-
: undefined;
|
|
51
43
|
return {
|
|
52
44
|
// General
|
|
53
45
|
track: async ({ userId, anonymousId, groupId, event, packageName, properties, timestamp = new Date(), }) => {
|
|
@@ -63,48 +55,7 @@ const useTracking = ({ dataset, env, name }, isDev) => {
|
|
|
63
55
|
packageName,
|
|
64
56
|
},
|
|
65
57
|
}).id);
|
|
66
|
-
if (
|
|
67
|
-
posthog?.capture({
|
|
68
|
-
distinctId: anonymousId,
|
|
69
|
-
event,
|
|
70
|
-
groups: {
|
|
71
|
-
tenant: groupId,
|
|
72
|
-
},
|
|
73
|
-
timestamp,
|
|
74
|
-
properties: (0, utils_1.convertKeysToSnakeCase)(properties),
|
|
75
|
-
});
|
|
76
|
-
june?.track({
|
|
77
|
-
anonymousId,
|
|
78
|
-
event,
|
|
79
|
-
properties,
|
|
80
|
-
timestamp,
|
|
81
|
-
context: { groupId },
|
|
82
|
-
}, (err) => {
|
|
83
|
-
if (err)
|
|
84
|
-
console.error(err);
|
|
85
|
-
});
|
|
86
|
-
// no intercom for anonymous
|
|
87
|
-
}
|
|
88
|
-
else if (userId) {
|
|
89
|
-
posthog?.capture({
|
|
90
|
-
distinctId: userId,
|
|
91
|
-
event,
|
|
92
|
-
groups: {
|
|
93
|
-
tenant: groupId,
|
|
94
|
-
},
|
|
95
|
-
timestamp,
|
|
96
|
-
properties: (0, utils_1.convertKeysToSnakeCase)(properties),
|
|
97
|
-
});
|
|
98
|
-
june?.track({
|
|
99
|
-
userId,
|
|
100
|
-
event,
|
|
101
|
-
properties,
|
|
102
|
-
timestamp,
|
|
103
|
-
context: { groupId },
|
|
104
|
-
}, (err) => {
|
|
105
|
-
if (err)
|
|
106
|
-
console.error(err);
|
|
107
|
-
});
|
|
58
|
+
if (userId) {
|
|
108
59
|
try {
|
|
109
60
|
await intercom?.dataEvents.create({
|
|
110
61
|
body: {
|
|
@@ -120,19 +71,9 @@ const useTracking = ({ dataset, env, name }, isDev) => {
|
|
|
120
71
|
}
|
|
121
72
|
}
|
|
122
73
|
},
|
|
123
|
-
identify: async ({ traits, userId
|
|
74
|
+
identify: async ({ traits, userId }) => {
|
|
124
75
|
if (isDev || (0, utils_1.isTest)(userId))
|
|
125
76
|
return;
|
|
126
|
-
posthog?.identify({
|
|
127
|
-
distinctId: userId,
|
|
128
|
-
properties: (0, utils_1.convertKeysToSnakeCase)(traits),
|
|
129
|
-
disableGeoip,
|
|
130
|
-
});
|
|
131
|
-
june?.identify({
|
|
132
|
-
userId,
|
|
133
|
-
traits,
|
|
134
|
-
timestamp,
|
|
135
|
-
}, (err) => (err ? console.error(err) : {}));
|
|
136
77
|
// upsert intercom user
|
|
137
78
|
try {
|
|
138
79
|
const data = {
|
|
@@ -169,7 +110,7 @@ const useTracking = ({ dataset, env, name }, isDev) => {
|
|
|
169
110
|
console.error(e);
|
|
170
111
|
}
|
|
171
112
|
},
|
|
172
|
-
group: async ({ traits = {}, groupId, userId, anonymousId,
|
|
113
|
+
group: async ({ traits = {}, groupId, userId, anonymousId, }) => {
|
|
173
114
|
if (isDev || (0, utils_1.isTest)(userId || anonymousId || '', groupId))
|
|
174
115
|
return;
|
|
175
116
|
// add teamId to traits
|
|
@@ -221,23 +162,7 @@ const useTracking = ({ dataset, env, name }, isDev) => {
|
|
|
221
162
|
catch (e) {
|
|
222
163
|
console.error(e);
|
|
223
164
|
}
|
|
224
|
-
if (
|
|
225
|
-
posthog?.groupIdentify({
|
|
226
|
-
groupKey: groupId,
|
|
227
|
-
groupType: 'tenant',
|
|
228
|
-
properties: (0, utils_1.convertKeysToSnakeCase)(traits),
|
|
229
|
-
distinctId: anonymousId,
|
|
230
|
-
});
|
|
231
|
-
june?.group({ anonymousId, groupId, traits, timestamp }, (err) => err ? console.error(err) : {});
|
|
232
|
-
}
|
|
233
|
-
else if (userId) {
|
|
234
|
-
posthog?.groupIdentify({
|
|
235
|
-
groupKey: groupId,
|
|
236
|
-
groupType: 'tenant',
|
|
237
|
-
properties: (0, utils_1.convertKeysToSnakeCase)(traits),
|
|
238
|
-
distinctId: userId,
|
|
239
|
-
});
|
|
240
|
-
june?.group({ userId, groupId, traits, timestamp }, (err) => err ? console.error(err) : {});
|
|
165
|
+
if (userId) {
|
|
241
166
|
// attach intercom user to intercom company
|
|
242
167
|
try {
|
|
243
168
|
const intercomUser = (await intercom?.contacts.search({
|
|
@@ -257,11 +182,9 @@ const useTracking = ({ dataset, env, name }, isDev) => {
|
|
|
257
182
|
}
|
|
258
183
|
}
|
|
259
184
|
},
|
|
260
|
-
shutdown: async () =>
|
|
185
|
+
shutdown: async () => log?.flush(),
|
|
261
186
|
// export dependencies
|
|
262
187
|
intercom,
|
|
263
|
-
posthog,
|
|
264
|
-
june,
|
|
265
188
|
log,
|
|
266
189
|
};
|
|
267
190
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"src/","sources":["tracking/index.ts"],"names":[],"mappings":";;;;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AQ,EAAE,QAAQ,CAAC,SAAS,CAAC,MAAM,CAAC,YAAY,EAAE,EAAE,EAAE;4BACpD,UAAU,EAAE,eAAe,EAAE,EAAE;yBAChC,CAAC,CAAC;gBACP,CAAC;gBAAC,OAAO,CAAC,EAAE,CAAC;oBACX,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;gBACnB,CAAC;YACH,CAAC;QACH,CAAC;QACD,QAAQ,EAAE,KAAK,IAAI,EAAE,CAAC,GAAG,EAAE,KAAK,EAAE;QAClC,sBAAsB;QACtB,QAAQ;QACR,GAAG;KACJ,CAAC;AACJ,CAAC,CAAC;AAjMW,QAAA,WAAW,eAiMtB"}
|
|
@@ -24,8 +24,6 @@ export type IdentifyProps = {
|
|
|
24
24
|
role?: UserRole;
|
|
25
25
|
[key: string]: string | number | boolean | null | undefined;
|
|
26
26
|
};
|
|
27
|
-
disableGeoip?: boolean;
|
|
28
|
-
timestamp?: Date;
|
|
29
27
|
};
|
|
30
28
|
export type GroupProps = OptionalUser<{
|
|
31
29
|
groupId: string;
|
|
@@ -52,7 +50,6 @@ export type GroupProps = OptionalUser<{
|
|
|
52
50
|
trialUntil?: string;
|
|
53
51
|
[key: string]: string | number | boolean | null | undefined;
|
|
54
52
|
};
|
|
55
|
-
timestamp?: Date;
|
|
56
53
|
}>;
|
|
57
54
|
export type TrackingEventProps = {
|
|
58
55
|
account_invitation_accepted: AccountInvitationAcceptedProps;
|
|
@@ -85,9 +85,7 @@ declare module 'intercom-client' {
|
|
|
85
85
|
}
|
|
86
86
|
}
|
|
87
87
|
}
|
|
88
|
-
import { Analytics } from '@june-so/analytics-node';
|
|
89
88
|
import { Intercom } from 'intercom-client';
|
|
90
|
-
import { PostHog } from 'posthog-node';
|
|
91
89
|
import { type LogBindings, type WorkerLog } from '../log';
|
|
92
90
|
import type { GroupProps, IdentifyProps, TrackProps, TrackingEvent } from './types';
|
|
93
91
|
export * from './types';
|
|
@@ -99,8 +97,6 @@ export type UseTracking = {
|
|
|
99
97
|
dataset: string;
|
|
100
98
|
env: {
|
|
101
99
|
INTERCOM_TOKEN?: string;
|
|
102
|
-
JUNESO_TOKEN?: string;
|
|
103
|
-
POSTHOG_TOKEN?: string;
|
|
104
100
|
HASURA_GRAPHQL_ADMIN_SECRET?: string;
|
|
105
101
|
HASURA_ADMIN_SECRET?: string;
|
|
106
102
|
} & LogBindings;
|
|
@@ -112,7 +108,5 @@ export declare const useTracking: ({ dataset, env, name }: UseTracking, isDev?:
|
|
|
112
108
|
group: (props: GroupProps) => Promise<void>;
|
|
113
109
|
shutdown: () => Promise<any>;
|
|
114
110
|
log: WorkerLog;
|
|
115
|
-
june?: Analytics;
|
|
116
111
|
intercom?: Intercom;
|
|
117
|
-
posthog?: PostHog;
|
|
118
112
|
};
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { createClientV2 } from '@finalytic/graphql';
|
|
2
|
-
import { Analytics } from '@june-so/analytics-node';
|
|
3
2
|
import { Intercom } from 'intercom-client';
|
|
4
|
-
import { PostHog } from 'posthog-node';
|
|
5
3
|
import { useLog } from '../log';
|
|
6
|
-
import {
|
|
4
|
+
import { isTest } from '../utils';
|
|
7
5
|
import { convertValuesToString } from '../utils/convertValuesToString';
|
|
8
6
|
export * from './types';
|
|
9
7
|
export * from 'intercom-client';
|
|
@@ -25,12 +23,6 @@ export const useTracking = ({ dataset, env, name }, isDev) => {
|
|
|
25
23
|
// }),
|
|
26
24
|
})
|
|
27
25
|
: undefined;
|
|
28
|
-
const june = env.JUNESO_TOKEN ? new Analytics(env.JUNESO_TOKEN) : undefined;
|
|
29
|
-
const posthog = env.POSTHOG_TOKEN
|
|
30
|
-
? new PostHog(env.POSTHOG_TOKEN, {
|
|
31
|
-
host: 'https://app.posthog.com',
|
|
32
|
-
})
|
|
33
|
-
: undefined;
|
|
34
26
|
return {
|
|
35
27
|
// General
|
|
36
28
|
track: async ({ userId, anonymousId, groupId, event, packageName, properties, timestamp = new Date(), }) => {
|
|
@@ -46,48 +38,7 @@ export const useTracking = ({ dataset, env, name }, isDev) => {
|
|
|
46
38
|
packageName,
|
|
47
39
|
},
|
|
48
40
|
}).id);
|
|
49
|
-
if (
|
|
50
|
-
posthog?.capture({
|
|
51
|
-
distinctId: anonymousId,
|
|
52
|
-
event,
|
|
53
|
-
groups: {
|
|
54
|
-
tenant: groupId,
|
|
55
|
-
},
|
|
56
|
-
timestamp,
|
|
57
|
-
properties: convertKeysToSnakeCase(properties),
|
|
58
|
-
});
|
|
59
|
-
june?.track({
|
|
60
|
-
anonymousId,
|
|
61
|
-
event,
|
|
62
|
-
properties,
|
|
63
|
-
timestamp,
|
|
64
|
-
context: { groupId },
|
|
65
|
-
}, (err) => {
|
|
66
|
-
if (err)
|
|
67
|
-
console.error(err);
|
|
68
|
-
});
|
|
69
|
-
// no intercom for anonymous
|
|
70
|
-
}
|
|
71
|
-
else if (userId) {
|
|
72
|
-
posthog?.capture({
|
|
73
|
-
distinctId: userId,
|
|
74
|
-
event,
|
|
75
|
-
groups: {
|
|
76
|
-
tenant: groupId,
|
|
77
|
-
},
|
|
78
|
-
timestamp,
|
|
79
|
-
properties: convertKeysToSnakeCase(properties),
|
|
80
|
-
});
|
|
81
|
-
june?.track({
|
|
82
|
-
userId,
|
|
83
|
-
event,
|
|
84
|
-
properties,
|
|
85
|
-
timestamp,
|
|
86
|
-
context: { groupId },
|
|
87
|
-
}, (err) => {
|
|
88
|
-
if (err)
|
|
89
|
-
console.error(err);
|
|
90
|
-
});
|
|
41
|
+
if (userId) {
|
|
91
42
|
try {
|
|
92
43
|
await intercom?.dataEvents.create({
|
|
93
44
|
body: {
|
|
@@ -103,19 +54,9 @@ export const useTracking = ({ dataset, env, name }, isDev) => {
|
|
|
103
54
|
}
|
|
104
55
|
}
|
|
105
56
|
},
|
|
106
|
-
identify: async ({ traits, userId
|
|
57
|
+
identify: async ({ traits, userId }) => {
|
|
107
58
|
if (isDev || isTest(userId))
|
|
108
59
|
return;
|
|
109
|
-
posthog?.identify({
|
|
110
|
-
distinctId: userId,
|
|
111
|
-
properties: convertKeysToSnakeCase(traits),
|
|
112
|
-
disableGeoip,
|
|
113
|
-
});
|
|
114
|
-
june?.identify({
|
|
115
|
-
userId,
|
|
116
|
-
traits,
|
|
117
|
-
timestamp,
|
|
118
|
-
}, (err) => (err ? console.error(err) : {}));
|
|
119
60
|
// upsert intercom user
|
|
120
61
|
try {
|
|
121
62
|
const data = {
|
|
@@ -152,7 +93,7 @@ export const useTracking = ({ dataset, env, name }, isDev) => {
|
|
|
152
93
|
console.error(e);
|
|
153
94
|
}
|
|
154
95
|
},
|
|
155
|
-
group: async ({ traits = {}, groupId, userId, anonymousId,
|
|
96
|
+
group: async ({ traits = {}, groupId, userId, anonymousId, }) => {
|
|
156
97
|
if (isDev || isTest(userId || anonymousId || '', groupId))
|
|
157
98
|
return;
|
|
158
99
|
// add teamId to traits
|
|
@@ -204,23 +145,7 @@ export const useTracking = ({ dataset, env, name }, isDev) => {
|
|
|
204
145
|
catch (e) {
|
|
205
146
|
console.error(e);
|
|
206
147
|
}
|
|
207
|
-
if (
|
|
208
|
-
posthog?.groupIdentify({
|
|
209
|
-
groupKey: groupId,
|
|
210
|
-
groupType: 'tenant',
|
|
211
|
-
properties: convertKeysToSnakeCase(traits),
|
|
212
|
-
distinctId: anonymousId,
|
|
213
|
-
});
|
|
214
|
-
june?.group({ anonymousId, groupId, traits, timestamp }, (err) => err ? console.error(err) : {});
|
|
215
|
-
}
|
|
216
|
-
else if (userId) {
|
|
217
|
-
posthog?.groupIdentify({
|
|
218
|
-
groupKey: groupId,
|
|
219
|
-
groupType: 'tenant',
|
|
220
|
-
properties: convertKeysToSnakeCase(traits),
|
|
221
|
-
distinctId: userId,
|
|
222
|
-
});
|
|
223
|
-
june?.group({ userId, groupId, traits, timestamp }, (err) => err ? console.error(err) : {});
|
|
148
|
+
if (userId) {
|
|
224
149
|
// attach intercom user to intercom company
|
|
225
150
|
try {
|
|
226
151
|
const intercomUser = (await intercom?.contacts.search({
|
|
@@ -240,11 +165,9 @@ export const useTracking = ({ dataset, env, name }, isDev) => {
|
|
|
240
165
|
}
|
|
241
166
|
}
|
|
242
167
|
},
|
|
243
|
-
shutdown: async () =>
|
|
168
|
+
shutdown: async () => log?.flush(),
|
|
244
169
|
// export dependencies
|
|
245
170
|
intercom,
|
|
246
|
-
posthog,
|
|
247
|
-
june,
|
|
248
171
|
log,
|
|
249
172
|
};
|
|
250
173
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"src/","sources":["tracking/index.ts"],"names":[],"mappings":"AAoGA,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"src/","sources":["tracking/index.ts"],"names":[],"mappings":"AAoGA,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAoC,MAAM,EAAE,MAAM,QAAQ,CAAC;AAClE,OAAO,EAA0B,MAAM,EAAE,MAAM,UAAU,CAAC;AAC1D,OAAO,EAAE,qBAAqB,EAAE,MAAM,gCAAgC,CAAC;AAQvE,cAAc,SAAS,CAAC;AACxB,cAAc,iBAAiB,CAAC;AAChC,cAAc,UAAU,CAAC;AAczB,MAAM,CAAC,MAAM,WAAW,GAAG,CACzB,EAAE,OAAO,EAAE,GAAG,EAAE,IAAI,EAAe,EACnC,KAAe,EAQf,EAAE;IACF,MAAM,MAAM,GAAG,GAAG,CAAC,2BAA2B;QAC5C,CAAC,CAAC,cAAc,CAAC,yCAAyC,EAAE;YACxD,MAAM,EAAE,GAAG,CAAC,mBAAmB,IAAI,GAAG,CAAC,2BAA2B;SACnE,CAAC;QACJ,CAAC,CAAC,SAAS,CAAC;IACd,MAAM,GAAG,GAAG,MAAM,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,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AC,CAAC,SAAS;oBACb,aAAa,EAAE,MAAM,EAAE,GAAG;oBAC1B,iBAAiB;iBAClB,EACD,EAAE,CACH,CAAC;YACJ,CAAC;YAAC,OAAO,CAAC,EAAE,CAAC;gBACX,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;YACnB,CAAC;YAED,IAAI,MAAM,EAAE,CAAC;gBACX,2CAA2C;gBAC3C,IAAI,CAAC;oBACH,MAAM,YAAY,GAAG,CACnB,MAAM,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC;wBAC9B,KAAK,EAAE;4BACL,KAAK,EAAE,aAAa;4BACpB,QAAQ,EAAE,GAAG;4BACb,KAAK,EAAE,MAAM;yBACd;qBACF,CAAC,CACH,EAAE,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC;oBACf,IAAI,YAAY,EAAE,EAAE,IAAI,eAAe,EAAE,EAAE;wBACzC,QAAQ,EAAE,QAAQ,CAAC,SAAS,CAAC,MAAM,CAAC,YAAY,EAAE,EAAE,EAAE;4BACpD,UAAU,EAAE,eAAe,EAAE,EAAE;yBAChC,CAAC,CAAC;gBACP,CAAC;gBAAC,OAAO,CAAC,EAAE,CAAC;oBACX,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;gBACnB,CAAC;YACH,CAAC;QACH,CAAC;QACD,QAAQ,EAAE,KAAK,IAAI,EAAE,CAAC,GAAG,EAAE,KAAK,EAAE;QAClC,sBAAsB;QACtB,QAAQ;QACR,GAAG;KACJ,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -24,8 +24,6 @@ export type IdentifyProps = {
|
|
|
24
24
|
role?: UserRole;
|
|
25
25
|
[key: string]: string | number | boolean | null | undefined;
|
|
26
26
|
};
|
|
27
|
-
disableGeoip?: boolean;
|
|
28
|
-
timestamp?: Date;
|
|
29
27
|
};
|
|
30
28
|
export type GroupProps = OptionalUser<{
|
|
31
29
|
groupId: string;
|
|
@@ -52,7 +50,6 @@ export type GroupProps = OptionalUser<{
|
|
|
52
50
|
trialUntil?: string;
|
|
53
51
|
[key: string]: string | number | boolean | null | undefined;
|
|
54
52
|
};
|
|
55
|
-
timestamp?: Date;
|
|
56
53
|
}>;
|
|
57
54
|
export type TrackingEventProps = {
|
|
58
55
|
account_invitation_accepted: AccountInvitationAcceptedProps;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vrplatform/log",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.29",
|
|
4
4
|
"main": "build/main/index.js",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -19,9 +19,7 @@
|
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"@axiomhq/js": "1.0.0-rc.3",
|
|
21
21
|
"@finalytic/graphql": "1.12.133",
|
|
22
|
-
"@june-so/analytics-node": "8.0.0",
|
|
23
22
|
"intercom-client": "6.0.0-beta.3",
|
|
24
|
-
"posthog-node": "4.0.1",
|
|
25
23
|
"serialize-error": "11.0.3"
|
|
26
24
|
},
|
|
27
25
|
"devDependencies": {
|
package/src/tracking/index.ts
CHANGED
|
@@ -99,9 +99,7 @@ declare module 'intercom-client' {
|
|
|
99
99
|
}
|
|
100
100
|
|
|
101
101
|
import { createClientV2 } from '@finalytic/graphql';
|
|
102
|
-
import { Analytics } from '@june-so/analytics-node';
|
|
103
102
|
import { Intercom } from 'intercom-client';
|
|
104
|
-
import { PostHog } from 'posthog-node';
|
|
105
103
|
import { type LogBindings, type WorkerLog, useLog } from '../log';
|
|
106
104
|
import { convertKeysToSnakeCase, isTest } from '../utils';
|
|
107
105
|
import { convertValuesToString } from '../utils/convertValuesToString';
|
|
@@ -122,8 +120,6 @@ export type UseTracking = {
|
|
|
122
120
|
dataset: string;
|
|
123
121
|
env: {
|
|
124
122
|
INTERCOM_TOKEN?: string;
|
|
125
|
-
JUNESO_TOKEN?: string;
|
|
126
|
-
POSTHOG_TOKEN?: string;
|
|
127
123
|
HASURA_GRAPHQL_ADMIN_SECRET?: string;
|
|
128
124
|
HASURA_ADMIN_SECRET?: string;
|
|
129
125
|
} & LogBindings;
|
|
@@ -139,9 +135,7 @@ export const useTracking = (
|
|
|
139
135
|
group: (props: GroupProps) => Promise<void>;
|
|
140
136
|
shutdown: () => Promise<any>;
|
|
141
137
|
log: WorkerLog;
|
|
142
|
-
june?: Analytics;
|
|
143
138
|
intercom?: Intercom;
|
|
144
|
-
posthog?: PostHog;
|
|
145
139
|
} => {
|
|
146
140
|
const client = env.HASURA_GRAPHQL_ADMIN_SECRET
|
|
147
141
|
? createClientV2('https://finalytic.hasura.app/v1/graphql', {
|
|
@@ -159,12 +153,6 @@ export const useTracking = (
|
|
|
159
153
|
// }),
|
|
160
154
|
})
|
|
161
155
|
: undefined;
|
|
162
|
-
const june = env.JUNESO_TOKEN ? new Analytics(env.JUNESO_TOKEN) : undefined;
|
|
163
|
-
const posthog = env.POSTHOG_TOKEN
|
|
164
|
-
? new PostHog(env.POSTHOG_TOKEN, {
|
|
165
|
-
host: 'https://app.posthog.com',
|
|
166
|
-
})
|
|
167
|
-
: undefined;
|
|
168
156
|
|
|
169
157
|
return {
|
|
170
158
|
// General
|
|
@@ -193,55 +181,7 @@ export const useTracking = (
|
|
|
193
181
|
}).id
|
|
194
182
|
);
|
|
195
183
|
|
|
196
|
-
if (
|
|
197
|
-
posthog?.capture({
|
|
198
|
-
distinctId: anonymousId,
|
|
199
|
-
event,
|
|
200
|
-
groups: {
|
|
201
|
-
tenant: groupId,
|
|
202
|
-
},
|
|
203
|
-
timestamp,
|
|
204
|
-
properties: convertKeysToSnakeCase(properties),
|
|
205
|
-
});
|
|
206
|
-
|
|
207
|
-
june?.track(
|
|
208
|
-
{
|
|
209
|
-
anonymousId,
|
|
210
|
-
event,
|
|
211
|
-
properties,
|
|
212
|
-
timestamp,
|
|
213
|
-
context: { groupId },
|
|
214
|
-
},
|
|
215
|
-
(err) => {
|
|
216
|
-
if (err) console.error(err);
|
|
217
|
-
}
|
|
218
|
-
);
|
|
219
|
-
|
|
220
|
-
// no intercom for anonymous
|
|
221
|
-
} else if (userId) {
|
|
222
|
-
posthog?.capture({
|
|
223
|
-
distinctId: userId,
|
|
224
|
-
event,
|
|
225
|
-
groups: {
|
|
226
|
-
tenant: groupId,
|
|
227
|
-
},
|
|
228
|
-
timestamp,
|
|
229
|
-
properties: convertKeysToSnakeCase(properties),
|
|
230
|
-
});
|
|
231
|
-
|
|
232
|
-
june?.track(
|
|
233
|
-
{
|
|
234
|
-
userId,
|
|
235
|
-
event,
|
|
236
|
-
properties,
|
|
237
|
-
timestamp,
|
|
238
|
-
context: { groupId },
|
|
239
|
-
},
|
|
240
|
-
(err) => {
|
|
241
|
-
if (err) console.error(err);
|
|
242
|
-
}
|
|
243
|
-
);
|
|
244
|
-
|
|
184
|
+
if (userId) {
|
|
245
185
|
try {
|
|
246
186
|
await intercom?.dataEvents.create({
|
|
247
187
|
body: {
|
|
@@ -256,29 +196,9 @@ export const useTracking = (
|
|
|
256
196
|
}
|
|
257
197
|
}
|
|
258
198
|
},
|
|
259
|
-
identify: async ({
|
|
260
|
-
traits,
|
|
261
|
-
userId,
|
|
262
|
-
disableGeoip,
|
|
263
|
-
timestamp = new Date(),
|
|
264
|
-
}: IdentifyProps) => {
|
|
199
|
+
identify: async ({ traits, userId }: IdentifyProps) => {
|
|
265
200
|
if (isDev || isTest(userId)) return;
|
|
266
201
|
|
|
267
|
-
posthog?.identify({
|
|
268
|
-
distinctId: userId,
|
|
269
|
-
properties: convertKeysToSnakeCase(traits),
|
|
270
|
-
disableGeoip,
|
|
271
|
-
});
|
|
272
|
-
|
|
273
|
-
june?.identify(
|
|
274
|
-
{
|
|
275
|
-
userId,
|
|
276
|
-
traits,
|
|
277
|
-
timestamp,
|
|
278
|
-
},
|
|
279
|
-
(err) => (err ? console.error(err) : {})
|
|
280
|
-
);
|
|
281
|
-
|
|
282
202
|
// upsert intercom user
|
|
283
203
|
try {
|
|
284
204
|
const data = {
|
|
@@ -322,7 +242,6 @@ export const useTracking = (
|
|
|
322
242
|
groupId,
|
|
323
243
|
userId,
|
|
324
244
|
anonymousId,
|
|
325
|
-
timestamp = new Date(),
|
|
326
245
|
}: GroupProps) => {
|
|
327
246
|
if (isDev || isTest(userId || anonymousId || '', groupId)) return;
|
|
328
247
|
|
|
@@ -374,29 +293,7 @@ export const useTracking = (
|
|
|
374
293
|
console.error(e);
|
|
375
294
|
}
|
|
376
295
|
|
|
377
|
-
if (
|
|
378
|
-
posthog?.groupIdentify({
|
|
379
|
-
groupKey: groupId,
|
|
380
|
-
groupType: 'tenant',
|
|
381
|
-
properties: convertKeysToSnakeCase(traits),
|
|
382
|
-
distinctId: anonymousId,
|
|
383
|
-
});
|
|
384
|
-
|
|
385
|
-
june?.group({ anonymousId, groupId, traits, timestamp }, (err) =>
|
|
386
|
-
err ? console.error(err) : {}
|
|
387
|
-
);
|
|
388
|
-
} else if (userId) {
|
|
389
|
-
posthog?.groupIdentify({
|
|
390
|
-
groupKey: groupId,
|
|
391
|
-
groupType: 'tenant',
|
|
392
|
-
properties: convertKeysToSnakeCase(traits),
|
|
393
|
-
distinctId: userId,
|
|
394
|
-
});
|
|
395
|
-
|
|
396
|
-
june?.group({ userId, groupId, traits, timestamp }, (err) =>
|
|
397
|
-
err ? console.error(err) : {}
|
|
398
|
-
);
|
|
399
|
-
|
|
296
|
+
if (userId) {
|
|
400
297
|
// attach intercom user to intercom company
|
|
401
298
|
try {
|
|
402
299
|
const intercomUser = (
|
|
@@ -417,12 +314,9 @@ export const useTracking = (
|
|
|
417
314
|
}
|
|
418
315
|
}
|
|
419
316
|
},
|
|
420
|
-
shutdown: async () =>
|
|
421
|
-
Promise.all([posthog?.shutdown(), june?.closeAndFlush(), log?.flush()]),
|
|
317
|
+
shutdown: async () => log?.flush(),
|
|
422
318
|
// export dependencies
|
|
423
319
|
intercom,
|
|
424
|
-
posthog,
|
|
425
|
-
june,
|
|
426
320
|
log,
|
|
427
321
|
};
|
|
428
322
|
};
|
package/src/tracking/types.ts
CHANGED
|
@@ -36,8 +36,6 @@ export type IdentifyProps = {
|
|
|
36
36
|
role?: UserRole;
|
|
37
37
|
[key: string]: string | number | boolean | null | undefined;
|
|
38
38
|
};
|
|
39
|
-
disableGeoip?: boolean;
|
|
40
|
-
timestamp?: Date;
|
|
41
39
|
};
|
|
42
40
|
|
|
43
41
|
export type GroupProps = OptionalUser<{
|
|
@@ -65,7 +63,6 @@ export type GroupProps = OptionalUser<{
|
|
|
65
63
|
trialUntil?: string;
|
|
66
64
|
[key: string]: string | number | boolean | null | undefined;
|
|
67
65
|
};
|
|
68
|
-
timestamp?: Date;
|
|
69
66
|
}>;
|
|
70
67
|
|
|
71
68
|
export type TrackingEventProps = {
|