mirror of
https://github.com/dadosfera/maestro.git
synced 2026-10-18 07:09:07 +00:00
34 lines
950 B
TypeScript
34 lines
950 B
TypeScript
import { Body, Controller, Inject, Param, Post } from '@nestjs/common';
|
|
import { init } from 'mixpanel';
|
|
import { Authenticated } from 'src/authentication/authentication.decorator';
|
|
import { RequestUser, User } from 'src/authentication/user.decorator';
|
|
|
|
@Authenticated()
|
|
@Controller('trackEvent')
|
|
export class MixpanelController {
|
|
constructor(
|
|
@Inject('MIXPANEL_TOKEN')
|
|
private readonly mixpanelToken: string,
|
|
) {}
|
|
@Post(':id')
|
|
async trackEvent(@Param('id') id, @Body() body, @User() user: RequestUser) {
|
|
delete body.info;
|
|
const mixpanel = init(this.mixpanelToken);
|
|
|
|
await mixpanel.people.set(user.username, {
|
|
$name: user.username,
|
|
$email: user.username,
|
|
customer_name: user.customer_name,
|
|
});
|
|
|
|
await mixpanel.track(id, {
|
|
distinct_id: user.username,
|
|
customer: user.customer_name,
|
|
env: process.env.ENV,
|
|
...body,
|
|
});
|
|
|
|
return { id, body, user: user.username };
|
|
}
|
|
}
|