Documentation
¶
Index ¶
- Variables
- type ErrTrackFailed
- type Event
- type Mixpanel
- type MixpanelError
- type Mock
- func (m *Mock) Alias(distinctId, newId string) error
- func (m *Mock) Import(distinctId, eventName string, e *Event) error
- func (m *Mock) String() string
- func (m *Mock) Track(distinctId, eventName string, e *Event) error
- func (m *Mock) Update(distinctId string, u *Update) error
- func (m *Mock) UpdateGroup(groupKey, groupUser string, u *Update) error
- func (m *Mock) UpdateUser(distinctId string, u *Update) error
- type MockEvent
- type MockPeople
- type Update
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var IgnoreTime *time.Time = &time.Time{}
Functions ¶
This section is empty.
Types ¶
type ErrTrackFailed ¶
type ErrTrackFailed struct {
Message string
}
func (*ErrTrackFailed) Error ¶
func (err *ErrTrackFailed) Error() string
type Event ¶
type Event struct {
// IP-address of the user. Leave empty to use autodetect, or set to "0" to
// not specify an ip-address.
IP string
// Timestamp. Set to nil to use the current time.
Timestamp *time.Time
// Custom properties. At least one must be specified.
Properties map[string]interface{}
}
A mixpanel event
type Mixpanel ¶
type Mixpanel interface {
// Create a mixpanel event using the track api
Track(distinctId, eventName string, e *Event) error
// Create a mixpanel event using the import api
Import(distinctId, eventName string, e *Event) error
// Set properties for a mixpanel user.
// Deprecated: Use UpdateUser instead
Update(distinctId string, u *Update) error
// Set properties for a mixpanel user.
UpdateUser(distinctId string, u *Update) error
// Set properties for a mixpanel group.
UpdateGroup(groupKey, groupId string, u *Update) error
// Create an alias for an existing distinct id
Alias(distinctId, newId string) error
}
The Mixapanel struct store the mixpanel endpoint and the project token
Example ¶
client := New("mytoken", "")
client.Track("1", "Sign Up", &Event{
Properties: map[string]interface{}{
"from": "email",
},
})
func New ¶
New returns the client instance. If apiURL is blank, the default will be used ("https://api.mixpanel.com").
Example ¶
New("mytoken", "")
func NewFromClient ¶
NewFromClient creates a client instance using the specified client instance. This is useful when using a proxy.
func NewFromClientWithSecret ¶
NewFromClientWithSecret creates a client instance using the specified client instance and secret.
func NewWithSecret ¶
NewWithSecret returns the client instance using a secret.If apiURL is blank, the default will be used ("https://api.mixpanel.com").
Example ¶
NewWithSecret("mytoken", "myapisecret", "")
type MixpanelError ¶
func (*MixpanelError) Cause ¶
func (err *MixpanelError) Cause() error
func (*MixpanelError) Error ¶
func (err *MixpanelError) Error() string
type Mock ¶
type Mock struct {
// All People identified, mapped by distinctId
People map[string]*MockPeople
}
Mocked version of Mixpanel which can be used in unit tests.
Example ¶
package main
import (
"fmt"
"time"
)
var fullfillsInterface Mixpanel = &Mock{}
func main() {
client := NewMock()
t, _ := time.Parse(time.RFC3339, "2016-03-03T15:17:53+01:00")
client.Update("1", &Update{
Operation: "$set",
Timestamp: &t,
IP: "127.0.0.1",
Properties: map[string]interface{}{
"custom_field": "cool!",
},
})
client.Track("1", "Sign Up", &Event{
IP: "1.2.3.4",
Properties: map[string]interface{}{
"from": "email",
},
})
client.Import("1", "Sign Up", &Event{
IP: "1.2.3.4",
Timestamp: &t,
Properties: map[string]interface{}{
"imported": true,
},
})
fmt.Println(client)
}
Output: 1: ip: 127.0.0.1 time: 2016-03-03T15:17:53+01:00 properties: custom_field: cool! events: Sign Up: IP: 1.2.3.4 Timestamp: from: email Sign Up: IP: 1.2.3.4 Timestamp: 2016-03-03T15:17:53+01:00 imported: true
type MockPeople ¶
type MockPeople struct {
Properties map[string]interface{}
Time *time.Time
IP string
Events []MockEvent
}
func (*MockPeople) String ¶
func (mp *MockPeople) String() string
type Update ¶
type Update struct {
// IP-address of the user. Leave empty to use autodetect, or set to "0" to
// not specify an ip-address at all.
IP string
// Timestamp. Set to nil to use the current time, or IgnoreTime to not use a
// timestamp.
Timestamp *time.Time
// Update operation such as "$set", "$update" etc.
Operation string
// Custom properties. At least one must be specified.
Properties map[string]interface{}
}
An update of a user in mixpanel
Click to show internal directories.
Click to hide internal directories.