diff --git a/index.js b/index.js index b80692d..7025444 100644 --- a/index.js +++ b/index.js @@ -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 @@ -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, diff --git a/package.json b/package.json index aa82c3b..36c4dfe 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,7 @@ "license": "MIT", "devDependencies": { "jest": "^29.5.0", - "lodash": "^4.17.21" + "lodash": "^4.17.21", + "uuidv5": "^1.0.0" } -} +} \ No newline at end of file diff --git a/prepare-tests.sh b/prepare-tests.sh index 045cfa6..e5e1870 100755 --- a/prepare-tests.sh +++ b/prepare-tests.sh @@ -7,6 +7,12 @@ set -e cp index.js module.js cat >> module.js < { segment_groupId: 'GroupId1', }, timestamp: '2015-12-12T19:11:01.249Z', + uuid: '2e1e762e-c318-5c5b-a96e-955e840a3cf2', }) }) }) @@ -86,6 +87,7 @@ describe('Segment Integration', () => { expect(JSON.parse(lastFetchCall[1].body)).toEqual({ timestamp: '2015-02-23T22:28:55.111Z', + uuid: '38c091ab-1857-58c9-bf58-b98a022f95dd', event: '$identify', api_key: 'test-key', properties: { @@ -123,6 +125,7 @@ describe('Segment Integration', () => { expect(JSON.parse(lastFetchCall[1].body)).toEqual({ timestamp: '2015-02-23T22:28:55.111Z', + uuid: '38c091ab-1857-58c9-bf58-b98a022f95dd', event: '$set', api_key: 'test-key', properties: { @@ -163,6 +166,7 @@ describe('Segment Integration', () => { expect(JSON.parse(lastFetchCall[1].body)).toEqual({ timestamp: '2015-02-23T22:28:55.111Z', + uuid: '38c091ab-1857-58c9-bf58-b98a022f95dd', event: '$groupidentify', api_key: 'test-key', properties: { @@ -199,6 +203,7 @@ describe('Segment Integration', () => { expect(JSON.parse(lastFetchCall[1].body)).toEqual({ timestamp: '2015-02-23T22:28:55.111Z', + uuid: '38c091ab-1857-58c9-bf58-b98a022f95dd', event: '$pageview', api_key: 'test-key', properties: { @@ -228,6 +233,7 @@ describe('Segment Integration', () => { expect(JSON.parse(lastFetchCall[1].body)).toEqual({ timestamp: '2015-02-23T22:28:55.111Z', + uuid: '38c091ab-1857-58c9-bf58-b98a022f95dd', event: '$screen', api_key: 'test-key', properties: { @@ -255,6 +261,7 @@ describe('Segment Integration', () => { expect(JSON.parse(lastFetchCall[1].body)).toEqual({ timestamp: '2015-02-23T22:28:55.111Z', + uuid: '38c091ab-1857-58c9-bf58-b98a022f95dd', event: '$create_alias', api_key: 'test-key', properties: {