2023-07-13 00:26:20 +00:00
|
|
|
import { Analytics } from '@segment/analytics-node'
|
|
|
|
import { v4 as uuid } from 'uuid'
|
|
|
|
|
|
|
|
const analytics = new Analytics({ writeKey: process.env.TELEMETRY_WRITE_KEY || '<empty>' })
|
|
|
|
|
|
|
|
export async function POST(req: Request) {
|
|
|
|
const { email } = await req.json()
|
|
|
|
|
2023-07-19 23:11:56 +00:00
|
|
|
const id = uuid()
|
|
|
|
|
|
|
|
await analytics.identify({
|
|
|
|
anonymousId: id,
|
2023-07-13 00:26:20 +00:00
|
|
|
traits: {
|
|
|
|
email,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2023-07-19 23:11:56 +00:00
|
|
|
await analytics.track({
|
|
|
|
anonymousId: id,
|
|
|
|
event: 'signup',
|
|
|
|
properties: {
|
|
|
|
email,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2023-07-13 00:26:20 +00:00
|
|
|
return new Response(null, { status: 200 })
|
|
|
|
}
|