mirror of
https://github.com/FlipsideCrypto/DefinitelyTyped.git
synced 2026-02-06 10:56:53 +00:00
feat(types): adds mixpanel-browser types
This commit is contained in:
parent
36a32d8a72
commit
4b3cd54ddf
105
types/mixpanel-browser/index.d.ts
vendored
Normal file
105
types/mixpanel-browser/index.d.ts
vendored
Normal file
@ -0,0 +1,105 @@
|
||||
// Type definitions for mixpanel-browser 2.23
|
||||
// Project: https://github.com/mixpanel/mixpanel-js
|
||||
// Definitions by: Carlos López <https://github.com/karlos1337>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.2
|
||||
|
||||
export type Persistence = 'cookie' | 'localStorage';
|
||||
|
||||
export type PushItem = Array<string | Dict>;
|
||||
|
||||
export interface Dict {[key: string]: any; }
|
||||
|
||||
export interface XhrHeadersDef {[header: string]: any; }
|
||||
|
||||
export interface HasOptedInOutOptions {
|
||||
persistence_type: Persistence;
|
||||
cookie_prefix: string;
|
||||
}
|
||||
|
||||
export interface ClearOptOutInOutOptions extends HasOptedInOutOptions {
|
||||
cookie_expiration: number;
|
||||
cross_subdomain_cookie: boolean;
|
||||
secure_cookie: boolean;
|
||||
}
|
||||
|
||||
export interface InTrackingOptions extends ClearOptOutInOutOptions {
|
||||
track: () => void;
|
||||
track_event_name: string;
|
||||
track_event_properties: Dict;
|
||||
}
|
||||
|
||||
export interface OutTrackingOptions extends ClearOptOutInOutOptions {
|
||||
delete_user: boolean;
|
||||
}
|
||||
|
||||
export interface Config {
|
||||
api_host: string;
|
||||
app_host: string;
|
||||
autrotrack: boolean;
|
||||
cdn: string;
|
||||
cross_subdomain_cookie: boolean;
|
||||
persistence: Persistence;
|
||||
persistence_name: string;
|
||||
cookie_name: string;
|
||||
loaded: (mixpanel: MixPanel) => void;
|
||||
store_google: boolean;
|
||||
save_referrer: boolean;
|
||||
test: boolean;
|
||||
verbose: boolean;
|
||||
img: boolean;
|
||||
track_pageview: boolean;
|
||||
debug: boolean;
|
||||
track_links_timeout: number;
|
||||
cookie_expiration: number;
|
||||
upgrade: boolean;
|
||||
disable_persistence: boolean;
|
||||
disable_cookie: boolean;
|
||||
secure_cookie: boolean;
|
||||
ip: boolean;
|
||||
property_blacklist: string[];
|
||||
xhr_headers: XhrHeadersDef;
|
||||
opt_out_tracking_by_default: boolean;
|
||||
opt_out_tracking_persistence_type: Persistence;
|
||||
opt_out_tracking_cookie_prefix: string;
|
||||
}
|
||||
|
||||
export interface People {
|
||||
set(prop: Dict | string, to?: any, callback?: () => void): void;
|
||||
set_once(prop: Dict | string, to?: any, callback?: () => void): void;
|
||||
unset(prop: string[] | string, callback?: () => void): void;
|
||||
increment(prop: Dict | string, by?: number, callback?: () => void): void;
|
||||
append(prop: Dict | string, value?: any, callback?: () => void): void;
|
||||
union(prop: Dict | string, value?: any, callback?: () => void): void;
|
||||
track_charge(amount: number, properties?: Dict, callback?: () => void): void;
|
||||
clear_charges(callback?: () => void): void;
|
||||
delete_user(): void;
|
||||
}
|
||||
|
||||
export interface MixPanel {
|
||||
alias(alias: string, original?: string): void;
|
||||
clear_opt_in_out_tracking(options?: Partial<ClearOptOutInOutOptions>): void;
|
||||
disable(events?: string[]): void;
|
||||
get_config(prop_name?: string): any;
|
||||
get_distinct_id(): any;
|
||||
get_property(property_name: string): any;
|
||||
has_opted_in_tracking(options?: Partial<HasOptedInOutOptions>): boolean;
|
||||
has_opted_out_tracking(options?: Partial<HasOptedInOutOptions>): boolean;
|
||||
identify(unique_id?: string): any;
|
||||
init(token: string, config?: Partial<Config>, name?: string): MixPanel;
|
||||
opt_in_tracking(options?: Partial<InTrackingOptions>): void;
|
||||
opt_out_tracking(options?: Partial<OutTrackingOptions>): void;
|
||||
push(item: PushItem): void;
|
||||
register(props: Dict, days?: number): void;
|
||||
register_once(props: Dict, default_value?: any, days?: number): void;
|
||||
reset(): void;
|
||||
set_config(config: Partial<Config>): void;
|
||||
time_event(event_name: string): void;
|
||||
track(event_name: string, properties?: Dict, callback?: () => void): void;
|
||||
track_forms(query: string, event_name: string, properties?: Dict | (() => void)): void;
|
||||
track_links(query: string, event_name: string, properties?: Dict | (() => void)): void;
|
||||
unregister(property: string): void;
|
||||
people: People;
|
||||
}
|
||||
|
||||
export const mixpanel: MixPanel;
|
||||
91
types/mixpanel-browser/mixpanel-browser-tests.ts
Normal file
91
types/mixpanel-browser/mixpanel-browser-tests.ts
Normal file
@ -0,0 +1,91 @@
|
||||
import { mixpanel } from 'mixpanel-browser';
|
||||
|
||||
const lib = mixpanel.init('new token', { secure_cookie: true }, 'library_name');
|
||||
lib.track('event name');
|
||||
mixpanel.push(['register', { a: 'b' }]);
|
||||
mixpanel.disable();
|
||||
mixpanel.track('Registered', {Gender: 'Male', Age: 21});
|
||||
mixpanel.track_links('#nav', 'Clicked Nav Link');
|
||||
mixpanel.track_forms('#register', 'Created Account');
|
||||
mixpanel.time_event('Registered');
|
||||
mixpanel.track('Registered', {Gender: 'Male', Age: 21});
|
||||
mixpanel.register({Gender: 'Female'});
|
||||
mixpanel.register({
|
||||
Email: 'jdoe@example.com',
|
||||
'Account Type': 'Free'
|
||||
});
|
||||
mixpanel.register_once({
|
||||
'First Login Date': new Date().toISOString()
|
||||
});
|
||||
mixpanel.init('YOUR PROJECT TOKEN', {
|
||||
loaded: (mixpanel) => {
|
||||
const distinct_id = mixpanel.get_distinct_id();
|
||||
}
|
||||
});
|
||||
mixpanel.alias('new_id', 'existing_id');
|
||||
mixpanel.alias('newer_id', 'new_id');
|
||||
mixpanel.init('YOUR PROJECT TOKEN', {
|
||||
loaded: (mixpanel) => {
|
||||
const user_id = mixpanel.get_property('user_id');
|
||||
}
|
||||
});
|
||||
mixpanel.opt_in_tracking();
|
||||
mixpanel.opt_in_tracking({
|
||||
track_event_name: 'User opted in',
|
||||
track_event_properties: {
|
||||
Email: 'jdoe@example.com'
|
||||
},
|
||||
cookie_expiration: 30,
|
||||
secure_cookie: true
|
||||
});
|
||||
mixpanel.opt_out_tracking();
|
||||
mixpanel.opt_out_tracking({
|
||||
cookie_expiration: 30,
|
||||
secure_cookie: true
|
||||
});
|
||||
const has_opted_in = mixpanel.has_opted_in_tracking();
|
||||
const has_opted_out = mixpanel.has_opted_out_tracking();
|
||||
mixpanel.clear_opt_in_out_tracking();
|
||||
mixpanel.clear_opt_in_out_tracking({
|
||||
cookie_expiration: 30,
|
||||
secure_cookie: true
|
||||
});
|
||||
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.unset('gender');
|
||||
mixpanel.people.unset(['gender', 'Company']);
|
||||
mixpanel.people.increment('page_views', 1);
|
||||
mixpanel.people.increment('page_views');
|
||||
mixpanel.people.increment('credits_left', -1);
|
||||
mixpanel.people.increment({
|
||||
counter1: 1,
|
||||
counter2: 6
|
||||
});
|
||||
mixpanel.people.append('pages_visited', 'homepage');
|
||||
mixpanel.people.append({
|
||||
list1: 'bob',
|
||||
list2: 123
|
||||
});
|
||||
mixpanel.people.union('pages_visited', 'homepage');
|
||||
mixpanel.people.union({
|
||||
list1: 'bob',
|
||||
list2: 123
|
||||
});
|
||||
mixpanel.people.union({
|
||||
list1: ['bob', 'billy']
|
||||
});
|
||||
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();
|
||||
23
types/mixpanel-browser/tsconfig.json
Normal file
23
types/mixpanel-browser/tsconfig.json
Normal file
@ -0,0 +1,23 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"mixpanel-browser-tests.ts"
|
||||
]
|
||||
}
|
||||
1
types/mixpanel-browser/tslint.json
Normal file
1
types/mixpanel-browser/tslint.json
Normal file
@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Loading…
Reference in New Issue
Block a user