Skip to content

Commit

Permalink
add user properties if more that one identifier is present
Browse files Browse the repository at this point in the history
  • Loading branch information
murph committed Feb 8, 2023
1 parent e3c311e commit bb4fb94
Showing 1 changed file with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ const action: ActionDefinition<Settings, Payload> = {
idempotency_key: payload.message_id
}

event.user_identifier = getUserIdentifier({ identity: payload.identity, anonymous_id: payload.anonymous_id })
const identity = getUserIdentifier({ identity: payload.identity, anonymous_id: payload.anonymous_id })
event.user_identifier = identity

if (payload.timestamp && dayjs.utc(payload.timestamp).isValid()) {
event.timestamp = dayjs.utc(payload.timestamp).toISOString()
Expand All @@ -131,10 +132,30 @@ const action: ActionDefinition<Settings, Payload> = {
library: 'Segment'
}

return request('https://heapanalytics.com/api/integrations/track', {
const responses = []
const trackCall = request('https://heapanalytics.com/api/integrations/track', {
method: 'post',
json: payLoad
})

responses.push(trackCall)

if (payload.identity && payload.anonymous_id) {
const addUserPropertiesPayload = {
app_id: settings.appId,
identity,
properties: {
anonymous_id: payload.anonymous_id
}
}
const addUserPropertiesRequest = request('https://heapanalytics.com/api/add_user_properties', {
method: 'post',
json: addUserPropertiesPayload
})
responses.push(addUserPropertiesRequest)
}

return Promise.all(responses)
}
}

Expand Down

0 comments on commit bb4fb94

Please sign in to comment.