Skip to content

Commit

Permalink
Add UUID to events, based on Segment's messageId
Browse files Browse the repository at this point in the history
  • Loading branch information
bretthoerner committed Apr 29, 2024
1 parent 325e50a commit fc880d7
Show file tree
Hide file tree
Showing 5 changed files with 338 additions and 351 deletions.
4 changes: 4 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ async function onTrack(event, settings) {
const endpoint = new URL(`${baseUrl}/capture/`)
endpoint.searchParams.set('ts', event.timestamp)

const namespace = uuidv5.uuidv5('null', 'PostHog', true)
const uuid = uuidv5.uuidv5(namespace, event.messageId)

if (event.properties && event.properties.url) {
event.properties['$current_url'] = event.properties.url
delete event.properties.url
Expand All @@ -67,6 +70,7 @@ async function onTrack(event, settings) {

const res = await fetch(endpoint, {
body: JSON.stringify({
uuid,
timestamp: event.timestamp,
event: event.event,
api_key: settings.apiKey,
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"license": "MIT",
"devDependencies": {
"jest": "^29.5.0",
"lodash": "^4.17.21"
"lodash": "^4.17.21",
"uuidv5": "^1.0.0"
}
}
}
Loading

0 comments on commit fc880d7

Please sign in to comment.