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 1/3] 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 000000000..fd52bd989 --- /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 000000000..236899632 --- /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 From ddf90b4d8138fdd42bd8c4f6f12a80ec296baacc Mon Sep 17 00:00:00 2001 From: Knut Eirik Leira Hjelle Date: Thu, 12 Jun 2014 10:24:36 +0200 Subject: [PATCH 2/3] Changed definition to interfaces, added global var mixpanel. --- mixpanel/mixpanel-tests.ts | 2 -- mixpanel/mixpanel.d.ts | 8 +++++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/mixpanel/mixpanel-tests.ts b/mixpanel/mixpanel-tests.ts index fd52bd989..a9cf296c3 100644 --- a/mixpanel/mixpanel-tests.ts +++ b/mixpanel/mixpanel-tests.ts @@ -1,6 +1,4 @@ /// -var mixpanel = new Mixpanel(); - function mixpanel_base() { mixpanel.init("new token", { your: "config" }, "library_name"); diff --git a/mixpanel/mixpanel.d.ts b/mixpanel/mixpanel.d.ts index 236899632..9d1ef9527 100644 --- a/mixpanel/mixpanel.d.ts +++ b/mixpanel/mixpanel.d.ts @@ -3,7 +3,7 @@ // Definitions by: Knut Eirik Leira Hjelle // Definitions: https://github.com/borisyankov/DefinitelyTyped -declare class Mixpanel +interface Mixpanel { people:Mixpanel.People; @@ -40,7 +40,7 @@ declare class Mixpanel declare module Mixpanel { - class People + interface People { set(keys:{[index:string]:any}, callback?:() => void):void; @@ -66,4 +66,6 @@ declare module Mixpanel delete_user():void; } -} \ No newline at end of file +} + +declare var mixpanel:Mixpanel; \ No newline at end of file From 32c78eedd876b6456d8082cfbc2f960e0cde6b1b Mon Sep 17 00:00:00 2001 From: Knut Eirik Leira Hjelle Date: Thu, 12 Jun 2014 10:28:18 +0200 Subject: [PATCH 3/3] Added contribution entry. --- CONTRIBUTORS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 801a1d07a..9bc1f3698 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -218,6 +218,7 @@ All definitions files include a header with the author and editors, so at some p * [Microsoft Live Connect](http://msdn.microsoft.com/en-us/library/live/hh243643.aspx) (by [John Vilk](https://github.com/jvilk)) * [Minimatch](https://github.com/isaacs/minimatch) (by [vvakame](https://github.com/vvakame)) * [minimist](https://github.com/substack/minimist) (by [Bart van der Schoor](https://github.com/Bartvds)) +* [Mixpanel](https://github.com/mixpanel/mixpanel-js) (by [Knut Eirik Leira Hjelle](https://github.com/hjellek)) * [mixto](https://github.com/atom/mixto) (by [vvakame](https://github.com/vvakame)) * [Modernizr](http://modernizr.com/) (by [Boris Yankov](https://github.com/borisyankov) and [Theodore Brown](https://github.com/theodorejb/)) * [Moment.js](https://github.com/timrwood/moment) (by [Michael Lakerveld](https://github.com/Lakerfield))