Documentation
¶
Overview ¶
Package amplitude provides a http client for working with various Amplitude APIs.
Index ¶
- Constants
- func AsError(resp *http.Response) error
- type BatchEventsSuccessSummary
- type Client
- func (c *Client) Do(req *http.Request, v interface{}) (*http.Response, error)
- func (c *Client) NewRequest(ctx context.Context, method, endpoint string, body RequestBody) (*http.Request, error)
- func (c *Client) NewRequestBody() RequestBody
- func (c *Client) SendMiddleware() *SendMiddleware
- func (c *Client) WithHttpClient(client *http.Client) *Client
- type Error
- type Event
- type EventsService
- type RequestBody
- type SendMiddleware
- func (m *SendMiddleware) DeviceHeader(h string) *SendMiddleware
- func (m *SendMiddleware) Environment(env string) *SendMiddleware
- func (m *SendMiddleware) Error() error
- func (m *SendMiddleware) Event() *Event
- func (m *SendMiddleware) Flush(ctx context.Context)
- func (m *SendMiddleware) Handle(next http.Handler) http.Handler
- func (m *SendMiddleware) Send(event *Event) *SendMiddleware
- func (m *SendMiddleware) SendError(err error) *SendMiddleware
- func (m *SendMiddleware) UserHeader(h string) *SendMiddleware
- func (m *SendMiddleware) Version(v string) *SendMiddleware
Constants ¶
const ( // MaxEvents is the max number of events to track before dropping occurs MaxEvents = 1024 // MaxErrors is the max number of errors to track before dropping occurs MaxErrors = 1024 )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type BatchEventsSuccessSummary ¶
type BatchEventsSuccessSummary struct { Code int `json:"code"` EventsIngested int `json:"events_ingested"` PayloadSize int `json:"payload_size_bytes"` UploadTime int64 `json:"server_upload_time"` }
BatchEventsSuccessSummary is expected to be returned for all successful requests.
func (*BatchEventsSuccessSummary) String ¶
func (s *BatchEventsSuccessSummary) String() string
String converts the summary response to a pretty string format.
type Client ¶
type Client struct { // BaseURL for all API requests. Exposed services should // use relative paths for making requests. BaseURL *url.URL UserAgent string APIKey string Events *EventsService // contains filtered or unexported fields }
Client allows interaction with amplitude services
func (*Client) NewRequest ¶
func (c *Client) NewRequest(ctx context.Context, method, endpoint string, body RequestBody) (*http.Request, error)
NewRequest provides a http request to be sent to Amplitude
func (*Client) NewRequestBody ¶
func (c *Client) NewRequestBody() RequestBody
NewRequestBody creates a request body with authentication
func (*Client) SendMiddleware ¶ added in v0.2.2
func (c *Client) SendMiddleware() *SendMiddleware
SendMiddleware creates a new http middleware instance from the client
type Error ¶
Error houses any potential http error responses from the API The body is not well-defined so more information can be obtained by access the context
type Event ¶
type Event struct { UserId string `json:"user_id,omitempty"` DeviceId string `json:"device_id,omitempty"` Name string `json:"event_type"` Time int64 `json:"time,omitempty"` Properties map[string]interface{} `json:"event_properties,omitempty"` UserProperties map[string]interface{} `json:"user_properties,omitempty"` Groups map[string]interface{} `json:"groups,omitempty"` GroupProperties map[string]interface{} `json:"group_properties,omitempty"` AppVersion string `json:"app_version,omitempty"` Platform string `json:"platform,omitempty"` OSName string `json:"os_name,omitempty"` OSVersion string `json:"os_version,omitempty"` DeviceBrand string `json:"device_brand,omitempty"` DeviceManufacturer string `json:"device_manufacturer,omitempty"` DeviceModel string `json:"device_model,omitempty"` Carrier string `json:"carrier,omitempty"` Country string `json:"country,omitempty"` Region string `json:"region,omitempty"` City string `json:"city,omitempty"` DMA string `json:"dma,omitempty"` Language string `json:"language,omitempty"` Price float64 `json:"price,omitempty"` Quantity int `json:"quantity,omitempty"` Revenue float64 `json:"revenue,omitempty"` ProductId string `json:"productId,omitempty"` RevenueType string `json:"revenueType,omitempty"` Latitude float64 `json:"location_lat,omitempty"` Longitude float64 `json:"location_lng,omitempty"` IP string `json:"ip,omitempty"` IOSAdvertiserId string `json:"idfa,omitempty"` IOSVendorId string `json:"idfv,omitempty"` AndroidAdvertiserId string `json:"adid,omitempty"` AndroidId string `json:"android_id,omitempty"` Id int `json:"event_id,omitempty"` SessionId int `json:"session_id,omitempty"` InsertId string `json:"insert_id,omitempty"` }
Event is the base analytic structure for capturing user activity
func NewEventFromRequest ¶ added in v0.2.2
NewEventFromRequest creates a new amplitude event from a http request
func (*Event) Environment ¶ added in v0.2.2
Environment sets the environment of the event
type EventsService ¶
type EventsService service
EventsService provides access to events related functions
func (*EventsService) Send ¶ added in v0.2.2
func (s *EventsService) Send(ctx context.Context, events ...*Event) (*BatchEventsSuccessSummary, error)
Send batches of events via the Batch Event Upload API This endpoint is recommended for Customers that want to send large batches of data at a time, for example through scheduled jobs, rather than in a continuous realtime stream. Due to the higher rate of data that is permitted to this endpoint, data sent to this endpoint may be delayed based on load.
type RequestBody ¶
type RequestBody map[string]interface{}
RequestBody is sent as the body of all requests
func (RequestBody) WithValue ¶
func (b RequestBody) WithValue(key string, v interface{}) RequestBody
WithValue adds a value to the request body
type SendMiddleware ¶ added in v0.2.2
type SendMiddleware struct {
// contains filtered or unexported fields
}
SendMiddleware is a http middleware for sending request metrics to amplitude
func NewSendMiddleware ¶ added in v0.2.2
func NewSendMiddleware(c *Client) *SendMiddleware
NewSendMiddleware create a new instance of the amplitude middleware
func (*SendMiddleware) DeviceHeader ¶ added in v0.2.2
func (m *SendMiddleware) DeviceHeader(h string) *SendMiddleware
DeviceHeader sets the header to retrieve device id from
func (*SendMiddleware) Environment ¶ added in v0.2.2
func (m *SendMiddleware) Environment(env string) *SendMiddleware
Environment sets the environment the app is running
func (*SendMiddleware) Error ¶ added in v0.2.2
func (m *SendMiddleware) Error() error
Error gets any errors that have occurred
func (*SendMiddleware) Event ¶ added in v0.2.2
func (m *SendMiddleware) Event() *Event
Event gets any events that have occurred
func (*SendMiddleware) Flush ¶ added in v0.2.2
func (m *SendMiddleware) Flush(ctx context.Context)
Flush will send all batched events to the amplitude batch upload API
func (*SendMiddleware) Handle ¶ added in v0.2.2
func (m *SendMiddleware) Handle(next http.Handler) http.Handler
func (*SendMiddleware) Send ¶ added in v0.2.2
func (m *SendMiddleware) Send(event *Event) *SendMiddleware
Send buffers an event
func (*SendMiddleware) SendError ¶ added in v0.2.2
func (m *SendMiddleware) SendError(err error) *SendMiddleware
SendError buffers an error
func (*SendMiddleware) UserHeader ¶ added in v0.2.2
func (m *SendMiddleware) UserHeader(h string) *SendMiddleware
UserHeader sets the header to retrieve user id from
func (*SendMiddleware) Version ¶ added in v0.2.2
func (m *SendMiddleware) Version(v string) *SendMiddleware
Version sets the version of your app