Skip to content

Commit d950e94

Browse files
committed
Update tracking
1 parent 69689d5 commit d950e94

File tree

2 files changed

+125
-47
lines changed

2 files changed

+125
-47
lines changed

apps/event-system/services/stripe/stripe-webhook.service.ts

Lines changed: 100 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
11
import { ServiceSchema } from 'moleculer';
22
import Stripe from 'stripe';
3-
import { resultErr, resultOk } from '@event-inc/utils';
3+
import { resultErr, resultOk, makeHttpNetworkCall } from '@event-inc/utils';
4+
5+
const TRACK_EVENT = `${process.env.CONNECTIONS_API_BASE_URL}v1/public/mark`;
6+
7+
const context = {
8+
locale: "",
9+
page: {
10+
path: "",
11+
search: "",
12+
title: "",
13+
url: ""
14+
},
15+
userAgent: "",
16+
}
417

518
export default {
619
name: 'stripe-webhook',
@@ -65,15 +78,22 @@ export default {
6578
billing
6679
});
6780

68-
await ctx.broker.call('v1.tracking.public.track', {
69-
path: 't',
81+
await makeHttpNetworkCall({
82+
url: TRACK_EVENT,
83+
method: 'POST',
7084
data: {
71-
event: 'Created Subscription',
72-
properties: subscriptionCreated,
73-
userId: client?.author?._id
85+
path: 't',
86+
data: {
87+
event: 'Created Subscription',
88+
properties: {
89+
...subscriptionCreated,
90+
version: "pica-1.0.0"
91+
},
92+
context,
93+
userId: client?.author?._id
94+
}
7495
}
7596
});
76-
7797
}
7898

7999
break;
@@ -103,13 +123,21 @@ export default {
103123
}
104124
);
105125

106-
await ctx.broker.call('v1.tracking.public.track', {
107-
path: 't',
126+
await makeHttpNetworkCall({
127+
url: TRACK_EVENT,
128+
method: 'POST',
108129
data: {
109-
event: 'Updated Subscription',
110-
properties: subscriptionUpdated,
111-
userId: updatedClient?.author?._id,
112-
},
130+
path: 't',
131+
data: {
132+
event: 'Updated Subscription',
133+
properties: {
134+
...subscriptionUpdated,
135+
version: "pica-1.0.0"
136+
},
137+
context,
138+
userId: updatedClient?.author?._id,
139+
}
140+
}
113141
});
114142

115143
break;
@@ -151,14 +179,22 @@ export default {
151179
billing: updatedBilling,
152180
}
153181
);
154-
155-
await ctx.broker.call('v1.tracking.public.track', {
156-
path: 't',
182+
183+
await makeHttpNetworkCall({
184+
url: TRACK_EVENT,
185+
method: 'POST',
157186
data: {
158-
event: 'Created Subscription',
159-
properties: subscriptionCreated,
160-
userId: client?.author?._id,
161-
},
187+
path: 't',
188+
data: {
189+
event: 'Created Subscription',
190+
properties: {
191+
...subscriptionCreated,
192+
version: "pica-1.0.0"
193+
},
194+
context,
195+
userId: client?.author?._id,
196+
}
197+
}
162198
});
163199
}
164200

@@ -169,15 +205,23 @@ export default {
169205
}
170206
);
171207

172-
await ctx.broker.call('v1.tracking.public.track', {
173-
path: 't',
208+
await makeHttpNetworkCall({
209+
url: TRACK_EVENT,
210+
method: 'POST',
174211
data: {
175-
event: 'Deleted Subscription',
176-
properties: subscriptionDeleted,
177-
userId: client?.author?._id,
178-
},
212+
path: 't',
213+
data: {
214+
event: 'Deleted Subscription',
215+
properties: {
216+
...subscriptionDeleted,
217+
version: "pica-1.0.0"
218+
},
219+
context,
220+
userId: client?.author?._id,
221+
}
222+
}
179223
});
180-
224+
181225
break;
182226

183227
case 'invoice.payment_failed':
@@ -200,16 +244,24 @@ export default {
200244
}
201245
);
202246

203-
await ctx.broker.call('v1.tracking.public.track', {
204-
path: 't',
247+
await makeHttpNetworkCall({
248+
url: TRACK_EVENT,
249+
method: 'POST',
205250
data: {
206-
event: 'Failed Invoice Payment',
207-
properties: invoicePaymentFailed,
208-
userId: currentClient?.author?._id,
209-
},
251+
path: 't',
252+
data: {
253+
event: 'Failed Invoice Payment',
254+
properties: {
255+
...invoicePaymentFailed,
256+
version: "pica-1.0.0"
257+
},
258+
context,
259+
userId: currentClient?.author?._id,
260+
}
261+
}
210262
});
211-
break;
212263

264+
break;
213265
case 'invoice.payment_succeeded':
214266
const invoicePaymentSucceeded = event.data.object;
215267

@@ -225,13 +277,21 @@ export default {
225277
}
226278
);
227279

228-
await ctx.broker.call('v1.tracking.public.track', {
229-
path: 't',
280+
await makeHttpNetworkCall({
281+
url: TRACK_EVENT,
282+
method: 'POST',
230283
data: {
231-
event: 'Successful Invoice Payment',
232-
properties: invoicePaymentSucceeded,
233-
userId: succeededInvoiceClient?.author?._id,
234-
},
284+
path: 't',
285+
data: {
286+
event: 'Successful Invoice Payment',
287+
properties: {
288+
...invoicePaymentSucceeded,
289+
version: "pica-1.0.0"
290+
},
291+
context,
292+
userId: succeededInvoiceClient?.author?._id,
293+
}
294+
}
235295
});
236296

237297
break;

libs-private/service-logic/services/onboarding/useOnboardingService.ts

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ import { Context } from 'moleculer';
22
import { Ownership } from '@libs-private/data-models';
33
import Stripe from 'stripe';
44
import { BResult } from '@event-inc/types';
5-
import { resultErr, resultOk } from '@event-inc/utils';
5+
import { makeHttpNetworkCall, resultErr, resultOk } from '@event-inc/utils';
66
import { ClientRecord } from '@event-inc/types/generic';
77
import { useSettingsService } from '../settings/useSettingsService';
88

9+
const TRACK_EVENT = `${process.env.CONNECTIONS_API_BASE_URL}v1/public/mark`;
10+
911
export const useOnboardingService = (ctx: Context, ownership: Ownership) => {
1012
return {
1113
async init({
@@ -50,13 +52,29 @@ export const useOnboardingService = (ctx: Context, ownership: Ownership) => {
5052
billing,
5153
});
5254

53-
// Track customer creation
54-
await ctx.broker.call('v1.tracking.public.track', {
55-
path: 't',
55+
await makeHttpNetworkCall({
56+
url: TRACK_EVENT,
57+
method: 'POST',
5658
data: {
57-
event: 'Created Customer',
58-
properties: response?.customer,
59-
userId: client?.author?._id
59+
path: 't',
60+
data: {
61+
event: 'Created Customer',
62+
properties: {
63+
...response?.customer,
64+
version: "pica-1.0.0"
65+
},
66+
context: {
67+
locale: "",
68+
page: {
69+
path: "",
70+
search: "",
71+
title: "",
72+
url: ""
73+
},
74+
userAgent: "",
75+
},
76+
userId: client?.author?._id,
77+
}
6078
}
6179
});
6280

0 commit comments

Comments
 (0)