@vrplatform/log 2.0.0-alpha.12 → 2.0.0-alpha.14
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 +35 -18
- package/build/main/tracking/index.js +55 -22
- package/build/main/tracking/index.js.map +1 -1
- package/build/module/tracking/index.d.ts +35 -18
- package/build/module/tracking/index.js +49 -18
- package/build/module/tracking/index.js.map +1 -1
- package/package.json +1 -1
- package/src/tracking/index.ts +77 -44
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { Analytics } from '@june-so/analytics-node';
|
|
2
2
|
import { PostHog } from 'posthog-node';
|
|
3
|
+
export declare const isTest: (userId: string, groupId?: string, userEmail?: string) => boolean | "" | undefined;
|
|
4
|
+
export declare const convertKeysToSnakeCase: (obj?: Record<string, any>) => Record<string, any>;
|
|
3
5
|
type AuthEvent = 'account_signin_completed' | 'account_signup_code_requested' | 'account_signup_code_completed' | 'account_signup_code_failed' | 'account_signup_completed' | 'account_password_reset_requested' | 'account_password_reset_failed' | 'account_password_reset_completed' | 'account_invitation_accepted' | 'account_signed_out';
|
|
4
6
|
type TeamEvent = 'team_added' | 'team_info_updated' | 'team_deleted' | 'team_member_removed';
|
|
5
7
|
type ConnectionEvent = 'connection_created' | 'connection_reconnected' | 'connection_deleted' | 'connection_requested';
|
|
@@ -20,8 +22,26 @@ export type TrackingProps = {
|
|
|
20
22
|
JUNESO_TOKEN?: string;
|
|
21
23
|
POSTHOG_TOKEN?: string;
|
|
22
24
|
};
|
|
25
|
+
debugging?: boolean;
|
|
23
26
|
};
|
|
24
27
|
export type Tracking = ReturnType<typeof useTracking>;
|
|
28
|
+
type TrackProps = {
|
|
29
|
+
userId: string;
|
|
30
|
+
groupId: string;
|
|
31
|
+
event: TrackingEvent;
|
|
32
|
+
properties: Record<string, string | number | boolean | null | undefined>;
|
|
33
|
+
};
|
|
34
|
+
type IdentifyProps = {
|
|
35
|
+
userId: string;
|
|
36
|
+
traits: Record<string, any>;
|
|
37
|
+
disableGeoip?: boolean;
|
|
38
|
+
timestamp?: Date;
|
|
39
|
+
};
|
|
40
|
+
type GroupProps = OptionalUser<{
|
|
41
|
+
groupId: string;
|
|
42
|
+
traits?: Record<string, any>;
|
|
43
|
+
timestamp?: Date;
|
|
44
|
+
}>;
|
|
25
45
|
type OptionalUser<T> = T & ({
|
|
26
46
|
userId: string;
|
|
27
47
|
anonymousId?: string;
|
|
@@ -29,24 +49,21 @@ type OptionalUser<T> = T & ({
|
|
|
29
49
|
userId?: string;
|
|
30
50
|
anonymousId: string;
|
|
31
51
|
});
|
|
32
|
-
export declare const useTracking: ({ dataset, env, name }: TrackingProps, isDev?: boolean) => {
|
|
33
|
-
track: (
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}) => void
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
traits?: Record<string, any>;
|
|
48
|
-
timestamp?: Date;
|
|
49
|
-
}>) => void;
|
|
52
|
+
export declare const useTracking: ({ dataset, env, name, debugging }: TrackingProps, isDev?: boolean) => {
|
|
53
|
+
track: (props: TrackProps) => void;
|
|
54
|
+
identify: (props: IdentifyProps) => void;
|
|
55
|
+
group: (props: GroupProps) => void;
|
|
56
|
+
log: Console;
|
|
57
|
+
june: {};
|
|
58
|
+
intercom: {};
|
|
59
|
+
posthog: {};
|
|
60
|
+
shutdown?: undefined;
|
|
61
|
+
alias?: undefined;
|
|
62
|
+
isFeatureEnabled?: undefined;
|
|
63
|
+
} | {
|
|
64
|
+
track: ({ userId, groupId, event, properties }: TrackProps) => Promise<void>;
|
|
65
|
+
identify: ({ traits, userId, disableGeoip, timestamp }: IdentifyProps) => void;
|
|
66
|
+
group: ({ traits, groupId, userId, anonymousId, timestamp, }: GroupProps) => void;
|
|
50
67
|
shutdown: () => Promise<[void | undefined, void | undefined, void]>;
|
|
51
68
|
alias: ((data: {
|
|
52
69
|
distinctId: string;
|
|
@@ -1,23 +1,56 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useTracking = void 0;
|
|
3
|
+
exports.useTracking = exports.convertKeysToSnakeCase = exports.isTest = void 0;
|
|
4
4
|
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
|
-
'
|
|
10
|
-
'
|
|
11
|
-
'
|
|
12
|
-
'
|
|
13
|
-
|
|
14
|
-
const E2E_TEST_TEAMS =
|
|
15
|
-
'c4fd21b4-8447-43a2-bdcb-f06a85a935ad',
|
|
16
|
-
'8f21060e-afe6-410a-b2f4-00a3caa20786',
|
|
17
|
-
|
|
18
|
-
const isTest = (userId, groupId) => E2E_TEST_USERS.includes(userId) ||
|
|
19
|
-
(groupId && E2E_TEST_TEAMS.includes(groupId))
|
|
20
|
-
|
|
8
|
+
const E2E_TEST_USERS = {
|
|
9
|
+
'e2e-invite-member@finalytic.io': '113d73d8-ee21-46b7-a12a-a74f632401ca',
|
|
10
|
+
'e2e-invite-owner@finalytic.io': '917b7c4e-cb03-491c-9e94-d33a5bdeca05',
|
|
11
|
+
'e2e-sign-up@finalytic.io': 'ec8e5572-74d0-4ae6-af73-bca8db9a27e9',
|
|
12
|
+
'lars+checkly@finalytic.co': '9e7dfc88-503c-4222-9905-9116169d2203',
|
|
13
|
+
};
|
|
14
|
+
const E2E_TEST_TEAMS = {
|
|
15
|
+
'VRP Automated Testing': 'c4fd21b4-8447-43a2-bdcb-f06a85a935ad',
|
|
16
|
+
test_company_xxxx: '8f21060e-afe6-410a-b2f4-00a3caa20786',
|
|
17
|
+
};
|
|
18
|
+
const isTest = (userId, groupId, userEmail) => Object.values(E2E_TEST_USERS).includes(userId) ||
|
|
19
|
+
(groupId && Object.values(E2E_TEST_TEAMS).includes(groupId)) ||
|
|
20
|
+
(userEmail && Object.keys(E2E_TEST_USERS).includes(userEmail));
|
|
21
|
+
exports.isTest = isTest;
|
|
22
|
+
const camelToSnakeCase = (str) => str.replace(/([a-z])([A-Z])/g, '$1_$2').toLowerCase();
|
|
23
|
+
// todo: move to utils
|
|
24
|
+
const convertKeysToSnakeCase = (obj) => {
|
|
25
|
+
const result = {};
|
|
26
|
+
const hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
27
|
+
for (const key in obj) {
|
|
28
|
+
if (hasOwnProperty.call(obj, key)) {
|
|
29
|
+
const snakeKey = camelToSnakeCase(key);
|
|
30
|
+
if (typeof obj[key] === 'object' &&
|
|
31
|
+
!Array.isArray(obj[key]) &&
|
|
32
|
+
obj[key] !== null) {
|
|
33
|
+
result[snakeKey] = (0, exports.convertKeysToSnakeCase)(obj[key]);
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
result[snakeKey] = obj[key];
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return result;
|
|
41
|
+
};
|
|
42
|
+
exports.convertKeysToSnakeCase = convertKeysToSnakeCase;
|
|
43
|
+
const useTracking = ({ dataset, env, name, debugging }, isDev) => {
|
|
44
|
+
if (debugging)
|
|
45
|
+
return {
|
|
46
|
+
track: (props) => console.log(props),
|
|
47
|
+
identify: (props) => console.log(props),
|
|
48
|
+
group: (props) => console.log(props),
|
|
49
|
+
log: console,
|
|
50
|
+
june: {},
|
|
51
|
+
intercom: {},
|
|
52
|
+
posthog: {},
|
|
53
|
+
};
|
|
21
54
|
const axiom = (0, log_1.useLog)({ name, dataset, env });
|
|
22
55
|
const intercom = env.INTERCOM_TOKEN
|
|
23
56
|
? (0, intercom_1.useIntercom)(env.INTERCOM_TOKEN, axiom)
|
|
@@ -30,8 +63,8 @@ const useTracking = ({ dataset, env, name }, isDev) => {
|
|
|
30
63
|
: undefined;
|
|
31
64
|
return {
|
|
32
65
|
// General
|
|
33
|
-
track: async ({ userId, groupId, event, properties
|
|
34
|
-
if (isDev || isTest(userId, groupId))
|
|
66
|
+
track: async ({ userId, groupId, event, properties }) => {
|
|
67
|
+
if (isDev || (0, exports.isTest)(userId, groupId))
|
|
35
68
|
return;
|
|
36
69
|
posthog?.capture({
|
|
37
70
|
distinctId: userId,
|
|
@@ -39,7 +72,7 @@ const useTracking = ({ dataset, env, name }, isDev) => {
|
|
|
39
72
|
groups: {
|
|
40
73
|
tenant: groupId,
|
|
41
74
|
},
|
|
42
|
-
properties,
|
|
75
|
+
properties: (0, exports.convertKeysToSnakeCase)(properties),
|
|
43
76
|
});
|
|
44
77
|
juneso?.track({
|
|
45
78
|
userId,
|
|
@@ -61,12 +94,12 @@ const useTracking = ({ dataset, env, name }, isDev) => {
|
|
|
61
94
|
console.error(error);
|
|
62
95
|
}
|
|
63
96
|
},
|
|
64
|
-
identify: ({ traits, userId, disableGeoip, timestamp
|
|
65
|
-
if (isDev || isTest(userId))
|
|
97
|
+
identify: ({ traits, userId, disableGeoip, timestamp }) => {
|
|
98
|
+
if (isDev || (0, exports.isTest)(userId))
|
|
66
99
|
return;
|
|
67
100
|
posthog?.identify({
|
|
68
101
|
distinctId: userId,
|
|
69
|
-
properties: traits,
|
|
102
|
+
properties: (0, exports.convertKeysToSnakeCase)(traits),
|
|
70
103
|
disableGeoip,
|
|
71
104
|
});
|
|
72
105
|
juneso?.identify({
|
|
@@ -79,12 +112,12 @@ const useTracking = ({ dataset, env, name }, isDev) => {
|
|
|
79
112
|
});
|
|
80
113
|
},
|
|
81
114
|
group: ({ traits, groupId, userId, anonymousId, timestamp, }) => {
|
|
82
|
-
if (isDev || isTest(userId || anonymousId || '', groupId))
|
|
115
|
+
if (isDev || (0, exports.isTest)(userId || anonymousId || '', groupId))
|
|
83
116
|
return;
|
|
84
117
|
posthog?.groupIdentify({
|
|
85
118
|
groupKey: groupId,
|
|
86
119
|
groupType: 'tenant',
|
|
87
|
-
properties: traits,
|
|
120
|
+
properties: (0, exports.convertKeysToSnakeCase)(traits),
|
|
88
121
|
distinctId: userId,
|
|
89
122
|
});
|
|
90
123
|
if (anonymousId)
|
|
@@ -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,
|
|
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,gCAAgC,EAAE,sCAAsC;IACxE,+BAA+B,EAAE,sCAAsC;IACvE,0BAA0B,EAAE,sCAAsC;IAClE,2BAA2B,EAAE,sCAAsC;CACpE,CAAC;AAEF,MAAM,cAAc,GAAG;IACrB,uBAAuB,EAAE,sCAAsC;IAC/D,iBAAiB,EAAE,sCAAsC;CAC1D,CAAC;AAEK,MAAM,MAAM,GAAG,CAAC,MAAc,EAAE,OAAgB,EAAE,SAAkB,EAAE,EAAE,CAC7E,MAAM,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC;IAC9C,CAAC,OAAO,IAAI,MAAM,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;IAC5D,CAAC,SAAS,IAAI,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC;AAHpD,QAAA,MAAM,UAG8C;AAEjE,MAAM,gBAAgB,GAAG,CAAC,GAAW,EAAE,EAAE,CACvC,GAAG,CAAC,OAAO,CAAC,iBAAiB,EAAE,OAAO,CAAC,CAAC,WAAW,EAAE,CAAC;AAExD,sBAA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,SAAS,EAAE,EAAE,CAAC,GAAG,EAAE,EAAE;oBACjE,IAAI,GAAG;wBAAE,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;gBAC9B,CAAC,CAAC,CAAC;iBACA,IAAI,MAAM;gBACb,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,EAAE,CAAC,GAAG,EAAE,EAAE;oBAC5D,IAAI,GAAG;wBAAE,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;gBAC9B,CAAC,CAAC,CAAC;QACP,CAAC;QACD,QAAQ,EAAE,KAAK,IAAI,EAAE,CACnB,OAAO,CAAC,GAAG,CAAC;YACV,OAAO,EAAE,QAAQ,EAAE;YACnB,MAAM,EAAE,aAAa,EAAE;YACvB,KAAK,EAAE,KAAK,EAAE;SACf,CAAC;QACJ,mBAAmB;QACnB,KAAK,EAAE,OAAO,EAAE,KAAK;QACrB,gBAAgB,EAAE,OAAO,EAAE,gBAAgB;QAC3C,4BAA4B;QAC5B,QAAQ;QACR,OAAO;QACP,IAAI,EAAE,MAAM;QACZ,GAAG,EAAE,KAAK;KACX,CAAC;AACJ,CAAC,CAAC;AAvHW,QAAA,WAAW,eAuHtB"}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { Analytics } from '@june-so/analytics-node';
|
|
2
2
|
import { PostHog } from 'posthog-node';
|
|
3
|
+
export declare const isTest: (userId: string, groupId?: string, userEmail?: string) => boolean | "" | undefined;
|
|
4
|
+
export declare const convertKeysToSnakeCase: (obj?: Record<string, any>) => Record<string, any>;
|
|
3
5
|
type AuthEvent = 'account_signin_completed' | 'account_signup_code_requested' | 'account_signup_code_completed' | 'account_signup_code_failed' | 'account_signup_completed' | 'account_password_reset_requested' | 'account_password_reset_failed' | 'account_password_reset_completed' | 'account_invitation_accepted' | 'account_signed_out';
|
|
4
6
|
type TeamEvent = 'team_added' | 'team_info_updated' | 'team_deleted' | 'team_member_removed';
|
|
5
7
|
type ConnectionEvent = 'connection_created' | 'connection_reconnected' | 'connection_deleted' | 'connection_requested';
|
|
@@ -20,8 +22,26 @@ export type TrackingProps = {
|
|
|
20
22
|
JUNESO_TOKEN?: string;
|
|
21
23
|
POSTHOG_TOKEN?: string;
|
|
22
24
|
};
|
|
25
|
+
debugging?: boolean;
|
|
23
26
|
};
|
|
24
27
|
export type Tracking = ReturnType<typeof useTracking>;
|
|
28
|
+
type TrackProps = {
|
|
29
|
+
userId: string;
|
|
30
|
+
groupId: string;
|
|
31
|
+
event: TrackingEvent;
|
|
32
|
+
properties: Record<string, string | number | boolean | null | undefined>;
|
|
33
|
+
};
|
|
34
|
+
type IdentifyProps = {
|
|
35
|
+
userId: string;
|
|
36
|
+
traits: Record<string, any>;
|
|
37
|
+
disableGeoip?: boolean;
|
|
38
|
+
timestamp?: Date;
|
|
39
|
+
};
|
|
40
|
+
type GroupProps = OptionalUser<{
|
|
41
|
+
groupId: string;
|
|
42
|
+
traits?: Record<string, any>;
|
|
43
|
+
timestamp?: Date;
|
|
44
|
+
}>;
|
|
25
45
|
type OptionalUser<T> = T & ({
|
|
26
46
|
userId: string;
|
|
27
47
|
anonymousId?: string;
|
|
@@ -29,24 +49,21 @@ type OptionalUser<T> = T & ({
|
|
|
29
49
|
userId?: string;
|
|
30
50
|
anonymousId: string;
|
|
31
51
|
});
|
|
32
|
-
export declare const useTracking: ({ dataset, env, name }: TrackingProps, isDev?: boolean) => {
|
|
33
|
-
track: (
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}) => void
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
traits?: Record<string, any>;
|
|
48
|
-
timestamp?: Date;
|
|
49
|
-
}>) => void;
|
|
52
|
+
export declare const useTracking: ({ dataset, env, name, debugging }: TrackingProps, isDev?: boolean) => {
|
|
53
|
+
track: (props: TrackProps) => void;
|
|
54
|
+
identify: (props: IdentifyProps) => void;
|
|
55
|
+
group: (props: GroupProps) => void;
|
|
56
|
+
log: Console;
|
|
57
|
+
june: {};
|
|
58
|
+
intercom: {};
|
|
59
|
+
posthog: {};
|
|
60
|
+
shutdown?: undefined;
|
|
61
|
+
alias?: undefined;
|
|
62
|
+
isFeatureEnabled?: undefined;
|
|
63
|
+
} | {
|
|
64
|
+
track: ({ userId, groupId, event, properties }: TrackProps) => Promise<void>;
|
|
65
|
+
identify: ({ traits, userId, disableGeoip, timestamp }: IdentifyProps) => void;
|
|
66
|
+
group: ({ traits, groupId, userId, anonymousId, timestamp, }: GroupProps) => void;
|
|
50
67
|
shutdown: () => Promise<[void | undefined, void | undefined, void]>;
|
|
51
68
|
alias: ((data: {
|
|
52
69
|
distinctId: string;
|
|
@@ -2,19 +2,50 @@ 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
|
-
'
|
|
7
|
-
'
|
|
8
|
-
'
|
|
9
|
-
'
|
|
10
|
-
|
|
11
|
-
const E2E_TEST_TEAMS =
|
|
12
|
-
'c4fd21b4-8447-43a2-bdcb-f06a85a935ad',
|
|
13
|
-
'8f21060e-afe6-410a-b2f4-00a3caa20786',
|
|
14
|
-
|
|
15
|
-
const isTest = (userId, groupId) => E2E_TEST_USERS.includes(userId) ||
|
|
16
|
-
(groupId && E2E_TEST_TEAMS.includes(groupId))
|
|
17
|
-
|
|
5
|
+
const E2E_TEST_USERS = {
|
|
6
|
+
'e2e-invite-member@finalytic.io': '113d73d8-ee21-46b7-a12a-a74f632401ca',
|
|
7
|
+
'e2e-invite-owner@finalytic.io': '917b7c4e-cb03-491c-9e94-d33a5bdeca05',
|
|
8
|
+
'e2e-sign-up@finalytic.io': 'ec8e5572-74d0-4ae6-af73-bca8db9a27e9',
|
|
9
|
+
'lars+checkly@finalytic.co': '9e7dfc88-503c-4222-9905-9116169d2203',
|
|
10
|
+
};
|
|
11
|
+
const E2E_TEST_TEAMS = {
|
|
12
|
+
'VRP Automated Testing': 'c4fd21b4-8447-43a2-bdcb-f06a85a935ad',
|
|
13
|
+
test_company_xxxx: '8f21060e-afe6-410a-b2f4-00a3caa20786',
|
|
14
|
+
};
|
|
15
|
+
export const isTest = (userId, groupId, userEmail) => Object.values(E2E_TEST_USERS).includes(userId) ||
|
|
16
|
+
(groupId && Object.values(E2E_TEST_TEAMS).includes(groupId)) ||
|
|
17
|
+
(userEmail && Object.keys(E2E_TEST_USERS).includes(userEmail));
|
|
18
|
+
const camelToSnakeCase = (str) => str.replace(/([a-z])([A-Z])/g, '$1_$2').toLowerCase();
|
|
19
|
+
// todo: move to utils
|
|
20
|
+
export const convertKeysToSnakeCase = (obj) => {
|
|
21
|
+
const result = {};
|
|
22
|
+
const hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
23
|
+
for (const key in obj) {
|
|
24
|
+
if (hasOwnProperty.call(obj, key)) {
|
|
25
|
+
const snakeKey = camelToSnakeCase(key);
|
|
26
|
+
if (typeof obj[key] === 'object' &&
|
|
27
|
+
!Array.isArray(obj[key]) &&
|
|
28
|
+
obj[key] !== null) {
|
|
29
|
+
result[snakeKey] = convertKeysToSnakeCase(obj[key]);
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
result[snakeKey] = obj[key];
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return result;
|
|
37
|
+
};
|
|
38
|
+
export const useTracking = ({ dataset, env, name, debugging }, isDev) => {
|
|
39
|
+
if (debugging)
|
|
40
|
+
return {
|
|
41
|
+
track: (props) => console.log(props),
|
|
42
|
+
identify: (props) => console.log(props),
|
|
43
|
+
group: (props) => console.log(props),
|
|
44
|
+
log: console,
|
|
45
|
+
june: {},
|
|
46
|
+
intercom: {},
|
|
47
|
+
posthog: {},
|
|
48
|
+
};
|
|
18
49
|
const axiom = useLog({ name, dataset, env });
|
|
19
50
|
const intercom = env.INTERCOM_TOKEN
|
|
20
51
|
? useIntercom(env.INTERCOM_TOKEN, axiom)
|
|
@@ -27,7 +58,7 @@ export const useTracking = ({ dataset, env, name }, isDev) => {
|
|
|
27
58
|
: undefined;
|
|
28
59
|
return {
|
|
29
60
|
// General
|
|
30
|
-
track: async ({ userId, groupId, event, properties
|
|
61
|
+
track: async ({ userId, groupId, event, properties }) => {
|
|
31
62
|
if (isDev || isTest(userId, groupId))
|
|
32
63
|
return;
|
|
33
64
|
posthog?.capture({
|
|
@@ -36,7 +67,7 @@ export const useTracking = ({ dataset, env, name }, isDev) => {
|
|
|
36
67
|
groups: {
|
|
37
68
|
tenant: groupId,
|
|
38
69
|
},
|
|
39
|
-
properties,
|
|
70
|
+
properties: convertKeysToSnakeCase(properties),
|
|
40
71
|
});
|
|
41
72
|
juneso?.track({
|
|
42
73
|
userId,
|
|
@@ -58,12 +89,12 @@ export const useTracking = ({ dataset, env, name }, isDev) => {
|
|
|
58
89
|
console.error(error);
|
|
59
90
|
}
|
|
60
91
|
},
|
|
61
|
-
identify: ({ traits, userId, disableGeoip, timestamp
|
|
92
|
+
identify: ({ traits, userId, disableGeoip, timestamp }) => {
|
|
62
93
|
if (isDev || isTest(userId))
|
|
63
94
|
return;
|
|
64
95
|
posthog?.identify({
|
|
65
96
|
distinctId: userId,
|
|
66
|
-
properties: traits,
|
|
97
|
+
properties: convertKeysToSnakeCase(traits),
|
|
67
98
|
disableGeoip,
|
|
68
99
|
});
|
|
69
100
|
juneso?.identify({
|
|
@@ -81,7 +112,7 @@ export const useTracking = ({ dataset, env, name }, isDev) => {
|
|
|
81
112
|
posthog?.groupIdentify({
|
|
82
113
|
groupKey: groupId,
|
|
83
114
|
groupType: 'tenant',
|
|
84
|
-
properties: traits,
|
|
115
|
+
properties: convertKeysToSnakeCase(traits),
|
|
85
116
|
distinctId: userId,
|
|
86
117
|
});
|
|
87
118
|
if (anonymousId)
|
|
@@ -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,
|
|
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,gCAAgC,EAAE,sCAAsC;IACxE,+BAA+B,EAAE,sCAAsC;IACvE,0BAA0B,EAAE,sCAAsC;IAClE,2BAA2B,EAAE,sCAAsC;CACpE,CAAC;AAEF,MAAM,cAAc,GAAG;IACrB,uBAAuB,EAAE,sCAAsC;IAC/D,iBAAiB,EAAE,sCAAsC;CAC1D,CAAC;AAEF,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,MAAc,EAAE,OAAgB,EAAE,SAAkB,EAAE,EAAE,CAC7E,MAAM,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC;IAC9C,CAAC,OAAO,IAAI,MAAM,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;IAC5D,CAAC,SAAS,IAAI,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,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ACH,IAAI,WAAW;gBACb,MAAM,EAAE,KAAK,CAAC,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,EAAE,CAAC,GAAG,EAAE,EAAE;oBACjE,IAAI,GAAG;wBAAE,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;gBAC9B,CAAC,CAAC,CAAC;iBACA,IAAI,MAAM;gBACb,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,EAAE,CAAC,GAAG,EAAE,EAAE;oBAC5D,IAAI,GAAG;wBAAE,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;gBAC9B,CAAC,CAAC,CAAC;QACP,CAAC;QACD,QAAQ,EAAE,KAAK,IAAI,EAAE,CACnB,OAAO,CAAC,GAAG,CAAC;YACV,OAAO,EAAE,QAAQ,EAAE;YACnB,MAAM,EAAE,aAAa,EAAE;YACvB,KAAK,EAAE,KAAK,EAAE;SACf,CAAC;QACJ,mBAAmB;QACnB,KAAK,EAAE,OAAO,EAAE,KAAK;QACrB,gBAAgB,EAAE,OAAO,EAAE,gBAAgB;QAC3C,4BAA4B;QAC5B,QAAQ;QACR,OAAO;QACP,IAAI,EAAE,MAAM;QACZ,GAAG,EAAE,KAAK;KACX,CAAC;AACJ,CAAC,CAAC"}
|
package/package.json
CHANGED
package/src/tracking/index.ts
CHANGED
|
@@ -3,20 +3,48 @@ import { PostHog } from 'posthog-node';
|
|
|
3
3
|
import { useLog } from '../log';
|
|
4
4
|
import { useIntercom } from './intercom';
|
|
5
5
|
|
|
6
|
-
const E2E_TEST_USERS =
|
|
7
|
-
'
|
|
8
|
-
'
|
|
9
|
-
'
|
|
10
|
-
'
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
'
|
|
15
|
-
|
|
6
|
+
const E2E_TEST_USERS = {
|
|
7
|
+
'e2e-invite-member@finalytic.io': '113d73d8-ee21-46b7-a12a-a74f632401ca',
|
|
8
|
+
'e2e-invite-owner@finalytic.io': '917b7c4e-cb03-491c-9e94-d33a5bdeca05',
|
|
9
|
+
'e2e-sign-up@finalytic.io': 'ec8e5572-74d0-4ae6-af73-bca8db9a27e9',
|
|
10
|
+
'lars+checkly@finalytic.co': '9e7dfc88-503c-4222-9905-9116169d2203',
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
const E2E_TEST_TEAMS = {
|
|
14
|
+
'VRP Automated Testing': 'c4fd21b4-8447-43a2-bdcb-f06a85a935ad',
|
|
15
|
+
test_company_xxxx: '8f21060e-afe6-410a-b2f4-00a3caa20786',
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export const isTest = (userId: string, groupId?: string, userEmail?: string) =>
|
|
19
|
+
Object.values(E2E_TEST_USERS).includes(userId) ||
|
|
20
|
+
(groupId && Object.values(E2E_TEST_TEAMS).includes(groupId)) ||
|
|
21
|
+
(userEmail && Object.keys(E2E_TEST_USERS).includes(userEmail));
|
|
22
|
+
|
|
23
|
+
const camelToSnakeCase = (str: string) =>
|
|
24
|
+
str.replace(/([a-z])([A-Z])/g, '$1_$2').toLowerCase();
|
|
16
25
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
26
|
+
// todo: move to utils
|
|
27
|
+
export const convertKeysToSnakeCase = (obj?: Record<string, any>) => {
|
|
28
|
+
const result: Record<string, any> = {};
|
|
29
|
+
const hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
30
|
+
|
|
31
|
+
for (const key in obj) {
|
|
32
|
+
if (hasOwnProperty.call(obj, key)) {
|
|
33
|
+
const snakeKey = camelToSnakeCase(key);
|
|
34
|
+
if (
|
|
35
|
+
typeof obj[key] === 'object' &&
|
|
36
|
+
!Array.isArray(obj[key]) &&
|
|
37
|
+
obj[key] !== null
|
|
38
|
+
) {
|
|
39
|
+
result[snakeKey] = convertKeysToSnakeCase(obj[key]);
|
|
40
|
+
} else {
|
|
41
|
+
result[snakeKey] = obj[key];
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return result;
|
|
47
|
+
};
|
|
20
48
|
|
|
21
49
|
type AuthEvent =
|
|
22
50
|
| 'account_signin_completed'
|
|
@@ -115,9 +143,27 @@ export type TrackingProps = {
|
|
|
115
143
|
JUNESO_TOKEN?: string;
|
|
116
144
|
POSTHOG_TOKEN?: string;
|
|
117
145
|
};
|
|
146
|
+
debugging?: boolean;
|
|
118
147
|
};
|
|
119
148
|
export type Tracking = ReturnType<typeof useTracking>;
|
|
120
149
|
|
|
150
|
+
type TrackProps = {
|
|
151
|
+
userId: string;
|
|
152
|
+
groupId: string;
|
|
153
|
+
event: TrackingEvent;
|
|
154
|
+
properties: Record<string, string | number | boolean | null | undefined>;
|
|
155
|
+
};
|
|
156
|
+
type IdentifyProps = {
|
|
157
|
+
userId: string;
|
|
158
|
+
traits: Record<string, any>;
|
|
159
|
+
disableGeoip?: boolean;
|
|
160
|
+
timestamp?: Date;
|
|
161
|
+
};
|
|
162
|
+
type GroupProps = OptionalUser<{
|
|
163
|
+
groupId: string;
|
|
164
|
+
traits?: Record<string, any>;
|
|
165
|
+
timestamp?: Date;
|
|
166
|
+
}>;
|
|
121
167
|
type OptionalUser<T> = T &
|
|
122
168
|
(
|
|
123
169
|
| { userId: string; anonymousId?: string }
|
|
@@ -128,9 +174,20 @@ type OptionalUser<T> = T &
|
|
|
128
174
|
);
|
|
129
175
|
|
|
130
176
|
export const useTracking = (
|
|
131
|
-
{ dataset, env, name }: TrackingProps,
|
|
177
|
+
{ dataset, env, name, debugging }: TrackingProps,
|
|
132
178
|
isDev?: boolean
|
|
133
179
|
) => {
|
|
180
|
+
if (debugging)
|
|
181
|
+
return {
|
|
182
|
+
track: (props: TrackProps) => console.log(props),
|
|
183
|
+
identify: (props: IdentifyProps) => console.log(props),
|
|
184
|
+
group: (props: GroupProps) => console.log(props),
|
|
185
|
+
log: console,
|
|
186
|
+
june: {},
|
|
187
|
+
intercom: {},
|
|
188
|
+
posthog: {},
|
|
189
|
+
};
|
|
190
|
+
|
|
134
191
|
const axiom = useLog({ name, dataset, env });
|
|
135
192
|
const intercom = env.INTERCOM_TOKEN
|
|
136
193
|
? useIntercom(env.INTERCOM_TOKEN, axiom)
|
|
@@ -144,17 +201,7 @@ export const useTracking = (
|
|
|
144
201
|
|
|
145
202
|
return {
|
|
146
203
|
// General
|
|
147
|
-
track: async ({
|
|
148
|
-
userId,
|
|
149
|
-
groupId,
|
|
150
|
-
event,
|
|
151
|
-
properties,
|
|
152
|
-
}: {
|
|
153
|
-
userId: string;
|
|
154
|
-
groupId: string;
|
|
155
|
-
event: TrackingEvent;
|
|
156
|
-
properties: Record<string, string | number | boolean | null | undefined>;
|
|
157
|
-
}) => {
|
|
204
|
+
track: async ({ userId, groupId, event, properties }: TrackProps) => {
|
|
158
205
|
if (isDev || isTest(userId, groupId)) return;
|
|
159
206
|
|
|
160
207
|
posthog?.capture({
|
|
@@ -163,7 +210,7 @@ export const useTracking = (
|
|
|
163
210
|
groups: {
|
|
164
211
|
tenant: groupId,
|
|
165
212
|
},
|
|
166
|
-
properties,
|
|
213
|
+
properties: convertKeysToSnakeCase(properties),
|
|
167
214
|
});
|
|
168
215
|
juneso?.track(
|
|
169
216
|
{
|
|
@@ -187,22 +234,12 @@ export const useTracking = (
|
|
|
187
234
|
console.error(error);
|
|
188
235
|
}
|
|
189
236
|
},
|
|
190
|
-
identify: ({
|
|
191
|
-
traits,
|
|
192
|
-
userId,
|
|
193
|
-
disableGeoip,
|
|
194
|
-
timestamp,
|
|
195
|
-
}: {
|
|
196
|
-
userId: string;
|
|
197
|
-
traits: Record<string, any>;
|
|
198
|
-
disableGeoip?: boolean;
|
|
199
|
-
timestamp?: Date;
|
|
200
|
-
}) => {
|
|
237
|
+
identify: ({ traits, userId, disableGeoip, timestamp }: IdentifyProps) => {
|
|
201
238
|
if (isDev || isTest(userId)) return;
|
|
202
239
|
|
|
203
240
|
posthog?.identify({
|
|
204
241
|
distinctId: userId,
|
|
205
|
-
properties: traits,
|
|
242
|
+
properties: convertKeysToSnakeCase(traits),
|
|
206
243
|
disableGeoip,
|
|
207
244
|
});
|
|
208
245
|
juneso?.identify(
|
|
@@ -222,17 +259,13 @@ export const useTracking = (
|
|
|
222
259
|
userId,
|
|
223
260
|
anonymousId,
|
|
224
261
|
timestamp,
|
|
225
|
-
}:
|
|
226
|
-
groupId: string;
|
|
227
|
-
traits?: Record<string, any>;
|
|
228
|
-
timestamp?: Date;
|
|
229
|
-
}>) => {
|
|
262
|
+
}: GroupProps) => {
|
|
230
263
|
if (isDev || isTest(userId || anonymousId || '', groupId)) return;
|
|
231
264
|
|
|
232
265
|
posthog?.groupIdentify({
|
|
233
266
|
groupKey: groupId,
|
|
234
267
|
groupType: 'tenant',
|
|
235
|
-
properties: traits,
|
|
268
|
+
properties: convertKeysToSnakeCase(traits),
|
|
236
269
|
distinctId: userId,
|
|
237
270
|
});
|
|
238
271
|
if (anonymousId)
|