Segment API
Jitsu has a Segment API compatibility endpoint for sending events directly from apps or backends using Segment client libraries. You can install and configure Segment library to send data to Jitsu. Just set Jitsu endpoint and API key server secret (as a write key) in Segment library instance initialization. Income events are mapped on JS SDK 2.0 structure automatically.
If you are using deprecated events API (events structure with eventn_ctx
prefix) please use /api/v1/segment/compat
endpoint.
Node.js example#
import Analytics from 'analytics-node';
//if you are using JS SDK 2.0 events structure
let analytics = new Analytics(`Jitsu API key server secret`, {
host: `https://Jitsu_host/api/v1/segment`
})
//or if you are using deprecated events structure
//let analytics = new Analytics(`Jitsu API key server secret`, {
// host: `https://Jitsu_host/api/v1/segment/compat`
//})
analytics.track({...});
analytics.identify({
anonymousId: 'anonym1',
traits: {
email: 'newuser@gmail.com'
}
});
Go example#
package main
import (
"gopkg.in/segmentio/analytics-go.v3"
"log"
"time"
)
func main() {
//if you are using JS SDK 2.0 events structure
client, _ := analytics.NewWithConfig("Jitsu API key server secret", analytics.Config{Endpoint: "https://Jitsu_host/api/v1/segment"})
//or if you are using deprecated events structure
//client, _ := analytics.NewWithConfig("Jitsu API key server secret", analytics.Config{Endpoint: "https://Jitsu_host/api/v1/segment/compat"})
//sending event
analyticsTraits := analytics.NewTraits().
SetFirstName("Ned").
SetLastName("Stark").
Set("role", "the Lord of Winterfell").
SetEmail("ned@starkinc.com")
analyticsContext := &analytics.Context{
App: analytics.AppInfo{
Name: "my_app",
Version: "1.0",
},
Device: analytics.DeviceInfo{
Manufacturer: "Apple",
Model: "iPhone",
Type: "mobile",
},
Location: analytics.LocationInfo{
City: "San Francisco",
Country: "US",
Latitude: 1.0,
Longitude: 2.0,
Region: "CA",
Speed: 100,
},
IP: net.IPv4(1, 1, 1, 1),
Traits: analyticsTraits,
}
err := client.Enqueue(analytics.Track{
MessageId: "track1",
AnonymousId: "anonym1",
Event: "test_track",
Timestamp: time.Now(),
Context: analyticsContext,
})
if err != nil {
//handle error
}
}
POST/api/v1/segment#
For JS SDK 2.0 events structures. Authorization server secret token should be provided via Basic auth or HTTP header or query string parameter.
Parameters
Request Payload
The body is a Segment JSON object:
{
"anonymousId": "anonym1",
"context": {
"app": {
"build": "build",
"name": "app1",
"namespace": "namespace",
"version": "1.0"
},
"device": {
"advertisingId": "an_advertising_id",
"id": "device1",
"manufacturer": "Apple",
"model": "iPhone",
"name": "iPhone 12",
"type": "mobile",
"version": "12"
},
"ip": "1.1.1.1",
"library": {
"name": "analytics-node",
"version": "4.0.1"
},
"locale": "en-EU",
"page": {
"referrer": "page_referrer",
"search": "page_search",
"title": "page_title",
"url": "page_url"
},
"referrer": {
"url": "ref_url"
},
"screen": {
"height": 768,
"width": 1024
},
"timezone": "UTC",
"traits": {
"Role": "the Lord of Winterfell",
"firstName": "Ned",
"lastName": "Stark"
},
"userAgent": "Mozilla/5.0 (iPod; CPU iPhone OS 12_0 like macOS) AppleWebKit/602.1.50 (KHTML, like Gecko) Version/12.0 Mobile/14A5335d Safari/602.1.50"
}
}
or Segment batch:
{
"batch": [
{...},
{...}
]
}
Response
{"status": "ok"}
POST/api/v1/segment/compat#
For deprecated events structures. Authorization server secret token should be provided via Basic auth or HTTP header or query string parameter.
Parameters
Request Payload
The body is a Segment JSON object:
{
"anonymousId": "anonym1",
"context": {
"app": {
"build": "build",
"name": "app1",
"namespace": "namespace",
"version": "1.0"
},
"device": {
"advertisingId": "an_advertising_id",
"id": "device1",
"manufacturer": "Apple",
"model": "iPhone",
"name": "iPhone 12",
"type": "mobile",
"version": "12"
},
"ip": "1.1.1.1",
"library": {
"name": "analytics-node",
"version": "4.0.1"
},
"locale": "en-EU",
"page": {
"referrer": "page_referrer",
"search": "page_search",
"title": "page_title",
"url": "page_url"
},
"referrer": {
"url": "ref_url"
},
"screen": {
"height": 768,
"width": 1024
},
"timezone": "UTC",
"traits": {
"Role": "the Lord of Winterfell",
"firstName": "Ned",
"lastName": "Stark"
},
"userAgent": "Mozilla/5.0 (iPod; CPU iPhone OS 12_0 like macOS) AppleWebKit/602.1.50 (KHTML, like Gecko) Version/12.0 Mobile/14A5335d Safari/602.1.50"
}
}
or Segment batch:
{
"batch": [
{...},
{...}
]
}
Response
{"status": "ok"}
Default Geo data and User-Agent lookup enrichment are applied only if request doesn't have location
, device
and os
fields data respectively.