amplitude

package module
v0.0.0-...-b98b7a3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 29, 2015 License: MIT Imports: 6 Imported by: 1

README

Amplitude HTTP API Client

GoDoc Build StatusCoverage Status

APIs supported:

  • Events API (httpapi)
  • Identify API

Basic usage example:


import (
  "fmt"

  "github.com/replaygaming/amplitude"
)

func main() {
  apiKey := "abcdef"
  c := amplitude.NewClient(apiKey)
  e := amplitude.Event{EventType: "test", UserID: "1"}
  if _, err := c.Send(e); err != nil {
    fmt.Println(err)
  }
}

Documentation

Overview

Package amplitude is a simple client implementation of the Amplitude HTTP API.

Basic usage example:

import (
	"fmt"

	"github.com/replaygaming/amplitude"
)

func main() {
	apiKey := "abcdef"
	c := amplitude.NewClient(apiKey)
	e := amplitude.Event{EventType: "test", UserID: "1"}
	if _, err := c.Send(e); err != nil {
		fmt.Println(err)
	}
}

Index

Constants

View Source
const (
	// APIURL is the url for the HTTP-API endpoint.
	APIURL = "https://api.amplitude.com"

	// EventsPath is the url part to post/get requests for events.
	EventsPath = "httpapi"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client interface {
	Send(Payload) ([]byte, error)
}

Client interface requires a Send method to post a payload to Amplitude.

type DefaultClient

type DefaultClient struct {
	// APIKey provided by Amplitude for the account.
	APIKey string

	// URL endpoint for Amplitude HTTP-API.
	URL string
}

DefaultClient implements the client interface and wraps the API endpoint and allows events to be sent.

func NewClient

func NewClient(apiKey string) *DefaultClient

NewClient returns a default client with values for the Amplitude HTTP-API implementation.

func (*DefaultClient) Send

func (c *DefaultClient) Send(p Payload) ([]byte, error)

Send sends a payload (an event or a list of events) to Amplitude using the client config.

type Device

type Device struct {
	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"`
	DeviceType         string `json:"device_type,omitempty"`
	Carrier            string `json:"carrier,omitempty"`
}

Device fields must all be updated together. Setting any of these fields will automatically reset all of the others if they are not also set on the same event.

type Event

type Event struct {
	UserID          string     `json:"user_id,omitempty"`
	DeviceID        string     `json:"device_id,omitempty"`
	EventType       string     `json:"event_type"`
	Time            int64      `json:"time,omitempty"`
	EventProperties Properties `json:"event_properties,omitempty"`
	UserProperties  Properties `json:"user_properties,omitempty"`
	AppVersion      string     `json:"app_version,omitempty"`
	Platform        string     `json:"platform,omitempty"`
	Language        string     `json:"language,omitempty"`
	Revenue         float64    `json:"revenue,omitempty"`
	LocationLat     float64    `json:"location_lat,omitempty"`
	LocationLng     float64    `json:"location_lng,omitempty"`
	IP              string     `json:"ip,omitempty"`
	IDFA            string     `json:"idfa,omitempty"`
	ADID            string     `json:"adid,omitempty"`
	Device
	Location
	EventAugment
}

Event implements the Payload interface.

func (Event) Encode

func (e Event) Encode() ([]byte, error)

Encode returns the event serialized into JSON.

type EventAugment

type EventAugment struct {
	EventID   int    `json:"event_id,omitempty"`
	SessionID int64  `json:"session_id,omitempty"`
	InsertID  string `json:"insert_id,omitempty"`
}

EventAugment are optional keys interpreted in a special way by Amplitude.

type Events

type Events []Event

Events represents a list of events. Implements the Payload interface.

func (Events) Encode

func (e Events) Encode() ([]byte, error)

Encode returns all events serialized into JSON.

type Location

type Location struct {
	Country string `json:"country,omitempty"`
	Region  string `json:"region,omitempty"`
	City    string `json:"city,omitempty"`
	DMA     string `json:"dma,omitempty"`
}

Location fields must all be updated together. Setting any of these fields will automatically reset all of the others if they are not also set on the same event.

type NoopClient

type NoopClient struct {
}

NoopClient implements the client interface, but doesn't do anything.

func (NoopClient) Send

func (c NoopClient) Send(Payload) ([]byte, error)

Send return a blank body and no error.

type Payload

type Payload interface {
	Encode() ([]byte, error)
}

Payload is the event data sent to the server.

type Properties

type Properties map[string]*json.RawMessage

Properties is a dictionary type for both user and event properties.

type ResponseError

type ResponseError struct {
	StatusCode int
	Body       []byte
}

ResponseError is a description of the error returned from Amplitude API.

func (ResponseError) Error

func (e ResponseError) Error() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL