Skip to content

Commit 2f41e14

Browse files
authored
Change tinybird event format (twentyhq#7272)
Separate pageview analytics from core events
1 parent a10324c commit 2f41e14

File tree

1 file changed

+32
-12
lines changed

1 file changed

+32
-12
lines changed

Diff for: packages/twenty-server/src/engine/core-modules/analytics/analytics.service.ts

+32-12
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ type CreateEventInput = {
1313
@Injectable()
1414
export class AnalyticsService {
1515
private readonly logger = new Logger(AnalyticsService.name);
16-
private readonly datasource = 'event';
16+
private readonly defaultDatasource = 'event';
1717

1818
constructor(
1919
private readonly environmentService: EnvironmentService,
@@ -29,16 +29,31 @@ export class AnalyticsService {
2929
return { success: true };
3030
}
3131

32-
const data = {
33-
action: createEventInput.action,
34-
timestamp: new Date().toISOString(),
35-
version: '1',
36-
payload: {
37-
userId: userId,
38-
workspaceId: workspaceId,
39-
...createEventInput.payload,
40-
},
41-
};
32+
let data;
33+
34+
switch (createEventInput.action) {
35+
case 'pageview':
36+
data = {
37+
timestamp: new Date().toISOString(),
38+
version: '1',
39+
userId: userId,
40+
workspaceId: workspaceId,
41+
...createEventInput.payload,
42+
};
43+
break;
44+
default:
45+
data = {
46+
action: createEventInput.action,
47+
timestamp: new Date().toISOString(),
48+
version: '1',
49+
userId: userId,
50+
workspaceId: workspaceId,
51+
payload: {
52+
...createEventInput.payload,
53+
},
54+
};
55+
break;
56+
}
4257

4358
const config: AxiosRequestConfig = {
4459
headers: {
@@ -47,9 +62,14 @@ export class AnalyticsService {
4762
},
4863
};
4964

65+
const datasource =
66+
createEventInput.action === 'pageview'
67+
? 'pageview'
68+
: this.defaultDatasource;
69+
5070
try {
5171
await this.httpService.axiosRef.post(
52-
`/events?name=${this.datasource}`,
72+
`/events?name=${datasource}`,
5373
data,
5474
config,
5575
);

0 commit comments

Comments
 (0)