Describes Dynamic Customer Profile (DCP) API functions
You can use the dcp APIs if both of the following conditions are true:
- Dynamic Customer Profiles is enabled for your account.
- One of your active and published experiments or campaigns includes an External Attribute audience condition.
If either of the previous do not apply, then window.optimizely.get('dcp') returns undefined.
Syntax
dcp = window["optimizely"].get("dcp");
Parameters
| Parameter and type | Child attribute | Description |
|---|---|---|
| dcp string | N/A | Required. |
Return value
| Parameter and type | Child Attribute | Description |
|---|---|---|
| DCPObject | N/A | N/A |
| getAttributeValue function[getAttributeValue] | Child attribute of type DCPObject. | This API function returns the visitor's value for a content-enabled profile attribute. |
| waitForAttributeValue function[waitForAttributeValue] | Child attribute of type DCPObject. | This API function returns a Promise that is resolved as soon as Web Experimentation receives the visitor's value for a content-enabled profile attribute. |
Example call
dcp = window["optimizely"].get("dcp");Example return value
dcp.getAttributeValue(attribute);
dcp.waitForAttributeValue(attribute);getAttributeValue()
This API function returns the visitor's value for a content-enabled profile attribute.
Syntax
dcp.getAttributeValue(datasourceId, attributeId, attributeName);
Parameters
| Parameter and type | Child attribute | Description |
|---|---|---|
| datasourceId integer | N/A | Required. |
| attributeId integer | N/A | Required if attributeName is not provided. |
| attributeName string | N/A | Required if attributeId is not provided. Does not work if descriptive names are masked in the Web Experimentation snippet. |
Return value
| Parameter and type | Child attribute | Description |
|---|---|---|
| number or Boolean or string or Error | N/A | The uploaded attribute value, or undefined if any of the following are true:
|
Example call
dcp.getAttributeValue(datasourceId, attributeId, attributeName);Examples
Specify an attribute by ID
Get the value for a customer profile attribute.
var dcp = window.optimizely.get('dcp');
var attributeValue = dcp.getAttributeValue({
datasourceId: 123,
attributeId: 456
});Specify an attribute by name
Get the value for a customer profile attribute.
var dcp = window.optimizely.get('dcp');
var attributeValue = dcp.getAttributeValue({
datasourceId: 123,
attributeName: 'Preferred Locale'
});waitForAttributeValue()
This API function returns a Promise that is resolved as soon as Optimizely Web Experimentation receives the visitor's value for a content-enabled profile attribute.
Syntax
dcp.waitForAttributeValue(datasourceId, attributeId, attributeName);
Parameters
| Parameter and type | Child attribute | Description |
|---|---|---|
| datasourceId integer | N/A | Required. |
| attributeId string | N/A | Required if attributeName is not provided. |
| attributeName string | N/A | Required if attributeId is not provided. Does not work if descriptive names are masked in the Web Experimentation snippet. |
Return value
| Parameter and type | Child attribute | Description |
|---|---|---|
| Promise or Error | N/A | An ES6-style Promise that is resolved with the uploaded attribute value, or with undefined if any of the following are true:
|
Example call
dcp.waitForAttributeValue(datasourceId, attributeId, attributeName);Examples
Specify an attribute by ID
Receive the value for a customer profile attribute once it has been fetched from the DCP server.
var dcp = window.optimizely.get('dcp');
dcp.waitForAttributeValue({
datasourceId: 123,
attributeId: 456
}).then(
function(attributeValue) {
...
}
);Specify an attribute by name
Receive the value for a customer profile attribute once it has been fetched from the DCP server.
var dcp = window.optimizely.get('dcp');
dcp.waitForAttributeValue({
datasourceId: 123,
attributeName: 'Preferred Locale'
}).then(
function(attributeValue) {
...
}
);