User Profile Data

Data can be stored on a user Profile that can then be used throughout the system. These attributes can include Semantic User Attributes.

Operations on user Profile data use the message type userDataOps.

Operations

The operations parameter takes an array of operations. These can be of the following type:

  • set - sets a Profile attribute to a given value

  • setOnce - sets a Profile attribute to a given value if it currently does not exist

  • unset - removes a Profile attribute

  • increment - increments a Profile attribute by a given integer amount

You can send as many operations as needed at a time, and they can be of more than one type.

Expiry

Both set and setOnce allow you to supply an expiresOn property. This must be an integer of epoch time UTC; in milliseconds.

Set

Use this to set an attribute on a Profile.

Example

This example sets the attribute favoriteColor to red. This Profile property will expire near the beginning of 2024.

{
  "type": "userDataOps",
  // the operations
  "operations": [{
    "type": "set",
    "key": "favoriteColor",
    "value": "red",
    "expiresOn": 1704139200000
  }],
  // general message properties
  "writeKey": "<WRITE_KEY>",
  "messageId": "213d7f53-ffac-4a58-a20b-5d609455d64c",
  "timestamp": "2022-11-15T04:31:44Z",
  "userId": "5.wBOQ7hKNVgIUcJn5IbX.1670273082",
  "sessionId": "28eef5c8-1098-4f76-abe9-58a921cabfaf",
  "pageId": "eca34e0f-4802-4fa4-8db1-11c727839dbd"
  "context": {
    "page": {
      "url": "https://www.weather-station.com/",
      "path": "/",
      "referrer": "",
      "title": "Weather Station - Get Weather"
    },
  }
}

Set Once

Use this to set an attribute on a Profile only if it has not yet been set..

Example

This example, if run after the set example, will not change the Profile attribute as the value has already been set.

{
  "type": "userDataOps",
  // the operations
  "operations": [{
    "type": "setOnce",
    "key": "favoriteColor",
    "value": "green"
  }],
  // general message properties
  "writeKey": "<WRITE_KEY>",
  "messageId": "213d7f53-ffac-4a58-a20b-5d609455d64c",
  "timestamp": "2022-11-15T04:31:44Z",
  "userId": "5.wBOQ7hKNVgIUcJn5IbX.1670273082",
  "sessionId": "28eef5c8-1098-4f76-abe9-58a921cabfaf",
  "pageId": "eca34e0f-4802-4fa4-8db1-11c727839dbd"
  "context": {
    "page": {
      "url": "https://www.weather-station.com/",
      "path": "/",
      "referrer": "",
      "title": "Weather Station - Get Weather"
    },
  }
}

Unset

Use this to remove an attribute from a Profile.

Example

This example removed the attribute favoriteColor.

{
  "type": "userDataOps",
  // the operations
  "operations": [{
    "type": "unset",
    "key": "favoriteColor"
  }],
  // general message properties
  "writeKey": "<WRITE_KEY>",
  "messageId": "213d7f53-ffac-4a58-a20b-5d609455d64c",
  "timestamp": "2022-11-15T04:31:44Z",
  "userId": "5.wBOQ7hKNVgIUcJn5IbX.1670273082",
  "sessionId": "28eef5c8-1098-4f76-abe9-58a921cabfaf",
  "pageId": "eca34e0f-4802-4fa4-8db1-11c727839dbd"
  "context": {
    "page": {
      "url": "https://www.weather-station.com/",
      "path": "/",
      "referrer": "",
      "title": "Weather Station - Get Weather"
    },
  }
}

Increment

Use this to increment a value on a Profile attribute.

If an attribute with the name already exists, and it is not an integer, the value will also be set to 1. This is true even if the value is a string of "1" rather than the actual value of 1. Also float values such as 10.5 will be reset to 1 on the first increment call.

Example

This example will increment the attribute numberOfLoginAttempts by 1.

{
  "type": "userDataOps",
  // the operations
  "operations": [{
    "type": "increment",
    "key": "numberOfLoginAttempts",
    "value": 1
  }],
  // general message properties
  "writeKey": "<WRITE_KEY>",
  "messageId": "213d7f53-ffac-4a58-a20b-5d609455d64c",
  "timestamp": "2022-11-15T04:31:44Z",
  "userId": "5.wBOQ7hKNVgIUcJn5IbX.1670273082",
  "sessionId": "28eef5c8-1098-4f76-abe9-58a921cabfaf",
  "pageId": "eca34e0f-4802-4fa4-8db1-11c727839dbd"
  "context": {
    "page": {
      "url": "https://www.weather-station.com/",
      "path": "/",
      "referrer": "",
      "title": "Weather Station - Get Weather"
    },
  }
}

Last updated