Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Update tracking #55

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
140 changes: 100 additions & 40 deletions apps/event-system/services/stripe/stripe-webhook.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
import { ServiceSchema } from 'moleculer';
import Stripe from 'stripe';
import { resultErr, resultOk } from '@event-inc/utils';
import { resultErr, resultOk, makeHttpNetworkCall } from '@event-inc/utils';

const TRACK_EVENT = `${process.env.CONNECTIONS_API_BASE_URL}v1/public/mark`;

const context = {
locale: "",
page: {
path: "",
search: "",
title: "",
url: ""
},
userAgent: "",
}

export default {
name: 'stripe-webhook',
Expand Down Expand Up @@ -65,15 +78,22 @@ export default {
billing
});

await ctx.broker.call('v1.tracking.public.track', {
path: 't',
await makeHttpNetworkCall({
url: TRACK_EVENT,
method: 'POST',
data: {
event: 'Created Subscription',
properties: subscriptionCreated,
userId: client?.author?._id
path: 't',
data: {
event: 'Created Subscription',
properties: {
...subscriptionCreated,
version: "pica-1.0.0"
},
context,
userId: client?.author?._id
}
}
});

}

break;
Expand Down Expand Up @@ -103,13 +123,21 @@ export default {
}
);

await ctx.broker.call('v1.tracking.public.track', {
path: 't',
await makeHttpNetworkCall({
url: TRACK_EVENT,
method: 'POST',
data: {
event: 'Updated Subscription',
properties: subscriptionUpdated,
userId: updatedClient?.author?._id,
},
path: 't',
data: {
event: 'Updated Subscription',
properties: {
...subscriptionUpdated,
version: "pica-1.0.0"
},
context,
userId: updatedClient?.author?._id,
}
}
});

break;
Expand Down Expand Up @@ -151,14 +179,22 @@ export default {
billing: updatedBilling,
}
);

await ctx.broker.call('v1.tracking.public.track', {
path: 't',

await makeHttpNetworkCall({
url: TRACK_EVENT,
method: 'POST',
data: {
event: 'Created Subscription',
properties: subscriptionCreated,
userId: client?.author?._id,
},
path: 't',
data: {
event: 'Created Subscription',
properties: {
...subscriptionCreated,
version: "pica-1.0.0"
},
context,
userId: client?.author?._id,
}
}
});
}

Expand All @@ -169,15 +205,23 @@ export default {
}
);

await ctx.broker.call('v1.tracking.public.track', {
path: 't',
await makeHttpNetworkCall({
url: TRACK_EVENT,
method: 'POST',
data: {
event: 'Deleted Subscription',
properties: subscriptionDeleted,
userId: client?.author?._id,
},
path: 't',
data: {
event: 'Deleted Subscription',
properties: {
...subscriptionDeleted,
version: "pica-1.0.0"
},
context,
userId: client?.author?._id,
}
}
});

break;

case 'invoice.payment_failed':
Expand All @@ -200,16 +244,24 @@ export default {
}
);

await ctx.broker.call('v1.tracking.public.track', {
path: 't',
await makeHttpNetworkCall({
url: TRACK_EVENT,
method: 'POST',
data: {
event: 'Failed Invoice Payment',
properties: invoicePaymentFailed,
userId: currentClient?.author?._id,
},
path: 't',
data: {
event: 'Failed Invoice Payment',
properties: {
...invoicePaymentFailed,
version: "pica-1.0.0"
},
context,
userId: currentClient?.author?._id,
}
}
});
break;

break;
case 'invoice.payment_succeeded':
const invoicePaymentSucceeded = event.data.object;

Expand All @@ -225,13 +277,21 @@ export default {
}
);

await ctx.broker.call('v1.tracking.public.track', {
path: 't',
await makeHttpNetworkCall({
url: TRACK_EVENT,
method: 'POST',
data: {
event: 'Successful Invoice Payment',
properties: invoicePaymentSucceeded,
userId: succeededInvoiceClient?.author?._id,
},
path: 't',
data: {
event: 'Successful Invoice Payment',
properties: {
...invoicePaymentSucceeded,
version: "pica-1.0.0"
},
context,
userId: succeededInvoiceClient?.author?._id,
}
}
});

break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ import { Context } from 'moleculer';
import { Ownership } from '@libs-private/data-models';
import Stripe from 'stripe';
import { BResult } from '@event-inc/types';
import { resultErr, resultOk } from '@event-inc/utils';
import { makeHttpNetworkCall, resultErr, resultOk } from '@event-inc/utils';
import { ClientRecord } from '@event-inc/types/generic';
import { useSettingsService } from '../settings/useSettingsService';

const TRACK_EVENT = `${process.env.CONNECTIONS_API_BASE_URL}v1/public/mark`;

export const useOnboardingService = (ctx: Context, ownership: Ownership) => {
return {
async init({
Expand Down Expand Up @@ -50,13 +52,29 @@ export const useOnboardingService = (ctx: Context, ownership: Ownership) => {
billing,
});

// Track customer creation
await ctx.broker.call('v1.tracking.public.track', {
path: 't',
await makeHttpNetworkCall({
url: TRACK_EVENT,
method: 'POST',
data: {
event: 'Created Customer',
properties: response?.customer,
userId: client?.author?._id
path: 't',
data: {
event: 'Created Customer',
properties: {
...response?.customer,
version: "pica-1.0.0"
},
context: {
locale: "",
page: {
path: "",
search: "",
title: "",
url: ""
},
userAgent: "",
},
userId: client?.author?._id,
}
}
});

Expand Down
Loading