Skip to content

Commit

Permalink
Dynamic Yield: fix for non standard identifiers (#2162)
Browse files Browse the repository at this point in the history
* fix for non standard identifiers

* supporting deviceId and advertisingId OOB

* further tweak

* generated types
  • Loading branch information
joe-ayoub-segment authored Jul 16, 2024
1 parent b3a8d63 commit 9b2b9b4
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const destination: AudienceDestinationDefinition<Settings, AudienceSettings> = {
label: 'Identifier Type',
required: true,
description:
'The type of Identifier to send to Dynamic Yield. E.g. `email`, `anonymous_id`, `user_id`, or any other custom identifier. Make sure you configure the `Customized Setup` below so that your chosen include identifier is sent to Dynamic Yield.'
'The type of Identifier to send to Dynamic Yield. E.g. `email`, `anonymousId`, `userId` or any other custom identifier. Make sure to configure the identifier in the `Customized Setup` below so that it is sent to Dynamic Yield.'
}
},
authentication: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,14 @@ const action: ActionDefinition<Settings, Payload, AudienceSettings> = {
}

const audienceName = audienceSettings?.audience_name
const identifierType = (audienceSettings?.identifier_type).toLowerCase().replace(/_/g, '')
const identifierType = audienceSettings?.identifier_type ?? ''
const normalizedIdentifierType = identifierType.toLowerCase().replace(/_/g, '')
const audienceValue = payload.traits_or_props[payload.segment_audience_key]
let sendNormalizeIdType = true

let primaryIdentifier: string | undefined

switch (identifierType) {
switch (normalizedIdentifierType) {
case 'email':
primaryIdentifier = payload.email ?? undefined
break
Expand All @@ -138,14 +140,18 @@ const action: ActionDefinition<Settings, Payload, AudienceSettings> = {
case 'anonymousid':
primaryIdentifier = payload.anonymousId ?? undefined
break
default:
default: {
primaryIdentifier = (payload.traits_or_props[identifierType] as string) ?? undefined
sendNormalizeIdType = false
}
}

if (!primaryIdentifier) {
throw new IntegrationError('Primary Identifier not found', 'MISSING_REQUIRED_FIELD', 400)
}

const idTypeToSend = sendNormalizeIdType ? normalizedIdentifierType : identifierType

const URL = getUpsertURL(settings.dataCenter)

const json = {
Expand All @@ -155,17 +161,17 @@ const action: ActionDefinition<Settings, Payload, AudienceSettings> = {
account: {
account_settings: {
section_id: settings.sectionId,
identifier_type: identifierType,
identifier_type: idTypeToSend,
accessKey: settings.accessKey
}
},
user_profiles: [
{
user_identities: [
{
type: identifierType,
encoding: identifierType === 'email' ? '"sha-256"' : 'raw',
value: identifierType === 'email' ? hashAndEncode(primaryIdentifier) : primaryIdentifier
type: idTypeToSend,
encoding: idTypeToSend === 'email' ? '"sha-256"' : 'raw',
value: idTypeToSend === 'email' ? hashAndEncode(primaryIdentifier) : primaryIdentifier
}
],
audiences: [
Expand Down

0 comments on commit 9b2b9b4

Please sign in to comment.