Documentation menuAPI: Sending events

API

Send events with the Loogika API

POST /track records an event from any code that can make an HTTP request. Use it for things the browser never sees, such as a payment confirmed by your payment provider or activity in a mobile app.

Last updated . This guide belongs to Custom events and goals.

What does a request look like?

curl -X POST "https://app.loogika.com/api/track" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "site_id": "12",
    "type": "custom_event",
    "event_name": "order_completed",
    "pathname": "/checkout",
    "properties": "{\"total\": 129.5, \"currency\": \"EUR\"}",
    "anonymous_id": "visitor-8f2c",
    "ip_address": "203.0.113.7",
    "user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.0 Safari/605.1.15"
  }'

properties is a JSON object written as a string.

Do you need an API key?

The endpoint accepts requests without a key. Send one anyway when you track from a server.

Without a key, Loogika ignores ip_address and user_agent in the body and uses those of your server. Every event then looks like one visitor, and most HTTP clients are classified as bots.

The key must be a full-access key or have the ingest:write scope. It must be sent as a Bearer token. A key in the query string does not count here.

A key without that scope causes no error. Loogika ignores the two fields and records the event as usual.

Which fields can you send?

FieldTypeRequiredContent
site_idTextYesThe site the event belongs to
typeTextYesThe event type. See the next table
event_nameTextFor custom_event and errorThe name, up to 256 characters
propertiesTextFor some typesA JSON object as text, up to 2,048 characters
pathnameTextNoThe page path, up to 2,048 characters
querystringTextNoThe query string
hostnameTextNoThe domain
page_titleTextNoUp to 512 characters
referrerTextNoWhere the visitor came from
anonymous_idTextNoYour own ID for the visitor. Keep it the same for one visitor
user_idTextNoYour user ID, for identified users
ip_addressTextNoThe visitor's IP address. Used only with a qualifying key
user_agentTextNoThe visitor's user agent. Used only with a qualifying key
languageTextNoThe visitor's language
screenWidth, screenHeightNumberNoThe screen size in pixels
tagTextNoA tag, up to 256 characters

A field that is not in the list makes the request fail with status 400.

Which event types are there?

typeNeedsContent of properties
pageviewNothing more
custom_eventevent_nameYour own properties, optional
performanceNothing moreNot used. Send lcp, cls, inp, fcp and ttfb as numbers at the top level
outboundpropertiesurl, and optionally text and target
errorevent_name and propertiesmessage, and optionally stack, fileName, lineNumber, columnNumber
button_clickNothing moreOptional object
copypropertiessourceElement, and optionally text and textLength
form_submitpropertiesformId, formName, formAction, method and fieldCount
input_changepropertieselement and inputName

What does the API answer?

StatusBodyMeaning
200{"success":true}The event was accepted
200{"success":true,"message":"Event not tracked - ..."}An exclusion rule matched. The event was not stored
200Plain textThe event was not stored, for example when the site is over its monthly limit
400{"success":false,"error":"Invalid payload","details":...}A field is wrong. details names it
404{"success":false,"error":"Site not found"}The site_id does not exist

An event that Loogika classifies as a bot also gets status 200. It is stored as bot traffic and stays out of your reports.

Check the body, not only the status, when you test.

How do you keep visitors apart?

Send the same anonymous_id for every event from one visitor, and send the visitor's real IP address and user agent with a key.

If you send neither, all your events share your server's address and count as one visitor.

How do you identify a user from a server?

POST /identify links a visitor to your user ID and stores traits.

FieldTypeRequired
site_idTextYes
user_idTextYes
anonymous_idTextNo
traitsObjectNo
ip_address, user_agentTextNo. Used only with a qualifying key

Questions about sending events

Can you put the API key in browser code?

No. Anyone can read a key in a web page. Use the tracking script in the browser and the API from your server.

Do events sent through the API count toward your plan?

Yes. An event counts the same way however it arrives.