forked from mixpanel/mixpanel-node
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.js
43 lines (34 loc) · 1.2 KB
/
example.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// grab the Mixpanel factory
var Mixpanel = require('./lib/mixpanel-node');
// create an instance of the mixpanel client
var mixpanel = Mixpanel.init('962dbca1bbc54701d402c94d65b4a20e');
mixpanel.set_config({ debug: true });
// track an event with optional properties
mixpanel.track("my event", {
distinct_id: "some unique client id",
as: "many",
properties: "as",
you: "want"
});
mixpanel.track("played_game");
// create or update a user in Mixpanel Engage
mixpanel.people.set("billybob", {
$first_name: "Billy",
$last_name: "Bob",
plan: "premium",
games_played: 1,
points: 0
});
// set a single property on a user
mixpanel.people.set("billybob", "plan", "free");
// increment a numeric property
mixpanel.people.increment("billybob", "games_played");
// increment a numeric property by a different amount
mixpanel.people.increment("billybob", "points", 15);
// increment multiple properties
mixpanel.people.increment("billybob", {"points": 10, "games_played": 1});
// delete a user
mixpanel.people.delete_user("billybob");
// all functions that send data to mixpanel take an optional
// callback as the last argument
mixpanel.track("test", function(err) { if (err) throw err; });