Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverb123 committed Oct 23, 2024
1 parent 0854bcc commit d205ddc
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,16 @@ async function onTrack(event, settings) {
event.properties['$groups'] = { segment_group: event.context.groupId }
}

// In alias cases, we set the distinct id explicitly and it has to be what's expected. In all other
// cases, we use the userId if it exists, otherwise the anonymousId.
let distinct_id = null;

if (event.event === '$create_alias') {
distinct_id = event.properties.distinct_id;
} else {
distinct_id = event.userId || event.anonymousId;
}

const res = await fetch(endpoint, {
body: JSON.stringify({
uuid,
Expand All @@ -77,7 +87,7 @@ async function onTrack(event, settings) {
properties: {
...parseContext(event.context),
...event.properties,
distinct_id: event.userId || event.anonymousId,
distinct_id: distinct_id,
$lib: 'Segment',
},
}),
Expand Down

0 comments on commit d205ddc

Please sign in to comment.