User Affinity Script Function

This API fetches the current user's affinity profile.

📌

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

Syntax:

DY.ServerUtil.getUserAffinities(callbackFn, maxItemsPerAttribute)
ParameterDescriptionType
callbackFnFunction to be called when the response is received or an error occurred.function
maxItemsPerAttributeThe number of items to return per attribute. Limited to 10.integer

Example:

DY.API('callback', function() {
  DY.ServerUtil.getUserAffinities(function(err, affinityProfile) {
    if (err) {
      console.log("An error occured while fetching the affinity profile");
    } else {
      console.log(affinityProfile);
    }
  }, 5);
});

Sample response:

{
  "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
  }
}
🚧

Note

The user affinity API is loaded in the collection script and not immediately available, therefore the call to this API is wrapped by the DY.API('callback') function.


Did this page help you?