mixpanel

package module
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2024 License: Apache-2.0 Imports: 13 Imported by: 2

README

Dancing Gopher

Mixpanel Go SDK

Go Reference Go Go Report Card codecov

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

Getting Started

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

Documentation

Index

Constants

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

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

Variables

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

Functions

This section is empty.

Types

type Api added in v0.1.2

type Api interface {
	Ingestion
	Export
	Identity
}

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

type ApiClient added in v0.1.2

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

func NewApiClient added in v0.1.2

func NewApiClient(token string, options ...Options) *ApiClient

NewApiClient create a new mixpanel client

func (*ApiClient) Alias added in v0.1.2

func (a *ApiClient) Alias(ctx context.Context, aliasID, distinctID string) error

https://developer.mixpanel.com/reference/identity-create-alias

func (*ApiClient) Export added in v0.1.2

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

Export calls the Raw Export API https://developer.mixpanel.com/reference/raw-event-export

func (*ApiClient) GroupDelete added in v0.1.2

func (a *ApiClient) GroupDelete(ctx context.Context, groupKey, groupID string) error

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

func (*ApiClient) GroupDeleteProperty added in v0.1.2

func (a *ApiClient) 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 (*ApiClient) GroupRemoveListProperty added in v0.1.2

func (a *ApiClient) GroupRemoveListProperty(ctx context.Context, groupKey, groupID string, remove map[string]any) error

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

func (*ApiClient) GroupSet added in v0.1.2

func (a *ApiClient) GroupSet(ctx context.Context, groupKey, groupID string, set map[string]any) error

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

func (*ApiClient) GroupSetOnce added in v0.1.2

func (a *ApiClient) 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 (*ApiClient) GroupUnionListProperty added in v0.1.2

func (a *ApiClient) 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 (*ApiClient) Import added in v0.1.2

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

Import calls the Import api https://developer.mixpanel.com/reference/import-events Need to provide project id a service account, project token or api secret to the client

func (*ApiClient) Merge added in v0.1.2

func (a *ApiClient) Merge(ctx context.Context, distinctID1, distinctID2 string) error

https://developer.mixpanel.com/reference/identity-merge must provide api secret

func (*ApiClient) NewEvent added in v0.1.2

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

NewEvent creates a new mixpanel event to track

func (*ApiClient) NewEventFromJson added in v0.1.2

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

func (*ApiClient) PeopleAppendListProperty added in v0.1.2

func (a *ApiClient) 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 (*ApiClient) PeopleDeleteProfile added in v0.1.2

func (a *ApiClient) PeopleDeleteProfile(ctx context.Context, distinctID string, ignoreAlias bool) error

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

func (*ApiClient) PeopleDeleteProperty added in v0.1.2

func (a *ApiClient) 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 (*ApiClient) PeopleIncrement added in v0.1.2

func (a *ApiClient) 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 (*ApiClient) PeopleRemoveListProperty added in v0.1.2

func (a *ApiClient) 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 (*ApiClient) PeopleSet added in v0.1.2

func (a *ApiClient) PeopleSet(ctx context.Context, people []*PeopleProperties) error

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

func (*ApiClient) PeopleSetOnce added in v0.1.2

func (a *ApiClient) 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 (*ApiClient) PeopleUnionProperty added in v0.1.2

func (a *ApiClient) 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 (*ApiClient) Track added in v0.1.2

func (m *ApiClient) 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 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

func (HttpError) Unwrap added in v0.1.1

func (h HttpError) Unwrap() error

type Identity added in v0.0.3

type Identity interface {
	Alias(ctx context.Context, distinctID, aliasID string) error
	Merge(ctx context.Context, distinctID1, distinctID2 string) error
}

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
	GroupSet(ctx context.Context, groupKey, groupID string, set map[string]any) 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]any) error
	GroupUnionListProperty(ctx context.Context, groupKey, groupID string, union map[string]any) error
	GroupDelete(ctx context.Context, groupKey, groupID string) error
}

type MpCompression

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

type Options

type Options func(mixpanel *ApiClient)

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 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(projectID int, username, secret string) Options

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

type PeopleIpOptions added in v1.1.0

type PeopleIpOptions = func(peopleProperties *PeopleProperties)

func UseRequestIp added in v1.1.0

func UseRequestIp() PeopleIpOptions

type PeopleProperties added in v0.0.4

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

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, options ...PeopleIpOptions)

SetIp will cause mixpanel to geo lookup the ip for the user if no ip is provided, we will not lookup if ip is provided, we will lookup the ip if you want to use the request ip to lookup the geo location then use UseRequestIp option

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