@vrplatform/log 2.0.0-alpha.30 → 2.0.0-alpha.32
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/_intercom.d.ts +109 -0
- package/build/main/tracking/_intercom.js +139 -0
- package/build/main/tracking/_intercom.js.map +1 -0
- package/build/main/tracking/index.d.ts +2 -38
- package/build/main/tracking/index.js +0 -42
- package/build/main/tracking/index.js.map +1 -1
- package/build/main/tracking/types.d.ts +173 -0
- package/build/module/tracking/_intercom.d.ts +109 -0
- package/build/module/tracking/_intercom.js +136 -0
- package/build/module/tracking/_intercom.js.map +1 -0
- package/build/module/tracking/index.d.ts +2 -38
- package/build/module/tracking/index.js +0 -42
- package/build/module/tracking/index.js.map +1 -1
- package/build/module/tracking/types.d.ts +173 -0
- package/package.json +1 -1
- package/src/tracking/index.ts +7 -92
- package/src/tracking/types.ts +180 -0
- /package/src/tracking/{intercom.ts → _intercom.ts} +0 -0
package/src/tracking/index.ts
CHANGED
|
@@ -2,52 +2,20 @@ import { Analytics } from '@june-so/analytics-node';
|
|
|
2
2
|
import { Intercom, IntercomClient } from 'intercom-client';
|
|
3
3
|
import { fetcher } from 'intercom-client/core/fetcher/Fetcher';
|
|
4
4
|
import { PostHog } from 'posthog-node';
|
|
5
|
-
import { type
|
|
5
|
+
import { type WorkerLog, useLog } from '../log';
|
|
6
6
|
import { convertKeysToSnakeCase, isTest } from '../utils';
|
|
7
7
|
import { convertValuesToString } from '../utils/convertValuesToString';
|
|
8
|
-
import {
|
|
9
|
-
|
|
8
|
+
import type {
|
|
9
|
+
GroupProps,
|
|
10
|
+
IdentifyProps,
|
|
11
|
+
TrackProps,
|
|
12
|
+
TrackingProps,
|
|
13
|
+
} from './types';
|
|
10
14
|
|
|
11
15
|
export * from './types';
|
|
12
16
|
|
|
13
|
-
export type TrackingProps = {
|
|
14
|
-
name: string;
|
|
15
|
-
dataset: string;
|
|
16
|
-
env: {
|
|
17
|
-
INTERCOM_TOKEN?: string;
|
|
18
|
-
JUNESO_TOKEN?: string;
|
|
19
|
-
POSTHOG_TOKEN?: string;
|
|
20
|
-
} & LogBindings;
|
|
21
|
-
debugging?: boolean;
|
|
22
|
-
};
|
|
23
17
|
export type Tracking = ReturnType<typeof useTracking>;
|
|
24
18
|
|
|
25
|
-
export type TrackProps = OptionalUser<{
|
|
26
|
-
groupId: string;
|
|
27
|
-
event: TrackingEvent;
|
|
28
|
-
properties: Record<string, string | number | boolean | null | undefined>;
|
|
29
|
-
timestamp?: Date;
|
|
30
|
-
}>;
|
|
31
|
-
export type IdentifyProps = {
|
|
32
|
-
userId: string;
|
|
33
|
-
traits: Record<string, string | number | boolean | null | undefined>;
|
|
34
|
-
disableGeoip?: boolean;
|
|
35
|
-
timestamp?: Date;
|
|
36
|
-
};
|
|
37
|
-
export type GroupProps = OptionalUser<{
|
|
38
|
-
groupId: string;
|
|
39
|
-
traits?: Record<string, string | number | boolean | null | undefined>;
|
|
40
|
-
timestamp?: Date;
|
|
41
|
-
}>;
|
|
42
|
-
type OptionalUser<T> = T &
|
|
43
|
-
(
|
|
44
|
-
| { userId: string; anonymousId?: string }
|
|
45
|
-
| {
|
|
46
|
-
userId?: string;
|
|
47
|
-
anonymousId: string;
|
|
48
|
-
}
|
|
49
|
-
);
|
|
50
|
-
|
|
51
19
|
export const useTracking = (
|
|
52
20
|
{ dataset, env, name }: TrackingProps,
|
|
53
21
|
isDev?: boolean
|
|
@@ -59,7 +27,6 @@ export const useTracking = (
|
|
|
59
27
|
log: WorkerLog;
|
|
60
28
|
june?: Analytics;
|
|
61
29
|
intercom?: IntercomClient;
|
|
62
|
-
_intercom?: ReturnType<typeof useIntercom>;
|
|
63
30
|
posthog?: PostHog;
|
|
64
31
|
} => {
|
|
65
32
|
const log = useLog({ name, dataset, env });
|
|
@@ -74,9 +41,6 @@ export const useTracking = (
|
|
|
74
41
|
}),
|
|
75
42
|
})
|
|
76
43
|
: undefined;
|
|
77
|
-
const _intercom = env.INTERCOM_TOKEN
|
|
78
|
-
? useIntercom(env.INTERCOM_TOKEN, log)
|
|
79
|
-
: undefined;
|
|
80
44
|
|
|
81
45
|
const june = env.JUNESO_TOKEN ? new Analytics(env.JUNESO_TOKEN) : undefined;
|
|
82
46
|
|
|
@@ -187,27 +151,6 @@ export const useTracking = (
|
|
|
187
151
|
},
|
|
188
152
|
(err) => (err ? console.error(err) : {})
|
|
189
153
|
);
|
|
190
|
-
|
|
191
|
-
const intercomUserId = (
|
|
192
|
-
await intercom?.contacts.search({
|
|
193
|
-
query: {
|
|
194
|
-
field: 'external_id',
|
|
195
|
-
operator: Intercom.SingleFilterSearchRequestOperator.Equals,
|
|
196
|
-
value: userId,
|
|
197
|
-
},
|
|
198
|
-
})
|
|
199
|
-
)?.data.at(0)?.id;
|
|
200
|
-
const props = {
|
|
201
|
-
external_id: userId,
|
|
202
|
-
name: traits.name ? traits.name.toString() : undefined,
|
|
203
|
-
email: traits.email ? traits.email.toString() : undefined,
|
|
204
|
-
role: traits.role ? traits.role.toString() : undefined,
|
|
205
|
-
avatar: traits.avatar ? traits.avatar.toString() : undefined,
|
|
206
|
-
custom_attributes: traits,
|
|
207
|
-
};
|
|
208
|
-
if (intercomUserId)
|
|
209
|
-
await intercom?.contacts.update(intercomUserId, props);
|
|
210
|
-
else await intercom?.contacts.create(props);
|
|
211
154
|
},
|
|
212
155
|
group: async ({
|
|
213
156
|
traits,
|
|
@@ -218,18 +161,6 @@ export const useTracking = (
|
|
|
218
161
|
}: GroupProps) => {
|
|
219
162
|
if (isDev || isTest(userId || anonymousId || '', groupId)) return;
|
|
220
163
|
|
|
221
|
-
// upsert intercom company
|
|
222
|
-
const intercomCompanyId = (
|
|
223
|
-
await intercom?.companies.create(
|
|
224
|
-
{
|
|
225
|
-
name: groupId,
|
|
226
|
-
company_id: groupId,
|
|
227
|
-
remote_created_at: timestamp ? timestamp.getTime() : Date.now(),
|
|
228
|
-
},
|
|
229
|
-
traits
|
|
230
|
-
)
|
|
231
|
-
)?.id;
|
|
232
|
-
|
|
233
164
|
if (anonymousId) {
|
|
234
165
|
posthog?.groupIdentify({
|
|
235
166
|
groupKey: groupId,
|
|
@@ -252,28 +183,12 @@ export const useTracking = (
|
|
|
252
183
|
june?.group({ userId, groupId, traits, timestamp }, (err) =>
|
|
253
184
|
err ? console.error(err) : {}
|
|
254
185
|
);
|
|
255
|
-
|
|
256
|
-
// attach user to intercom company
|
|
257
|
-
const intercomUserId = (
|
|
258
|
-
await intercom?.contacts.search({
|
|
259
|
-
query: {
|
|
260
|
-
field: 'external_id',
|
|
261
|
-
operator: Intercom.SingleFilterSearchRequestOperator.Equals,
|
|
262
|
-
value: userId,
|
|
263
|
-
},
|
|
264
|
-
})
|
|
265
|
-
)?.data.at(0)?.id;
|
|
266
|
-
if (intercomUserId && intercomCompanyId)
|
|
267
|
-
intercom?.companies.attachContact(intercomUserId, {
|
|
268
|
-
id: intercomCompanyId,
|
|
269
|
-
});
|
|
270
186
|
}
|
|
271
187
|
},
|
|
272
188
|
shutdown: async () =>
|
|
273
189
|
Promise.all([posthog?.shutdown(), june?.closeAndFlush(), log?.flush()]),
|
|
274
190
|
// export dependencies
|
|
275
191
|
intercom,
|
|
276
|
-
_intercom,
|
|
277
192
|
posthog,
|
|
278
193
|
june,
|
|
279
194
|
log,
|
package/src/tracking/types.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { LogBindings } from '../log';
|
|
2
|
+
|
|
1
3
|
type AuthEvent =
|
|
2
4
|
| 'account_signin_completed'
|
|
3
5
|
| 'account_signup_code_requested'
|
|
@@ -95,3 +97,181 @@ export type TrackingEvent =
|
|
|
95
97
|
| ListingEvent
|
|
96
98
|
| ReportEvent
|
|
97
99
|
| TestEvent;
|
|
100
|
+
|
|
101
|
+
type IntercomContactCustomAttributes = {
|
|
102
|
+
article_id?: string; // undefined
|
|
103
|
+
workflowInstanceId?: number; // undefined
|
|
104
|
+
Onboarding_Support?: string; // The customer's preferred onboarding level
|
|
105
|
+
Active_Listings?: string; // The number of active listings a user has
|
|
106
|
+
Accounting_Software?: string; // The client's accounting software
|
|
107
|
+
userType?: string; // User Type (user or owner)
|
|
108
|
+
};
|
|
109
|
+
export type IntercomContactAttributes = {
|
|
110
|
+
role?: string; // A person's role in their company, such as the name of their department
|
|
111
|
+
name?: string; // A person's full name
|
|
112
|
+
owner_id?: number; // The teammate that owns a lead or user in Intercom
|
|
113
|
+
email?: string; // The email address assigned to a user or lead
|
|
114
|
+
email_domain?: string; // The email domain of a user or lead
|
|
115
|
+
phone?: string; // A person's phone number
|
|
116
|
+
external_id?: string; // A number identifying a person (applies to both users and leads)
|
|
117
|
+
created_at?: Date; // The first day a person visited your site or app
|
|
118
|
+
signed_up_at?: Date; // The day a person first signed up for your product
|
|
119
|
+
last_seen_at?: Date; // The last day a person visited your site or app
|
|
120
|
+
last_contacted_at?: Date; // The last day you or a teammate contacted a person
|
|
121
|
+
last_replied_at?: Date; // The last day a person contacted you via a message or email
|
|
122
|
+
last_email_opened_at?: Date; // The last day a person opened an email
|
|
123
|
+
last_email_clicked_at?: Date; // The last day a person clicked on a link in an email
|
|
124
|
+
location?: {
|
|
125
|
+
country?: string; // The country a person is in (or their IP address location)
|
|
126
|
+
region?: string; // A subdivision of a country, such as a state, province or territory
|
|
127
|
+
city?: string; // The city a person is in (or their IP address location)
|
|
128
|
+
};
|
|
129
|
+
browser_language?: string; // The language set by the browser a person is using
|
|
130
|
+
language_override?: string; // A preferred language setting for a person, used by the Intercom Messenger even if their browser settings change
|
|
131
|
+
browser?: string; // The browser a person is using
|
|
132
|
+
browser_version?: string; // The precise version of the browser a person is using
|
|
133
|
+
os?: string; // The operating system a person is using
|
|
134
|
+
unsubscribed_from_emails?: boolean; // Has a person unsubscribed from emails from your team?
|
|
135
|
+
marked_email_as_spam?: boolean; // Has a person marked an email from your team as spam?
|
|
136
|
+
has_hard_bounced?: boolean; // Has an email sent from your team to a person bounced?
|
|
137
|
+
whatsapp_number?: string; // A person's WhatsApp number
|
|
138
|
+
phone_country?: string; // The ISO country code of the person's phone number
|
|
139
|
+
id?: string; // The Intercom defined id representing the user
|
|
140
|
+
avatar?: string; // An avatar image URL
|
|
141
|
+
updated_at?: Date; // The last time the user was updated
|
|
142
|
+
workspace_id?: string; // The Intercom defined id representing the workspace
|
|
143
|
+
android_app_name?: string; // The name of Android app a person is using
|
|
144
|
+
android_sdk_version?: string; // The version of the Android SDK a person is using
|
|
145
|
+
ios_app_name?: string; // The name of iOS app a person is using
|
|
146
|
+
ios_sdk_version?: string; // The version of the iOS SDK a person is using
|
|
147
|
+
custom_attributes?: IntercomContactCustomAttributes;
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
type IntercomCompanyCustomAttributes = {
|
|
151
|
+
firstName?: string; // undefined
|
|
152
|
+
lastName?: string; // undefined
|
|
153
|
+
email?: string; // undefined
|
|
154
|
+
teamId?: string; // undefined
|
|
155
|
+
team?: string; // undefined
|
|
156
|
+
type?: string; // undefined
|
|
157
|
+
status?: string; // undefined
|
|
158
|
+
'SaaS User'?: boolean; // undefined
|
|
159
|
+
pms?: string; // undefined
|
|
160
|
+
accountingSoftware?: string; // Accounting software used by the team.
|
|
161
|
+
creation_source?: string; // undefined
|
|
162
|
+
activeListings?: number; // Active Listings
|
|
163
|
+
partnerName?: string; // Partner Name
|
|
164
|
+
paymentMethodType?: string; // Payment Method
|
|
165
|
+
billingPortalUrl?: string; // Billing Portal URL
|
|
166
|
+
billingStatus?: string; // undefined
|
|
167
|
+
billingPartner?: string; // Name of billing partner
|
|
168
|
+
accountingPartner?: string; // Name of accounting partner
|
|
169
|
+
apps?: string; // All active connections besides pms/accounting
|
|
170
|
+
};
|
|
171
|
+
export type IntercomCompanyAttributes = {
|
|
172
|
+
name?: string; // The name of a company
|
|
173
|
+
company_id?: string; // A number identifying a company
|
|
174
|
+
last_request_at?: Date; // The last day anyone from a company visited your site or app
|
|
175
|
+
remote_created_at?: Date; // The day a company was added to Intercom
|
|
176
|
+
user_count?: number; // The number of people in a company
|
|
177
|
+
session_count?: number; // All visits from anyone in a company to your product's site or app
|
|
178
|
+
monthly_spend?: number; // The monthly revenue you receive from a company
|
|
179
|
+
size?: number; // The number of people employed in this company, expressed as a single number
|
|
180
|
+
industry?: string; // The category or domain this company belongs to e.g. 'ecommerce' or 'SaaS'
|
|
181
|
+
website?: string; // The web address for the company's primary marketing site
|
|
182
|
+
id?: string; // The Intercom defined id representing the company
|
|
183
|
+
created_at?: Date; // The time the company was added to Intercom
|
|
184
|
+
updated_at?: Date; // The last time the company was updated
|
|
185
|
+
plan?: {
|
|
186
|
+
id?: string; // The Intercom defined id representing the plan
|
|
187
|
+
name?: string; // A specific plan or level within your product that companies have signed up to
|
|
188
|
+
};
|
|
189
|
+
app_id?: string; // The Intercom defined id representing the app
|
|
190
|
+
custom_attributes?: IntercomCompanyCustomAttributes;
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
declare module 'intercom-client' {
|
|
194
|
+
export namespace Intercom {
|
|
195
|
+
interface UpdateContactRequest {
|
|
196
|
+
/** The role of the contact. */
|
|
197
|
+
role?: string;
|
|
198
|
+
/** A unique identifier for the contact which is given to Intercom */
|
|
199
|
+
external_id?: string;
|
|
200
|
+
/** The contacts email */
|
|
201
|
+
email?: string;
|
|
202
|
+
/** The contacts phone */
|
|
203
|
+
phone?: string;
|
|
204
|
+
/** The contacts name */
|
|
205
|
+
name?: string;
|
|
206
|
+
/** An image URL containing the avatar of a contact */
|
|
207
|
+
avatar?: string;
|
|
208
|
+
/** The time specified for when a contact signed up */
|
|
209
|
+
signed_up_at?: number;
|
|
210
|
+
/** The time when the contact was last seen (either where the Intercom Messenger was installed or when specified manually) */
|
|
211
|
+
last_seen_at?: number;
|
|
212
|
+
/** The id of an admin that has been assigned account ownership of the contact */
|
|
213
|
+
owner_id?: number;
|
|
214
|
+
/** Whether the contact is unsubscribed from emails */
|
|
215
|
+
unsubscribed_from_emails?: boolean;
|
|
216
|
+
/** The custom attributes which are set for the contact */
|
|
217
|
+
custom_attributes?: IntercomContactCustomAttributes;
|
|
218
|
+
}
|
|
219
|
+
interface CreateOrUpdateCompanyRequest {
|
|
220
|
+
/** The name of the Company */
|
|
221
|
+
name?: string;
|
|
222
|
+
/** The company id you have defined for the company. Can't be updated */
|
|
223
|
+
company_id?: string;
|
|
224
|
+
/** The name of the plan you have associated with the company. */
|
|
225
|
+
plan?: string;
|
|
226
|
+
/** The number of employees in this company. */
|
|
227
|
+
size?: number;
|
|
228
|
+
/** The URL for this company's website. Please note that the value specified here is not validated. Accepts any string. */
|
|
229
|
+
website?: string;
|
|
230
|
+
/** The industry that this company operates in. */
|
|
231
|
+
industry?: string;
|
|
232
|
+
/** A hash of key/value pairs containing any other data about the company you want Intercom to store. */
|
|
233
|
+
custom_attributes?: IntercomCompanyCustomAttributes;
|
|
234
|
+
/** The time the company was created by you. */
|
|
235
|
+
remote_created_at?: number;
|
|
236
|
+
/** How much revenue the company generates for your business. Note that this will truncate floats. i.e. it only allow for whole integers, 155.98 will be truncated to 155. Note that this has an upper limit of 2\*\*31-1 or 2147483647.. */
|
|
237
|
+
monthly_spend?: number;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
export type TrackingProps = {
|
|
243
|
+
name: string;
|
|
244
|
+
dataset: string;
|
|
245
|
+
env: {
|
|
246
|
+
INTERCOM_TOKEN?: string;
|
|
247
|
+
JUNESO_TOKEN?: string;
|
|
248
|
+
POSTHOG_TOKEN?: string;
|
|
249
|
+
} & LogBindings;
|
|
250
|
+
debugging?: boolean;
|
|
251
|
+
};
|
|
252
|
+
|
|
253
|
+
export type TrackProps = OptionalUser<{
|
|
254
|
+
groupId: string;
|
|
255
|
+
event: TrackingEvent;
|
|
256
|
+
properties: Record<string, string | number | boolean | null | undefined>;
|
|
257
|
+
timestamp?: Date;
|
|
258
|
+
}>;
|
|
259
|
+
export type IdentifyProps = {
|
|
260
|
+
userId: string;
|
|
261
|
+
traits: Record<string, string | number | boolean | null | undefined>;
|
|
262
|
+
disableGeoip?: boolean;
|
|
263
|
+
timestamp?: Date;
|
|
264
|
+
};
|
|
265
|
+
export type GroupProps = OptionalUser<{
|
|
266
|
+
groupId: string;
|
|
267
|
+
traits?: Record<string, string | number | boolean | null | undefined>;
|
|
268
|
+
timestamp?: Date;
|
|
269
|
+
}>;
|
|
270
|
+
type OptionalUser<T> = T &
|
|
271
|
+
(
|
|
272
|
+
| { userId: string; anonymousId?: string }
|
|
273
|
+
| {
|
|
274
|
+
userId?: string;
|
|
275
|
+
anonymousId: string;
|
|
276
|
+
}
|
|
277
|
+
);
|
|
File without changes
|