BETA
Skip to content

Goals

Create, manage, and query conversion goals for your analytics sites. Goals let you track specific user actions and measure conversion rates with optional revenue tracking.

Base URL: https://app.krafter.dev/api/v1/analytics

Goal Object

json
{
  "id": "550e8400-e29b-41d4-a716-446655440000",
  "name": "Signup",
  "type": "event",
  "match_type": "exact",
  "match_value": "signup",
  "currency": "USD"
}
FieldTypeDescription
idstringUnique identifier (UUID).
namestringDisplay name for the goal.
typestringGoal type: pageview, event, or custom.
match_typestringHow the match value is evaluated: exact, contains, or regex.
match_valuestringThe value to match against (page path, event name, or custom goal name).
currencystring | nullISO 4217 currency code for revenue tracking. null if revenue is not tracked.

Goal Types

TypeTriggers WhenMatch Value
pageviewA visitor views a page matching the valuePage path (e.g., /thank-you)
eventA custom event fires matching the valueEvent name (e.g., signup)
customka.goal() is called with a matching nameGoal name (e.g., purchase)

Match Types

Match TypeBehaviorExample
exactValue must match exactly/pricing matches only /pricing
containsValue must contain the stringsignup matches newsletter_signup
regexValue must match the regular expression/blog/\d+ matches /blog/42

Create Goal

Create a new conversion goal for a site.

POST /analytics/sites/:key/goals

Required scope: analytics:write

Request Body

FieldTypeRequiredDescription
namestringYesDisplay name for the goal.
typestringYesOne of: pageview, event, custom.
match_typestringYesOne of: exact, contains, regex.
match_valuestringYesThe value to match against.
currencystringNoISO 4217 currency code (e.g., USD, EUR).

Example: Pageview Goal

Track conversions when visitors reach a thank-you page:

bash
curl -X POST https://app.krafter.dev/api/v1/analytics/sites/sk_abc123def456/goals \
  -H "Authorization: Bearer YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Thank You Page",
    "type": "pageview",
    "match_type": "exact",
    "match_value": "/thank-you"
  }'

Example: Event Goal with Revenue

Track purchase events with revenue in USD:

bash
curl -X POST https://app.krafter.dev/api/v1/analytics/sites/sk_abc123def456/goals \
  -H "Authorization: Bearer YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Purchase",
    "type": "custom",
    "match_type": "exact",
    "match_value": "purchase",
    "currency": "USD"
  }'

Example Response

json
// 201 Created
{
  "data": {
    "id": "550e8400-e29b-41d4-a716-446655440000",
    "name": "Purchase",
    "type": "custom",
    "match_type": "exact",
    "match_value": "purchase",
    "currency": "USD"
  }
}

List Goals

Retrieve all goals for a site.

GET /analytics/sites/:key/goals

Required scope: analytics:read

Example Request

bash
curl https://app.krafter.dev/api/v1/analytics/sites/sk_abc123def456/goals \
  -H "Authorization: Bearer YOUR_API_TOKEN"

Example Response

json
{
  "data": [
    {
      "id": "550e8400-e29b-41d4-a716-446655440000",
      "name": "Purchase",
      "type": "custom",
      "match_type": "exact",
      "match_value": "purchase",
      "currency": "USD"
    },
    {
      "id": "661f9511-f39c-52e5-b827-557766551111",
      "name": "Newsletter Signup",
      "type": "pageview",
      "match_type": "exact",
      "match_value": "/newsletter/confirmed",
      "currency": null
    },
    {
      "id": "772a0622-a40d-63f6-c938-668877662222",
      "name": "Contact Form",
      "type": "event",
      "match_type": "contains",
      "match_value": "contact",
      "currency": null
    }
  ]
}

Update Goal

Update an existing goal.

PATCH /analytics/sites/:key/goals/:id

Required scope: analytics:write

Request Body

All fields are optional. Only include the fields you want to change.

FieldTypeDescription
namestringNew display name.
typestringNew goal type.
match_typestringNew match type.
match_valuestringNew match value.
currencystringNew currency code.

Example Request

bash
curl -X PATCH https://app.krafter.dev/api/v1/analytics/sites/sk_abc123def456/goals/550e8400-e29b-41d4-a716-446655440000 \
  -H "Authorization: Bearer YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Completed Purchase",
    "currency": "EUR"
  }'

Example Response

json
{
  "data": {
    "id": "550e8400-e29b-41d4-a716-446655440000",
    "name": "Completed Purchase",
    "type": "custom",
    "match_type": "exact",
    "match_value": "purchase",
    "currency": "EUR"
  }
}

Delete Goal

Delete a goal. This does not delete historical conversion data.

DELETE /analytics/sites/:key/goals/:id

Required scope: analytics:write

Example Request

bash
curl -X DELETE https://app.krafter.dev/api/v1/analytics/sites/sk_abc123def456/goals/550e8400-e29b-41d4-a716-446655440000 \
  -H "Authorization: Bearer YOUR_API_TOKEN"

Example Response

json
// 200 OK
{
  "data": {
    "deleted": true
  }
}

Get Goal Stats

Retrieve conversion statistics for a specific goal.

GET /analytics/sites/:key/goals/:id/stats

Required scope: analytics:read

Query Parameters

ParameterTypeDefaultDescription
periodstring30dTime period. One of: 7d, 30d, 12mo, custom.
fromstring--Start date. Required when period=custom.
tostring--End date. Required when period=custom.

Example Request

bash
curl "https://app.krafter.dev/api/v1/analytics/sites/sk_abc123def456/goals/550e8400-e29b-41d4-a716-446655440000/stats?period=30d" \
  -H "Authorization: Bearer YOUR_API_TOKEN"

Example Response

json
{
  "data": {
    "conversions": 342,
    "unique_conversions": 298,
    "revenue": 16758.00
  }
}
FieldDescription
conversionsTotal number of times the goal was triggered.
unique_conversionsNumber of unique visitors who triggered the goal.
revenueTotal revenue attributed to the goal. null if no currency is set on the goal.

Scopes

ScopeEndpoints
analytics:readGET /analytics/sites/:key/goals, GET /analytics/sites/:key/goals/:id/stats
analytics:writePOST /analytics/sites/:key/goals, PATCH /analytics/sites/:key/goals/:id, DELETE /analytics/sites/:key/goals/:id

Built by Krafter Studio