@vrplatform/log 1.0.20 → 1.0.21

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.
Files changed (71) hide show
  1. package/build/main/baselog.js.map +1 -0
  2. package/build/main/color.js.map +1 -0
  3. package/build/main/common.js.map +1 -0
  4. package/build/main/index.d.ts +22 -2
  5. package/build/main/index.js +74 -2
  6. package/build/main/index.js.map +1 -1
  7. package/build/main/index.spec.d.ts +0 -0
  8. package/build/main/index.spec.js +2 -0
  9. package/build/main/index.spec.js.map +1 -0
  10. package/build/{module/log → main}/type.d.ts +3 -1
  11. package/build/main/type.js.map +1 -0
  12. package/build/module/baselog.js.map +1 -0
  13. package/build/module/color.js.map +1 -0
  14. package/build/module/common.js.map +1 -0
  15. package/build/module/index.d.ts +22 -2
  16. package/build/module/index.js +73 -2
  17. package/build/module/index.js.map +1 -1
  18. package/build/module/index.spec.d.ts +0 -0
  19. package/build/module/index.spec.js +2 -0
  20. package/build/module/index.spec.js.map +1 -0
  21. package/build/{main/log → module}/type.d.ts +3 -1
  22. package/build/module/type.js.map +1 -0
  23. package/package.json +20 -24
  24. package/src/index.ts +127 -2
  25. package/src/{log/type.ts → type.ts} +5 -1
  26. package/build/main/log/baselog.js.map +0 -1
  27. package/build/main/log/color.js.map +0 -1
  28. package/build/main/log/common.js.map +0 -1
  29. package/build/main/log/index.d.ts +0 -22
  30. package/build/main/log/index.js +0 -91
  31. package/build/main/log/index.js.map +0 -1
  32. package/build/main/log/type.js.map +0 -1
  33. package/build/main/tracking/index.d.ts +0 -36
  34. package/build/main/tracking/index.js +0 -77
  35. package/build/main/tracking/index.js.map +0 -1
  36. package/build/main/tracking/intercom.d.ts +0 -108
  37. package/build/main/tracking/intercom.js +0 -139
  38. package/build/main/tracking/intercom.js.map +0 -1
  39. package/build/module/log/baselog.js.map +0 -1
  40. package/build/module/log/color.js.map +0 -1
  41. package/build/module/log/common.js.map +0 -1
  42. package/build/module/log/index.d.ts +0 -22
  43. package/build/module/log/index.js +0 -74
  44. package/build/module/log/index.js.map +0 -1
  45. package/build/module/log/type.js.map +0 -1
  46. package/build/module/tracking/index.d.ts +0 -36
  47. package/build/module/tracking/index.js +0 -73
  48. package/build/module/tracking/index.js.map +0 -1
  49. package/build/module/tracking/intercom.d.ts +0 -108
  50. package/build/module/tracking/intercom.js +0 -136
  51. package/build/module/tracking/intercom.js.map +0 -1
  52. package/src/log/index.ts +0 -127
  53. package/src/tracking/index.ts +0 -113
  54. package/src/tracking/intercom.ts +0 -257
  55. /package/build/main/{log/baselog.d.ts → baselog.d.ts} +0 -0
  56. /package/build/main/{log/baselog.js → baselog.js} +0 -0
  57. /package/build/main/{log/color.d.ts → color.d.ts} +0 -0
  58. /package/build/main/{log/color.js → color.js} +0 -0
  59. /package/build/main/{log/common.d.ts → common.d.ts} +0 -0
  60. /package/build/main/{log/common.js → common.js} +0 -0
  61. /package/build/main/{log/type.js → type.js} +0 -0
  62. /package/build/module/{log/baselog.d.ts → baselog.d.ts} +0 -0
  63. /package/build/module/{log/baselog.js → baselog.js} +0 -0
  64. /package/build/module/{log/color.d.ts → color.d.ts} +0 -0
  65. /package/build/module/{log/color.js → color.js} +0 -0
  66. /package/build/module/{log/common.d.ts → common.d.ts} +0 -0
  67. /package/build/module/{log/common.js → common.js} +0 -0
  68. /package/build/module/{log/type.js → type.js} +0 -0
  69. /package/src/{log/baselog.ts → baselog.ts} +0 -0
  70. /package/src/{log/color.ts → color.ts} +0 -0
  71. /package/src/{log/common.ts → common.ts} +0 -0
@@ -1,36 +0,0 @@
1
- import { type IntercomAPI, useIntercom } from './intercom';
2
- export type TrackingProps = {
3
- name: string;
4
- dataset: string;
5
- env: {
6
- INTERCOM_TOKEN: string;
7
- JUNESO_ANALYTICS_WRITE_KEY: string;
8
- POSTHOG_API_KEY: string;
9
- };
10
- };
11
- export type Tracking = ReturnType<typeof useTracking>;
12
- export type Intercom = ReturnType<typeof useIntercom>;
13
- export declare const useTracking: ({ dataset, env, name }: TrackingProps, isDev?: boolean) => {
14
- track: ({ userId, groupId, event, properties, }: {
15
- userId: string;
16
- groupId: string;
17
- event: string;
18
- properties: Record<string, any>;
19
- }) => Promise<void>;
20
- identify: ({ traits, userId, }: {
21
- userId: string;
22
- traits: Record<string, any>;
23
- }) => void;
24
- group: ({ traits, groupId, userId, }: {
25
- groupId: string;
26
- userId: string;
27
- traits?: Record<string, any>;
28
- }) => void;
29
- alias: ({ distinctId, alias }: {
30
- distinctId: string;
31
- alias: string;
32
- }) => void;
33
- shutdown: () => Promise<[void, void, void]>;
34
- intercom: IntercomAPI;
35
- log: import("../log").WorkerLog;
36
- };
@@ -1,73 +0,0 @@
1
- import { Analytics } from '@june-so/analytics-node';
2
- import { PostHog } from 'posthog-node';
3
- import { useLog } from '../log';
4
- import { useIntercom } from './intercom';
5
- export const useTracking = ({ dataset, env, name }, isDev) => {
6
- const axiom = useLog({ name, dataset, env });
7
- const intercom = useIntercom(env.INTERCOM_TOKEN, axiom);
8
- const juneso = new Analytics(env.JUNESO_ANALYTICS_WRITE_KEY);
9
- const posthog = new PostHog(env.POSTHOG_API_KEY, {
10
- host: 'https://app.posthog.com',
11
- });
12
- return {
13
- // General
14
- track: async ({ userId, groupId, event, properties, }) => {
15
- if (isDev)
16
- return;
17
- posthog.capture({
18
- distinctId: userId,
19
- event,
20
- groups: {
21
- tenant: groupId,
22
- },
23
- properties,
24
- });
25
- juneso.track({
26
- userId,
27
- event,
28
- properties,
29
- context: { groupId },
30
- });
31
- try {
32
- await intercom.trackEvent({
33
- user_id: userId,
34
- event_name: event,
35
- metadata: properties,
36
- });
37
- }
38
- catch (error) {
39
- console.error(error);
40
- }
41
- },
42
- identify: ({ traits, userId, }) => {
43
- posthog.identify({
44
- distinctId: userId,
45
- properties: traits,
46
- });
47
- juneso.identify({
48
- userId,
49
- traits,
50
- });
51
- },
52
- group: ({ traits, groupId, userId, }) => {
53
- posthog.groupIdentify({
54
- groupKey: groupId,
55
- groupType: 'tenant',
56
- properties: traits,
57
- distinctId: userId,
58
- });
59
- juneso.group({
60
- userId,
61
- groupId,
62
- traits,
63
- });
64
- },
65
- // Posthog specific
66
- alias: ({ distinctId, alias }) => posthog.alias({ distinctId, alias }),
67
- shutdown: async () => Promise.all([posthog.shutdown(), juneso.closeAndFlush(), axiom.flush()]),
68
- // export intercom and axiom
69
- intercom,
70
- log: axiom,
71
- };
72
- };
73
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
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,EAAoB,WAAW,EAAE,MAAM,YAAY,CAAC;AAe3D,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;IACxD,MAAM,MAAM,GAAG,IAAI,SAAS,CAAC,GAAG,CAAC,0BAA0B,CAAC,CAAC;IAC7D,MAAM,OAAO,GAAG,IAAI,OAAO,CAAC,GAAG,CAAC,eAAe,EAAE;QAC/C,IAAI,EAAE,yBAAyB;KAChC,CAAC,CAAC;IAEH,OAAO;QACL,UAAU;QACV,KAAK,EAAE,KAAK,EAAE,EACZ,MAAM,EACN,OAAO,EACP,KAAK,EACL,UAAU,GAMX,EAAE,EAAE;YACH,IAAI,KAAK;gBAAE,OAAO;YAElB,OAAO,CAAC,OAAO,CAAC;gBACd,UAAU,EAAE,MAAM;gBAClB,KAAK;gBAC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,CAAC,OAAO,CAAC,QAAQ,EAAE,EAAE,MAAM,CAAC,aAAa,EAAE,EAAE,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC;QAC1E,4BAA4B;QAC5B,QAAQ;QACR,GAAG,EAAE,KAAK;KACX,CAAC;AACJ,CAAC,CAAC"}
@@ -1,108 +0,0 @@
1
- import type { Log } from '../log';
2
- export declare class IntercomAPI {
3
- constructor(token: string, log?: Log);
4
- private headers;
5
- private log?;
6
- private fetch;
7
- getUserByUserId(userId: string): Promise<{
8
- type: "list";
9
- data: {
10
- id: string;
11
- }[] | undefined;
12
- total_count: 0;
13
- pages: {
14
- type: "pages";
15
- page: 1;
16
- per_page: 10;
17
- total_pages: 0;
18
- };
19
- } | undefined>;
20
- createUser({ data, userId, }: {
21
- userId: string;
22
- data: {
23
- email: string;
24
- name: string;
25
- custom_attributes: Record<string, any>;
26
- };
27
- }): Promise<unknown>;
28
- updateUser({ data, contactId, }: {
29
- contactId: string;
30
- data: {
31
- email?: string;
32
- name?: string;
33
- custom_attributes: Record<string, any>;
34
- };
35
- }): Promise<unknown>;
36
- deleteUser(intercom_contact_id: string): Promise<{
37
- id: "6657adf56abd0167d9419d1c";
38
- external_id: "70";
39
- type: "contact";
40
- deleted: true;
41
- } | undefined>;
42
- createCompanyUser(data: {
43
- intercom_contact_id: string;
44
- intercom_company_id: string;
45
- }): Promise<unknown>;
46
- deleteCompanyUser({ intercom_company_id, intercom_contact_id, }: {
47
- intercom_contact_id: string;
48
- intercom_company_id: string;
49
- }): Promise<{
50
- id: "6657adc96abd0167d9419ca7";
51
- } | undefined>;
52
- trackEvent(data: {
53
- user_id: string;
54
- event_name: string;
55
- metadata: Record<string, any>;
56
- }): Promise<unknown>;
57
- getCompanyByTenantId(tenantId: string): Promise<{
58
- type: "list";
59
- data: [{
60
- type: "company";
61
- company_id: "remote_companies_scroll_2";
62
- id: "664df5436abd01f7945e1a78";
63
- app_id: "this_is_an_id111_that_should_be_at_least_";
64
- name: "IntercomQATest1";
65
- remote_created_at: 1716385091;
66
- created_at: 1716385091;
67
- updated_at: 1716385091;
68
- monthly_spend: 0;
69
- session_count: 0;
70
- user_count: 4;
71
- tags: {
72
- type: "tag.list";
73
- tags: [];
74
- };
75
- segments: {
76
- type: "segment.list";
77
- segments: [];
78
- };
79
- custom_attributes: Record<string, string>;
80
- }] | undefined;
81
- pages: {
82
- type: "pages";
83
- next: null;
84
- page: 1;
85
- per_page: 15;
86
- total_pages: 1;
87
- };
88
- total_count: 1;
89
- } | undefined>;
90
- createCompany({ data, tenantId, }: {
91
- tenantId: string;
92
- data: {
93
- name: string;
94
- remote_created_at: string;
95
- custom_attributes: Record<string, any>;
96
- };
97
- }): Promise<unknown>;
98
- updateCompany({ data, companyId, }: {
99
- companyId: string;
100
- data: Record<string, any>;
101
- }): Promise<unknown>;
102
- deleteCompany(intercom_company_id: string): Promise<{
103
- id: "6657adc96abd0167d9419ca7";
104
- object: "company";
105
- deleted: true;
106
- } | undefined>;
107
- }
108
- export declare function useIntercom(token: string, log?: Log): IntercomAPI;
@@ -1,136 +0,0 @@
1
- export class IntercomAPI {
2
- constructor(token, log) {
3
- this.headers = {
4
- 'Content-Type': 'application/json',
5
- Accept: 'application/json',
6
- 'Intercom-Version': '2.11',
7
- Authorization: `Bearer ${token}`,
8
- };
9
- this.log = log;
10
- }
11
- headers;
12
- log;
13
- async fetch(path, options) {
14
- if (options?.data) {
15
- options.body = JSON.stringify(options.data);
16
- options.data = undefined;
17
- }
18
- try {
19
- const result = await fetch(`https://api.intercom.io${path}`, {
20
- method: 'GET',
21
- headers: this.headers,
22
- ...options,
23
- });
24
- if (!result.ok) {
25
- this.log?.info('Failed to fetch from Intercom', {
26
- result: {
27
- status: result.status,
28
- statusText: result.statusText,
29
- body: await result.text(),
30
- },
31
- });
32
- if (result.status === 404)
33
- return undefined;
34
- if (result.status === 429) {
35
- console.log('Intercom rate limit exceeded, waiting for 1 minute');
36
- // X-RateLimit-Reset: 1487332520 => timestamp from header response when resetting
37
- const reset = Number(result.headers.get('X-RateLimit-Reset'));
38
- if (reset) {
39
- const now = Math.floor(Date.now() / 1000);
40
- const wait = reset - now + 1;
41
- console.log(`Waiting for ${wait} seconds`);
42
- await new Promise((resolve) => setTimeout(resolve, wait * 1000));
43
- return await this.fetch(path, options);
44
- }
45
- }
46
- }
47
- return result.status === 202 ? {} : (await result.json());
48
- }
49
- catch (error) {
50
- this.log?.error(error);
51
- return undefined;
52
- }
53
- }
54
- // User
55
- async getUserByUserId(userId) {
56
- return await this.fetch('/contacts/search', {
57
- method: 'POST',
58
- data: {
59
- query: {
60
- field: 'external_id',
61
- operator: '=',
62
- value: userId,
63
- },
64
- },
65
- });
66
- }
67
- async createUser({ data, userId, }) {
68
- return await this.fetch('/contacts', {
69
- method: 'POST',
70
- data: { ...data, external_id: userId },
71
- });
72
- }
73
- async updateUser({ data, contactId, }) {
74
- return await this.fetch(`/contacts/${contactId}`, {
75
- method: 'PUT',
76
- data,
77
- });
78
- }
79
- async deleteUser(intercom_contact_id) {
80
- return await this.fetch(`/contacts/${intercom_contact_id}`, {
81
- method: 'DELETE',
82
- });
83
- }
84
- async createCompanyUser(data) {
85
- return await this.fetch(`/contacts/${data.intercom_contact_id}/companies`, {
86
- method: 'POST',
87
- data: {
88
- id: data.intercom_company_id,
89
- },
90
- });
91
- }
92
- async deleteCompanyUser({ intercom_company_id, intercom_contact_id, }) {
93
- return await this.fetch(`/contacts/${intercom_contact_id}/companies/${intercom_company_id}`, {
94
- method: 'DELETE',
95
- });
96
- }
97
- async trackEvent(data) {
98
- return await this.fetch('/events', {
99
- method: 'POST',
100
- data: {
101
- created_at: Math.floor(new Date().getTime() / 1000), // to seconds
102
- ...data,
103
- },
104
- });
105
- }
106
- // Company
107
- async getCompanyByTenantId(tenantId) {
108
- return await this.fetch(`/companies?company_id=${tenantId}`, {
109
- method: 'GET',
110
- });
111
- }
112
- async createCompany({ data, tenantId, }) {
113
- return await this.fetch('/companies', {
114
- method: 'POST',
115
- data: {
116
- ...data,
117
- company_id: tenantId,
118
- },
119
- });
120
- }
121
- async updateCompany({ data, companyId, }) {
122
- return await this.fetch(`/companies/${companyId}`, {
123
- method: 'PUT',
124
- data,
125
- });
126
- }
127
- async deleteCompany(intercom_company_id) {
128
- return await this.fetch(`/companies/${intercom_company_id}`, {
129
- method: 'DELETE',
130
- });
131
- }
132
- }
133
- export function useIntercom(token, log) {
134
- return new IntercomAPI(token, log);
135
- }
136
- //# sourceMappingURL=intercom.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"intercom.js","sourceRoot":"src/","sources":["tracking/intercom.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,WAAW;IACtB,YAAY,KAAa,EAAE,GAAS;QAClC,IAAI,CAAC,OAAO,GAAG;YACb,cAAc,EAAE,kBAAkB;YAClC,MAAM,EAAE,kBAAkB;YAC1B,kBAAkB,EAAE,MAAM;YAC1B,aAAa,EAAE,UAAU,KAAK,EAAE;SACjC,CAAC;QAEF,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;IACjB,CAAC;IAEO,OAAO,CAAyB;IAChC,GAAG,CAAO;IAEV,KAAK,CAAC,KAAK,CACjB,IAAY,EACZ,OAAsC;QAEtC,IAAI,OAAO,EAAE,IAAI,EAAE,CAAC;YAClB,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;YAC5C,OAAO,CAAC,IAAI,GAAG,SAAS,CAAC;QAC3B,CAAC;QAED,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,MAAM,KAAK,CAAC,0BAA0B,IAAI,EAAE,EAAE;gBAC3D,MAAM,EAAE,KAAK;gBACb,OAAO,EAAE,IAAI,CAAC,OAAO;gBACrB,GAAG,OAAO;aACX,CAAC,CAAC;YAEH,IAAI,CAAC,MAAM,CAAC,EAAE,EAAE,CAAC;gBACf,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,+BAA+B,EAAE;oBAC9C,MAAM,EAAE;w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@ -1,127 +0,0 @@
1
- import { createBaseLog } from './baselog';
2
- import {
3
- AXIOM_AUTH_TOKEN_ENV,
4
- AXIOM_DATASET_ENV,
5
- AXIOM_ORG_ID_ENV,
6
- LOG_ENV,
7
- TASK_QUEUE_HEADER,
8
- WORKFLOW_ID_HEADER,
9
- getCorrelationId,
10
- getEnvironment,
11
- requestToContext,
12
- } from './common';
13
- import type { RequestLike, WorkerLog } from './type';
14
-
15
- export * from './common';
16
- export * from './baselog';
17
- export * from './type';
18
-
19
- export function useLog({
20
- environment: _environment,
21
- name,
22
- request,
23
- body,
24
- env,
25
- correlationId: cid,
26
- version,
27
- executionContext,
28
- logRequest,
29
- dataset: _dataset,
30
- context: initialContext = {},
31
- }: {
32
- environment?: string;
33
- name: string;
34
- request?: RequestLike & { cf?: any };
35
- logRequest?: boolean | ((raw: ReturnType<typeof requestToContext>) => any);
36
- body?: any;
37
- correlationId?: string;
38
- version?: string;
39
- dataset?: string;
40
- env?: Record<string, any>;
41
- context?: Record<string, any>;
42
- executionContext?: {
43
- waitUntil(promise: Promise<any>): void;
44
- };
45
- }): WorkerLog {
46
- const environment = _environment || getEnvironment(env);
47
- const colorLogs = env?.[LOG_ENV] === '*' || environment === 'development';
48
- const correlationId = cid || getCorrelationId(request); //const logger = nodeColorLog;
49
-
50
- const axiomToken = env?.[AXIOM_AUTH_TOKEN_ENV];
51
-
52
- const axiom = createBaseLog(
53
- {
54
- token: axiomToken,
55
- orgId: env?.[AXIOM_ORG_ID_ENV],
56
- dataset: _dataset || env?.[AXIOM_DATASET_ENV] || 'default',
57
- consoleLog: colorLogs ? 'color' : false,
58
- },
59
- {
60
- environment,
61
- type: 'worker',
62
- executionContext,
63
- workerId: env?.MACHINE_NAME || name || 'default',
64
- app: name || 'default',
65
- version: version || 'default',
66
- correlationId,
67
- context: {
68
- ...initialContext,
69
- rootCorrelationId: correlationId,
70
- correlationId,
71
- taskQueue: request?.headers?.get(TASK_QUEUE_HEADER) || undefined,
72
- workflowId: request?.headers?.get(WORKFLOW_ID_HEADER) || undefined,
73
- child: undefined as any as string,
74
- },
75
- }
76
- ) as WorkerLog;
77
-
78
- if (logRequest !== false) {
79
- const { message, ...raw } =
80
- typeof logRequest === 'function'
81
- ? logRequest(requestToContext(request, body))
82
- : requestToContext(request, body);
83
- axiom.info(message || 'Request', raw);
84
- }
85
-
86
- axiom.respond = async (res) => {
87
- const temp = await (typeof res === 'function' ? res() : res);
88
-
89
- const response = (() => {
90
- if (temp instanceof Response) {
91
- axiom?.info(`Response ${temp.status}`, {
92
- response: {
93
- body: temp
94
- .clone()
95
- .json()
96
- .catch(() => undefined),
97
- response: temp,
98
- status: temp.status,
99
- statusText: temp.statusText,
100
- headers: temp.headers,
101
- },
102
- });
103
-
104
- return temp;
105
- } else {
106
- // We have no response status code YET
107
- axiom?.info('Response 200', {
108
- response: temp,
109
- });
110
-
111
- return new Response(
112
- typeof temp.body === 'object' ? JSON.stringify(temp.body) : temp.body,
113
- {
114
- status: temp.status,
115
- statusText: temp.statusText,
116
- headers: temp.headers,
117
- }
118
- );
119
- }
120
- })();
121
-
122
- await axiom?.flush();
123
-
124
- return response!;
125
- };
126
- return axiom;
127
- }
@@ -1,113 +0,0 @@
1
- import { Analytics } from '@june-so/analytics-node';
2
- import { PostHog } from 'posthog-node';
3
- import { useLog } from '../log';
4
- import { type IntercomAPI, useIntercom } from './intercom';
5
-
6
- export type TrackingProps = {
7
- name: string;
8
- dataset: string;
9
- env: {
10
- INTERCOM_TOKEN: string;
11
- JUNESO_ANALYTICS_WRITE_KEY: string;
12
- POSTHOG_API_KEY: string;
13
- };
14
- };
15
-
16
- export type Tracking = ReturnType<typeof useTracking>;
17
- export type Intercom = ReturnType<typeof useIntercom>;
18
-
19
- export const useTracking = (
20
- { dataset, env, name }: TrackingProps,
21
- isDev?: boolean
22
- ) => {
23
- const axiom = useLog({ name, dataset, env });
24
- const intercom = useIntercom(env.INTERCOM_TOKEN, axiom);
25
- const juneso = new Analytics(env.JUNESO_ANALYTICS_WRITE_KEY);
26
- const posthog = new PostHog(env.POSTHOG_API_KEY, {
27
- host: 'https://app.posthog.com',
28
- });
29
-
30
- return {
31
- // General
32
- track: async ({
33
- userId,
34
- groupId,
35
- event,
36
- properties,
37
- }: {
38
- userId: string;
39
- groupId: string;
40
- event: string;
41
- properties: Record<string, any>;
42
- }) => {
43
- if (isDev) return;
44
-
45
- posthog.capture({
46
- distinctId: userId,
47
- event,
48
- groups: {
49
- tenant: groupId,
50
- },
51
- properties,
52
- });
53
- juneso.track({
54
- userId,
55
- event,
56
- properties,
57
- context: { groupId },
58
- });
59
-
60
- try {
61
- await intercom.trackEvent({
62
- user_id: userId,
63
- event_name: event,
64
- metadata: properties,
65
- });
66
- } catch (error: any) {
67
- console.error(error);
68
- }
69
- },
70
- identify: ({
71
- traits,
72
- userId,
73
- }: { userId: string; traits: Record<string, any> }) => {
74
- posthog.identify({
75
- distinctId: userId,
76
- properties: traits,
77
- });
78
- juneso.identify({
79
- userId,
80
- traits,
81
- });
82
- },
83
- group: ({
84
- traits,
85
- groupId,
86
- userId,
87
- }: {
88
- groupId: string;
89
- userId: string;
90
- traits?: Record<string, any>;
91
- }) => {
92
- posthog.groupIdentify({
93
- groupKey: groupId,
94
- groupType: 'tenant',
95
- properties: traits,
96
- distinctId: userId,
97
- });
98
- juneso.group({
99
- userId,
100
- groupId,
101
- traits,
102
- });
103
- },
104
- // Posthog specific
105
- alias: ({ distinctId, alias }: { distinctId: string; alias: string }) =>
106
- posthog.alias({ distinctId, alias }),
107
- shutdown: async () =>
108
- Promise.all([posthog.shutdown(), juneso.closeAndFlush(), axiom.flush()]),
109
- // export intercom and axiom
110
- intercom,
111
- log: axiom,
112
- };
113
- };