Skip to content

Conversation

joe-ayoub-segment
Copy link
Contributor

@joe-ayoub-segment joe-ayoub-segment commented Aug 25, 2025

The current Segment <> DY Audience Destination allows customers to select an identifier to send to DY.
The name of the identifier selected must be the same in Segment as it is in DY. However we've had a customer ask if we could allow for the names to be different.

This PR allows customers to sync a Segment identifier (for example user_id) to a different identifier name in Dynamic Yield (for example externalid)

It does this by adding a new configuration field named dy_identifier_type. It's an optional field.

If the customer wanted to sync a Segment identifier named userId to a DY identifier named externalid, then they would apply the following settings:

identifier_type: userid
dy_identifier_type: externalid

The payload sent to DY would look like the following:

{
      type: 'audience_membership_change_request',
      id: "message id value here",
      timestamp_ms: "date value here",
      account: {
        account_settings: {
          sectionId: getSectionId(settings.sectionId),
          identifier: dyIdType ?? segIdType,  // this defaults to the dy_identifier_type and falls back to the name of the segment identifier which is identifier_type
          connectionKey: settings.accessKey
        }
      },
      user_profiles: [
        {
          user_identities: [
            {
              type: dyIdType ?? segIdType, // this defaults to the dy_identifier_type and falls back to the name of the segment identifier which is identifier_type
              encoding: segIdType === 'email' ? '"sha-256"' : 'raw',
              value: segIdType === 'email' ? hashAndEncode(primaryIdentifier) : primaryIdentifier
            }
          ],
          audiences: [
            {
              audience_id: Number(external_audience_id), // must be sent as an integer
              audience_name: audienceName,
              action: audienceValue ? 'add' : 'delete'
            }
          ]
        }
      ]
    }

Testing

Unit tests added

Tested locally. Staging test had a network issue.

Old functionality: Checks that we can still send payloads to DY without using the new dy_identifier_type field.

POST /syncAudience
header = {"Content-Type":"application/json","Authorization":"f3f('5Y[s6zyb!JSNguj2i[HqIZl&i"}
URL = https://cdp-extensions-api.use1.dev.pub.dydy.io/cdp/segment/audiences/membership-change
JSON = {
  "type": "audience_membership_change_request",
  "id": "test-message-ugl6vuyjzl",
  "timestamp_ms": 1756308279780,
  "account": {
    "account_settings": {
      "sectionId": "8790032",
      "identifier": "email",
      "connectionKey": "44feac4206cab6caaecd"
    }
  },
  "user_profiles": [
    {
      "user_identities": [
        {
          "type": "email",
          "encoding": "\"sha-256\"",
          "value": "388c735eec8225c4ad7a507944dd0a975296baea383198aa87177f29af2c6f69"
        }
      ],
      "audiences": [
        {
          "audience_id": 11122233344455,
          "audience_name": "audience_name_1",
          "action": "add"
        }
      ]
    }
  ]
}

New functionality: Makes use of the new dy_identifier_type field to use the name of the ID in DY.

INFO: 💬  200 POST /syncAudience - 10055ms
header = {"Content-Type":"application/json","Authorization":"f3f('5Y[s6zyb!JSNguj2i[HqIZl&i"}
URL = https://cdp-extensions-api.use1.dev.pub.dydy.io/cdp/segment/audiences/membership-change
JSON = {
  "type": "audience_membership_change_request",
  "id": "test-message-ugl6vuyjzl",
  "timestamp_ms": 1756308279780,
  "account": {
    "account_settings": {
      "sectionId": "8790032",
      "identifier": "externalid",
      "connectionKey": "44feac4206cab6caaecd"
    }
  },
  "user_profiles": [
    {
      "user_identities": [
        {
          "type": "externalid",
          "encoding": "\"sha-256\"",
          "value": "388c735eec8225c4ad7a507944dd0a975296baea383198aa87177f29af2c6f69"
        }
      ],
      "audiences": [
        {
          "audience_id": 11122233344455,
          "audience_name": "audience_name_1",
          "action": "add"
        }
      ]
    }
  ]
}

Copy link

codecov bot commented Aug 25, 2025

Codecov Report

❌ Patch coverage is 80.00000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 79.77%. Comparing base (f090092) to head (83fc1aa).
⚠️ Report is 15 commits behind head on main.

Files with missing lines Patch % Lines
...ions/dynamic-yield-audiences/syncAudience/index.ts 80.00% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3197      +/-   ##
==========================================
+ Coverage   79.65%   79.77%   +0.12%     
==========================================
  Files        1177     1177              
  Lines       21686    21703      +17     
  Branches     4219     4222       +3     
==========================================
+ Hits        17273    17314      +41     
+ Misses       3672     3639      -33     
- Partials      741      750       +9     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@joe-ayoub-segment joe-ayoub-segment marked this pull request as ready for review August 28, 2025 12:30
@joe-ayoub-segment joe-ayoub-segment requested a review from a team as a code owner August 28, 2025 12:30
@joe-ayoub-segment joe-ayoub-segment merged commit 3b89396 into main Sep 3, 2025
14 checks passed
@joe-ayoub-segment joe-ayoub-segment deleted the dynamic-yield-identifiers branch September 3, 2025 08:22
@joe-ayoub-segment
Copy link
Contributor Author

PR deployed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants