Movatterモバイル変換


[0]ホーム

URL:


Dev GuideAPI Reference
Dev GuideAPI ReferenceUser GuideGitHubDev CommunityOptimizely AcademySubmit a ticketLog InWeb Experimentation
API Reference
All
Pages
Start typing to search…

State

Returns a module exposing several functions to access information about the current visitor's state.

Get the Optimizely state

Syntax

const state = window["optimizely"].get("state");

Parameters


Parameter and Type

Child attribute

Description

state(string)

N/A

The argument indicating to get the state object. Required.

Return value

Parameter and TypeChild attributeDescription
StateObjectN/AAn object with functions that return information about the current state of Optimizely Web Experimentation.
getActiveExperimentIds (function)Child attribute ofStateObjectGet an array of experiment IDs that are currently active on the page for the visitor.
getCampaignStates (function)Child attribute ofStateObjectGet all the campaigns and their current states.
getExperimentStates (function)Child attribute ofStateObjectGet all the experiments and their current states.
getPageStates (function)Child attribute ofStateObjectGet all the pages and their current states.
getRedirectInfo (function)Child attribute ofStateObjectIf a redirect variation executed on the previous page, return details of that experiment.
getVariationMap (function)Child attribute ofStateObjectGet a mapping from each experiment the visitor has ever seen to its current corresponding variation.
getDecisionString (function)Child attribute ofStateObjectGet a single string describing the decision for a given campaign ID.
getDecisionObject (function)Child attribute ofStateObjectGet an object with strings that describe the decision for a given campaign ID.

Example

const state = window["optimizely"].get("state");

getCampaignStates()

Get all the campaigns and their current states.

Syntax

state.getCampaignStates(filter);

Parameters

Parameter and TypeChild attributeDescription
filter (CampaignFilterObjectCampaignFilterFunction)Optional filter to limit results.

CampaignFilterObject fields

Parameter and TypeChild attributeDescription
isActive (boolean)Child attribute ofCampaignFilterObjectIndicates if the campaign is active.

Return value

Parameter and TypeChild attributeDescription
objectN/AKeys are campaign IDs. Values describe each campaign's state.
id (string)Child attribute ofCampaignStateObjectCampaign ID.
campaignName (string)Child attribute ofCampaignStateObjectCampaign name.
experiment (NameIdObject)Child attribute ofCampaignStateObjectThe experiment the visitor is bucketed in.
id (string)Child attribute of experimentNameIdObjectObject ID.
name (string)Child attribute of experimentNameIdObjectObject name.
variation (NameIdObject)Child attribute ofCampaignStateObjectThe variation the visitor is bucketed in.
id (string)Child attribute of variationNameIdObjectObject ID.
name (string)Child attribute of variationNameIdObjectObject name.
isActive (boolean)Child attribute ofCampaignStateObjectWhether the campaign is currently active.
visitorRedirected (boolean)Child attribute ofCampaignStateObjectWhether the visitor was redirected due to this campaign.
isInCampaignHoldback (boolean)Child attribute ofCampaignStateObjectWhether the visitor is in the campaign holdback.
audiences (array)Child attribute ofCampaignStateObjectAudiences the visitor was in when the campaign activated.

Example call

state.getCampaignStates({ isActive: true });

Example return value

{  "6676370413": {    "id": "6676370413",    "campaignName": "Example personalization campaign",    "experiment": { "id": "6666781105", "name": null },    "variation": { "id": "6626731852", "name": "Variation #1" },    "isActive": true,    "visitorRedirected": false,    "isInCampaignHoldback": false,    "audiences": [{ "id": "6672770135", "name": "Chrome users" }]  }}

Description

Get all the campaigns and their current states. Use a filter object or function to limit the results.

Example: filter with a function

const state = window["optimizely"].get("state");state.getCampaignStates(function (campaignState) {  return !!campaignState.isActive;});

getExperimentStates()

Get all the experiments and their current states.

Syntax

state.getExperimentStates(filter);

Parameters

Parameter and TypeChild attributeDescription
filter (CampaignFilterObjectCampaignFilterFunction)N/AOptional filter to limit results.

CampaignFilterObject fields

Parameter and TypeChild attributeDescription
isActive (boolean)Child attribute ofCampaignFilterObjectIndicates if the experiment is active.

Return value

Parameter and Type

Child attribute

Description

object

N/A

Keys are experiment IDs. Values describe each experiments state.

id (string)

Child attribute ofExperimentStateObject

Experiment ID.

experimentName (string)

Child attribute ofExperimentStateObject

Experiment name.

audiences (array)

Child attribute ofExperimentStateObject

Audiences the visitor was in when the experiment was activated.

id (string)

Child attribute of audiencesNameIdObject

Object ID. Required.

name (string)

Child attribute of audiencesNameIdObject

Object name. Required.

variation (NameIdObject

null)

Child attribute ofExperimentStateObject.

Variation bucketed into, ornull if not bucketed.

id (string)

Child attribute of variationNameIdObject

Object ID. Required.

name (string)

Child attribute of variationNameIdObject

Object name. Required.

isActive (boolean)

Child attribute ofExperimentStateObject

Whether the experiment is currently active.

isInExperimentHoldback (boolean)

Child attribute ofExperimentStateObject

Whether the visitor is excluded due to traffic allocation.

visitorRedirected (boolean)

Child attribute ofExperimentStateObject

Whether the visitor was redirected due to this experiment.

Example call

state.getExperimentStates({ isActive: true });

Example return value

{  "6666781105": {    "id": "6666781105",    "experimentName": null,    "variation": { "id": "6626731852", "name": "Variation #1" },    "isActive": true,    "visitorRedirected": false,    "isInExperimentHoldback": false,    "audiences": [{ "id": "6672770135", "name": "Chrome users" }]  }}

Description

Get A/B experiments and their current states (excludes Personalization campaigns). Use a filter object or function to limit results.

Examples

Filter with a function

const state = window["optimizely"].get("state");// "Not variation #1"state.getExperimentStates(function (expState) {  return !expState.variation || expState.variation.name !== "Variation #1";});

Filter with an object

const state = window["optimizely"].get("state");state.getExperimentStates({ isActive: true });

getPageStates()

Get all the pages and their current states.

Syntax

state.getPageStates(filter);

Parameters

Parameter and TypeChild attributeDescription
filter (PageFilterObject)N/AOptional filter to limit results.
isActive (boolean)Child attribute ofPageFilterObjectIndicates if the page is active.

Return value

Parameter and TypeChild attributeDescription
objectN/AKeys are page IDs. Values describe each page's state.
id (string)Child attribute ofPageStateObjectPage ID.
name (string)Child attribute ofPageStateObjectPage name.
apiName (string)Child attribute ofPageStateObjectAPI name of the page.
staticConditions (array)Child attribute ofPageStateObjectURL conditions for the page object.
category (string)Child attribute ofPageStateObjectPage category.
tags (array)Child attribute ofPageStateObjectTags associated with the page.
type (string)Child attribute ofTagObjectStatic value indicating thetag function (required).
tags (PageTag)Child attribute ofTagObjectSingle-level JSON object with metadata (for URL-targeted pages).
* (*)Child attribute ofPageTagArbitrary project- or environment-specific properties.
isActive (boolean)Child attribute ofPageStateObjectWhether the page is currently active.

Example call

state.getPageStates({ isActive: true });

Example return value

{  "6678290257": {    "id": "6678290257",    "name": "Homepage",    "apiName": "homepage",    "category": "other",    "staticConditions": ["and", ["or", { "type": "url", "value": "https://developers.optimizely.com/", "match": "simple" }]],    "tags": [{      "category": "other",      "locator": ".push-quad > a:nth-of-type(1)",      "valueType": "string",      "locatorType": "css_selector",      "apiName": "view_docs_button"    }],    "isActive": true,    "metadata": { "view_docs_button": "View Docs" }  }}

Description

Get all the pages and their current states. Use a filter object to limit results.

Example: filter with a function

const state = window["optimizely"].get("state");state.getCampaignStates(function (pageState) {  return !!pageState.isActive;});
📘

Note

The previous example demonstrates function-style filtering. Swap ingetPageStates if you prefer to filter page states specifically.

getVariationMap()

Get a mapping from each experiment the visitor has ever seen to its current corresponding variation.

Syntax

state.getVariationMap();

Return value

Parameter and TypeChild attributeDescription
objectN/AKeys are experiment IDs; values are variation descriptors.
id (string)Child attribute ofVariationIdNameVariation ID. Required.
name (string)Child attribute ofVariationIdNameVariation name. Required.
index (number)Child attribute ofVariationIdNameIndex of the variation in the experiment’s list (0-based). Required.

Example call

state.getVariationMap();

Example return value

{  "6661191859": {    "id": "6670551924",    "name": "Variation #1",    "index": 1  }}

Description

Get the mapping of all experiments the visitor has ever seen to its current corresponding variation. If the visitor is excluded from an experiment due to traffic allocation, the experiment is considered active and the visitor is bucketed into a variation, but no visual changes are applied.

getActiveExperimentIds()

Get an array of experiment IDs that are currently active on the page for the visitor.

Syntax

state.getActiveExperimentIds();

Return value

Parameter and TypeChild attributeDescription
array<string>N/AAn array of experiment IDs that are currently active on the page for the visitor.

Example call

state.getActiveExperimentIds();

Example return value

["6661191859", "6666781105", "7555673865"]

Description

Get an array of experiment IDs that are currently active on the page for the visitor. If the visitor is excluded from an experiment due to traffic allocation, the experiment is considered active and the visitor is bucketed into a variation, but no visual changes are applied. This situation is referred to asisInExperimentHoldback in thegetExperimentStates API:

state.getExperimentStates()[{experiment_id}].isInExperimentHoldback

getRedirectInfo()

If a redirect variation was executed on the previous page, all the experiment details are accessible on the next page throughgetRedirectInfo().

Syntax

state.getRedirectInfo();

Return value

Parameter and TypeChild attributeDescription
nullRedirectInfoObjectDetails about a redirect experiment that ran on the previous page, ornull if none.
experimentId (string)Child attribute ofRedirectInfoObjectRedirect experiment ID. Required.
variationId (string)Child attribute ofRedirectInfoObjectRedirect variation ID. Required.
referrer (string)Child attribute ofRedirectInfoObjectOriginal referrer value before the redirect. Required.

Example call

state.getRedirectInfo();

Example return value

{  "experimentId": "7669390999",  "variationId": "7662661235",  "referrer": "https://www.google.com/"}

Description

Use this when you need to correct referrer values in analytics after a redirect variation.

getDecisionString()

Get a single string describing the campaign/experiment decision for a given campaign ID.

Syntax

state.getDecisionString(config);

Parameters

Parameters and TypeChild attributeDescription
config (DecisionConfigObject)N/AConfiguration for the function. Required.
campaignId (string)Child attribute ofDecisionConfigObjectCampaign ID to get the decision string for. Required.
shouldCleanString (boolean)Child attribute ofDecisionConfigObjectIftrue, replace characters matching/[^a-zA-Z0-9\.\~\!\*\(\)\']+/g with_. Default:false.
maxLength (number)Child attribute ofDecisionConfigObjectMaximum length of the returned string. Names are truncated preferentially (campaign first) to meet the limit. Default:255.

Return value

Parameter and TypeChild attributeDescription
stringN/AFor personalization decisions: concatenation of campaign, experiment, and variation names/IDs and holdback status. For A/B decisions: concatenation of experiment and variation names/IDs.

Example call

state.getDecisionString({ "campaignId": "6676370413" });

Example return value

"Example personalization campaign(6676370413):Example experiment(6666781105):Variation #1(6626731852):holdback"

Description

Often used to send campaign decision data to third-party analytics. Pass a campaign ID. If the campaign is an A/B test, the API returns only the fields relevant to A/B tests. Your code does not need to branch on campaign type.

getDecisionObject()

Get an object with strings that describe the campaign or experiment decision for a given campaign ID.

Syntax

state.getDecisionObject(config);

Parameters

Parameter and TypeChild attributeDescription
config (DecisionConfigObject)N/AConfiguration for the function. Required.
campaignId (string)Child attribute ofDecisionConfigObjectCampaign ID to get the decision object for. Required.
shouldCleanString (boolean)Child attribute ofDecisionConfigObjectIftrue, replace characters matching/[^a-zA-Z0-9\.\~\!\*\(\)\']+/g with_. Default:false.
maxLength (number)Child attribute ofDecisionConfigObjectMaximum length of returned string fields. Default:255.

Return value

Parameter and Type

Child attribute

Description

GetDecisionObjectReturn

N/A

For personalization decisions, contains fields for campaign, experiment, variation, and holdback status. For A/B decisions, contains fields for experiment and variation.

campaign (string

undefined)

Child attribute ofGetDecisionObjectReturn.Decision’s campaign name and ID. Not included for A/B tests.

experiment (string)

Child attribute ofGetDecisionObjectReturn

Decision’s experiment name and ID.

variation (string)

Child attribute ofGetDecisionObjectReturn

Decision’s variation name and ID.

holdback (boolean

undefined)

Child attribute ofGetDecisionObjectReturn.Whether the visitor was placed in the campaign holdback. Not included for A/B tests.

Example call

state.getDecisionObject({ "campaignId": "6676370413" });

Example return value

{  "campaign": "Shopping Cart (6676370413)",  "experiment": "New Visitors (3243212353)",  "variation": "Variation #1 (2344343121)",  "holdback": false}

Description

Often used to send campaign decision data to third-party analytics. Pass a campaign ID. If the campaign is an A/B test, the API returns only A/B-relevant fields so your code does not need to branch on type.



[8]ページ先頭

©2009-2025 Movatter.jp