Change tinybird event format (#7272)
Separate pageview analytics from core events
This commit is contained in:
@ -13,7 +13,7 @@ type CreateEventInput = {
|
|||||||
@Injectable()
|
@Injectable()
|
||||||
export class AnalyticsService {
|
export class AnalyticsService {
|
||||||
private readonly logger = new Logger(AnalyticsService.name);
|
private readonly logger = new Logger(AnalyticsService.name);
|
||||||
private readonly datasource = 'event';
|
private readonly defaultDatasource = 'event';
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private readonly environmentService: EnvironmentService,
|
private readonly environmentService: EnvironmentService,
|
||||||
@ -29,16 +29,31 @@ export class AnalyticsService {
|
|||||||
return { success: true };
|
return { success: true };
|
||||||
}
|
}
|
||||||
|
|
||||||
const data = {
|
let data;
|
||||||
action: createEventInput.action,
|
|
||||||
timestamp: new Date().toISOString(),
|
switch (createEventInput.action) {
|
||||||
version: '1',
|
case 'pageview':
|
||||||
payload: {
|
data = {
|
||||||
userId: userId,
|
timestamp: new Date().toISOString(),
|
||||||
workspaceId: workspaceId,
|
version: '1',
|
||||||
...createEventInput.payload,
|
userId: userId,
|
||||||
},
|
workspaceId: workspaceId,
|
||||||
};
|
...createEventInput.payload,
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
data = {
|
||||||
|
action: createEventInput.action,
|
||||||
|
timestamp: new Date().toISOString(),
|
||||||
|
version: '1',
|
||||||
|
userId: userId,
|
||||||
|
workspaceId: workspaceId,
|
||||||
|
payload: {
|
||||||
|
...createEventInput.payload,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
const config: AxiosRequestConfig = {
|
const config: AxiosRequestConfig = {
|
||||||
headers: {
|
headers: {
|
||||||
@ -47,9 +62,14 @@ export class AnalyticsService {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const datasource =
|
||||||
|
createEventInput.action === 'pageview'
|
||||||
|
? 'pageview'
|
||||||
|
: this.defaultDatasource;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await this.httpService.axiosRef.post(
|
await this.httpService.axiosRef.post(
|
||||||
`/events?name=${this.datasource}`,
|
`/events?name=${datasource}`,
|
||||||
data,
|
data,
|
||||||
config,
|
config,
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user