Documentation ¶
Index ¶
Examples ¶
Constants ¶
View Source
const BatchUploadMaxAttempts = 360
Max attempts for the retry when the batch upload to Segment API fails
View Source
const BatchUploadRetryInterval = 15 * time.Second
Retry interval when the batch upload to Segment API fails
View Source
const Endpoint = "https://api.segment.io"
Endpoint for the Segment API.
View Source
const Version = "2.1.0"
Version of the client.
Variables ¶
View Source
var Backo = backo.DefaultBacko()
Backoff policy.
View Source
var DefaultContext = map[string]interface{}{ "library": map[string]interface{}{ "name": "analytics-go", "version": Version, }, }
DefaultContext of message batches.
Functions ¶
This section is empty.
Types ¶
type Batch ¶
type Batch struct { Context map[string]interface{} `json:"context,omitempty"` Messages []interface{} `json:"batch"` Message }
Batch message.
type Client ¶
type Client struct { Endpoint string // Interval represents the duration at which messages are flushed. It may be // configured only before any messages are enqueued. Interval time.Duration Size int Logger *log.Logger Verbose bool Client http.Client // contains filtered or unexported fields }
Client which batches messages and flushes at the given Interval or when the Size limit is exceeded. Set Verbose to true to enable logging output.
type Group ¶
type Group struct { Context map[string]interface{} `json:"context,omitempty"` Integrations map[string]interface{} `json:"integrations,omitempty"` Traits map[string]interface{} `json:"traits,omitempty"` AnonymousId string `json:"anonymousId,omitempty"` UserId string `json:"userId,omitempty"` GroupId string `json:"groupId"` Message }
Group message.
type Identify ¶
type Identify struct { Context map[string]interface{} `json:"context,omitempty"` Integrations map[string]interface{} `json:"integrations,omitempty"` Traits map[string]interface{} `json:"traits,omitempty"` AnonymousId string `json:"anonymousId,omitempty"` UserId string `json:"userId,omitempty"` Message }
Identify message.
type Message ¶
type Message struct { Type string `json:"type,omitempty"` MessageId string `json:"messageId,omitempty"` Timestamp string `json:"timestamp,omitempty"` SentAt string `json:"sentAt,omitempty"` }
Message fields common to all.
type Page ¶
type Page struct { Context map[string]interface{} `json:"context,omitempty"` Integrations map[string]interface{} `json:"integrations,omitempty"` Traits map[string]interface{} `json:"properties,omitempty"` AnonymousId string `json:"anonymousId,omitempty"` UserId string `json:"userId,omitempty"` Category string `json:"category,omitempty"` Name string `json:"name,omitempty"` Message }
Page message.
type Track ¶
type Track struct { Context map[string]interface{} `json:"context,omitempty"` Integrations map[string]interface{} `json:"integrations,omitempty"` Properties map[string]interface{} `json:"properties,omitempty"` AnonymousId string `json:"anonymousId,omitempty"` UserId string `json:"userId,omitempty"` Event string `json:"event"` Message }
Track message.
Example ¶
body, server := mockServer() defer server.Close() client := New("h97jamjwbh") client.Endpoint = server.URL client.now = mockTime client.uid = mockId client.Size = 1 client.Track(&Track{ Event: "Download", UserId: "123456", Properties: map[string]interface{}{ "application": "Segment Desktop", "version": "1.1.0", "platform": "osx", }, }) fmt.Printf("%s\n", <-body)
Output: { "batch": [ { "event": "Download", "messageId": "I'm unique", "properties": { "application": "Segment Desktop", "platform": "osx", "version": "1.1.0" }, "timestamp": "2009-11-10T23:00:00+0000", "type": "track", "userId": "123456" } ], "context": { "library": { "name": "analytics-go", "version": "2.1.0" } }, "messageId": "I'm unique", "sentAt": "2009-11-10T23:00:00+0000" }
Example (Context) ¶
body, server := mockServer() defer server.Close() client := New("h97jamjwbh") client.Endpoint = server.URL client.now = mockTime client.uid = mockId client.Size = 1 client.Track(&Track{ Event: "Download", UserId: "123456", Properties: map[string]interface{}{ "application": "Segment Desktop", "version": "1.1.0", "platform": "osx", }, Context: map[string]interface{}{ "whatever": "here", }, }) fmt.Printf("%s\n", <-body)
Output: { "batch": [ { "context": { "whatever": "here" }, "event": "Download", "messageId": "I'm unique", "properties": { "application": "Segment Desktop", "platform": "osx", "version": "1.1.0" }, "timestamp": "2009-11-10T23:00:00+0000", "type": "track", "userId": "123456" } ], "context": { "library": { "name": "analytics-go", "version": "2.1.0" } }, "messageId": "I'm unique", "sentAt": "2009-11-10T23:00:00+0000" }
Example (Many) ¶
body, server := mockServer() defer server.Close() client := New("h97jamjwbh") client.Endpoint = server.URL client.now = mockTime client.uid = mockId client.Size = 3 for i := 0; i < 5; i++ { client.Track(&Track{ Event: "Download", UserId: "123456", Properties: map[string]interface{}{ "application": "Segment Desktop", "version": i, }, }) } fmt.Printf("%s\n", <-body)
Output: { "batch": [ { "event": "Download", "messageId": "I'm unique", "properties": { "application": "Segment Desktop", "version": 0 }, "timestamp": "2009-11-10T23:00:00+0000", "type": "track", "userId": "123456" }, { "event": "Download", "messageId": "I'm unique", "properties": { "application": "Segment Desktop", "version": 1 }, "timestamp": "2009-11-10T23:00:00+0000", "type": "track", "userId": "123456" }, { "event": "Download", "messageId": "I'm unique", "properties": { "application": "Segment Desktop", "version": 2 }, "timestamp": "2009-11-10T23:00:00+0000", "type": "track", "userId": "123456" } ], "context": { "library": { "name": "analytics-go", "version": "2.1.0" } }, "messageId": "I'm unique", "sentAt": "2009-11-10T23:00:00+0000" }
Directories ¶
Path | Synopsis |
---|---|
Godeps
|
|
_workspace/src/github.com/jehiah/go-strftime
go implementation of strftime
|
go implementation of strftime |
_workspace/src/github.com/xtgo/uuid
Package uuid can be used to generate and parse universally unique identifiers, a standardized format in the form of a 128 bit number.
|
Package uuid can be used to generate and parse universally unique identifiers, a standardized format in the form of a 128 bit number. |
Click to show internal directories.
Click to hide internal directories.