@vrplatform/log 2.0.0-alpha.36 → 2.0.0-alpha.38
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 +28 -12
- package/build/main/tracking/index.js +66 -0
- package/build/main/tracking/index.js.map +1 -1
- package/build/main/tracking/types.d.ts +35 -2
- package/build/module/tracking/index.d.ts +28 -12
- package/build/module/tracking/index.js +66 -0
- package/build/module/tracking/index.js.map +1 -1
- package/build/module/tracking/types.d.ts +35 -2
- package/package.json +1 -1
- package/src/tracking/index.ts +108 -12
- package/src/tracking/types.ts +42 -2
|
@@ -1,8 +1,28 @@
|
|
|
1
1
|
declare module 'intercom-client' {
|
|
2
2
|
namespace Intercom {
|
|
3
|
+
interface CreateContactRequestWithExternalId {
|
|
4
|
+
/** A unique identifier for the contact which is given to Intercom */
|
|
5
|
+
external_id: string;
|
|
6
|
+
/** The contacts phone */
|
|
7
|
+
phone?: string;
|
|
8
|
+
/** The contacts name */
|
|
9
|
+
name?: string;
|
|
10
|
+
/** An image URL containing the avatar of a contact */
|
|
11
|
+
avatar?: string;
|
|
12
|
+
/** The time specified for when a contact signed up */
|
|
13
|
+
signed_up_at?: number;
|
|
14
|
+
/** The time when the contact was last seen (either where the Intercom Messenger was installed or when specified manually) */
|
|
15
|
+
last_seen_at?: number;
|
|
16
|
+
/** The id of an admin that has been assigned account ownership of the contact */
|
|
17
|
+
owner_id?: number;
|
|
18
|
+
/** Whether the contact is unsubscribed from emails */
|
|
19
|
+
unsubscribed_from_emails?: boolean;
|
|
20
|
+
/** The custom attributes which are set for the contact */
|
|
21
|
+
custom_attributes?: ContactCustomAttributes;
|
|
22
|
+
}
|
|
3
23
|
interface UpdateContactRequest {
|
|
4
24
|
/** The role of the contact. */
|
|
5
|
-
role?:
|
|
25
|
+
role?: 'user' | 'lead';
|
|
6
26
|
/** A unique identifier for the contact which is given to Intercom */
|
|
7
27
|
external_id?: string;
|
|
8
28
|
/** The contacts email */
|
|
@@ -22,7 +42,11 @@ declare module 'intercom-client' {
|
|
|
22
42
|
/** Whether the contact is unsubscribed from emails */
|
|
23
43
|
unsubscribed_from_emails?: boolean;
|
|
24
44
|
/** The custom attributes which are set for the contact */
|
|
25
|
-
custom_attributes?:
|
|
45
|
+
custom_attributes?: ContactCustomAttributes;
|
|
46
|
+
}
|
|
47
|
+
interface ContactCustomAttributes {
|
|
48
|
+
Onboarding_Support?: string;
|
|
49
|
+
userType?: string;
|
|
26
50
|
}
|
|
27
51
|
interface CreateOrUpdateCompanyRequest {
|
|
28
52
|
/** The name of the Company */
|
|
@@ -38,21 +62,13 @@ declare module 'intercom-client' {
|
|
|
38
62
|
/** The industry that this company operates in. */
|
|
39
63
|
industry?: string;
|
|
40
64
|
/** A hash of key/value pairs containing any other data about the company you want Intercom to store. */
|
|
41
|
-
custom_attributes?:
|
|
65
|
+
custom_attributes?: CompanyCustomAttributes;
|
|
42
66
|
/** The time the company was created by you. */
|
|
43
67
|
remote_created_at?: number;
|
|
44
68
|
/** 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.. */
|
|
45
69
|
monthly_spend?: number;
|
|
46
70
|
}
|
|
47
|
-
interface
|
|
48
|
-
article_id?: string;
|
|
49
|
-
workflowInstanceId?: number;
|
|
50
|
-
Onboarding_Support?: string;
|
|
51
|
-
Active_Listings?: string;
|
|
52
|
-
Accounting_Software?: string;
|
|
53
|
-
userType?: string;
|
|
54
|
-
}
|
|
55
|
-
interface IntercomCompanyCustomAttributes {
|
|
71
|
+
interface CompanyCustomAttributes {
|
|
56
72
|
teamId?: string;
|
|
57
73
|
team?: string;
|
|
58
74
|
type?: string;
|
|
@@ -117,10 +117,64 @@ const useTracking = ({ dataset, env, name }, isDev) => {
|
|
|
117
117
|
traits,
|
|
118
118
|
timestamp,
|
|
119
119
|
}, (err) => (err ? console.error(err) : {}));
|
|
120
|
+
// upsert intercom user
|
|
121
|
+
const data = {
|
|
122
|
+
external_id: userId,
|
|
123
|
+
email: traits?.email,
|
|
124
|
+
name: traits?.name ||
|
|
125
|
+
(traits?.firstName
|
|
126
|
+
? `${traits.firstName} ${traits.lastName}`
|
|
127
|
+
: traits?.lastName),
|
|
128
|
+
avatar: traits?.avatar,
|
|
129
|
+
signed_up_at: traits?.createdAt
|
|
130
|
+
? new Date(traits.createdAt).getTime() / 1000
|
|
131
|
+
: undefined,
|
|
132
|
+
last_seen_at: new Date().getTime() / 1000,
|
|
133
|
+
custom_attributes: { userType: traits?.role },
|
|
134
|
+
};
|
|
135
|
+
const intercomUser = (await intercom?.contacts.search({
|
|
136
|
+
query: {
|
|
137
|
+
field: 'external_id',
|
|
138
|
+
operator: intercom_client_1.Intercom.SingleFilterSearchRequestOperator.Equals,
|
|
139
|
+
value: userId,
|
|
140
|
+
},
|
|
141
|
+
}))?.data.at(0);
|
|
142
|
+
if (intercomUser?.id)
|
|
143
|
+
await intercom?.contacts.update(intercomUser?.id, data);
|
|
144
|
+
else
|
|
145
|
+
await intercom?.contacts.create(data);
|
|
120
146
|
},
|
|
121
147
|
group: async ({ traits, groupId, userId, anonymousId, timestamp, }) => {
|
|
122
148
|
if (isDev || (0, utils_1.isTest)(userId || anonymousId || '', groupId))
|
|
123
149
|
return;
|
|
150
|
+
const cid = traits?.billingCustomerId || traits?.hyperlineCustomerId;
|
|
151
|
+
const intercomCompany = await intercom?.companies.create({
|
|
152
|
+
name: traits?.name,
|
|
153
|
+
company_id: groupId,
|
|
154
|
+
// plan: string;
|
|
155
|
+
remote_created_at: traits?.createdAt
|
|
156
|
+
? new Date(traits.createdAt).getTime() / 1000
|
|
157
|
+
: undefined,
|
|
158
|
+
// monthly_spend: number;
|
|
159
|
+
custom_attributes: {
|
|
160
|
+
teamId: groupId,
|
|
161
|
+
team: traits?.name,
|
|
162
|
+
type: traits?.type,
|
|
163
|
+
status: traits?.status,
|
|
164
|
+
pms: traits?.pms,
|
|
165
|
+
accountingSoftware: traits?.accountingSoftware,
|
|
166
|
+
activeListings: traits?.activeListings,
|
|
167
|
+
// paymentMethodType: string; // Payment Method
|
|
168
|
+
partnerName: traits?.partner || traits?.accountingPartner,
|
|
169
|
+
billingPortalUrl: cid
|
|
170
|
+
? `https://billing.vrplatform.app/portal/${cid}`
|
|
171
|
+
: undefined,
|
|
172
|
+
billingStatus: traits?.billingSubscriptionStatus,
|
|
173
|
+
billingPartner: traits?.billingPartner ||
|
|
174
|
+
traits?.partner ||
|
|
175
|
+
traits?.accountingPartner,
|
|
176
|
+
},
|
|
177
|
+
});
|
|
124
178
|
if (anonymousId) {
|
|
125
179
|
posthog?.groupIdentify({
|
|
126
180
|
groupKey: groupId,
|
|
@@ -138,6 +192,18 @@ const useTracking = ({ dataset, env, name }, isDev) => {
|
|
|
138
192
|
distinctId: userId,
|
|
139
193
|
});
|
|
140
194
|
june?.group({ userId, groupId, traits, timestamp }, (err) => err ? console.error(err) : {});
|
|
195
|
+
// attach intercom user to intercom company
|
|
196
|
+
const intercomUser = (await intercom?.contacts.search({
|
|
197
|
+
query: {
|
|
198
|
+
field: 'external_id',
|
|
199
|
+
operator: intercom_client_1.Intercom.SingleFilterSearchRequestOperator.Equals,
|
|
200
|
+
value: userId,
|
|
201
|
+
},
|
|
202
|
+
}))?.data.at(0);
|
|
203
|
+
if (intercomUser?.id && intercomCompany?.id)
|
|
204
|
+
intercom?.companies.attachContact(intercomUser?.id, {
|
|
205
|
+
id: intercomCompany?.id,
|
|
206
|
+
});
|
|
141
207
|
}
|
|
142
208
|
},
|
|
143
209
|
shutdown: async () => Promise.all([posthog?.shutdown(), june?.closeAndFlush(), log?.flush()]),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"src/","sources":["tracking/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"src/","sources":["tracking/index.ts"],"names":[],"mappings":";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
34
34
|
userId: string;
|
|
35
|
-
traits
|
|
35
|
+
traits?: {
|
|
36
|
+
id?: string;
|
|
37
|
+
email?: string;
|
|
38
|
+
avatar?: string;
|
|
39
|
+
name?: string;
|
|
40
|
+
firstName?: string;
|
|
41
|
+
lastName?: string;
|
|
42
|
+
createdAt?: string;
|
|
43
|
+
country?: string;
|
|
44
|
+
isSuperAdmin?: boolean;
|
|
45
|
+
isVrpAdmin?: boolean;
|
|
46
|
+
isPartnerAdmin?: boolean;
|
|
47
|
+
isTeamAdmin?: boolean;
|
|
48
|
+
role?: 'super-admin' | 'vrp-admin' | 'partner-admin' | 'team-admin' | 'admin' | 'owner' | 'user';
|
|
49
|
+
[key: string]: string | number | boolean | null | undefined;
|
|
50
|
+
};
|
|
36
51
|
disableGeoip?: boolean;
|
|
37
52
|
timestamp?: Date;
|
|
38
53
|
};
|
|
39
54
|
export type GroupProps = OptionalUser<{
|
|
40
55
|
groupId: string;
|
|
41
|
-
traits?:
|
|
56
|
+
traits?: {
|
|
57
|
+
name?: string;
|
|
58
|
+
type?: 'admin' | 'partner' | 'propertyManager';
|
|
59
|
+
avatar?: string;
|
|
60
|
+
createdAt?: string;
|
|
61
|
+
partner?: string;
|
|
62
|
+
partnerId?: string;
|
|
63
|
+
billingCustomerId?: string;
|
|
64
|
+
billingSubscriptionStatus?: string;
|
|
65
|
+
status?: 'active' | 'inactive';
|
|
66
|
+
isOnboarding?: boolean;
|
|
67
|
+
accountingPartner?: string;
|
|
68
|
+
billingPartner?: string;
|
|
69
|
+
pms?: string;
|
|
70
|
+
apps?: string;
|
|
71
|
+
accountingSoftware?: string;
|
|
72
|
+
activeListings?: number;
|
|
73
|
+
[key: string]: string | number | boolean | null | undefined;
|
|
74
|
+
};
|
|
42
75
|
timestamp?: Date;
|
|
43
76
|
}>;
|
|
44
77
|
type OptionalUser<T> = T & ({
|
|
@@ -1,8 +1,28 @@
|
|
|
1
1
|
declare module 'intercom-client' {
|
|
2
2
|
namespace Intercom {
|
|
3
|
+
interface CreateContactRequestWithExternalId {
|
|
4
|
+
/** A unique identifier for the contact which is given to Intercom */
|
|
5
|
+
external_id: string;
|
|
6
|
+
/** The contacts phone */
|
|
7
|
+
phone?: string;
|
|
8
|
+
/** The contacts name */
|
|
9
|
+
name?: string;
|
|
10
|
+
/** An image URL containing the avatar of a contact */
|
|
11
|
+
avatar?: string;
|
|
12
|
+
/** The time specified for when a contact signed up */
|
|
13
|
+
signed_up_at?: number;
|
|
14
|
+
/** The time when the contact was last seen (either where the Intercom Messenger was installed or when specified manually) */
|
|
15
|
+
last_seen_at?: number;
|
|
16
|
+
/** The id of an admin that has been assigned account ownership of the contact */
|
|
17
|
+
owner_id?: number;
|
|
18
|
+
/** Whether the contact is unsubscribed from emails */
|
|
19
|
+
unsubscribed_from_emails?: boolean;
|
|
20
|
+
/** The custom attributes which are set for the contact */
|
|
21
|
+
custom_attributes?: ContactCustomAttributes;
|
|
22
|
+
}
|
|
3
23
|
interface UpdateContactRequest {
|
|
4
24
|
/** The role of the contact. */
|
|
5
|
-
role?:
|
|
25
|
+
role?: 'user' | 'lead';
|
|
6
26
|
/** A unique identifier for the contact which is given to Intercom */
|
|
7
27
|
external_id?: string;
|
|
8
28
|
/** The contacts email */
|
|
@@ -22,7 +42,11 @@ declare module 'intercom-client' {
|
|
|
22
42
|
/** Whether the contact is unsubscribed from emails */
|
|
23
43
|
unsubscribed_from_emails?: boolean;
|
|
24
44
|
/** The custom attributes which are set for the contact */
|
|
25
|
-
custom_attributes?:
|
|
45
|
+
custom_attributes?: ContactCustomAttributes;
|
|
46
|
+
}
|
|
47
|
+
interface ContactCustomAttributes {
|
|
48
|
+
Onboarding_Support?: string;
|
|
49
|
+
userType?: string;
|
|
26
50
|
}
|
|
27
51
|
interface CreateOrUpdateCompanyRequest {
|
|
28
52
|
/** The name of the Company */
|
|
@@ -38,21 +62,13 @@ declare module 'intercom-client' {
|
|
|
38
62
|
/** The industry that this company operates in. */
|
|
39
63
|
industry?: string;
|
|
40
64
|
/** A hash of key/value pairs containing any other data about the company you want Intercom to store. */
|
|
41
|
-
custom_attributes?:
|
|
65
|
+
custom_attributes?: CompanyCustomAttributes;
|
|
42
66
|
/** The time the company was created by you. */
|
|
43
67
|
remote_created_at?: number;
|
|
44
68
|
/** 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.. */
|
|
45
69
|
monthly_spend?: number;
|
|
46
70
|
}
|
|
47
|
-
interface
|
|
48
|
-
article_id?: string;
|
|
49
|
-
workflowInstanceId?: number;
|
|
50
|
-
Onboarding_Support?: string;
|
|
51
|
-
Active_Listings?: string;
|
|
52
|
-
Accounting_Software?: string;
|
|
53
|
-
userType?: string;
|
|
54
|
-
}
|
|
55
|
-
interface IntercomCompanyCustomAttributes {
|
|
71
|
+
interface CompanyCustomAttributes {
|
|
56
72
|
teamId?: string;
|
|
57
73
|
team?: string;
|
|
58
74
|
type?: string;
|
|
@@ -100,10 +100,64 @@ export const useTracking = ({ dataset, env, name }, isDev) => {
|
|
|
100
100
|
traits,
|
|
101
101
|
timestamp,
|
|
102
102
|
}, (err) => (err ? console.error(err) : {}));
|
|
103
|
+
// upsert intercom user
|
|
104
|
+
const data = {
|
|
105
|
+
external_id: userId,
|
|
106
|
+
email: traits?.email,
|
|
107
|
+
name: traits?.name ||
|
|
108
|
+
(traits?.firstName
|
|
109
|
+
? `${traits.firstName} ${traits.lastName}`
|
|
110
|
+
: traits?.lastName),
|
|
111
|
+
avatar: traits?.avatar,
|
|
112
|
+
signed_up_at: traits?.createdAt
|
|
113
|
+
? new Date(traits.createdAt).getTime() / 1000
|
|
114
|
+
: undefined,
|
|
115
|
+
last_seen_at: new Date().getTime() / 1000,
|
|
116
|
+
custom_attributes: { userType: traits?.role },
|
|
117
|
+
};
|
|
118
|
+
const intercomUser = (await intercom?.contacts.search({
|
|
119
|
+
query: {
|
|
120
|
+
field: 'external_id',
|
|
121
|
+
operator: Intercom.SingleFilterSearchRequestOperator.Equals,
|
|
122
|
+
value: userId,
|
|
123
|
+
},
|
|
124
|
+
}))?.data.at(0);
|
|
125
|
+
if (intercomUser?.id)
|
|
126
|
+
await intercom?.contacts.update(intercomUser?.id, data);
|
|
127
|
+
else
|
|
128
|
+
await intercom?.contacts.create(data);
|
|
103
129
|
},
|
|
104
130
|
group: async ({ traits, groupId, userId, anonymousId, timestamp, }) => {
|
|
105
131
|
if (isDev || isTest(userId || anonymousId || '', groupId))
|
|
106
132
|
return;
|
|
133
|
+
const cid = traits?.billingCustomerId || traits?.hyperlineCustomerId;
|
|
134
|
+
const intercomCompany = await intercom?.companies.create({
|
|
135
|
+
name: traits?.name,
|
|
136
|
+
company_id: groupId,
|
|
137
|
+
// plan: string;
|
|
138
|
+
remote_created_at: traits?.createdAt
|
|
139
|
+
? new Date(traits.createdAt).getTime() / 1000
|
|
140
|
+
: undefined,
|
|
141
|
+
// monthly_spend: number;
|
|
142
|
+
custom_attributes: {
|
|
143
|
+
teamId: groupId,
|
|
144
|
+
team: traits?.name,
|
|
145
|
+
type: traits?.type,
|
|
146
|
+
status: traits?.status,
|
|
147
|
+
pms: traits?.pms,
|
|
148
|
+
accountingSoftware: traits?.accountingSoftware,
|
|
149
|
+
activeListings: traits?.activeListings,
|
|
150
|
+
// paymentMethodType: string; // Payment Method
|
|
151
|
+
partnerName: traits?.partner || traits?.accountingPartner,
|
|
152
|
+
billingPortalUrl: cid
|
|
153
|
+
? `https://billing.vrplatform.app/portal/${cid}`
|
|
154
|
+
: undefined,
|
|
155
|
+
billingStatus: traits?.billingSubscriptionStatus,
|
|
156
|
+
billingPartner: traits?.billingPartner ||
|
|
157
|
+
traits?.partner ||
|
|
158
|
+
traits?.accountingPartner,
|
|
159
|
+
},
|
|
160
|
+
});
|
|
107
161
|
if (anonymousId) {
|
|
108
162
|
posthog?.groupIdentify({
|
|
109
163
|
groupKey: groupId,
|
|
@@ -121,6 +175,18 @@ export const useTracking = ({ dataset, env, name }, isDev) => {
|
|
|
121
175
|
distinctId: userId,
|
|
122
176
|
});
|
|
123
177
|
june?.group({ userId, groupId, traits, timestamp }, (err) => err ? console.error(err) : {});
|
|
178
|
+
// attach intercom user to intercom company
|
|
179
|
+
const intercomUser = (await intercom?.contacts.search({
|
|
180
|
+
query: {
|
|
181
|
+
field: 'external_id',
|
|
182
|
+
operator: Intercom.SingleFilterSearchRequestOperator.Equals,
|
|
183
|
+
value: userId,
|
|
184
|
+
},
|
|
185
|
+
}))?.data.at(0);
|
|
186
|
+
if (intercomUser?.id && intercomCompany?.id)
|
|
187
|
+
intercom?.companies.attachContact(intercomUser?.id, {
|
|
188
|
+
id: intercomCompany?.id,
|
|
189
|
+
});
|
|
124
190
|
}
|
|
125
191
|
},
|
|
126
192
|
shutdown: async () => Promise.all([posthog?.shutdown(), june?.closeAndFlush(), log?.flush()]),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"src/","sources":["tracking/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"src/","sources":["tracking/index.ts"],"names":[],"mappings":"AAoGA,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACpD,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAC3D,OAAO,EAAE,OAAO,EAAE,MAAM,sCAAsC,CAAC;AAC/D,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAkB,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChD,OAAO,EAAE,sBAAsB,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAC1D,OAAO,EAAE,qBAAqB,EAAE,MAAM,gCAAgC,CAAC;AAQvE,cAAc,SAAS,CAAC;AACxB,cAAc,iBAAiB,CAAC;AAIhC,MAAM,CAAC,MAAM,WAAW,GAAG,CACzB,EAAE,OAAO,EAAE,GAAG,EAAE,IAAI,EAAiB,E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C,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAC9B,CAAC;gBAEF,2CAA2C;gBAC3C,MAAM,YAAY,GAAG,CACnB,MAAM,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC;oBAC9B,KAAK,EAAE;wBACL,KAAK,EAAE,aAAa;wBACpB,QAAQ,EAAE,QAAQ,CAAC,iCAAiC,CAAC,MAAM;wBAC3D,KAAK,EAAE,MAAM;qBACd;iBACF,CAAC,CACH,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;gBACd,IAAI,YAAY,EAAE,EAAE,IAAI,eAAe,EAAE,EAAE;oBACzC,QAAQ,EAAE,SAAS,CAAC,aAAa,CAAC,YAAY,EAAE,EAAE,EAAE;wBAClD,EAAE,EAAE,eAAe,EAAE,EAAE;qBACxB,CAAC,CAAC;YACP,CAAC;QACH,CAAC;QACD,QAAQ,EAAE,KAAK,IAAI,EAAE,CACnB,OAAO,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,QAAQ,EAAE,EAAE,IAAI,EAAE,aAAa,EAAE,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC,CAAC;QACzE,sBAAsB;QACtB,QAAQ;QACR,OAAO;QACP,IAAI;QACJ,GAAG;KACJ,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -32,13 +32,46 @@ export type TrackProps = OptionalUser<{
|
|
|
32
32
|
}>;
|
|
33
33
|
export type IdentifyProps = {
|
|
34
34
|
userId: string;
|
|
35
|
-
traits
|
|
35
|
+
traits?: {
|
|
36
|
+
id?: string;
|
|
37
|
+
email?: string;
|
|
38
|
+
avatar?: string;
|
|
39
|
+
name?: string;
|
|
40
|
+
firstName?: string;
|
|
41
|
+
lastName?: string;
|
|
42
|
+
createdAt?: string;
|
|
43
|
+
country?: string;
|
|
44
|
+
isSuperAdmin?: boolean;
|
|
45
|
+
isVrpAdmin?: boolean;
|
|
46
|
+
isPartnerAdmin?: boolean;
|
|
47
|
+
isTeamAdmin?: boolean;
|
|
48
|
+
role?: 'super-admin' | 'vrp-admin' | 'partner-admin' | 'team-admin' | 'admin' | 'owner' | 'user';
|
|
49
|
+
[key: string]: string | number | boolean | null | undefined;
|
|
50
|
+
};
|
|
36
51
|
disableGeoip?: boolean;
|
|
37
52
|
timestamp?: Date;
|
|
38
53
|
};
|
|
39
54
|
export type GroupProps = OptionalUser<{
|
|
40
55
|
groupId: string;
|
|
41
|
-
traits?:
|
|
56
|
+
traits?: {
|
|
57
|
+
name?: string;
|
|
58
|
+
type?: 'admin' | 'partner' | 'propertyManager';
|
|
59
|
+
avatar?: string;
|
|
60
|
+
createdAt?: string;
|
|
61
|
+
partner?: string;
|
|
62
|
+
partnerId?: string;
|
|
63
|
+
billingCustomerId?: string;
|
|
64
|
+
billingSubscriptionStatus?: string;
|
|
65
|
+
status?: 'active' | 'inactive';
|
|
66
|
+
isOnboarding?: boolean;
|
|
67
|
+
accountingPartner?: string;
|
|
68
|
+
billingPartner?: string;
|
|
69
|
+
pms?: string;
|
|
70
|
+
apps?: string;
|
|
71
|
+
accountingSoftware?: string;
|
|
72
|
+
activeListings?: number;
|
|
73
|
+
[key: string]: string | number | boolean | null | undefined;
|
|
74
|
+
};
|
|
42
75
|
timestamp?: Date;
|
|
43
76
|
}>;
|
|
44
77
|
type OptionalUser<T> = T & ({
|
package/package.json
CHANGED
package/src/tracking/index.ts
CHANGED
|
@@ -1,8 +1,28 @@
|
|
|
1
1
|
declare module 'intercom-client' {
|
|
2
2
|
export namespace Intercom {
|
|
3
|
+
export interface CreateContactRequestWithExternalId {
|
|
4
|
+
/** A unique identifier for the contact which is given to Intercom */
|
|
5
|
+
external_id: string;
|
|
6
|
+
/** The contacts phone */
|
|
7
|
+
phone?: string;
|
|
8
|
+
/** The contacts name */
|
|
9
|
+
name?: string;
|
|
10
|
+
/** An image URL containing the avatar of a contact */
|
|
11
|
+
avatar?: string;
|
|
12
|
+
/** The time specified for when a contact signed up */
|
|
13
|
+
signed_up_at?: number;
|
|
14
|
+
/** The time when the contact was last seen (either where the Intercom Messenger was installed or when specified manually) */
|
|
15
|
+
last_seen_at?: number;
|
|
16
|
+
/** The id of an admin that has been assigned account ownership of the contact */
|
|
17
|
+
owner_id?: number;
|
|
18
|
+
/** Whether the contact is unsubscribed from emails */
|
|
19
|
+
unsubscribed_from_emails?: boolean;
|
|
20
|
+
/** The custom attributes which are set for the contact */
|
|
21
|
+
custom_attributes?: ContactCustomAttributes;
|
|
22
|
+
}
|
|
3
23
|
interface UpdateContactRequest {
|
|
4
24
|
/** The role of the contact. */
|
|
5
|
-
role?:
|
|
25
|
+
role?: 'user' | 'lead';
|
|
6
26
|
/** A unique identifier for the contact which is given to Intercom */
|
|
7
27
|
external_id?: string;
|
|
8
28
|
/** The contacts email */
|
|
@@ -22,7 +42,16 @@ declare module 'intercom-client' {
|
|
|
22
42
|
/** Whether the contact is unsubscribed from emails */
|
|
23
43
|
unsubscribed_from_emails?: boolean;
|
|
24
44
|
/** The custom attributes which are set for the contact */
|
|
25
|
-
custom_attributes?:
|
|
45
|
+
custom_attributes?: ContactCustomAttributes;
|
|
46
|
+
}
|
|
47
|
+
interface ContactCustomAttributes {
|
|
48
|
+
Onboarding_Support?: string; // The customer's preferred onboarding level
|
|
49
|
+
userType?: string; // User Type (user or owner)
|
|
50
|
+
// ARCHIVED
|
|
51
|
+
// article_id?: string; // undefined
|
|
52
|
+
// workflowInstanceId?: number; // undefined
|
|
53
|
+
// Active_Listings?: string; // The number of active listings a user has
|
|
54
|
+
// Accounting_Software?: string; // The client's accounting software
|
|
26
55
|
}
|
|
27
56
|
interface CreateOrUpdateCompanyRequest {
|
|
28
57
|
/** The name of the Company */
|
|
@@ -38,21 +67,13 @@ declare module 'intercom-client' {
|
|
|
38
67
|
/** The industry that this company operates in. */
|
|
39
68
|
industry?: string;
|
|
40
69
|
/** A hash of key/value pairs containing any other data about the company you want Intercom to store. */
|
|
41
|
-
custom_attributes?:
|
|
70
|
+
custom_attributes?: CompanyCustomAttributes;
|
|
42
71
|
/** The time the company was created by you. */
|
|
43
72
|
remote_created_at?: number;
|
|
44
73
|
/** 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.. */
|
|
45
74
|
monthly_spend?: number;
|
|
46
75
|
}
|
|
47
|
-
interface
|
|
48
|
-
article_id?: string; // undefined
|
|
49
|
-
workflowInstanceId?: number; // undefined
|
|
50
|
-
Onboarding_Support?: string; // The customer's preferred onboarding level
|
|
51
|
-
Active_Listings?: string; // The number of active listings a user has
|
|
52
|
-
Accounting_Software?: string; // The client's accounting software
|
|
53
|
-
userType?: string; // User Type (user or owner)
|
|
54
|
-
}
|
|
55
|
-
interface IntercomCompanyCustomAttributes {
|
|
76
|
+
interface CompanyCustomAttributes {
|
|
56
77
|
teamId?: string; // undefined
|
|
57
78
|
team?: string; // undefined
|
|
58
79
|
type?: string; // undefined
|
|
@@ -231,6 +252,36 @@ export const useTracking = (
|
|
|
231
252
|
},
|
|
232
253
|
(err) => (err ? console.error(err) : {})
|
|
233
254
|
);
|
|
255
|
+
|
|
256
|
+
// upsert intercom user
|
|
257
|
+
const data = {
|
|
258
|
+
external_id: userId,
|
|
259
|
+
email: traits?.email,
|
|
260
|
+
name:
|
|
261
|
+
traits?.name ||
|
|
262
|
+
(traits?.firstName
|
|
263
|
+
? `${traits.firstName} ${traits.lastName}`
|
|
264
|
+
: traits?.lastName),
|
|
265
|
+
avatar: traits?.avatar,
|
|
266
|
+
signed_up_at: traits?.createdAt
|
|
267
|
+
? new Date(traits.createdAt).getTime() / 1000
|
|
268
|
+
: undefined,
|
|
269
|
+
last_seen_at: new Date().getTime() / 1000,
|
|
270
|
+
custom_attributes: { userType: traits?.role },
|
|
271
|
+
};
|
|
272
|
+
|
|
273
|
+
const intercomUser = (
|
|
274
|
+
await intercom?.contacts.search({
|
|
275
|
+
query: {
|
|
276
|
+
field: 'external_id',
|
|
277
|
+
operator: Intercom.SingleFilterSearchRequestOperator.Equals,
|
|
278
|
+
value: userId,
|
|
279
|
+
},
|
|
280
|
+
})
|
|
281
|
+
)?.data.at(0);
|
|
282
|
+
if (intercomUser?.id)
|
|
283
|
+
await intercom?.contacts.update(intercomUser?.id, data);
|
|
284
|
+
else await intercom?.contacts.create(data);
|
|
234
285
|
},
|
|
235
286
|
group: async ({
|
|
236
287
|
traits,
|
|
@@ -241,6 +292,36 @@ export const useTracking = (
|
|
|
241
292
|
}: GroupProps) => {
|
|
242
293
|
if (isDev || isTest(userId || anonymousId || '', groupId)) return;
|
|
243
294
|
|
|
295
|
+
const cid = traits?.billingCustomerId || traits?.hyperlineCustomerId;
|
|
296
|
+
const intercomCompany = await intercom?.companies.create({
|
|
297
|
+
name: traits?.name,
|
|
298
|
+
company_id: groupId,
|
|
299
|
+
// plan: string;
|
|
300
|
+
remote_created_at: traits?.createdAt
|
|
301
|
+
? new Date(traits.createdAt).getTime() / 1000
|
|
302
|
+
: undefined,
|
|
303
|
+
// monthly_spend: number;
|
|
304
|
+
custom_attributes: {
|
|
305
|
+
teamId: groupId,
|
|
306
|
+
team: traits?.name,
|
|
307
|
+
type: traits?.type,
|
|
308
|
+
status: traits?.status,
|
|
309
|
+
pms: traits?.pms,
|
|
310
|
+
accountingSoftware: traits?.accountingSoftware,
|
|
311
|
+
activeListings: traits?.activeListings,
|
|
312
|
+
// paymentMethodType: string; // Payment Method
|
|
313
|
+
partnerName: traits?.partner || traits?.accountingPartner,
|
|
314
|
+
billingPortalUrl: cid
|
|
315
|
+
? `https://billing.vrplatform.app/portal/${cid}`
|
|
316
|
+
: undefined,
|
|
317
|
+
billingStatus: traits?.billingSubscriptionStatus,
|
|
318
|
+
billingPartner:
|
|
319
|
+
traits?.billingPartner ||
|
|
320
|
+
traits?.partner ||
|
|
321
|
+
traits?.accountingPartner,
|
|
322
|
+
},
|
|
323
|
+
});
|
|
324
|
+
|
|
244
325
|
if (anonymousId) {
|
|
245
326
|
posthog?.groupIdentify({
|
|
246
327
|
groupKey: groupId,
|
|
@@ -263,6 +344,21 @@ export const useTracking = (
|
|
|
263
344
|
june?.group({ userId, groupId, traits, timestamp }, (err) =>
|
|
264
345
|
err ? console.error(err) : {}
|
|
265
346
|
);
|
|
347
|
+
|
|
348
|
+
// attach intercom user to intercom company
|
|
349
|
+
const intercomUser = (
|
|
350
|
+
await intercom?.contacts.search({
|
|
351
|
+
query: {
|
|
352
|
+
field: 'external_id',
|
|
353
|
+
operator: Intercom.SingleFilterSearchRequestOperator.Equals,
|
|
354
|
+
value: userId,
|
|
355
|
+
},
|
|
356
|
+
})
|
|
357
|
+
)?.data.at(0);
|
|
358
|
+
if (intercomUser?.id && intercomCompany?.id)
|
|
359
|
+
intercom?.companies.attachContact(intercomUser?.id, {
|
|
360
|
+
id: intercomCompany?.id,
|
|
361
|
+
});
|
|
266
362
|
}
|
|
267
363
|
},
|
|
268
364
|
shutdown: async () =>
|
package/src/tracking/types.ts
CHANGED
|
@@ -117,13 +117,53 @@ export type TrackProps = OptionalUser<{
|
|
|
117
117
|
}>;
|
|
118
118
|
export type IdentifyProps = {
|
|
119
119
|
userId: string;
|
|
120
|
-
traits
|
|
120
|
+
traits?: {
|
|
121
|
+
id?: string;
|
|
122
|
+
email?: string;
|
|
123
|
+
avatar?: string;
|
|
124
|
+
name?: string;
|
|
125
|
+
firstName?: string;
|
|
126
|
+
lastName?: string;
|
|
127
|
+
createdAt?: string;
|
|
128
|
+
country?: string;
|
|
129
|
+
isSuperAdmin?: boolean;
|
|
130
|
+
isVrpAdmin?: boolean;
|
|
131
|
+
isPartnerAdmin?: boolean;
|
|
132
|
+
isTeamAdmin?: boolean;
|
|
133
|
+
role?:
|
|
134
|
+
| 'super-admin'
|
|
135
|
+
| 'vrp-admin'
|
|
136
|
+
| 'partner-admin'
|
|
137
|
+
| 'team-admin'
|
|
138
|
+
| 'admin'
|
|
139
|
+
| 'owner'
|
|
140
|
+
| 'user';
|
|
141
|
+
[key: string]: string | number | boolean | null | undefined;
|
|
142
|
+
};
|
|
121
143
|
disableGeoip?: boolean;
|
|
122
144
|
timestamp?: Date;
|
|
123
145
|
};
|
|
124
146
|
export type GroupProps = OptionalUser<{
|
|
125
147
|
groupId: string;
|
|
126
|
-
traits?:
|
|
148
|
+
traits?: {
|
|
149
|
+
name?: string;
|
|
150
|
+
type?: 'admin' | 'partner' | 'propertyManager';
|
|
151
|
+
avatar?: string;
|
|
152
|
+
createdAt?: string;
|
|
153
|
+
partner?: string;
|
|
154
|
+
partnerId?: string;
|
|
155
|
+
billingCustomerId?: string;
|
|
156
|
+
billingSubscriptionStatus?: string; // todo: update type as enum
|
|
157
|
+
status?: 'active' | 'inactive';
|
|
158
|
+
isOnboarding?: boolean;
|
|
159
|
+
accountingPartner?: string;
|
|
160
|
+
billingPartner?: string;
|
|
161
|
+
pms?: string;
|
|
162
|
+
apps?: string;
|
|
163
|
+
accountingSoftware?: string;
|
|
164
|
+
activeListings?: number;
|
|
165
|
+
[key: string]: string | number | boolean | null | undefined;
|
|
166
|
+
};
|
|
127
167
|
timestamp?: Date;
|
|
128
168
|
}>;
|
|
129
169
|
|