Skip to main content

Create Goal

POST/v2/project/{project_key}/goal

Create a goal profile for the selected project. Goals define what counts as a conversion — clicks, page views, form submissions, or custom events.

Required body fields

FieldTypeDescription
goal_namestringHuman-readable name for the goal (e.g., "Signup Form Submit")
goal_typestringThe type of conversion to track (see table below)
goal_valuestringThe selector, URL, text, or trigger value (depends on goal_type)

Goal types

goal_typeTracksgoal_value example
clickOnElementClicks on a CSS selector.cta-button, #hero-cta, [data-testid="buy-now"]
clickOnTextClicks on any element matching visible textStart Free Trial
formSubmitForm submissions matching a selectorform#signup, form.checkout-form
pageviewVisits to a URL (partial match)https://example.com/pricing
pageviewExactVisits where the full URL matches exactlyhttps://example.com/pricing?plan=pro
pageviewWildcardVisits matching a wildcard URL patternhttps://example.com/blog/*
pageviewRegexVisits matching a regular expression^https://example\.com/blog/.+$
scriptManual trigger from custom JavaScript codesignup_completed

Optional fields

FieldTypeDescription
goal_keystringSlug identifier (auto-generated if omitted). Must be unique per project.
goal_purposestringIntent of the goal. Default: "sell". Other values: "engage", "generate".
element_urlstringThe page URL where the element or form is located. Helps the Mida script know which page to listen on.

Example

curl -X POST "https://api-{region}.mida.so/v2/project/YOUR_PROJECT_KEY/goal" \
-H "Authorization: Bearer YOUR_GENERATED_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"goal_name": "CTA Button Click",
"goal_type": "clickOnElement",
"goal_value": ".cta-button",
"goal_purpose": "sell",
"element_url": "https://example.com/"
}'

Example: pageview goal

curl -X POST "https://api-{region}.mida.so/v2/project/YOUR_PROJECT_KEY/goal" \
-H "Authorization: Bearer YOUR_GENERATED_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"goal_name": "Reached Thank You Page",
"goal_type": "pageview",
"goal_value": "https://example.com/thank-you"
}'

Success response

{
"success": true,
"goal_profile_id": 3003,
"goal_key": "cta_button_click",
"company_id": 1001
}

Response fields

FieldTypeDescription
goal_profile_idintegerThe newly created goal's ID — use this when referencing the goal in experiments
goal_keystringThe slug identifier for this goal
Reference goals in experiments

After creating a goal, attach it to a new experiment using primary_goal_key: "your-goal-key" in Create Experiment, rather than redefining the goal inline each time. This lets you reuse the same goal across multiple experiments.

Error responses

StatusMeaning
400Missing required field (goal_name, goal_type, or goal_value) or invalid goal_type value
401Invalid or missing API key
406A goal with the same goal_key already exists for this project
Next step

Now create an experiment that tracks this goal. Use Create Experiment and pass "primary_goal_key": "your-goal-key".