@@ -55,6 +55,8 @@ type Mixpanel struct {
5555const events_endpoint string = "https://api.mixpanel.com/track"
5656const people_endpoint string = "https://api.mixpanel.com/engage"
5757
58+ var import_endpoint string = "https://api.mixpanel.com/import"
59+
5860func b64 (payload []byte ) []byte {
5961 var b bytes.Buffer
6062 encoder := base64 .NewEncoder (base64 .URLEncoding , & b )
@@ -108,6 +110,20 @@ mp.Track("12345", "Welcome Email Sent", &P{
108110 })
109111*/
110112func (mp * Mixpanel ) Track (distinct_id , event string , prop * P ) error {
113+ import_endpoint += "?api_key=" + mp .Token
114+ return mp .sendEvent (distinct_id , event , prop , "events" )
115+ }
116+
117+ /*
118+ Imports events that occurred more than 5 days in the past. Takes the
119+ same arguments as Track and behaves in the same way.
120+ */
121+ func (mp * Mixpanel ) Import (distinct_id , event string , prop * P ) error {
122+ return mp .sendEvent (distinct_id , event , prop , "import" )
123+ }
124+
125+ /* Internal implementation of event sending. Can be used with Track or Import. */
126+ func (mp * Mixpanel ) sendEvent (distinct_id , event string , prop * P , endpoint string ) error {
111127 properties := & P {
112128 "token" : mp .Token ,
113129 "distinct_id" : distinct_id ,
@@ -129,7 +145,7 @@ func (mp *Mixpanel) Track(distinct_id, event string, prop *P) error {
129145 return err
130146 }
131147
132- return mp .c .Send ("events" , data )
148+ return mp .c .Send (endpoint , data )
133149}
134150
135151/*
@@ -337,6 +353,7 @@ func NewStdConsumer() *StdConsumer {
337353 c .endpoints = make (map [string ]string )
338354 c .endpoints ["events" ] = events_endpoint
339355 c .endpoints ["people" ] = people_endpoint
356+ c .endpoints ["import" ] = import_endpoint
340357 return c
341358}
342359
@@ -383,6 +400,7 @@ func NewBuffConsumer(maxSize int64) *BuffConsumer {
383400 bc .buffers = make (map [string ][][]byte )
384401 bc .buffers ["people" ] = make ([][]byte , 0 , maxSize )
385402 bc .buffers ["events" ] = make ([][]byte , 0 , maxSize )
403+ bc .buffers ["import" ] = make ([][]byte , 0 , maxSize )
386404 return bc
387405}
388406
0 commit comments