11// grab the Mixpanel factory
2- var Mixpanel = require ( ' ./lib/mixpanel-node' ) ;
2+ const Mixpanel = require ( " ./lib/mixpanel-node" ) ;
33
44// create an instance of the mixpanel client
5- var mixpanel = Mixpanel . init ( ' 962dbca1bbc54701d402c94d65b4a20e' ) ;
5+ const mixpanel = Mixpanel . init ( " 962dbca1bbc54701d402c94d65b4a20e" ) ;
66mixpanel . set_config ( { debug : true } ) ;
77
88// track an event with optional properties
99mixpanel . track ( "my event" , {
10- distinct_id : "some unique client id" ,
11- as : "many" ,
12- properties : "as" ,
13- you : "want"
10+ distinct_id : "some unique client id" ,
11+ as : "many" ,
12+ properties : "as" ,
13+ you : "want" ,
1414} ) ;
1515mixpanel . track ( "played_game" ) ;
1616
1717// create or update a user in Mixpanel Engage
1818mixpanel . people . set ( "billybob" , {
19- $first_name : "Billy" ,
20- $last_name : "Bob" ,
21- $created : ( new Date ( ' jan 1 2013' ) ) . toISOString ( ) ,
22- plan : "premium" ,
23- games_played : 1 ,
24- points : 0
19+ $first_name : "Billy" ,
20+ $last_name : "Bob" ,
21+ $created : new Date ( " jan 1 2013" ) . toISOString ( ) ,
22+ plan : "premium" ,
23+ games_played : 1 ,
24+ points : 0 ,
2525} ) ;
2626
2727// create or update a user in Mixpanel Engage without altering $last_seen
2828// - pass option `$ignore_time: true` to prevent the $last_seen property from being updated
29- mixpanel . people . set ( "billybob" , {
29+ mixpanel . people . set (
30+ "billybob" ,
31+ {
3032 plan : "premium" ,
31- games_played : 1
32- } , {
33- $ignore_time : true
34- } ) ;
33+ games_played : 1 ,
34+ } ,
35+ {
36+ $ignore_time : true ,
37+ } ,
38+ ) ;
3539
3640// set a single property on a user
3741mixpanel . people . set ( "billybob" , "plan" , "free" ) ;
3842
3943// set a single property on a user, don't override
40- mixpanel . people . set_once ( "billybob" , "first_game_play" , ( new Date ( 'jan 1 2013' ) ) . toISOString ( ) ) ;
44+ mixpanel . people . set_once (
45+ "billybob" ,
46+ "first_game_play" ,
47+ new Date ( "jan 1 2013" ) . toISOString ( ) ,
48+ ) ;
4149
4250// increment a numeric property
4351mixpanel . people . increment ( "billybob" , "games_played" ) ;
@@ -46,13 +54,16 @@ mixpanel.people.increment("billybob", "games_played");
4654mixpanel . people . increment ( "billybob" , "points" , 15 ) ;
4755
4856// increment multiple properties
49- mixpanel . people . increment ( "billybob" , { " points" : 10 , " games_played" : 1 } ) ;
57+ mixpanel . people . increment ( "billybob" , { points : 10 , games_played : 1 } ) ;
5058
5159// append value to a list
5260mixpanel . people . append ( "billybob" , "awards" , "Great Player" ) ;
5361
5462// append multiple values to a list
55- mixpanel . people . append ( "billybob" , { "awards" : "Great Player" , "levels_finished" : "Level 4" } ) ;
63+ mixpanel . people . append ( "billybob" , {
64+ awards : "Great Player" ,
65+ levels_finished : "Level 4" ,
66+ } ) ;
5667
5768// record a transaction for revenue analytics
5869mixpanel . people . track_charge ( "billybob" , 39.99 ) ;
@@ -65,38 +76,42 @@ mixpanel.people.delete_user("billybob");
6576
6677// all functions that send data to mixpanel take an optional
6778// callback as the last argument
68- mixpanel . track ( "test" , function ( err ) { if ( err ) { throw err ; } } ) ;
79+ mixpanel . track ( "test" , function ( err ) {
80+ if ( err ) {
81+ throw err ;
82+ }
83+ } ) ;
6984
7085// import an old event
71- var mixpanel_importer = Mixpanel . init ( ' valid mixpanel token' , {
72- secret : "valid api secret for project"
86+ const mixpanel_importer = Mixpanel . init ( " valid mixpanel token" , {
87+ secret : "valid api secret for project" ,
7388} ) ;
7489mixpanel_importer . set_config ( { debug : true } ) ;
7590
7691// needs to be in the system once for it to show up in the interface
77- mixpanel_importer . track ( ' old event' , { gender : '' } ) ;
92+ mixpanel_importer . track ( " old event" , { gender : "" } ) ;
7893
7994mixpanel_importer . import ( "old event" , new Date ( 2012 , 4 , 20 , 12 , 34 , 56 ) , {
80- distinct_id : ' billybob' ,
81- gender : ' male'
95+ distinct_id : " billybob" ,
96+ gender : " male" ,
8297} ) ;
8398
8499// import multiple events at once
85100mixpanel_importer . import_batch ( [
86- {
87- event : 'old event' ,
88- properties : {
89- time : new Date ( 2012 , 4 , 20 , 12 , 34 , 56 ) ,
90- distinct_id : 'billybob' ,
91- gender : 'male'
92- }
101+ {
102+ event : "old event" ,
103+ properties : {
104+ time : new Date ( 2012 , 4 , 20 , 12 , 34 , 56 ) ,
105+ distinct_id : "billybob" ,
106+ gender : "male" ,
107+ } ,
108+ } ,
109+ {
110+ event : "another old event" ,
111+ properties : {
112+ time : new Date ( 2012 , 4 , 21 , 11 , 33 , 55 ) ,
113+ distinct_id : "billybob" ,
114+ color : "red" ,
93115 } ,
94- {
95- event : 'another old event' ,
96- properties : {
97- time : new Date ( 2012 , 4 , 21 , 11 , 33 , 55 ) ,
98- distinct_id : 'billybob' ,
99- color : 'red'
100- }
101- }
116+ } ,
102117] ) ;
0 commit comments