Events API
Send events from your backend — purchases confirmed by a payment provider, sign-ups, background jobs. Available on the Business plan.
Create a token
Go to Workspace settings → API tokens, create a token and copy it (it is shown only once). Tokens belong to the workspace and can be revoked at any time.
Send an event
curl -X POST https://byanalytics.co/api/v1/events \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"site": "YOUR_SITE_KEY",
"name": "purchase",
"url": "https://example.com/checkout/thanks",
"props": { "plan": "pro", "value": 49.9 }
}'
Fields
| Field | Required | Description |
|---|---|---|
site |
yes | Site key of a site in the token's workspace. |
name |
yes | Event name (pageview is allowed). Max 64 characters. |
url |
no | Page the event belongs to. Defaults to the site's home page. |
referrer |
no | Referrer URL, used for source attribution. |
props |
no | Flat object of properties; value feeds revenue. |
visitor_ip, user_agent |
no | Forward the visitor's values to attribute country and device. They are hashed and discarded, never stored. |
Responses
202 Accepted—{ "status": "accepted" }(or"ignored"for excluded paths,"over_quota"when the monthly limit is exhausted)401invalid token ·403plan without API access or site outside the workspace ·422validation error ·429rate limited (120 requests/minute per token).
Laravel
The byanalytics/laravel package wraps the API:
ByAnalytics::event('purchase', ['value' => 49.9], url: route('checkout.thanks'));