mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-06-06 06:19:58 +08:00
update v2.1.2
This commit is contained in:
83
types/react-ga/index.d.ts
vendored
83
types/react-ga/index.d.ts
vendored
@@ -1,26 +1,71 @@
|
||||
// Type definitions for react-ga 1.4
|
||||
// Type definitions for react-ga v2.1.2
|
||||
// Project: https://github.com/react-ga/react-ga
|
||||
// Definitions by: Tim Aldridge <https://github.com/telshin>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
export interface EventArgs {
|
||||
category: string;
|
||||
action: string;
|
||||
label?: string;
|
||||
value?: number;
|
||||
nonInteraction?: boolean;
|
||||
declare namespace __reactGA {
|
||||
export interface EventArgs {
|
||||
category: string;
|
||||
action: string;
|
||||
label?: string;
|
||||
value?: number;
|
||||
nonInteraction?: boolean;
|
||||
}
|
||||
|
||||
interface GaOptions {
|
||||
name?: string;
|
||||
clientId?: string;
|
||||
sampleRate?: number;
|
||||
siteSpeedSampleRate?: number;
|
||||
alwaysSendReferrer?: boolean;
|
||||
allowAnchor?: boolean;
|
||||
cookieName?: string;
|
||||
cookieDomain?: string;
|
||||
cookieExpires?: number;
|
||||
legacyCookieDomain?: string;
|
||||
legacyHistoryImport?: boolean;
|
||||
allowLinker?: boolean;
|
||||
}
|
||||
|
||||
export interface InitializeOptions {
|
||||
debug?: boolean;
|
||||
titleCase?: boolean;
|
||||
gaOptions?: GaOptions;
|
||||
}
|
||||
|
||||
export interface FieldsObject {
|
||||
[i: string]: any;
|
||||
}
|
||||
|
||||
interface TimingArgs {
|
||||
category: string;
|
||||
variable: string;
|
||||
value: number;
|
||||
label?: string;
|
||||
}
|
||||
|
||||
interface Plugin {
|
||||
require(name: string, options: any): void;
|
||||
execute(pluginName: string, action: string, actionTypeOrPayload: string|Object, payload?: Object): void;
|
||||
}
|
||||
|
||||
interface OutboundLinkArgs {
|
||||
label: string;
|
||||
}
|
||||
|
||||
export function initialize(trackingCode: string, options?: InitializeOptions): void;
|
||||
export function ga(): Function;
|
||||
export function set(fieldsObject: FieldsObject): void;
|
||||
export function send(fieldsObject: FieldsObject): void;
|
||||
export function pageview(path: string): void;
|
||||
export function modalview(name: string): void;
|
||||
export function timing(args: TimingArgs): void;
|
||||
export function event(args: EventArgs): void;
|
||||
export function exception(fieldsObject: FieldsObject): void;
|
||||
export const plugin: Plugin;
|
||||
export function outboundLink(args: OutboundLinkArgs, hitCallback: Function): void;
|
||||
}
|
||||
|
||||
export interface InitializeOptions {
|
||||
debug?: boolean;
|
||||
declare module 'react-ga' {
|
||||
export = __reactGA;
|
||||
}
|
||||
|
||||
export interface FieldsObject {
|
||||
[i: string]: any;
|
||||
}
|
||||
|
||||
export function initialize(trackingCode: string, options?: InitializeOptions): void;
|
||||
export function pageview(path: string): void;
|
||||
export function modalview(name: string): void;
|
||||
export function event(args: EventArgs): void;
|
||||
export function set(fieldsObject: FieldsObject): void;
|
||||
|
||||
@@ -59,3 +59,42 @@ describe("Testing react-ga set calls", () => {
|
||||
ga.set(fieldObject);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Testing react-ga v2.1.2", () => {
|
||||
it("Able to make ga calls", () => {
|
||||
const gaObject: Function = __reactGA.ga();
|
||||
});
|
||||
it("Able to make send calls", () => {
|
||||
let fieldObject: __reactGA.FieldsObject = {
|
||||
page: '/users'
|
||||
};
|
||||
|
||||
__reactGA.send(fieldObject);
|
||||
});
|
||||
it("Able to make timing calls", () => {
|
||||
__reactGA.timing({
|
||||
category: 'string',
|
||||
variable: 'string',
|
||||
value: 1,
|
||||
label: 'string'
|
||||
})
|
||||
});
|
||||
it("Able to make exception calls", () => {
|
||||
let fieldObject: __reactGA.FieldsObject = {
|
||||
page: '/users'
|
||||
};
|
||||
__reactGA.exception(fieldObject);
|
||||
});
|
||||
it("Able to make plugin object calls", () => {
|
||||
const execute = __reactGA.plugin.execute;
|
||||
const require = __reactGA.plugin.require;
|
||||
const payload = {};
|
||||
|
||||
execute('name', 'action', payload);
|
||||
execute('name', 'action', 'type', payload);
|
||||
require('name', {});
|
||||
});
|
||||
it("Able to make outboundLink calls", () => {
|
||||
__reactGA.outboundLink({label: 'string'}, () => {});
|
||||
});
|
||||
});
|
||||
@@ -18,6 +18,6 @@
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"react-ga-tests.tsx"
|
||||
"react-ga-tests.ts"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user