diff --git a/types/react-ga/index.d.ts b/types/react-ga/index.d.ts index 1d64b23971..3913840ad0 100644 --- a/types/react-ga/index.d.ts +++ b/types/react-ga/index.d.ts @@ -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 // 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; diff --git a/types/react-ga/react-ga-tests.tsx b/types/react-ga/react-ga-tests.ts similarity index 57% rename from types/react-ga/react-ga-tests.tsx rename to types/react-ga/react-ga-tests.ts index 0db1be21c2..aa9f454e9d 100644 --- a/types/react-ga/react-ga-tests.tsx +++ b/types/react-ga/react-ga-tests.ts @@ -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'}, () => {}); + }); +}); diff --git a/types/react-ga/tsconfig.json b/types/react-ga/tsconfig.json index 6d786d97ed..69dc7f887b 100644 --- a/types/react-ga/tsconfig.json +++ b/types/react-ga/tsconfig.json @@ -18,6 +18,6 @@ }, "files": [ "index.d.ts", - "react-ga-tests.tsx" + "react-ga-tests.ts" ] -} \ No newline at end of file +}