mixpanel

package module
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: May 25, 2023 License: Apache-2.0 Imports: 12 Imported by: 7

README

Mixpanel Go SDK

Go Reference Go Go Report Card codecov

WebSite docs: https://docs.mixpanel.com/tracking/reference/go

Getting Started

 mp := mixpanel.NewClient("<PROJECT_TOKEN>")

Documentation

Index

Constants

View Source
const (
	ExportNoLimit       int    = 0
	ExportNoEventFilter string = ""
	ExportNoWhereFilter string = ""
)
View Source
const (
	MaxTrackEvents  = 50
	MaxImportEvents = 2_000

	MaxPeopleEvents = 2_000
)
View Source
const (
	EmptyDistinctID = ""
)

Variables

View Source
var (
	ErrStatusCode = errors.New("unexpected status code")
)
View Source
var ImportOptionsRecommend = ImportOptions{
	Strict:      true,
	Compression: Gzip,
}

Functions

This section is empty.

Types

type Event

type Event struct {
	Name       string         `json:"event"`
	Properties map[string]any `json:"properties"`
}

Event is a mixpanel event: https://help.mixpanel.com/hc/en-us/articles/360041995352-Mixpanel-Concepts-Events

func (*Event) AddIP

func (e *Event) AddIP(ip net.IP)

AddIP if you supply a property ip with an IP address Mixpanel will automatically do a GeoIP lookup and replace the ip property with geographic properties (City, Country, Region). These properties can be used in our UI to segment events geographically. https://developer.mixpanel.com/reference/import-events#geoip-enrichment

func (*Event) AddInsertID

func (e *Event) AddInsertID(insertID string)

AddInsertID inserts the insert_id property into the properties https://developer.mixpanel.com/reference/import-events#propertiesinsert_id

func (*Event) AddTime

func (e *Event) AddTime(t time.Time)

AddTime insert the time properties into the event https://developer.mixpanel.com/reference/import-events#propertiestime

type Export

type Export interface {
	Export(ctx context.Context, fromDate, toDate time.Time, limit int, event, where string) ([]*Event, error)
}

type HttpError

type HttpError struct {
	Status int
	Body   string
}

func (HttpError) Error

func (h HttpError) Error() string

type Identity added in v0.0.3

type Identity interface {
	CreateIdentity(ctx context.Context, events []*IdentityEvent, options IdentityOptions) error
}

type IdentityEvent added in v0.0.3

type IdentityEvent struct {
	*Event
}

func (*IdentityEvent) AnonId added in v0.0.3

func (i *IdentityEvent) AnonId(id string)

func (*IdentityEvent) IdentifiedId added in v0.0.3

func (i *IdentityEvent) IdentifiedId() any

func (*IdentityEvent) SetAnonId added in v0.0.3

func (i *IdentityEvent) SetAnonId(id string)

A distinct_id to merge with the $identified_id. The $anon_id must be UUID v4 format and not already merged to an $identified_id.

func (*IdentityEvent) SetIdentifiedId added in v0.0.3

func (i *IdentityEvent) SetIdentifiedId(id string)

A distinct_id to merge with the $anon_id.

type IdentityOptions added in v0.0.3

type IdentityOptions struct {
	Strict bool
}

type ImportFailedRecords

type ImportFailedRecords struct {
	Index    int    `json:"index"`
	InsertID string `json:"insert_id"`
	Field    string `json:"field"`
	Message  string `json:"message"`
}

type ImportFailedValidationError

type ImportFailedValidationError struct {
	Code                int                   `json:"code"`
	ApiError            string                `json:"error"`
	Status              interface{}           `json:"status"`
	NumRecordsImported  int                   `json:"num_records_imported"`
	FailedImportRecords []ImportFailedRecords `json:"failed_records"`
}

func (ImportFailedValidationError) Error

type ImportGenericError

type ImportGenericError struct {
	Code     int         `json:"code"`
	ApiError string      `json:"error"`
	Status   interface{} `json:"status"`
}

func (ImportGenericError) Error

func (e ImportGenericError) Error() string

type ImportOptions

type ImportOptions struct {
	Strict      bool
	Compression MpCompression
}

type ImportRateLimitError added in v0.0.4

type ImportRateLimitError struct {
	ImportGenericError
}

type ImportSuccess

type ImportSuccess struct {
	Code               int         `json:"code"`
	NumRecordsImported int         `json:"num_records_imported"`
	Status             interface{} `json:"status"`
}

type Ingestion

type Ingestion interface {
	// Events
	Track(ctx context.Context, events []*Event) error
	Import(ctx context.Context, events []*Event, options ImportOptions) (*ImportSuccess, error)

	// People
	PeopleSet(ctx context.Context, people []*PeopleProperties) error
	PeopleSetOnce(ctx context.Context, people []*PeopleProperties) error
	PeopleIncrement(ctx context.Context, distinctID string, add map[string]int) error
	PeopleUnionProperty(ctx context.Context, distinctID string, union map[string]any) error
	PeopleAppendListProperty(ctx context.Context, distinctID string, append map[string]any) error
	PeopleRemoveListProperty(ctx context.Context, distinctID string, remove map[string]any) error
	PeopleDeleteProperty(ctx context.Context, distinctID string, unset []string) error
	PeopleDeleteProfile(ctx context.Context, distinctID string, ignoreAlias bool) error

	// Groups
	GroupUpdateProperty(ctx context.Context, groupKey, groupID string, set map[string]string) error
	GroupSetOnce(ctx context.Context, groupKey, groupID string, set map[string]any) error
	GroupDeleteProperty(ctx context.Context, groupKey, groupID string, unset []string) error
	GroupRemoveListProperty(ctx context.Context, groupKey, groupID string, remove map[string]string) error
	GroupUnionListProperty(ctx context.Context, groupKey, groupID string, union map[string]any) error
	GroupDelete(ctx context.Context, groupKey, groupID string) error

	// Lookup
	ListLookupTables(ctx context.Context) (*LookupTable, error)
}

type LookupTable

type LookupTable struct {
	Code    int                  `json:"code"`
	Status  string               `json:"status"`
	Results []LookupTableResults `json:"results"`
}

type LookupTableError

type LookupTableError struct {
	Code     int         `json:"code"`
	ApiError string      `json:"error"`
	Status   interface{} `json:"status"`
}

func (LookupTableError) Error

func (e LookupTableError) Error() string

type LookupTableResults

type LookupTableResults struct {
	ID   string `json:"id"`
	Name string `json:"name"`
}

type Mixpanel

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

func NewClient

func NewClient(token string, options ...Options) *Mixpanel

NewClient create a new mixpanel client

func (*Mixpanel) CreateIdentity added in v0.0.3

func (m *Mixpanel) CreateIdentity(ctx context.Context, events []*IdentityEvent, identityOptions IdentityOptions) error

func (*Mixpanel) Export

func (m *Mixpanel) Export(ctx context.Context, fromDate, toDate time.Time, limit int, event, where string) ([]*Event, error)

Example on how to explore everything fromDate - toDate Export(ctx, fromDate, toDate, ExportNoLimit, ExportNoEventFilter, ExportNoWhereFilter)

func (*Mixpanel) GroupDelete

func (m *Mixpanel) GroupDelete(ctx context.Context, groupKey, groupID string) error

GroupDelete calls the Groups Delete API https://developer.mixpanel.com/reference/delete-group

func (*Mixpanel) GroupDeleteProperty

func (m *Mixpanel) GroupDeleteProperty(ctx context.Context, groupKey, groupID string, unset []string) error

GroupDeleteProperty calls the group delete property API https://developer.mixpanel.com/reference/group-delete-property

func (*Mixpanel) GroupRemoveListProperty

func (m *Mixpanel) GroupRemoveListProperty(ctx context.Context, groupKey, groupID string, remove map[string]string) error

GroupRemoveListProperty calls the Groups Remove from List Property API https://developer.mixpanel.com/reference/group-remove-from-list-property

func (*Mixpanel) GroupSetOnce

func (m *Mixpanel) GroupSetOnce(ctx context.Context, groupKey, groupID string, set map[string]any) error

GroupSetOnce calls the Group Set Property Once API https://developer.mixpanel.com/reference/group-set-property-once

func (*Mixpanel) GroupUnionListProperty

func (m *Mixpanel) GroupUnionListProperty(ctx context.Context, groupKey, groupID string, union map[string]any) error

GroupUnionListProperty calls the Groups Remove from Union Property API https://developer.mixpanel.com/reference/group-union

func (*Mixpanel) GroupUpdateProperty

func (m *Mixpanel) GroupUpdateProperty(ctx context.Context, groupKey, groupID string, set map[string]string) error

GroupUpdateProperty calls the Group Update Property API https://developer.mixpanel.com/reference/group-set-property

func (*Mixpanel) Import

func (m *Mixpanel) Import(ctx context.Context, events []*Event, options ImportOptions) (*ImportSuccess, error)

Import calls the Import api https://developer.mixpanel.com/reference/import-events

func (*Mixpanel) ListLookupTables

func (m *Mixpanel) ListLookupTables(ctx context.Context) (*LookupTable, error)

ListLookupTables calls the List Lookup Tables API https://developer.mixpanel.com/reference/list-lookup-tables

func (*Mixpanel) NewEvent

func (m *Mixpanel) NewEvent(name string, distinctID string, properties map[string]any) *Event

NewEvent creates a new mixpanel event to track

func (*Mixpanel) NewEventFromJson

func (m *Mixpanel) NewEventFromJson(json map[string]any) (*Event, error)

func (*Mixpanel) NewIdentityEvent added in v0.0.3

func (m *Mixpanel) NewIdentityEvent(distinctID string, properties map[string]any, identifiedId, anonId string) *IdentityEvent

func (*Mixpanel) PeopleAppendListProperty

func (m *Mixpanel) PeopleAppendListProperty(ctx context.Context, distinctID string, append map[string]any) error

PeopleAppend calls the Increment Numerical Property https://developer.mixpanel.com/reference/profile-numerical-add

func (*Mixpanel) PeopleDeleteProfile

func (m *Mixpanel) PeopleDeleteProfile(ctx context.Context, distinctID string, ignoreAlias bool) error

PeopleDeleteProfile calls the User Delete Profile API https://developer.mixpanel.com/reference/delete-profile

func (*Mixpanel) PeopleDeleteProperty

func (m *Mixpanel) PeopleDeleteProperty(ctx context.Context, distinctID string, unset []string) error

PeopleDeleteProperty calls the User Delete Property API https://developer.mixpanel.com/reference/profile-delete-property

func (*Mixpanel) PeopleIncrement

func (m *Mixpanel) PeopleIncrement(ctx context.Context, distinctID string, add map[string]int) error

PeopleIncrement calls the User Increment Numerical Property API https://developer.mixpanel.com/reference/profile-numerical-add

func (*Mixpanel) PeopleRemoveListProperty

func (m *Mixpanel) PeopleRemoveListProperty(ctx context.Context, distinctID string, remove map[string]any) error

PeopleRemoveListProperty calls the User Remove from List Property API https://developer.mixpanel.com/reference/profile-remove-from-list-property

func (*Mixpanel) PeopleSet

func (m *Mixpanel) PeopleSet(ctx context.Context, people []*PeopleProperties) error

PeopleSet calls the User Set Property API https://developer.mixpanel.com/reference/profile-set

func (*Mixpanel) PeopleSetOnce

func (m *Mixpanel) PeopleSetOnce(ctx context.Context, people []*PeopleProperties) error

PeopleSetOnce calls the User Set Property Once API https://developer.mixpanel.com/reference/profile-set-property-once

func (*Mixpanel) PeopleUnionProperty

func (m *Mixpanel) PeopleUnionProperty(ctx context.Context, distinctID string, union map[string]any) error

PeopleUnionProperty calls User Union To List Property API https://developer.mixpanel.com/reference/user-profile-union

func (*Mixpanel) Track

func (m *Mixpanel) Track(ctx context.Context, events []*Event) error

Track calls the Track endpoint For server side we recommend Import func more info here: https://developer.mixpanel.com/reference/track-event#when-to-use-track-vs-import

type MpApi

type MpApi interface {
	Ingestion
	Export
	Identity
}

MpApi is all the API's in the Mixpanel docs https://developer.mixpanel.com/reference/overview

type MpCompression

type MpCompression int
var (
	None MpCompression = 0
	Gzip MpCompression = 1
)

type Options

type Options func(mixpanel *Mixpanel)

func ApiSecret added in v0.0.4

func ApiSecret(apiSecret string) Options

func DebugHttpCalls

func DebugHttpCalls(writer io.Writer) Options

DebugHttpCalls streams payload information and url information for debugging purposes

func EuResidency

func EuResidency() Options

EuResidency sets the mixpanel client to use the eu endpoints Use for EU Projects

func HttpClient

func HttpClient(client *http.Client) Options

HttpClient will replace the http.DefaultClient with the provided http.Client

func ProjectID added in v0.0.4

func ProjectID(projectID int) Options

func ProxyApiLocation

func ProxyApiLocation(proxy string) Options

ProxyApiLocation sets the mixpanel client to use the custom location for all ingestion requests Example: http://locahosthost:8080

func ProxyDataLocation

func ProxyDataLocation(proxy string) Options

ProxyDataLocation sets the mixpanel client to use the custom location for all data requests Example: http://locahosthost:8080

func ServiceAccount

func ServiceAccount(username, secret string) Options

ServiceAccount add a service account to the mixpanel client https://developer.mixpanel.com/reference/service-accounts-api

type PeopleError

type PeopleError struct {
	Code int `json:"code"`
}

func (PeopleError) Error

func (p PeopleError) Error() string

type PeopleProperties added in v0.0.4

type PeopleProperties struct {
	DistinctID string
	Properties map[string]any
}

func NewPeopleProperties added in v0.0.4

func NewPeopleProperties(distinctID string, properties map[string]any) *PeopleProperties

func (*PeopleProperties) SetIp added in v0.0.4

func (p *PeopleProperties) SetIp(ip net.IP)

func (*PeopleProperties) SetReservedProperty added in v0.0.4

func (p *PeopleProperties) SetReservedProperty(property PeopleReveredProperties, value any)

type PeopleReveredProperties added in v0.0.4

type PeopleReveredProperties string
const (
	PeopleEmailProperty           PeopleReveredProperties = "$email"
	PeoplePhoneProperty           PeopleReveredProperties = "$phone"
	PeopleFirstNameProperty       PeopleReveredProperties = "$first_name"
	PeopleLastNameProperty        PeopleReveredProperties = "$last_name"
	PeopleNameProperty            PeopleReveredProperties = "$name"
	PeopleAvatarProperty          PeopleReveredProperties = "$avatar"
	PeopleCreatedProperty         PeopleReveredProperties = "$created"
	PeopleCityProperty            PeopleReveredProperties = "$city"
	PeopleRegionProperty          PeopleReveredProperties = "$region"
	PeopleCountryCodeProperty     PeopleReveredProperties = "$country_code"
	PeopleTimezoneProperty        PeopleReveredProperties = "$timezone"
	PeopleBucketProperty          PeopleReveredProperties = "$bucket"
	PeopleGeolocationByIpProperty PeopleReveredProperties = "$ip"
)

type VerboseError

type VerboseError struct {
	ApiError string `json:"error"`
	Status   int    `json:"status"`
}

func (VerboseError) Error

func (a VerboseError) Error() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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