amplitude

package module
v0.0.0-...-8e3139e Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2021 License: MIT Imports: 7 Imported by: 0

README

Go Amplitude GoDoc Build Status

Summary

A Go library for Amplitude

Installation

go get github.com/msingleton/amplitude-go

Usage

import "github.com/msingleton/amplitude-go"

client := amplitude.New("amplitude-api-key")
client.Event(amplitude.Event{
	UserId:     "1234",
	EventType:	"joined",
})

Documentation

Overview

Package amplitude provides access to the Amplitude API

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client manages the communication to the Amplitude API

func New

func New(key string) *Client

New client with API key

func (*Client) Event

func (c *Client) Event(msg Event) error

func (*Client) Events

func (c *Client) Events(events []Event) error

func (*Client) Identify

func (c *Client) Identify(msg Identify) error

func (*Client) SetClient

func (c *Client) SetClient(client *http.Client)

type Event

type Event struct {
	Adid               string                 `json:"adid,omitempty"`
	AppVersion         string                 `json:"app_version,omitempty"`
	Carrier            string                 `json:"carrier,omitempty"`
	City               string                 `json:"city,omitempty"`
	Country            string                 `json:"country,omitempty"`
	DeviceBrand        string                 `json:"device_brand,omitempty"`
	DeviceId           string                 `json:"device_id,omitempty"`
	DeviceManufacturer string                 `json:"device_manufacturer,omitempty"`
	DeviceModel        string                 `json:"device_model,omitempty"`
	DeviceType         string                 `json:"device_type,omitempty"`
	Dma                string                 `json:"dma,omitempty"`
	EventId            int                    `json:"event_id,omitempty"`
	EventProperties    map[string]interface{} `json:"event_properties,omitempty"`
	EventType          string                 `json:"event_type,omitempty"`
	Groups             map[string]interface{} `json:"groups,omitempty"`
	Ifda               string                 `json:"ifda,omitempty"`
	InsertId           string                 `json:"insert_id,omitempty"`
	Ip                 string                 `json:"ip,omitempty"`
	Language           string                 `json:"language,omitempty"`
	LocationLat        string                 `json:"location_lat,omitempty"`
	LocationLng        string                 `json:"location_lng,omitempty"`
	OsName             string                 `json:"os_name,omitempty"`
	OsVersion          string                 `json:"os_version,omitempty"`
	Paying             string                 `json:"paying,omitempty"`
	Platform           string                 `json:"platform,omitempty"`
	Price              float64                `json:"price,omitempty"`
	ProductId          string                 `json:"productId,omitempty"`
	Quantity           int                    `json:"quantity,omitempty"`
	Region             string                 `json:"region,omitempty"`
	Revenue            float64                `json:"revenue,omitempty"`
	RevenueType        string                 `json:"revenueType,omitempty"`
	SessionId          int64                  `json:"session_id,omitempty"`
	StartVersion       string                 `json:"start_version,omitempty"`
	Time               int64                  `json:"time,omitempty"`
	UserId             string                 `json:"user_id,omitempty"`
	UserProperties     map[string]interface{} `json:"user_properties,omitempty"`
}
Example
keyResp, bodyResp, server := mockServer("event")
defer server.Close()

client := New("s3cr3ts")
client.eventEndpoint = server.URL

client.Event(Event{
	UserId:    "0000001",
	EventType: "joined",
})

key := <-keyResp
body := <-bodyResp
fmt.Printf("Key: %s\n%s", string(key), string(body))
Output:

Key: s3cr3ts
{
  "event_type": "joined",
  "user_id": "0000001"
}

type EventRequest

type EventRequest struct {
	ApiKey string  `json:"api_key,omitempty"`
	Events []Event `json:"events,omitempty"`
}

type Identify

type Identify struct {
	AppVersion         string                 `json:"app_version,omitempty"`
	Carrier            string                 `json:"carrier,omitempty"`
	City               string                 `json:"city,omitempty"`
	Country            string                 `json:"country,omitempty"`
	DeviceBrand        string                 `json:"device_brand,omitempty"`
	DeviceId           string                 `json:"device_id,omitempty"`
	DeviceManufacturer string                 `json:"device_manufacturer,omitempty"`
	DeviceModel        string                 `json:"device_model,omitempty"`
	DeviceType         string                 `json:"device_type,omitempty"`
	Dma                string                 `json:"dma,omitempty"`
	Groups             map[string]interface{} `json:"groups,omitempty"`
	Language           string                 `json:"language,omitempty"`
	OsName             string                 `json:"os_name,omitempty"`
	OsVersion          string                 `json:"os_version,omitempty"`
	Paying             string                 `json:"paying,omitempty"`
	Platform           string                 `json:"platform,omitempty"`
	Region             string                 `json:"region,omitempty"`
	StartVersion       string                 `json:"start_version,omitempty"`
	UserId             string                 `json:"user_id,omitempty"`
	UserProperties     map[string]interface{} `json:"user_properties,omitempty"`
}
Example
keyResp, bodyResp, server := mockServer("identification")
defer server.Close()

client := New("s3cr3ts")
client.identifyEndpoint = server.URL

client.Identify(Identify{
	UserId: "0000001",
	UserProperties: map[string]interface{}{
		"name":  "Art Vandelay",
		"email": "art@vandelayindustries.com",
	},
})

key := <-keyResp
body := <-bodyResp
fmt.Printf("Key: %s\n%s", string(key), string(body))
Output:

Key: s3cr3ts
{
  "user_id": "0000001",
  "user_properties": {
    "email": "art@vandelayindustries.com",
    "name": "Art Vandelay"
  }
}

Jump to

Keyboard shortcuts

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