Skip to content

user_properties from ExperimentUser are not forwarded to exposure/assignment events #72

@FabricioFFC

Description

@FabricioFFC

Expected Behavior

When calling evaluateV2() with tracksExposure: true, the custom user_properties passed in ExperimentUser should be included in the [Experiment] Exposure event's user_properties.$set, so they are associated with the user profile in Amplitude.

const user: ExperimentUser = {
  user_id: 'user-123',
  device_id: 'device-456',
  user_properties: { anonymous: true, plan: 'premium' },
};

const variants = client.evaluateV2(user, ['my-flag'], { tracksExposure: true });

// Expected: Exposure event should include user_properties in $set
// {
//   event_type: '[Experiment] Exposure',
//   user_id: 'user-123',
//   device_id: 'device-456',
//   user_properties: {
//     $set: {
//       anonymous: true,           // <-- from ExperimentUser.user_properties
//       plan: 'premium',           // <-- from ExperimentUser.user_properties
//       '[Experiment] my-flag': 'treatment'
//     },
//     $unset: {}
//   }
// }

Possible Solution

Merge exposure.user.user_properties into the $set object when building the event:

user_properties: {
  $set: { ...exposure.user.user_properties, ...set },
  $unset: unset,
},

Current Behavior

The user_properties from ExperimentUser are only used for local evaluation targeting and are not forwarded to exposure events.

The same issue exists in assignment-service.ts.

Steps to Reproduce

  1. Initialize local evaluation client with exposureConfig
  2. Create an ExperimentUser with custom user_properties
  3. Call evaluateV2() with tracksExposure: true
  4. Check the exposure event in Amplitude - custom user_properties are missing
import { Experiment } from '@amplitude/experiment-node-server';

const client = Experiment.initializeLocal('DEPLOYMENT_KEY', {
  exposureConfig: { apiKey: 'API_KEY' },
});
await client.start();

const user = {
  user_id: 'user-123',
  device_id: 'device-456',
  user_properties: { anonymous: true },
};

// user_properties is used for targeting but NOT sent to Amplitude
const variants = client.evaluateV2(user, ['my-flag'], { tracksExposure: true });

Environment
JS Server SDK Version: 1.13.2
Installation Method: yarn
Runtime: Node.js

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions