Documentation ¶
Overview ¶
Package mixpanel provides the API client for making Mixpanel API calls.
Index ¶
- Constants
- type AddOperation
- type AppendOperation
- type BasicUpdateOperation
- type Client
- type DeleteOperation
- type Event
- type RemoveOperation
- type SetOnceOperation
- type SetOperation
- type UnionOperation
- type UnsetOperation
- type UpdateOperation
- func NewAddOperation(distinctID string, properties map[string]interface{}) UpdateOperation
- func NewAppendOperation(distinctID string, properties map[string]interface{}) UpdateOperation
- func NewDeleteOperation(distinctID string) UpdateOperation
- func NewRemovalOperation(distinctID string, properties map[string]interface{}) UpdateOperation
- func NewSetOnceOperation(distinctID string, properties map[string]interface{}) UpdateOperation
- func NewSetOperation(distinctID string, properties map[string]interface{}) UpdateOperation
- func NewUnionOperation(distinctID string, properties map[string][]interface{}) UpdateOperation
- func NewUnsetOperation(distinctID string, propertyNames []string) UpdateOperation
Examples ¶
Constants ¶
const ( // Protocol is the protocol being used for Mixpanel API request. Protocol = "https" // Host is the hostname of Mixpanel API. Host = "api.mixpanel.com" // TrackingPath is the API URL path for Mixpanel event tracking. // https://developer.mixpanel.com/docs/http#section-events TrackingPath = "track/" // UpdatePath is the API URL path for Mixpanel customer profile updates. // https://developer.mixpanel.com/docs/http#section-profile-updates UpdatePath = "engage/" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AddOperation ¶
type AddOperation struct { BasicUpdateOperation AddProperties map[string]interface{} `json:"$add"` }
func (AddOperation) JSON ¶
func (u AddOperation) JSON() string
type AppendOperation ¶
type AppendOperation struct { BasicUpdateOperation AppendProperties map[string]interface{} `json:"$append"` }
func (AppendOperation) JSON ¶
func (u AppendOperation) JSON() string
type BasicUpdateOperation ¶
type BasicUpdateOperation struct { Token string `json:"$token"` DistinctID string `json:"$distinct_id"` IP string `json:"$ip,omitempty"` Time uint `json:"$time,omitempty"` IgnoreTime bool `json:"$ignore_time,omitempty"` IgnoreAlias bool `json:"$ignore_alias,omitempty"` }
BasicUpdateOperation is the basic structure of a update operation. It has attributes which every kind of update operation consists.
func (BasicUpdateOperation) JSON ¶
func (u BasicUpdateOperation) JSON() string
JSON returns the JSON format string of this update operation struct.
func (*BasicUpdateOperation) SetToken ¶
func (u *BasicUpdateOperation) SetToken(token string)
SetToken is use by Mixpanel client to set the Mixpanel API token before making API request.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is the client for making Mixpanel API.
func NewClient ¶
NewClient is the constructor for Mixpanel API client. It takes the Mixpanel API token string.
func (Client) Track ¶
Track makes event tracking API call to Mixpanel. It returns the simple response from Mixpanel with a boolean to indicate the API call was successful or not. It returns error when the RESTful request to Mixpanel has error.
Example ¶
viper.SetEnvPrefix("mixpanel") viper.AutomaticEnv() viper.AllowEmptyEnv(true) token := viper.Get("token") if token == nil { log.Fatalf("Mixpanel Token is not provided for the test. You can add MIXPANEL_TOKEN to your environment variable for the test.\n") } client := NewClient(token.(string)) props := map[string]interface{}{"test": "testing"} event := NewEvent("go-test", props) event.DistinctID = "2" event.Time = uint(time.Now().Unix()) event.IP = "8.8.8.8" event.GroupKey = "MPGO" event.GroupID = "MPGOTEST" success, err := client.Track(event) if err != nil { log.Printf("Error occur when tracking event. Error: %+v\n", err) } if !success { log.Printf("Unsuccessful %s event tracking with distinct ID: %s\n", event.Title, event.DistinctID) }
Output:
func (Client) Update ¶
func (c Client) Update(u UpdateOperation) (success bool, err error)
Update makes profile update API call to Mixpanel. It returns the simple response from Mixpanel with a boolean to indicate the API call was successful or not. It returns error when the RESTful request to Mixpanel has error.
Example ¶
viper.SetEnvPrefix("mixpanel") viper.AutomaticEnv() viper.AllowEmptyEnv(true) token := viper.Get("token") if token == nil { log.Fatalf("Mixpanel Token is not provided for the test. You can add MIXPANEL_TOKEN to your environment variable for the test.\n") } client := NewClient(token.(string)) distinctID := "1" props := map[string]interface{}{"test": "testing"} update := NewSetOperation(distinctID, props) success, err := client.Update(update) if err != nil { log.Printf("Error occur when updating user profile. Error: %+v\n", err) } if !success { log.Printf("Unsuccessful updating user %s profile\n", distinctID) }
Output:
type DeleteOperation ¶
type DeleteOperation struct { BasicUpdateOperation Delete string `json:"$delete"` }
func (DeleteOperation) JSON ¶
func (u DeleteOperation) JSON() string
type Event ¶
type Event struct { Title string `json:"event"` Token string `json:"-"` Properties map[string]interface{} `json:"properties"` DistinctID string `json:"-"` Time uint `json:"-"` IP string `json:"-"` InsertID string `json:"-"` GroupKey string `json:"-"` GroupID string `json:"-"` }
Event is the structure of Mixpanel event. https://developer.mixpanel.com/docs/http#section-events
type RemoveOperation ¶
type RemoveOperation struct { BasicUpdateOperation RemoveProperties map[string]interface{} `json:"$remove"` }
func (RemoveOperation) JSON ¶
func (u RemoveOperation) JSON() string
type SetOnceOperation ¶
type SetOnceOperation struct { BasicUpdateOperation SetOnceProperties map[string]interface{} `json:"$set_once"` }
func (SetOnceOperation) JSON ¶
func (u SetOnceOperation) JSON() string
type SetOperation ¶
type SetOperation struct { BasicUpdateOperation SetProperties map[string]interface{} `json:"$set"` }
func (SetOperation) JSON ¶
func (u SetOperation) JSON() string
type UnionOperation ¶
type UnionOperation struct { BasicUpdateOperation UnionProperties map[string][]interface{} `json:"$union"` }
func (UnionOperation) JSON ¶
func (u UnionOperation) JSON() string
type UnsetOperation ¶
type UnsetOperation struct { BasicUpdateOperation UnsetProperties []string `json:"$unset"` }
func (UnsetOperation) JSON ¶
func (u UnsetOperation) JSON() string
type UpdateOperation ¶
func NewAddOperation ¶
func NewAddOperation(distinctID string, properties map[string]interface{}) UpdateOperation
func NewAppendOperation ¶
func NewAppendOperation(distinctID string, properties map[string]interface{}) UpdateOperation
func NewDeleteOperation ¶
func NewDeleteOperation(distinctID string) UpdateOperation
func NewRemovalOperation ¶
func NewRemovalOperation(distinctID string, properties map[string]interface{}) UpdateOperation
func NewSetOnceOperation ¶
func NewSetOnceOperation(distinctID string, properties map[string]interface{}) UpdateOperation
func NewSetOperation ¶
func NewSetOperation(distinctID string, properties map[string]interface{}) UpdateOperation
func NewUnionOperation ¶
func NewUnionOperation(distinctID string, properties map[string][]interface{}) UpdateOperation
func NewUnsetOperation ¶
func NewUnsetOperation(distinctID string, propertyNames []string) UpdateOperation