Data
Returns an object exposing the static data fields. These fields are the same for all visitors on all page loads until you modify your project.
Note: optimizely.get("data")
is a performance-intensive operation; as such you should use it sparingly. For example, if you need to get multiple pieces of data in the same function, call it once and reuse that reference:
var data = optimizely.get('data');
var experiment = data.experiments[myExperimentId];
var firstAudience = data.audiences[experiment.audienceIds[0]];
Syntax
data = window["optimizely"].get("data");
Parameters
Parameter | Child Attribute | Description |
---|---|---|
data | The argument indicating to get data information. Required. |
Return value
Parameter and Type | Child Attribute | Description |
---|---|---|
StaticData | The object contains the fields of the objects you've created using the Optimizely UI or REST API. | |
audiences | Child attribute of type StaticData | An object mapping an audience ID to an audience. |
conditions | Child attribute of type Audience | Conditions the visitor must have to be in the audience. |
id | Child attribute of type Audience | The ID of the audience. |
name | Child attribute of type Audience | The audience name. |
events | Child attribute of type StaticData | An object mapping an event ID to an event. Events determine how/what user behavior is tracked. |
apiName | Child attribute of type Event | A machine-readable name for the event. The |
eventType | Child attribute of type Event | The |
eventFilter | Child attribute of type Event | A filter that indicates when an event can automatically be triggered. This is currently only set for events with the eventType |
filterType | Child attribute of type EventFilter | The type of filter for an event. Currently the only valid value is |
selector | Child attribute of type EventFilter | A CSS style selector that indicates which element on the page is being tracked. |
id | Child attribute of type Event | The event ID. |
category | Child attribute of type Event | An event category that was selected upon creation of the event. Some valid values for category are "added to cart", "saved", "shared", "searched", "purchased", "converted", "signed up", "subscribed", "other". |
name | Child attribute of type Event | A user-chosen name for an event. |
pageId | Child attribute of type Event | A page ID that indicates the page object this event is related to. This event is only executed on the URLs set in the page object. The |
campaigns | Child attribute of type StaticData | An object mapping a campaign ID to a campaign. Campaigns are generated in projects and help tie audiences to experiences. |
changes | Child attribute of type Campaign | Changes on a campaign level. These changes are executed every time the campaign gets activated, regardless of the experiment and variation a visitor is assigned to. |
| Child attribute of type Change | This object can contain project- or environment-specific properties that are not predefined. |
commitId | Child attribute of type Campaign | A new "commit" is made every time a campaign is published. The commit ID refers to the commit that was made. Every time a campaign is published, the commit ID changes. |
experiments | Child attribute of type Campaign | An array of experiments within the campaign. For AB tests, there is always one experiment. Personalization campaigns can have more experiments. |
audienceIds | Child attribute of type Experiment | Representation of audience conditions for the experiment, including audience IDs and combinators. See audience_conditions for format. |
audienceName | Child attribute of type Experiment | Representation of the name of audience(s) used in the experiment. |
id | Child attribute of type Experiment | The ID of the experiment. |
name | Child attribute of type Experiment | The name of the experiment. |
integrationSettings | Child attribute of type Experiment | An object that contains all the integration settings enabled for this experiment. Each key in the object is mapped to a particular integration. |
| Child attribute of type IntegrationObject | This object can contain project- or environment-specific properties that are not predefined. |
variations | Child attribute of type Experiment | The variations within an experiment. There are one or more variations in an experiment. |
actions | Child attribute of type Variation | The actions that are executed once a visitor gets bucketed in this variation. The actions describe the variation. |
pageId | Child attribute of type Action | The ID of the page where the action will take place. |
changes | Child attribute of type Action | An array of changes that have been set up for this page. |
| Child attribute of type Change | This object can contain project- or environment-specific properties that are not predefined. |
id | Child attribute of type Variation | The ID of the variation. |
name | Child attribute of type Variation | The name of the variation. |
weightDistributions | Child attribute of type StaticData | Traffic allocation among the variations in the experiment. |
entityId | Child attribute of type WeightDistributionsObject | The ID of the variation that has the |
endOfRange | Child attribute of type WeightDistributionsObject | Each object in the array has a |
id | Child attribute of type Campaign | The ID of the campaign. |
name | Child attribute of type Campaign | The name of the campaign. |
holdback | Child attribute of type Campaign | The holdback value on a campaign represents the percentage of visitors excluded from a campaign. If the holdback is set to 500, then 5% of all visitors are excluded from the campaign. |
policy | Child attribute of type Campaign | The policy of a campaign indicates whether the campaign is an AB test or a Personalization campaign. The possible values are: |
integrationSettings | Child attribute of type Campaign | An object that contains all the integration settings enabled for this campaign. |
| Child attribute of type IntegrationObject | This object can contain project- or environment-specific properties that are not predefined. |
pageIds | Child attribute of type Campaign | An array with the IDs of all the pages that are used within the campaign. |
pages | Child attribute of type StaticData | An object mapping of a page ID to a page. Pages are used to determine where experiments will execute and to track user behavior. |
apiName | Child attribute of type Page | A machine-readable name for the page. The |
id | Child attribute of type Page | The page ID. |
category | Child attribute of type Page | An event category that was selected upon creation of the page. Some valid values for the category are "added to cart", "saved", "shared", "searched", "purchased", "converted", "signed up", "subscribed", "other". |
staticConditions | Child attribute of type Page | A user-chosen name for a page. |
tags | Child attribute of type Page | An array of the visual tags saved on a page. Read more about visual tags. |
category | Child attribute of type VisualTagObject | A tag category that was selected upon creation of the tag. Some valid values for the category are "category", "subcategory", "title", "price", "other". |
locator | Child attribute of type VisualTagObject | The logic/CSS selector indicating where a tag is located on the page. |
apiName | Child attribute of type VisualTagObject | A machine-readable name for the tag. |
locatorType | Child attribute of type VisualTagObject | A enum that indicates if the locator is custom "javascript" or a "css_selector". |
experiments | Child attribute of type StaticData | An object mapping of an experiment ID to an experiment. Every campaign has one or more experiments. |
audienceIds | Child attribute of type Experiment | Representation of audience conditions for the experiment, including audience IDs and combinators. See audience_conditions for format. |
audienceName | Child attribute of type Experiment | Representation of name of audience(s) used in the experiment. |
id | Child attribute of type Experiment | The ID of the experiment. |
name | Child attribute of type Experiment | The name of the experiment. |
integrationSettings | Child attribute of type Experiment | An object that contains all the integration settings that are enabled for this experiment. Each key in the object is mapped to a particular integration. |
| Child attribute of type IntegrationObject | This object can contain project- or environment-specific properties that are not predefined. |
variations | Child attribute of type Experiment | The variations within an experiment. There are one or more variations in an experiment. |
actions | Child attribute of type Variation | The actions that are executed once a visitor gets bucketed in this variation. The actions describe the variation. |
pageId | Child attribute of type Action | The ID of the page where the action will take place. |
changes | Child attribute of type Action | An array of changes that have been set up for this page. |
| Child attribute of type Change | This object can contain project- pr environment-specific properties that are not predefined. |
id | Child attribute of type Variation | The ID of the variation. |
name | Child attribute of type Variation | The name of the variation. |
weightDistributions | Child attribute of type StaticData | Traffic allocation among the variations in the experiment. |
entityId | Child attribute of type WeightDistributionsObject | The ID of the variation that has the |
endOfRange | Child attribute of type WeightDistributionsObject | Each object in the array has a |
variations | Child attribute of type StaticData | An object mapping of a variation ID to a variation. The variations are used in experiments and experiences. |
actions | Child attribute of type Variation | The actions that are executed once a visitor gets bucketed in this variation. The actions describe the variation. |
pageId | Child attribute of type Action | The ID of the page where the action will take place. |
changes | Child attribute of type Variation | An array of changes that have been set up for this page. |
| Child attribute of type Change | This object can contain project- or environment-specific properties that are not predefined. |
id | Child attribute of type Variation | The ID of the variation. |
name | Child attribute of type Variation | The name of the variation. |
projectId | Child attribute of type StaticData | The ID of your Optimizely project that is installed on this page. |
accountId | Child attribute of type StaticData | The ID of your Optimizely account. |
dcpServiceId | Child attribute of type StaticData | The ID of a DCP service associated to the project installed on this page. |
revision | Child attribute of type StaticData | The revision of your snippet. The revision is incremented every time the snippet is updated. |
Example Call
data = window["optimizely"].get("data");
Example Return Value
{
"audiences": {
"4728608810": {
"conditions": ["and", ["or", ["or", {
"value": "search",
"type": "source_type",
"name": null,
"match": null
}, {
"value": "campaign",
"type": "source_type",
"name": null,
"match": null
}]]],
"id": "6618392098",
"name": "Search traffic"
}
},
"events": {
"4958230289": {
"category": "other",
"name": null,
"eventType": "click",
"apiName": "blog_clicks_hero_nav",
"id": "4958230289",
"eventFilter": {
"filterType": ".hero-container",
"selector": "target_selector"
},
"pageId": "4761512980"
}
},
"campaign": {
"6676370413": {
"holdback": 500,
"activation": {},
"integrationSettings": {},
"viewIds": ["6678290257"],
"experiments": [{
"weightDistributions": null,
"audienceName": "Chrome users",
"name": null,
"bucketingStrategy": null,
"variations": [{
"id": "6626731852",
"actions": [],
"name": "Variation #1"
}],
"audienceIds": ["6672770135"],
"changes": null,
"id": "6666781105",
"integrationSettings": null
}],
"id": "6676370413",
"weightDistributions": null,
"name": "Example personalization campaign",
"commitId": "6667420425",
"decisionMetadata": null,
"policy": "ordered",
"changes": null,
"pageIds": ["6678290257"]
}
},
"pages": {
"6678290257": {
"category": "other",
"staticConditions": ["and", ["or", {
"type": "url",
"value": "https://developers.optimizely.com/",
"match": "simple"
}]],
"name": "Homepage",
"tags": [{
"category": "other",
"locator": ".push-quad > a:nth-of-type(1)",
"valueType": "string",
"locatorType": "css_selector",
"apiName": "view_docs_button"
}],
"apiName": "homepage",
"id": "6678290257"
}
},
"experiments": {
"6661191859": {
"weightDistributions": [{
"entityId": "6665951608",
"endOfRange": 5000
}, {
"entityId": "6670551924",
"endOfRange": 10000
}],
"audienceName": "Everyone else",
"name": null,
"bucketingStrategy": null,
"variations": [{
"id": "6665951608",
"actions": [],
"name": "Original"
}, {
"id": "6670551924",
"actions": [{
"viewId": "6678290257",
"changes": [{
"selector": ".flex-justified--center > div:nth-of-type(1) .push-double--top",
"dependencies": [],
"attributes": {
"html": "Web "
},
"type": "attribute",
"id": "4810EE32-D209-4EBD-A8DC-6CE245DA8B6B",
"css": {}
}],
"pageId": "6678290257"
}],
"name": "Variation #1"
}],
"audienceIds": null,
"changes": null,
"id": "6661191859",
"integrationSettings": null
}
},
"variations": {
"7600254716": {
"id": "7600254716",
"actions": [{
"viewId": "7585662249",
"changes": [{
"selector": "h1",
"dependencies": [],
"attributes": {
"html": "Develop with Optimizely! "
},
"type": "attribute",
"id": "EE809A94-4044-4DD0-B387-D05D478ED702",
"css": {}
}],
"pageId": "7585662249"
}],
"name": "Variation #1"
}
},
"projectId": "6663270427",
"accountId": "200607994",
"revision": "2433",
"dcpServiceId": "3383760141"
}
Description
A function to get the data
object. The data
object contains the fields of the objects you've created using the Optimizely UI or REST API. For example, if you create a new experiment using an audience, page and event, then you can expect to find all of those objects in the data
object that's returned from this function.
Updated about 3 years ago