Server Side Tracking
When you need to integrate Koala with your server-side application.
Sometimes you’ll need to send events from your backend application in addition to or instead of using Koala’s client-side SDK. This guide will show you how to do that.
What can it do?
- ❌ Autocapture (pageviews, forms, active session time)
- ❌ Sessions
- ✅ Custom Events
- ✅ Visitor Identification
- ✅ Account Traits
Important: Please make sure to always include the User-Agent
header in your requests to Koala, or it may be flagged as a bot and not processed.
The /batch
endpoint has a few constraints/requirements:
- you must send either a
profile_id
oremail
identifier as top-level properties in the request body - all events, identifies, or page_views collected are limited to up to 30 of each type
- each request should only send events for the same person (all events are tied to the same
profile_id
/email
)
Identifying visitors
If you’ve already got the Koala snippet installed client-side on the same top domain as your server you can identify visitors with known email addresses server-side. For example, if your website (www.example.com) has the JavaScript snippet installed, and your app (app.example.com) does not, you can enrich the data Koala is collecting across both.
Whenever users do something identifiable in your app, like logging in, you can identify them manually. This enables you to:
- Track a visitor across browsers or devices
- Differentiate truly anonymous visitors from known users
- Combine all activity from a visitor before and after they’ve logged in
- Associate visitors with company data
To identify anonymous visitors with an email, send a request to your workspace’s public API for collection:
Here’s an example bare-bones request:
If you want to explicitly collect identify
calls and see them appear in the debugger in the Koala app, you’ll need to include the identifies
array in the body of the request. See an example below.
You should ensure all websites sharing the same top domain also share the Koala anonymous profile_id
by respecting one if it’s already there, or setting it yourself if it isn’t there. You can read and modify the ko_id
cookie value in the request to do this.
Note: when setting your own randomly generated profile_id
, you should use a UUID v4 format.
Here’s an example of parsing the Koala cookie for a profile_id
using Express in Node.js:
Sending events
You can also send custom events to Koala using the same /batch
endpoint for your workspace.
You can send multiple events at once. You can omit the message_id
if you do not require it, but note that the event could potentially be captured more than once (if retries are needed). The message_id
acts as an idempotency key to dedupe replayed/retried events.
Sending Traits
You can send custom traits that can be attached to a Koala visitor using the /batch
endpoint for your workspace.
You must either pass a profile_id
or email
key in the body of a request in order for it to be attached to an existing visitor in Koala.
- You can find the
profile_id
for a visitor by reading theko_id
cookie that is set by the Koala pixel client side. - Alternatively, you can attach an
email
field to your/batch
call, and Koala will associate the traits to an existing user that has been previously identified using the same email.
Sending Account Traits
Sometimes you want to send traits that are associated with an account, rather than a visitor. You can do this by sending a domain
along with the traits for the Account.
Account traits will be associated with the domain
and will be available to all visitors that have been identified with the same account.
You should use the /accounts/batch
endpoint for your workspace to send Account traits:
The traits above will be visible in the Account page for getkoala.com
in the Koala app.
You must either pass an account_id
or domain
key in the body of a request in order for it to be attached to an existing Account in Koala.
We recommend using the domain
parameter to associate traits with an account.
- Koala will automatically create a new Account if the
domain
hasn’t been tracked in Koala yet.
Deduplicating Account Traits
There are scenarios where the same Account has multiple tenants in your App. For example, your customers may have a workspace for their development team and another for their marketing team.
In this case, you can pass along a group_id
parameter alongside your Account Traits, that way, Koala can disambiguate multiple groupings within the same company.
- The
group_id
parameter is optional, and you can use it to disambiguate multiple groupings within the same company. - Koala will group the traits by
group_id
and display them in the Account page in Koala under each individual grouping.