diff --git a/types/react-ga/index.d.ts b/types/react-ga/index.d.ts index 1d64b23971..66e8140299 100644 --- a/types/react-ga/index.d.ts +++ b/types/react-ga/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for react-ga 1.4 +// Type definitions for react-ga 2.1.2 // Project: https://github.com/react-ga/react-ga // Definitions by: Tim Aldridge // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped @@ -11,16 +11,56 @@ export interface EventArgs { nonInteraction?: boolean; } +export 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; + userId?: string; +} + export interface InitializeOptions { debug?: boolean; + titleCase?: boolean; + gaOptions?: GaOptions; } export interface FieldsObject { [i: string]: any; } +export interface TimingArgs { + category: string; + variable: string; + value: number; + label?: string; +} + +export interface Plugin { + require(name: string, options: any): void; + execute(pluginName: string, action: string, actionTypeOrPayload: string|any, payload?: any): void; +} + +export interface OutboundLinkArgs { + label: string; +} + export function initialize(trackingCode: string, options?: InitializeOptions): void; +export function ga(): any; +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 set(fieldsObject: FieldsObject): void; +export function exception(fieldsObject: FieldsObject): void; +export const plugin: Plugin; +export function outboundLink(args: OutboundLinkArgs, hitCallback: () => void): void; diff --git a/types/react-ga/react-ga-tests.tsx b/types/react-ga/react-ga-tests.ts similarity index 59% rename from types/react-ga/react-ga-tests.tsx rename to types/react-ga/react-ga-tests.ts index 0db1be21c2..57d2162e0e 100644 --- a/types/react-ga/react-ga-tests.tsx +++ b/types/react-ga/react-ga-tests.ts @@ -19,7 +19,6 @@ describe("Testing react-ga initialize object", () => { describe("Testing react-ga pageview calls", () => { it("Able to make pageview calls", () => { ga.initialize("UA-65432-1"); - ga.pageview("http://telshin.com"); }); }); @@ -59,3 +58,42 @@ describe("Testing react-ga set calls", () => { ga.set(fieldObject); }); }); + +describe("Testing react-ga v2.1.2", () => { + it("Able to make ga calls", () => { + ga.ga(); + }); + it("Able to make send calls", () => { + let fieldObject: ga.FieldsObject = { + page: '/users' + }; + + ga.send(fieldObject); + }); + it("Able to make timing calls", () => { + ga.timing({ + category: 'string', + variable: 'string', + value: 1, + label: 'string' + }); + }); + it("Able to make exception calls", () => { + let fieldObject: ga.FieldsObject = { + page: '/users' + }; + ga.exception(fieldObject); + }); + it("Able to make plugin object calls", () => { + const execute = ga.plugin.execute; + const require = ga.plugin.require; + const payload = {}; + + execute('name', 'action', payload); + execute('name', 'action', 'type', payload); + require('name', {}); + }); + it("Able to make outboundLink calls", () => { + ga.outboundLink({label: 'string'}, () => {}); + }); +}); diff --git a/types/react-ga/tsconfig.json b/types/react-ga/tsconfig.json index 6d786d97ed..0e8c21872c 100644 --- a/types/react-ga/tsconfig.json +++ b/types/react-ga/tsconfig.json @@ -13,11 +13,10 @@ ], "types": [], "noEmit": true, - "forceConsistentCasingInFileNames": true, - "jsx": "react" + "forceConsistentCasingInFileNames": true }, "files": [ "index.d.ts", - "react-ga-tests.tsx" + "react-ga-tests.ts" ] -} \ No newline at end of file +}