Skip to content

Commit 03c6cf4

Browse files
committed
add more endpoints
1 parent 589c247 commit 03c6cf4

File tree

2 files changed

+68
-3
lines changed

2 files changed

+68
-3
lines changed

mixpanel.go

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ Example:
122122
"Birthday": "1948-01-01"})
123123
*/
124124
func (mp *Mixpanel) PeopleSet(id string, properties *P) error {
125-
return mp.PeopleUpdate(id, &P{
125+
return mp.PeopleUpdate(&P{
126126
"$distinct_id": id,
127127
"$set" : properties,
128128
})
@@ -138,12 +138,62 @@ Example:
138138
mp.PeopleSetOnce("12345", &P{"First Login": "2013-04-01T13:20:00"})
139139
*/
140140
func (mp *Mixpanel) PeopleSetOnce(id string, properties *P) error {
141-
return mp.PeopleUpdate(id, &P{
141+
return mp.PeopleUpdate(&P{
142142
"$distinct_id": id,
143143
"$set" : properties,
144144
})
145145
}
146146

147+
/*
148+
PeopleIncrement Increments/decrements numerical properties of people record.
149+
150+
Takes in JSON object with keys and numerical values. Adds numerical
151+
values to current property of profile. If property doesn't exist adds
152+
value to zero. Takes in negative values for subtraction.
153+
Example:
154+
mp.PeopleIncrement("12345", &P{"Coins Gathered": 12})
155+
*/
156+
func (mp *Mixpanel) PeopleIncrement(id string, properties *P) error {
157+
return mp.PeopleUpdate(&P{
158+
"$distinct_id": id,
159+
"$add" : properties,
160+
})
161+
}
162+
163+
/*
164+
PeopleAppend appends to the list associated with a property.
165+
166+
Takes a JSON object containing keys and values, and appends each to a
167+
list associated with the corresponding property name. $appending to a
168+
property that doesn't exist will result in assigning a list with one
169+
element to that property.
170+
Example:
171+
mp.PeopleAppend("12345", &P{ "Power Ups": "Bubble Lead" })
172+
*/
173+
func (mp *Mixpanel) PeopleAppend(id string, properties *P) error {
174+
return mp.PeopleUpdate(&P{
175+
"$distinct_id": id,
176+
"$append" : properties,
177+
})
178+
}
179+
180+
/*
181+
PeopleUnion Merges the values for a list associated with a property.
182+
183+
Takes a JSON object containing keys and list values. The list values in
184+
the request are merged with the existing list on the user profile,
185+
ignoring duplicate list values.
186+
Example:
187+
mp.PeopleUnion("12345", &P{ "Items purchased": ["socks", "shirts"] } )
188+
*/
189+
func (mp *Mixpanel) PeopleUnion(id string, properties *P) error {
190+
return mp.PeopleUpdate(&P{
191+
"$distinct_id": id,
192+
"$union" : properties,
193+
})
194+
}
195+
196+
147197

148198
func parseJsonResponse(resp *http.Response) error {
149199
type jsonResponseT map[string]interface{}

mixpanel_test.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func TestTrack(t *testing.T) {
3131
}
3232
}
3333

34-
func TestSmoke(t *testing.T) {
34+
func TestSmoke(t *testing.T){
3535
mp := NewMixpanel(token)
3636
err := mp.PeopleSet("12345", &P{"Address": "1313 Mockingbird Lane",
3737
"Birthday": "1948-01-01"})
@@ -43,5 +43,20 @@ func TestSmoke(t *testing.T) {
4343
if err != nil {
4444
t.Error(err)
4545
}
46+
47+
err = mp.PeopleIncrement("12345", &P{"Coins Gathered": 12})
48+
if err != nil {
49+
t.Error(err)
50+
}
51+
52+
err = mp.PeopleAppend("12345", &P{ "Power Ups": "Bubble Lead" })
53+
if err != nil {
54+
t.Error(err)
55+
}
56+
57+
err = mp.PeopleUnion("12345", &P{ "Items purchased": ["socks", "shirts"] } )
58+
if err != nil {
59+
t.Error(err)
60+
}
4661
}
4762

0 commit comments

Comments
 (0)