Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add UUID to events, based on Segment's messageId #20

Merged
merged 2 commits into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 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)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

uuidv5 docs show this example for making a custom namespace: https://www.npmjs.com/package/uuidv5

(I don't think it's worth worrying about whether we can cache in global state or anything like that...)


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 Expand Up @@ -134,6 +138,7 @@ async function onGroup(event, settings) {
...event,
event: '$groupidentify',
properties: {
$geoip_disable: true,
$group_type: 'segment_group',
$group_key: event.groupId,
$group_set: event.traits,
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
Loading