Movatterモバイル変換


[0]ホーム

URL:


Dev guideRecipesAPI ReferenceChangelog
Dev guideAPI ReferenceRecipesChangelogUser GuideGitHubDev CommunityOptimizely AcademySubmit a ticketLog InFeature Experimentation
Dev guide
All
Pages
Start typing to search…

Create events

How to create and add an event in Optimizely Feature Experimentation.

Events track the success of your experiment by recording specific user actions, such as clicks, pageviews, form submissions, purchases, and scroll depth. To integrate events into your application code using the SDK, seeTrack events.

Create event

With the Feature Experimentation REST API

Use theCreate a custom event endpoint.

EndpointPOST https://api.optimizely.com/v2/projects/PROJECT_ID/custom_events

Authentication – Include your API key in theAuthorization header as a Bearer token. SeeGenerate tokens and use the REST APIs.

Request example

curl --request POST \     --url https://api.optimizely.com/v2/projects/PROJECT_ID/custom_events \     --header 'accept: application/json' \     --header 'authorization: Bearer TOKEN' \     --header 'content-type: application/json' \     --data '{  "archived": false,  "description": "Event used to track users that have added the item to the cart.",  "key": "add_to_cart"}'

Response example

{   "archived": false,    "category": "other",    "created": "2025-09-12T16:35:31.697630Z",    "description": "Event used to track users that have added the item to the cart."    "event_properties": [],    "event_type": "custom",    "id": ID,    "is_classic": false,    "key": "add_to_cart",    "name": "add_to_cart",    "project_id": PROJECT_ID}

See theCreate a custom event API endpoint reference documentation for information on creating an event with the Feature Experimentation API. You can also follow theREST API cookbookand seestep two to create a flag variation.

With the Feature Experimentation UI

See theCreate event section in the user documentation for a step-by-step guide to create events using the Feature Experimentation UI.

Add events to your experiments

With the REST API

Use theUpdate the Ruleset for a Flag in an Environment endpoint to update yourA/B test ora multi-armed bandit optimization with your event.

EndpointPATCH https://api.optimizely.com/flags/v1/projects/PROJECT_ID/flags/FLAG_KEY/environments/ENVIRONMENT_KEY/ruleset

🚧

Important

ForPATCH requests, firstGET the current object, merge only the fields you need to change, and then send thePATCH. This helps prevent overwriting existing settings you did not intend to modify.

Authentication – Include your API key in theAuthorization header as a Bearer token. SeeGenerate tokens and use the REST APIs.

Request example

curl --request PATCH \  --url "https://api.optimizely.com/flags/v1/projects/24566260139/flags/scheduled_changes_flag/environments/development/ruleset" \  --header "Authorization: Bearer TOKEN" \  --header "Content-Type: application/json" \  --data '[    {      "op": "add",      "path": "/rules/a-b-test/metrics/-",      "value": {        "event_id": 27189690020,        "event_type": "click",        "scope": "visitor",        "aggregator": "unique",        "winning_direction": "increasing",        "display_title": "Add to cart clicks"      }    }  ]'

Response example

{  "url": "/projects/24566260139/flags/scheduled_changes_flag/environments/development/ruleset",  "update_url": "/projects/24566260139/flags/scheduled_changes_flag/environments/development/ruleset",  "enable_url": "/projects/24566260139/flags/scheduled_changes_flag/environments/development/ruleset/enabled",  "rules": {    "a-b-test": {      "key": "a-b-test",      "name": "a-b-test",      "description": "",      "variations": {        "off": {          "key": "off",          "name": "Off",          "percentage_included": 5000,          "variation_id": 1502017,          "id": 6688991        },        "on": {          "key": "on",          "name": "On",          "percentage_included": 5000,          "variation_id": 1502018,          "id": 6688992        }      },      "baseline_variation_id": 1502017,      "type": "a/b",      "distribution_mode": "manual",      "id": 1599695,      "urn": "rules.flags.optimizely.com::1599695",      "archived": false,      "enabled": false,      "created_time": "2025-09-15T19:52:05.908420Z",      "updated_time": "2025-09-15T22:03:43.078372Z",      "audience_conditions": [],      "audience_ids": [],      "percentage_included": 10000,      "metrics": [        {          "event_id": 30097930171,          "event_type": "custom",          "scope": "visitor",          "aggregator": "unique",          "winning_direction": "increasing",          "display_title": "New event with properties"        },        {          "event_id": 27189690020,          "event_type": "click",          "scope": "visitor",          "aggregator": "unique",          "winning_direction": "increasing",          "display_title": "Add to cart clicks"        }      ],      "allow_list": {},      "group_rule": {        "group_id": 0,        "traffic_allocation": 0      },      "group_remaining_traffic_allocation": 100,      "layer_id": 9300001987253,      "layer_experiment_id": 9300002732965,      "status": "draft"    }  },  "rule_priorities": [    "a-b-test"  ],  "id": 1882548,  "urn": "rulesets.flags.optimizely.com::1882548",  "archived": false,  "enabled": false,  "updated_time": "2025-09-15T22:03:43.149140Z",  "flag_key": "scheduled_changes_flag",  "environment_key": "development",  "environment_name": "Development",  "environment_id": 24540890184,  "default_variation_key": "off",  "default_variation_name": "Off",  "revision": 4,  "status": "draft",  "role": "admin"}

In the Feature Experimentation UI

See theAdd events to your experiment section in the Manage events in Feature Experimentation user documentation for a step-by-step guide.

Track events in your application code

See the track event documentation in your SDK to implement event tracking in your code.

Create metrics

Metrics measure the success of your experiment by telling you whether an experiment is winning, losing, or inconclusive. Metrics are derived from events, which directly track actions like clicks, pageviews, form submissions, purchases, and scroll depth.

Optimizely Feature Experimentation uses a natural-language metrics builder in the UI that lets you define and add metrics to your experiments and campaigns. SeeCreate a metric in Optimizely using the metric builder for instructions on creating metrics in Feature Experimentation.

Updated 17 days ago



[8]ページ先頭

©2009-2025 Movatter.jp