Create a segment to target visitors by page URL
Goal
Next, we’ll create a segment to target visitors who browse a specific URL, such as www.site-test.com.
See this guide for details.
Requirements
access token
To use the Automation API, you first need an access token.
Follow the instructions in this section to retrieve it programmatically.
-
siteId-
You can retrieve it directly in your code with the
siteCodeby calling the get a site by code endpoint -
Or log into your Kameleoon account, go to the bottom left corner, and select Projects under the Admin section:

Click Edit on your project:

The
siteIdis the 5-digit number shown in the URL (e.g., 29353):
-
Create the Segment
Endpoint:
POST https://api.kameleoon.com/segments
| Name | Type | Description |
|---|---|---|
| conditionsData | Object | Defines targeting conditions. See API reference. |
| name | String | Segment name. |
| segmentType | String | Type of segment, e.g., STANDARD for experiments. |
| siteId | String | The project’s siteId. |
Example:
curl -L -X POST 'https://api.kameleoon.com/segments' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer <ACCESS_TOKEN>' \
--data-raw '{
"name": "New segment",
"description": "Target by webpage",
"siteId": 29353,
"segmentType": "STANDARD",
"conditionsData": {
"firstLevelOrOperators": [true],
"firstLevel": [
{
"conditions": [
{
"targetingType": "PAGE_URL",
"weight": 1,
"url": "www.site-test.com",
"matchType": "EXACT",
"include": true
}
]
}
]
}
}'
Create a goal for the experiment
Goal
Goals are metrics to track campaign success.
Here, we’ll create a Click goal to count clicks on the .cta-button element.
See this guide for more.
Steps
Create the goal
Endpoint:
POST https://api.kameleoon.com/goals
| Name | Type | Description |
|---|---|---|
| description | String | Goal description (e.g., "Number of CTA clicks"). |
| name | String | Goal name (e.g., "Clicks on CTA"). |
| siteId | String | The project’s siteId. |
| params | Object | Includes element selectors for click tracking. |
Example:
curl -L -X POST 'https://api.kameleoon.com/goals' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer <ACCESS_TOKEN>' \
--data-raw '{
"description": "Number of times CTA button was clicked",
"hasMultipleConversions": true,
"name": "Clicks on CTA",
"params": {
"customSelectors": [
{
"mode": "CUSTOM",
"selector": ".cta-button, #bloc-789"
}
]
},
"siteId": 29353,
"status": "ACTIVE",
"type": "CLICK"
}'
Add a goal and segment to your experiment before launching
Goal
We’ll now link the goal and segment to Experiment_1 and activate it.
Steps
1. Link and launch
Endpoint:
PATCH https://api.kameleoon.com/experiments/{experimentId}?action=ACTIVATE
| Name | Type | Description |
|---|---|---|
| targetingSegmentId | String | Segment ID to link. |
| goals | Array | Goal IDs to link. |
| deviations | Object | Traffic allocation between control and variations. |
| mainGoalId | String | Main goal ID. |
| status | String | Experiment status (ONLINE, PAUSED, etc.). |
Example:
curl -L -X PATCH 'https://api.kameleoon.com/experiments/283505?action=ACTIVATE' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer <ACCESS_TOKEN>' \
--data-raw '{
"targetingSegmentId": 298314,
"goals": [361517],
"deviations": {"origin": 0.5, "1053310": 0.5},
"mainGoalId": 361517,
"status": "ONLINE"
}'
2. Verify launch
Refresh the dashboard.
Experiment_1 should now display Online status:

This completes the process: you’ve created, configured, and launched an experiment using the Automation API.