Documentation menu

Webhooks

HTTP callbacks for pageview, goal and alert events. Webhooks are per-user. Signing secrets are shown in full exactly once.

5 endpoints, all relative to https://analytics.appfor.you. Shared rules live in Conventions, Rate limits and Error codes.

List webhooks

GET/api/v2/sites/{siteId}/webhooksscope: read

Signing secrets are MASKED as `****<last 4>` so a leaked listing cannot be used to forge signatures.

Path parameters

siteIdstringThe Mongo _id returned as `siteId` by GET /api/v2/sites, or the public `trackingId` embedded in the tracking snippet. Both are accepted everywhere.

Query parameters

NameTypeDescription
enabledbooleanFilter to only enabled (`true`) or only disabled (`false`) records. Omit for all.
limitintegerRows to return. Default 50, minimum 1, maximum 500.
offsetintegerRows to skip, for paging. Default 0.

Example request

curl -H "Authorization: Bearer $ANALYTICS_API_KEY" \
  "https://analytics.appfor.you/api/v2/sites/6507f1f77bcf86cd799439011/webhooks"

Example response

{
  "webhooks": [
    {
      "webhookId": "6512ee05bcf86cd7994390e5",
      "siteId": "6507f1f77bcf86cd799439011",
      "url": "https://hooks.example.com/analytics",
      "events": ["goal_completed", "alert_triggered"],
      "enabled": true,
      "secret": "****9f2c",
      "lastTriggeredAt": null,
      "createdAt": "2025-02-25T08:00:00.000Z",
      "updatedAt": "2025-02-25T08:00:00.000Z"
    }
  ],
  "total": 1,
  "limit": 50,
  "offset": 0
}

Register a webhook

POST/api/v2/sites/{siteId}/webhooksscope: write

A 32-byte hex signing secret is generated server-side and returned IN FULL only in this response, alongside `secretRevealed: true`. Store it immediately — every later read returns `****<last 4>` and the secret cannot be re-issued.

  • Viewers receive 403.

Path parameters

siteIdstringThe Mongo _id returned as `siteId` by GET /api/v2/sites, or the public `trackingId` embedded in the tracking snippet. Both are accepted everywhere.

Request body

FieldTypeRequiredDescription
urlstring (URL)YesDestination URL. Must be a valid absolute URL.
eventsArray<'pageview' | 'goal_completed' | 'alert_triggered'>YesEvents to subscribe to. At least one.
enabledbooleanNoStart enabled or paused.

Example request

curl -X POST "https://analytics.appfor.you/api/v2/sites/6507f1f77bcf86cd799439011/webhooks" \
  -H "Authorization: Bearer $ANALYTICS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "url": "https://hooks.example.com/analytics", "events": ["goal_completed", "alert_triggered"] }'

Example response (201)

{
  "webhookId": "6512ee05bcf86cd7994390e5",
  "siteId": "6507f1f77bcf86cd799439011",
  "url": "https://hooks.example.com/analytics",
  "events": ["goal_completed", "alert_triggered"],
  "enabled": true,
  "secret": "b7c1e0a4d29f4f5c8a3b1d6e0f2a7c519f2c",
  "secretRevealed": true,
  "lastTriggeredAt": null,
  "createdAt": "2025-03-21T09:00:00.000Z",
  "updatedAt": "2025-03-21T09:00:00.000Z"
}

Get a webhook

GET/api/v2/sites/{siteId}/webhooks/{webhookId}scope: read

The signing secret is masked as `****<last 4>`.

Path parameters

siteIdstringThe Mongo _id returned as `siteId` by GET /api/v2/sites, or the public `trackingId` embedded in the tracking snippet. Both are accepted everywhere.
webhookIdstringIdentifier of the webhook.

Example request

curl -H "Authorization: Bearer $ANALYTICS_API_KEY" \
  "https://analytics.appfor.you/api/v2/sites/6507f1f77bcf86cd799439011/webhooks/6512ee05bcf86cd7994390e5"

Example response

{
  "webhookId": "6512ee05bcf86cd7994390e5",
  "siteId": "6507f1f77bcf86cd799439011",
  "url": "https://hooks.example.com/analytics",
  "events": ["goal_completed"],
  "enabled": true,
  "secret": "****9f2c",
  "lastTriggeredAt": "2025-03-19T14:02:00.000Z",
  "createdAt": "2025-02-25T08:00:00.000Z",
  "updatedAt": "2025-02-25T08:00:00.000Z"
}

Update a webhook

PATCH/api/v2/sites/{siteId}/webhooks/{webhookId}scope: write

At least one field is required. `events` replaces the whole list. The signing secret is immutable and is never echoed back unmasked.

  • Viewers receive 403.

Path parameters

siteIdstringThe Mongo _id returned as `siteId` by GET /api/v2/sites, or the public `trackingId` embedded in the tracking snippet. Both are accepted everywhere.
webhookIdstringIdentifier of the webhook.

Request body

Every field is optional, but at least one must be supplied.

FieldTypeRequiredDescription
urlstring (URL)NoNew destination URL.
eventsArray<'pageview' | 'goal_completed' | 'alert_triggered'>NoFull replacement subscription list, at least one item.
enabledbooleanNofalse pauses deliveries.

Example request

curl -X PATCH "https://analytics.appfor.you/api/v2/sites/6507f1f77bcf86cd799439011/webhooks/6512ee05bcf86cd7994390e5" \
  -H "Authorization: Bearer $ANALYTICS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "events": ["goal_completed"] }'

Example response

{
  "webhookId": "6512ee05bcf86cd7994390e5",
  "siteId": "6507f1f77bcf86cd799439011",
  "url": "https://hooks.example.com/analytics",
  "events": ["goal_completed"],
  "enabled": true,
  "secret": "****9f2c",
  "updatedAt": "2025-03-21T09:40:00.000Z"
}

Delete a webhook

DELETE/api/v2/sites/{siteId}/webhooks/{webhookId}scope: adminDestructive

Requires `confirm=<webhookId>` as a query parameter or a `confirm` body field. The signing secret is lost with the record. Consider `enabled: false` via PATCH instead — it is reversible.

Irreversible. Requires the admin scope and confirm={webhookId} — see Destructive operations.

  • Viewers receive 403.

Path parameters

siteIdstringThe Mongo _id returned as `siteId` by GET /api/v2/sites, or the public `trackingId` embedded in the tracking snippet. Both are accepted everywhere.
webhookIdstringIdentifier of the webhook.

Query parameters

NameTypeDescription
confirmstringDestructive-operation confirmation. Must exactly equal the `webhookId` in the URL. May be sent as a `confirm` field in the JSON body instead.

Request body

Optional — send `{ "confirm": "<webhookId>" }` instead of the query parameter if you prefer.

FieldTypeRequiredDescription
confirmstringNoMust equal the webhookId in the URL.

Example request

curl -X DELETE "https://analytics.appfor.you/api/v2/sites/6507f1f77bcf86cd799439011/webhooks/6512ee05bcf86cd7994390e5?confirm=6512ee05bcf86cd7994390e5" \
  -H "Authorization: Bearer $ANALYTICS_API_KEY"

Example response

{
  "deleted": true,
  "webhookId": "6512ee05bcf86cd7994390e5"
}