From bdafe8620261e681a806b43ec7261ae547804ebc Mon Sep 17 00:00:00 2001 From: bglee Date: Sat, 8 Apr 2017 22:32:08 +0900 Subject: [PATCH 1/5] update v2.1.2 --- types/react-ga/index.d.ts | 83 ++++++++++++++----- .../{react-ga-tests.tsx => react-ga-tests.ts} | 39 +++++++++ types/react-ga/tsconfig.json | 4 +- 3 files changed, 105 insertions(+), 21 deletions(-) rename types/react-ga/{react-ga-tests.tsx => react-ga-tests.ts} (57%) 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 +} From d833d06ca03fbb4397e93afcd02fdeccd3169ef2 Mon Sep 17 00:00:00 2001 From: bglee Date: Sat, 8 Apr 2017 22:34:15 +0900 Subject: [PATCH 2/5] update v2.1.2 --- types/react-ga/index.d.ts | 122 ++++++++++++++++++-------------------- 1 file changed, 58 insertions(+), 64 deletions(-) diff --git a/types/react-ga/index.d.ts b/types/react-ga/index.d.ts index 3913840ad0..f0644c18d3 100644 --- a/types/react-ga/index.d.ts +++ b/types/react-ga/index.d.ts @@ -1,71 +1,65 @@ -// Type definitions for react-ga v2.1.2 +// 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 -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 EventArgs { + category: string; + action: string; + label?: string; + value?: number; + nonInteraction?: boolean; } -declare module 'react-ga' { - export = __reactGA; +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; From ba7f0539754b144083d949b9002efadbf9162cec Mon Sep 17 00:00:00 2001 From: bglee Date: Sat, 8 Apr 2017 22:35:55 +0900 Subject: [PATCH 3/5] update v2.1.2 --- types/react-ga/react-ga-tests.ts | 19 +++++++++---------- types/react-ga/tsconfig.json | 3 +-- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/types/react-ga/react-ga-tests.ts b/types/react-ga/react-ga-tests.ts index aa9f454e9d..4396cf9644 100644 --- a/types/react-ga/react-ga-tests.ts +++ 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"); }); }); @@ -62,17 +61,17 @@ describe("Testing react-ga set calls", () => { describe("Testing react-ga v2.1.2", () => { it("Able to make ga calls", () => { - const gaObject: Function = __reactGA.ga(); + const gaObject: Function = ga.ga(); }); it("Able to make send calls", () => { - let fieldObject: __reactGA.FieldsObject = { + let fieldObject: ga.FieldsObject = { page: '/users' }; - __reactGA.send(fieldObject); + ga.send(fieldObject); }); it("Able to make timing calls", () => { - __reactGA.timing({ + ga.timing({ category: 'string', variable: 'string', value: 1, @@ -80,14 +79,14 @@ describe("Testing react-ga v2.1.2", () => { }) }); it("Able to make exception calls", () => { - let fieldObject: __reactGA.FieldsObject = { + let fieldObject: ga.FieldsObject = { page: '/users' }; - __reactGA.exception(fieldObject); + ga.exception(fieldObject); }); it("Able to make plugin object calls", () => { - const execute = __reactGA.plugin.execute; - const require = __reactGA.plugin.require; + const execute = ga.plugin.execute; + const require = ga.plugin.require; const payload = {}; execute('name', 'action', payload); @@ -95,6 +94,6 @@ describe("Testing react-ga v2.1.2", () => { require('name', {}); }); it("Able to make outboundLink calls", () => { - __reactGA.outboundLink({label: 'string'}, () => {}); + ga.outboundLink({label: 'string'}, () => {}); }); }); diff --git a/types/react-ga/tsconfig.json b/types/react-ga/tsconfig.json index 69dc7f887b..0e8c21872c 100644 --- a/types/react-ga/tsconfig.json +++ b/types/react-ga/tsconfig.json @@ -13,8 +13,7 @@ ], "types": [], "noEmit": true, - "forceConsistentCasingInFileNames": true, - "jsx": "react" + "forceConsistentCasingInFileNames": true }, "files": [ "index.d.ts", From 428ec7e4f6928efc5b441cd52b06536c42d7f165 Mon Sep 17 00:00:00 2001 From: bglee Date: Sat, 8 Apr 2017 22:43:56 +0900 Subject: [PATCH 4/5] add userId to GaOptions --- types/react-ga/index.d.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/types/react-ga/index.d.ts b/types/react-ga/index.d.ts index f0644c18d3..d951cb2909 100644 --- a/types/react-ga/index.d.ts +++ b/types/react-ga/index.d.ts @@ -11,7 +11,7 @@ export interface EventArgs { nonInteraction?: boolean; } -interface GaOptions { +export interface GaOptions { name?: string; clientId?: string; sampleRate?: number; @@ -24,6 +24,7 @@ interface GaOptions { legacyCookieDomain?: string; legacyHistoryImport?: boolean; allowLinker?: boolean; + userId?: string; } export interface InitializeOptions { @@ -36,19 +37,19 @@ export interface FieldsObject { [i: string]: any; } -interface TimingArgs { +export interface TimingArgs { category: string; variable: string; value: number; label?: string; } -interface Plugin { +export interface Plugin { require(name: string, options: any): void; execute(pluginName: string, action: string, actionTypeOrPayload: string|Object, payload?: Object): void; } -interface OutboundLinkArgs { +export interface OutboundLinkArgs { label: string; } From fb1d30cbf8eed4f61ef7cca755107fddfef268be Mon Sep 17 00:00:00 2001 From: bglee Date: Sun, 9 Apr 2017 15:48:06 +0900 Subject: [PATCH 5/5] fix type error --- types/react-ga/index.d.ts | 6 +++--- types/react-ga/react-ga-tests.ts | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/types/react-ga/index.d.ts b/types/react-ga/index.d.ts index d951cb2909..66e8140299 100644 --- a/types/react-ga/index.d.ts +++ b/types/react-ga/index.d.ts @@ -46,7 +46,7 @@ export interface TimingArgs { export interface Plugin { require(name: string, options: any): void; - execute(pluginName: string, action: string, actionTypeOrPayload: string|Object, payload?: Object): void; + execute(pluginName: string, action: string, actionTypeOrPayload: string|any, payload?: any): void; } export interface OutboundLinkArgs { @@ -54,7 +54,7 @@ export interface OutboundLinkArgs { } export function initialize(trackingCode: string, options?: InitializeOptions): void; -export function ga(): Function; +export function ga(): any; export function set(fieldsObject: FieldsObject): void; export function send(fieldsObject: FieldsObject): void; export function pageview(path: string): void; @@ -63,4 +63,4 @@ 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 function outboundLink(args: OutboundLinkArgs, hitCallback: () => void): void; diff --git a/types/react-ga/react-ga-tests.ts b/types/react-ga/react-ga-tests.ts index 4396cf9644..57d2162e0e 100644 --- a/types/react-ga/react-ga-tests.ts +++ b/types/react-ga/react-ga-tests.ts @@ -61,7 +61,7 @@ describe("Testing react-ga set calls", () => { describe("Testing react-ga v2.1.2", () => { it("Able to make ga calls", () => { - const gaObject: Function = ga.ga(); + ga.ga(); }); it("Able to make send calls", () => { let fieldObject: ga.FieldsObject = { @@ -76,7 +76,7 @@ describe("Testing react-ga v2.1.2", () => { variable: 'string', value: 1, label: 'string' - }) + }); }); it("Able to make exception calls", () => { let fieldObject: ga.FieldsObject = {