From 1a1301e6d2aa8644e46b4ff6909e717f22e3cc36 Mon Sep 17 00:00:00 2001 From: Knut Eirik Leira Hjelle Date: Wed, 11 Jun 2014 09:41:33 +0200 Subject: [PATCH] Added Mixpanel definition. --- mixpanel/mixpanel-tests.ts | 72 ++++++++++++++++++++++++++++++++++++++ mixpanel/mixpanel.d.ts | 69 ++++++++++++++++++++++++++++++++++++ 2 files changed, 141 insertions(+) create mode 100644 mixpanel/mixpanel-tests.ts create mode 100644 mixpanel/mixpanel.d.ts diff --git a/mixpanel/mixpanel-tests.ts b/mixpanel/mixpanel-tests.ts new file mode 100644 index 0000000000..fd52bd9893 --- /dev/null +++ b/mixpanel/mixpanel-tests.ts @@ -0,0 +1,72 @@ +/// +var mixpanel = new Mixpanel(); + +function mixpanel_base() +{ + mixpanel.init("new token", { your: "config" }, "library_name"); + + mixpanel.push(['register', { a: 'b' }]); + + mixpanel.disable(['my_event']); + + mixpanel.track("Registered", {"Gender": "Male", "Age": 21}); + + mixpanel.track_links("#nav", "Clicked Nav Link"); + + mixpanel.track_forms("#register", "Created Account"); + + mixpanel.register({device: 'android', version: '4.0.1'}); + + mixpanel.register_once({device: 'android', version: '4.0.1'}); + + mixpanel.unregister('device'); + + mixpanel.identify('234234sdfdsf'); + + mixpanel.get_distinct_id(); + + mixpanel.alias('w3erwfsdf', '234234sdfdsf'); + + mixpanel.set_config({test: true}); + + mixpanel.get_config(); + + mixpanel.get_property('device'); +} + +function mixpanel_people() +{ + mixpanel.people.set('gender', 'm'); + mixpanel.people.set({ + 'Company': 'Acme', + 'Plan': 'Premium', + 'Upgrade date': new Date() + }); + + mixpanel.people.set_once('First Login Date', new Date()); + mixpanel.people.set_once({ + 'First Login Date': new Date(), + 'Starting Plan': 'Premium' + }); + + mixpanel.people.increment('page_views', 1); + mixpanel.people.increment('page_views'); + mixpanel.people.increment('credits_left', -1); + mixpanel.people.increment({ + counter1: 1, + counter2: 1 + }); + + mixpanel.people.append('pages_visited', 'homepage'); + mixpanel.people.append({ + list1: 'bob', + list2: 123 + }); + + mixpanel.people.track_charge(50); + mixpanel.people.track_charge(30.50, {'$time': new Date('jan 1 2012')}); + + mixpanel.people.clear_charges(); + + mixpanel.people.delete_user(); +} diff --git a/mixpanel/mixpanel.d.ts b/mixpanel/mixpanel.d.ts new file mode 100644 index 0000000000..236899632f --- /dev/null +++ b/mixpanel/mixpanel.d.ts @@ -0,0 +1,69 @@ +// Type definitions for Mixpanel +// Project: https://mixpanel.com/ (https://github.com/mixpanel/mixpanel-js) +// Definitions by: Knut Eirik Leira Hjelle +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +declare class Mixpanel +{ + people:Mixpanel.People; + + init(token:string, config:{[index:string]:any}, libraryName:string):Mixpanel; + + push(item:any[]):void; + + disable(events?:string[]):void; + + track(eventName:string, params?:{[index:string]:any}, callback?:() => void):void; + + track_links(querySelector:string, eventName:string, params?:{[index:string]:any}):void; + + track_forms(querySelector:string, eventName:string, params?:{[index:string]:any}):void; + + register(params:{[index:string]:any}, days?:number):void; + + register_once(params:{[index:string]:any}, defaultValue?:string, days?:number):void; + + unregister(propertyName:string):void; + + identify(id:string):void; + + get_distinct_id():string; + + alias(alias:string, currentId?:string):void; + + set_config(config:{[index:string]:any}):void; + + get_config():{[index:string]:any}; + + get_property(propertyName:string):any; +} + +declare module Mixpanel +{ + class People + { + set(keys:{[index:string]:any}, callback?:() => void):void; + + set(key:string, value:any, callback?:() => void):void; + + set_once(keys:{[index:string]:any}, callback?:() => void):void; + + set_once(key:string, value:any, callback?:() => void):void; + + increment(key:string):void; + + increment(keys:{[index:string]:number}):void; + + increment(key:string, value:number):void; + + append(keys:{[index:string]:any}):void; + + append(key:string, value:any):void; + + track_charge(amount:number, params?:{[index:string]:any}, callback?:() => void):void; + + clear_charges():void; + + delete_user():void; + } +} \ No newline at end of file