DY.ServerUtil.getUserAffinities()

Returns the current user's affinity profile as collected by the client-side collection script.

📌

The equivalent server-side API is Profile Anywhere, which returns user affinity data generated by Dynamic Yield.

Availability

This method is available only after the collection script has finished loading.
Wrap the call inside DY.API('callback').

Syntax

DY.ServerUtil.getUserAffinities(callbackFn, maxItemsPerAttribute)

Parameters

ParameterTypeDescription
callbackFnFunctionInvoked when the response is returned or when an error occurs. Receives (err, affinityProfile)
maxItemsPerAttributeIntegerMaximum number of items returned per attribute.
Maximum value: 10

Example

DY.API('callback', function() {
    DY.ServerUtil.getUserAffinities(function(err, affinityProfile) {
        if (err) {
            console.error("Failed to fetch affinity profile");
            return;
        }

        console.log(affinityProfile);
    }, 5);
});

Response structure

The response is an object containing affinity attributes and their scored values.

Example response (standard affinity)

Values are natural numbers representing affinity strength.

{
  "categories": {
    "mens-clothing": 152,
    "t-shirts": 140,
    "jeans": 118,
    "accessories": 24,
    "shoes": 8
  },
  "color": {
    "black": 214,
    "blue": 85,
    "white": 73
  },
  "in_sale": {
    "no": 180,
    "yes": 15
  }
}

Example response (AffinityML)

Values are floats between 0 and 1.

{
  "categories": {
    "mens-clothing": 0.11,
    "t-shirts": 0.34,
    "jeans": 0.41,
    "accessories": 0.57,
    "shoes": 0.79,
    "shorts": 0.8,
    "socks": 0.82,
    "sleepwear": 0.87,
    "winter": 0.93,
    "gloves": 0.94
  }
}