This guide shows how to measure sessions and conversion events from desktop and over-the-top (OTT) platforms such as Roku, with server-to-server (S2S) requests. Sessions go to the Attribution API, and conversion events go to the Events API. A session response can include deep link data, which lets you deep link someone to content, including deferred deep linking when they select a Branch Link, install the app, and open it.
The examples use Roku, and the platform table shows what changes for the others. For every field and response, see the Attribution API reference and the overview.
Before you begin
To measure sessions and conversion events from these platforms, you first need to:
- Set up your app in Branch with default link redirects, your
app.linkdomains, a URI scheme, and Universal Links. - Get your Branch Key and Branch Secret. Session requests use both, and conversion event requests use only the Branch Key. See Before you begin in the overview.
- Send the device's IP address if your server sends the requests. See Send the device's IP address.
Platform values
Sessions and conversion events spell some values differently. This table shows what to send for each platform.
| Platform | Session os | Event user_data. | Event user_data. | Advertising ID |
|---|---|---|---|---|
| macOS | mac_OS | MAC_OS | FULL_APP | idfa, or mac_address if you don't have one |
| Windows | WINDOWS | WINDOWS | FULL_APP | windows_advertising_id, plus mac_address |
| tvOS | tv_OS | TV_OS | TV_APP | idfa |
| Roku | ROKU | ROKU | TV_APP | roku_rida |
| Samsung | TIZEN or SAMSUNG | TIZEN or SAMSUNG | TV_APP | samsung_ifa |
| LG | WEBOS or LG | WEBOS or LG | TV_APP | lg_ifa |
| Xbox | XBOX | XBOX | TV_APP | xbox_msai |
For a session, send the advertising ID in advertising_ids, for example "advertising_ids": {"roku_rida": "ea31e5e0-1aa5-4181-91d7-0b56524e0274"}. Send mac_address as its own field, for example 88:66:5a:2f:81:fa. For a conversion event on macOS or tvOS, send the IDFA as user_data.idfa, not in advertising_ids. Panasonic and PlayStation work the same way, with panasonic_ifa and playstation_ifa.
Measure sessions
Send a request to POST /v1/open every time the app opens. Set server_to_server to true and send the Branch Secret. Set first_session to true on the first open, as described in Decide install, reinstall, or open. Most fields are in the reference. These need extra care on OTT platforms.
| Parameter | Type | What to send |
|---|---|---|
os | String | The session value from the platform table. |
advertising_ids | Object | The platform's key and the advertising ID, from the platform table. |
launch_options | Object | (Optional, Roku only) The launch arguments that your app receives, including source. For an app launched with contentId=1234 and source set to external-control, send all three keys. Branch uses it for attribution only when source is external-control or ad, or starts with ad:. |
randomized_device_token or device_fingerprint_id | String | Leave it out on the device's first request. After that, send the token that the last response returned, under the same name. |
Branch also reads the User-Agent header for these platforms, so send the device's user agent there.
Send a session
This request opens the Roku app for the first time.
curl -X POST "https://api2.branch.io/v1/open" \
-H "Content-Type: application/json" \
-H "User-Agent: Roku/DVP-12.0 (12.0.0.4189)" \
-H "X-IP-Override: 203.0.113.42" \
-d '{
"branch_key": "key_live_xxxx",
"branch_secret": "secret_live_xxxx",
"server_to_server": true,
"first_session": true,
"os": "ROKU",
"os_version": "10.0",
"app_version": "1.0.1",
"brand": "Roku",
"model": "4200X",
"screen_height": 1334,
"screen_width": 750,
"ad_tracking_enabled": true,
"advertising_ids": {
"roku_rida": "00000000-0000-0000-0000-000000000123"
},
"launch_options": {
"contentId": "1234",
"mediaType": "movie",
"source": "external-control"
}
}'The response holds the session ID, a token for the device, and the deep link data. It shows only some of the keys in data. Branch removes source from the launch options it returns. Save device_fingerprint_id, or randomized_device_token if the response has it instead.
{
"session_id": "685187705776489500",
"device_fingerprint_id": "123456789123456789",
"data": "{\"+clicked_branch_link\":true,\"+is_first_session\":true,\"+match_guaranteed\":true,\"~channel\":\"Roku\",\"contentId\":\"1234\",\"mediaType\":\"movie\"}"
}To set a custom user ID with server_to_server_identity and identity, see Set a custom user ID in the overview.
Measure conversion events
Conversion events are everything beyond sessions, such as sign-ups, content views, and purchases. For a Branch Standard Event, send the request to POST /v2/event/standard. If no Standard Event fits, send a Custom Event to POST /v2/event/custom with any name that isn't a Standard Event name. Use a Custom Event only when no Standard Event fits. For the list of Standard Events, see Track Branch events. For every field, see the Events API reference.
Send the Branch Key in branch_key. Conversion event requests never need the Branch Secret. These fields need extra care on OTT platforms.
| Parameter | Type | What to send |
|---|---|---|
user_data. | String | The event value from the platform table. |
user_data. | String | The environment from the platform table. Branch accepts FULL_APP, IMESSAGE_APP, INSTANT_APP, WATCH_APP, TV_APP, and APP_CLIP, and rejects DESKTOP_APP. |
user_data. | Boolean | The opposite of ad_tracking_enabled in a session request. |
user_data. | Object | The platform's key and the advertising ID, from the platform table. |
user_data. or user_data. | String | The token from the session response, under the same name. |
Branch needs one identifier in user_data to match the event to a device. Which ones it accepts depends on user_data.os.
- Roku, Samsung, LG, Xbox, and other TV platforms:
advertising_ids,developer_identity,randomized_device_token, ordevice_fingerprint_id, among others. - macOS and tvOS:
developer_identity,idfa,idfv,mac_address, orbrowser_fingerprint_id.advertising_idsisn't accepted. - Windows:
developer_identity,randomized_device_token,device_fingerprint_id, orbrowser_fingerprint_id.advertising_idsalone isn't enough.
Send a conversion event
This request sends a purchase from the Roku app.
curl -X POST "https://api2.branch.io/v2/event/standard" \
-H "Content-Type: application/json" \
-H "X-IP-Override: 203.0.113.42" \
-d '{
"name": "PURCHASE",
"customer_event_alias": "purchase 5 tokens",
"branch_key": "key_live_xxxx",
"user_data": {
"developer_identity": "user123",
"app_version": "1.0.1",
"os": "ROKU",
"os_version": "10.0",
"brand": "Roku",
"model": "4200X",
"screen_height": 1334,
"screen_width": 750,
"environment": "TV_APP",
"limit_ad_tracking": false,
"advertising_ids": {
"roku_rida": "00000000-0000-0000-0000-000000000123"
},
"device_fingerprint_id": "123456789123456789"
},
"event_data": {
"transaction_id": "foobar",
"currency": "USD",
"revenue": 100
},
"retryNumber": 0
}'You don't need to read the response body. Look for a 200 status code. Any other status code is an error.
