Track
Server API
Send goals and payments from your backend with the site key.
Find the key under Settings, Integrations, Server side API. Keep it on your server in an environment variable, never in browser code. Rotate it in Settings, Danger zone if it leaks.
Send a goal
Shell
curl -X POST https://earnedstats.com/api/v1/goals \
-H "Authorization: Bearer $EARNEDSTATS_API_KEY" \
-H "Content-Type: application/json" \
-d '{"visitor_id":"<es_visitor_id>","name":"email_confirmed","props":{"plan":"pro"}}'| Field | Required | Notes |
|---|---|---|
visitor_id | Yes | From earnedstats.attribution() in the browser. |
name | Yes | Up to 64 characters. |
props | No | Any small object. |
Send a payment
For providers without a webhook, or your own billing:
Shell
curl -X POST https://earnedstats.com/api/v1/payments \
-H "Authorization: Bearer $EARNEDSTATS_API_KEY" \
-H "Content-Type: application/json" \
-d '{"transaction_id":"txn_123","amount":29.99,"currency":"USD","visitor_id":"<es_visitor_id>"}'| Field | Required | Notes |
|---|---|---|
transaction_id | Yes | Your id. Sending it again does not count it twice. |
amount | Yes | A number in the currency, for example 29.99. |
currency | No | Defaults to the site's currency. |
visitor_id | No | Links the payment to the visit. |
email | No | Links it to an identified visitor when there is no visitor id. |
customer_id | No | Groups renewals from one customer. |
refunded | No | true for a refund of an earlier payment. |
timestamp | No | ISO date, defaults to now. |