EarnedStats Docs

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"}}'
FieldRequiredNotes
visitor_idYesFrom earnedstats.attribution() in the browser.
nameYesUp to 64 characters.
propsNoAny 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>"}'
FieldRequiredNotes
transaction_idYesYour id. Sending it again does not count it twice.
amountYesA number in the currency, for example 29.99.
currencyNoDefaults to the site's currency.
visitor_idNoLinks the payment to the visit.
emailNoLinks it to an identified visitor when there is no visitor id.
customer_idNoGroups renewals from one customer.
refundedNotrue for a refund of an earlier payment.
timestampNoISO date, defaults to now.