From c59c139444477fda75df8541cd8c7bcb5c93ec5b Mon Sep 17 00:00:00 2001 From: Arvydas Sidorenko Date: Sun, 22 May 2016 13:16:47 +0200 Subject: [PATCH 01/10] Implemented Amplitude SDK type definition. --- amplitude/amplitude-tests.ts | 85 ++++++++++++++++++++++++++++++++++++ amplitude/amplitude.d.ts | 58 ++++++++++++++++++++++++ 2 files changed, 143 insertions(+) create mode 100644 amplitude/amplitude-tests.ts create mode 100644 amplitude/amplitude.d.ts diff --git a/amplitude/amplitude-tests.ts b/amplitude/amplitude-tests.ts new file mode 100644 index 0000000000..c4ffb9e811 --- /dev/null +++ b/amplitude/amplitude-tests.ts @@ -0,0 +1,85 @@ +/// + +module Amplitude.Tests { + function all() { + amplitude.init('YOUR_API_KEY_HERE', null, { + // optional configuration options + saveEvents: true, + includeUtm: true, + includeReferrer: true, + batchEvents: true, + eventUploadThreshold: 50 + }); + amplitude.init('YOUR_API_KEY_HERE', 'USER_ID_HERE', null, () => {}); + + amplitude.logEvent('EVENT_IDENTIFIER_HERE'); + amplitude.setUserId('USER_ID_HERE'); + amplitude.init('YOUR_API_KEY_HERE', 'USER_ID_HERE'); + amplitude.setUserId(null); // not string 'null' + amplitude.setVersionName('VERSION_NAME_HERE'); + + amplitude.regenerateDeviceId(); + amplitude.setDeviceId('CUSTOM_DEVICE_ID'); + + amplitude.logEvent('EVENT_IDENTIFIER_HERE', { + 'color': 'blue', + 'age': 20, + 'key': 'value' + }); + amplitude.logEvent("EVENT_IDENTIFIER_HERE", null, (httpCode, response) => { }); + + let identify = new amplitude.Identify().set('gender', 'female').set('age', 20); + amplitude.identify(identify); + + identify = new amplitude.Identify().setOnce('sign_up_date', '08/24/2015'); + amplitude.identify(identify); + + identify = new amplitude.Identify().setOnce('sign_up_date', '09/14/2015'); + amplitude.identify(identify); + + identify = new amplitude.Identify().unset('gender').unset('age'); + amplitude.identify(identify); + + identify = new amplitude.Identify().add('karma', 1).add('friends', 1); + amplitude.identify(identify); + + identify = new amplitude.Identify().append('ab-tests', 'new-user-test').append('some_list', [1, 2, 3, 4, 'values']); + amplitude.identify(identify); + + identify = new amplitude.Identify().prepend('ab-tests', 'new-user-test').prepend('some_list', [1, 2, 3, 4, 'values']); + amplitude.identify(identify); + + identify = new amplitude.Identify() + .set('karma', 10) + .add('karma', 1) + .unset('karma'); + amplitude.identify(identify); + + identify = new amplitude.Identify() + .set('colors', ['rose', 'gold']) + .append('ab-tests', 'campaign_a') + .append('existing_list', [4, 5]); + amplitude.identify(identify); + + amplitude.setUserProperties({ + gender: 'female', + age: 20 + }); + + amplitude.clearUserProperties(); + + amplitude.setOptOut(true); + amplitude.setOptOut(false); + + amplitude.setGroup('orgId', '15'); + amplitude.setGroup('sport', ['soccer', 'tennis']); + + // Still to implement: + /* + var revenue = new amplitude.Revenue().setProductId('com.company.productId').setPrice(3.99).setQuantity(3); + amplitude.logRevenueV2(revenue); + + amplitude.logEventWithGroups('initialize_game', { 'key': 'value' }, { 'sport': 'soccer' }); + */ + } +} diff --git a/amplitude/amplitude.d.ts b/amplitude/amplitude.d.ts new file mode 100644 index 0000000000..339153634d --- /dev/null +++ b/amplitude/amplitude.d.ts @@ -0,0 +1,58 @@ +declare module amplitude { + interface Config { + batchEvents?: boolean; + cookieExpiration?: number; + cookieName?: string; + deviceId?: string; + domain?: string; + eventUploadPeriodMillis?: number; + eventUploadThreshold?: number; + includeReferrer?: boolean; + includeUtm?: boolean; + language?: string; + optOut?: boolean; + platform?: string; + saveEvents?: boolean; + savedMaxCount?: number; + sessionTimeout?: number; + uploadBatchSize?: number; + } + + export class Identify { + set(key: string, value: any): Identify; + setOnce(key: string, value: any): Identify; + add(key: string, value: number): Identify; + append(key: string, value: any): Identify; + prepend(key: string, value: any): Identify; + + unset(key: string): Identify; + } + + export function init(apiKey: string): void; + export function init(apiKey: string, userId: string): void; + export function init(apiKey: string, userId: string, options: Config): void; + export function init(apiKey: string, userId: string, options: Config, callback: () => void): void; + + export function setVersionName(version: string): void; + export function setUserId(userId: string): void; + + export function setDeviceId(id: string): void; + export function regenerateDeviceId(): void; + + export function identify(identify: Identify): void; + + export function setUserProperties(properties: Object): void; + export function clearUserProperties(): void; + + export function setOptOut(optOut: boolean): void; + + export function setGroup(groupType: string, groupName: string | string[]); + + export function logEvent(event: string): void; + export function logEvent(event: string, data: Object): void; + export function logEvent(event: string, data: Object, callback: (httpCode: number, response: any) => void): void; + + export var options: Config; +} + +//declare var amplitude: AmplitudeStatic; From 9a055b462ad6465f999facbd3b7013e564bebfc2 Mon Sep 17 00:00:00 2001 From: Arvydas Sidorenko Date: Sun, 22 May 2016 13:37:31 +0200 Subject: [PATCH 02/10] Added required header comments to amplitude definition files. --- amplitude/amplitude-tests.ts | 2 ++ amplitude/amplitude.d.ts | 2 ++ 2 files changed, 4 insertions(+) diff --git a/amplitude/amplitude-tests.ts b/amplitude/amplitude-tests.ts index c4ffb9e811..d60cf4bc7b 100644 --- a/amplitude/amplitude-tests.ts +++ b/amplitude/amplitude-tests.ts @@ -1,3 +1,5 @@ +// Tests for Amplitude SDK TypeScript definitions + /// module Amplitude.Tests { diff --git a/amplitude/amplitude.d.ts b/amplitude/amplitude.d.ts index 339153634d..3955ae128a 100644 --- a/amplitude/amplitude.d.ts +++ b/amplitude/amplitude.d.ts @@ -1,3 +1,5 @@ +// Type definitions for Amplitude SDK 2.12.1 + declare module amplitude { interface Config { batchEvents?: boolean; From ed54ec0de6b1ef627fcfd9382ae1e91c9aa97180 Mon Sep 17 00:00:00 2001 From: Arvydas Sidorenko Date: Sun, 22 May 2016 13:38:02 +0200 Subject: [PATCH 03/10] amplitude.setGroup() return value is now void instead instead of implicit any. --- amplitude/amplitude.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/amplitude/amplitude.d.ts b/amplitude/amplitude.d.ts index 3955ae128a..d3ad99c890 100644 --- a/amplitude/amplitude.d.ts +++ b/amplitude/amplitude.d.ts @@ -48,7 +48,7 @@ declare module amplitude { export function setOptOut(optOut: boolean): void; - export function setGroup(groupType: string, groupName: string | string[]); + export function setGroup(groupType: string, groupName: string | string[]): void; export function logEvent(event: string): void; export function logEvent(event: string, data: Object): void; From 6b5953e8d06043c69d3be715cef78ba278827503 Mon Sep 17 00:00:00 2001 From: Arvydas Sidorenko Date: Sun, 22 May 2016 13:40:29 +0200 Subject: [PATCH 04/10] Added required 'Project' comment to amplitude definition file header. --- amplitude/amplitude.d.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/amplitude/amplitude.d.ts b/amplitude/amplitude.d.ts index d3ad99c890..b8b208bcdd 100644 --- a/amplitude/amplitude.d.ts +++ b/amplitude/amplitude.d.ts @@ -1,4 +1,5 @@ // Type definitions for Amplitude SDK 2.12.1 +// Project: https://github.com/amplitude/Amplitude-Javascript declare module amplitude { interface Config { From 233b6e31fe562202a1c08a3eb23635350ab672fe Mon Sep 17 00:00:00 2001 From: Arvydas Sidorenko Date: Sun, 22 May 2016 13:43:33 +0200 Subject: [PATCH 05/10] Added required 'Definitions by' comment to amplitude definition file header. --- amplitude/amplitude.d.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/amplitude/amplitude.d.ts b/amplitude/amplitude.d.ts index b8b208bcdd..0e2c392e64 100644 --- a/amplitude/amplitude.d.ts +++ b/amplitude/amplitude.d.ts @@ -1,5 +1,6 @@ // Type definitions for Amplitude SDK 2.12.1 // Project: https://github.com/amplitude/Amplitude-Javascript +// Definitions by: Arvydas Sidorenko declare module amplitude { interface Config { From 759ae4713b69d6b96825c839472c0bf6c79662aa Mon Sep 17 00:00:00 2001 From: Arvydas Sidorenko Date: Sun, 22 May 2016 13:48:53 +0200 Subject: [PATCH 06/10] Added required 'Definitions' comment to amplitude definition file header. --- amplitude/amplitude.d.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/amplitude/amplitude.d.ts b/amplitude/amplitude.d.ts index 0e2c392e64..9a5df3d179 100644 --- a/amplitude/amplitude.d.ts +++ b/amplitude/amplitude.d.ts @@ -1,6 +1,7 @@ // Type definitions for Amplitude SDK 2.12.1 // Project: https://github.com/amplitude/Amplitude-Javascript // Definitions by: Arvydas Sidorenko +// Definitions: https://github.com/Asido/DefinitelyTyped declare module amplitude { interface Config { From beb9814807ffec927b1ef4eb74c735296ab33a63 Mon Sep 17 00:00:00 2001 From: Arvydas Sidorenko Date: Mon, 30 May 2016 10:11:37 +0200 Subject: [PATCH 07/10] Renamed amplitude to amplitude-js. --- .../amplitude-tests.ts => amplitude-js/amplitude-js-tests.ts | 4 ++-- amplitude/amplitude.d.ts => amplitude-js/amplitude-js.d.ts | 0 2 files changed, 2 insertions(+), 2 deletions(-) rename amplitude/amplitude-tests.ts => amplitude-js/amplitude-js-tests.ts (97%) rename amplitude/amplitude.d.ts => amplitude-js/amplitude-js.d.ts (100%) diff --git a/amplitude/amplitude-tests.ts b/amplitude-js/amplitude-js-tests.ts similarity index 97% rename from amplitude/amplitude-tests.ts rename to amplitude-js/amplitude-js-tests.ts index d60cf4bc7b..66285f10dd 100644 --- a/amplitude/amplitude-tests.ts +++ b/amplitude-js/amplitude-js-tests.ts @@ -1,6 +1,6 @@ // Tests for Amplitude SDK TypeScript definitions -/// +/// module Amplitude.Tests { function all() { @@ -76,7 +76,7 @@ module Amplitude.Tests { amplitude.setGroup('orgId', '15'); amplitude.setGroup('sport', ['soccer', 'tennis']); - // Still to implement: + // TODO: Implement those. /* var revenue = new amplitude.Revenue().setProductId('com.company.productId').setPrice(3.99).setQuantity(3); amplitude.logRevenueV2(revenue); diff --git a/amplitude/amplitude.d.ts b/amplitude-js/amplitude-js.d.ts similarity index 100% rename from amplitude/amplitude.d.ts rename to amplitude-js/amplitude-js.d.ts From 0b4348c5ed9aa385ec15aa139cea0c10ee3238db Mon Sep 17 00:00:00 2001 From: Arvydas Sidorenko Date: Tue, 16 Aug 2016 10:24:42 +0200 Subject: [PATCH 08/10] Moved amplitude-js definition to v2, because v3 is now available. --- amplitude-js/{ => v2}/amplitude-js-tests.ts | 0 amplitude-js/{ => v2}/amplitude-js.d.ts | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename amplitude-js/{ => v2}/amplitude-js-tests.ts (100%) rename amplitude-js/{ => v2}/amplitude-js.d.ts (100%) diff --git a/amplitude-js/amplitude-js-tests.ts b/amplitude-js/v2/amplitude-js-tests.ts similarity index 100% rename from amplitude-js/amplitude-js-tests.ts rename to amplitude-js/v2/amplitude-js-tests.ts diff --git a/amplitude-js/amplitude-js.d.ts b/amplitude-js/v2/amplitude-js.d.ts similarity index 100% rename from amplitude-js/amplitude-js.d.ts rename to amplitude-js/v2/amplitude-js.d.ts From 5c2eaa32e7f69b6f8193c6d1cb6ece6ff841c38d Mon Sep 17 00:00:00 2001 From: Arvydas Sidorenko Date: Tue, 16 Aug 2016 10:25:16 +0200 Subject: [PATCH 09/10] Removed redundant comment. --- amplitude-js/v2/amplitude-js.d.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/amplitude-js/v2/amplitude-js.d.ts b/amplitude-js/v2/amplitude-js.d.ts index 9a5df3d179..7cc031b34a 100644 --- a/amplitude-js/v2/amplitude-js.d.ts +++ b/amplitude-js/v2/amplitude-js.d.ts @@ -59,5 +59,3 @@ declare module amplitude { export var options: Config; } - -//declare var amplitude: AmplitudeStatic; From 62111c7509078492e169ec8a0ece6c30e88ab43b Mon Sep 17 00:00:00 2001 From: Arvydas Sidorenko Date: Tue, 16 Aug 2016 10:28:15 +0200 Subject: [PATCH 10/10] Converted tabs to 4-spaces. --- amplitude-js/v2/amplitude-js-tests.ts | 126 +++++++++++++------------- amplitude-js/v2/amplitude-js.d.ts | 86 +++++++++--------- 2 files changed, 106 insertions(+), 106 deletions(-) diff --git a/amplitude-js/v2/amplitude-js-tests.ts b/amplitude-js/v2/amplitude-js-tests.ts index 66285f10dd..3e69d7c867 100644 --- a/amplitude-js/v2/amplitude-js-tests.ts +++ b/amplitude-js/v2/amplitude-js-tests.ts @@ -3,85 +3,85 @@ /// module Amplitude.Tests { - function all() { - amplitude.init('YOUR_API_KEY_HERE', null, { - // optional configuration options - saveEvents: true, - includeUtm: true, - includeReferrer: true, - batchEvents: true, - eventUploadThreshold: 50 - }); - amplitude.init('YOUR_API_KEY_HERE', 'USER_ID_HERE', null, () => {}); + function all() { + amplitude.init('YOUR_API_KEY_HERE', null, { + // optional configuration options + saveEvents: true, + includeUtm: true, + includeReferrer: true, + batchEvents: true, + eventUploadThreshold: 50 + }); + amplitude.init('YOUR_API_KEY_HERE', 'USER_ID_HERE', null, () => {}); - amplitude.logEvent('EVENT_IDENTIFIER_HERE'); - amplitude.setUserId('USER_ID_HERE'); - amplitude.init('YOUR_API_KEY_HERE', 'USER_ID_HERE'); - amplitude.setUserId(null); // not string 'null' - amplitude.setVersionName('VERSION_NAME_HERE'); + amplitude.logEvent('EVENT_IDENTIFIER_HERE'); + amplitude.setUserId('USER_ID_HERE'); + amplitude.init('YOUR_API_KEY_HERE', 'USER_ID_HERE'); + amplitude.setUserId(null); // not string 'null' + amplitude.setVersionName('VERSION_NAME_HERE'); - amplitude.regenerateDeviceId(); - amplitude.setDeviceId('CUSTOM_DEVICE_ID'); + amplitude.regenerateDeviceId(); + amplitude.setDeviceId('CUSTOM_DEVICE_ID'); - amplitude.logEvent('EVENT_IDENTIFIER_HERE', { - 'color': 'blue', - 'age': 20, - 'key': 'value' - }); - amplitude.logEvent("EVENT_IDENTIFIER_HERE", null, (httpCode, response) => { }); + amplitude.logEvent('EVENT_IDENTIFIER_HERE', { + 'color': 'blue', + 'age': 20, + 'key': 'value' + }); + amplitude.logEvent("EVENT_IDENTIFIER_HERE", null, (httpCode, response) => { }); - let identify = new amplitude.Identify().set('gender', 'female').set('age', 20); - amplitude.identify(identify); + let identify = new amplitude.Identify().set('gender', 'female').set('age', 20); + amplitude.identify(identify); - identify = new amplitude.Identify().setOnce('sign_up_date', '08/24/2015'); - amplitude.identify(identify); + identify = new amplitude.Identify().setOnce('sign_up_date', '08/24/2015'); + amplitude.identify(identify); - identify = new amplitude.Identify().setOnce('sign_up_date', '09/14/2015'); - amplitude.identify(identify); + identify = new amplitude.Identify().setOnce('sign_up_date', '09/14/2015'); + amplitude.identify(identify); - identify = new amplitude.Identify().unset('gender').unset('age'); - amplitude.identify(identify); + identify = new amplitude.Identify().unset('gender').unset('age'); + amplitude.identify(identify); - identify = new amplitude.Identify().add('karma', 1).add('friends', 1); - amplitude.identify(identify); + identify = new amplitude.Identify().add('karma', 1).add('friends', 1); + amplitude.identify(identify); - identify = new amplitude.Identify().append('ab-tests', 'new-user-test').append('some_list', [1, 2, 3, 4, 'values']); - amplitude.identify(identify); + identify = new amplitude.Identify().append('ab-tests', 'new-user-test').append('some_list', [1, 2, 3, 4, 'values']); + amplitude.identify(identify); - identify = new amplitude.Identify().prepend('ab-tests', 'new-user-test').prepend('some_list', [1, 2, 3, 4, 'values']); - amplitude.identify(identify); + identify = new amplitude.Identify().prepend('ab-tests', 'new-user-test').prepend('some_list', [1, 2, 3, 4, 'values']); + amplitude.identify(identify); - identify = new amplitude.Identify() - .set('karma', 10) - .add('karma', 1) - .unset('karma'); - amplitude.identify(identify); + identify = new amplitude.Identify() + .set('karma', 10) + .add('karma', 1) + .unset('karma'); + amplitude.identify(identify); - identify = new amplitude.Identify() - .set('colors', ['rose', 'gold']) - .append('ab-tests', 'campaign_a') - .append('existing_list', [4, 5]); - amplitude.identify(identify); + identify = new amplitude.Identify() + .set('colors', ['rose', 'gold']) + .append('ab-tests', 'campaign_a') + .append('existing_list', [4, 5]); + amplitude.identify(identify); - amplitude.setUserProperties({ - gender: 'female', - age: 20 - }); + amplitude.setUserProperties({ + gender: 'female', + age: 20 + }); - amplitude.clearUserProperties(); + amplitude.clearUserProperties(); - amplitude.setOptOut(true); - amplitude.setOptOut(false); + amplitude.setOptOut(true); + amplitude.setOptOut(false); - amplitude.setGroup('orgId', '15'); - amplitude.setGroup('sport', ['soccer', 'tennis']); + amplitude.setGroup('orgId', '15'); + amplitude.setGroup('sport', ['soccer', 'tennis']); - // TODO: Implement those. - /* - var revenue = new amplitude.Revenue().setProductId('com.company.productId').setPrice(3.99).setQuantity(3); - amplitude.logRevenueV2(revenue); + // TODO: Implement those. + /* + var revenue = new amplitude.Revenue().setProductId('com.company.productId').setPrice(3.99).setQuantity(3); + amplitude.logRevenueV2(revenue); - amplitude.logEventWithGroups('initialize_game', { 'key': 'value' }, { 'sport': 'soccer' }); - */ - } + amplitude.logEventWithGroups('initialize_game', { 'key': 'value' }, { 'sport': 'soccer' }); + */ + } } diff --git a/amplitude-js/v2/amplitude-js.d.ts b/amplitude-js/v2/amplitude-js.d.ts index 7cc031b34a..613f5ad5d8 100644 --- a/amplitude-js/v2/amplitude-js.d.ts +++ b/amplitude-js/v2/amplitude-js.d.ts @@ -4,58 +4,58 @@ // Definitions: https://github.com/Asido/DefinitelyTyped declare module amplitude { - interface Config { - batchEvents?: boolean; - cookieExpiration?: number; - cookieName?: string; - deviceId?: string; - domain?: string; - eventUploadPeriodMillis?: number; - eventUploadThreshold?: number; - includeReferrer?: boolean; - includeUtm?: boolean; - language?: string; - optOut?: boolean; - platform?: string; - saveEvents?: boolean; - savedMaxCount?: number; - sessionTimeout?: number; - uploadBatchSize?: number; - } + interface Config { + batchEvents?: boolean; + cookieExpiration?: number; + cookieName?: string; + deviceId?: string; + domain?: string; + eventUploadPeriodMillis?: number; + eventUploadThreshold?: number; + includeReferrer?: boolean; + includeUtm?: boolean; + language?: string; + optOut?: boolean; + platform?: string; + saveEvents?: boolean; + savedMaxCount?: number; + sessionTimeout?: number; + uploadBatchSize?: number; + } - export class Identify { - set(key: string, value: any): Identify; - setOnce(key: string, value: any): Identify; - add(key: string, value: number): Identify; - append(key: string, value: any): Identify; - prepend(key: string, value: any): Identify; + export class Identify { + set(key: string, value: any): Identify; + setOnce(key: string, value: any): Identify; + add(key: string, value: number): Identify; + append(key: string, value: any): Identify; + prepend(key: string, value: any): Identify; - unset(key: string): Identify; - } + unset(key: string): Identify; + } - export function init(apiKey: string): void; - export function init(apiKey: string, userId: string): void; - export function init(apiKey: string, userId: string, options: Config): void; - export function init(apiKey: string, userId: string, options: Config, callback: () => void): void; + export function init(apiKey: string): void; + export function init(apiKey: string, userId: string): void; + export function init(apiKey: string, userId: string, options: Config): void; + export function init(apiKey: string, userId: string, options: Config, callback: () => void): void; - export function setVersionName(version: string): void; - export function setUserId(userId: string): void; + export function setVersionName(version: string): void; + export function setUserId(userId: string): void; - export function setDeviceId(id: string): void; - export function regenerateDeviceId(): void; + export function setDeviceId(id: string): void; + export function regenerateDeviceId(): void; - export function identify(identify: Identify): void; + export function identify(identify: Identify): void; - export function setUserProperties(properties: Object): void; - export function clearUserProperties(): void; + export function setUserProperties(properties: Object): void; + export function clearUserProperties(): void; - export function setOptOut(optOut: boolean): void; + export function setOptOut(optOut: boolean): void; - export function setGroup(groupType: string, groupName: string | string[]): void; + export function setGroup(groupType: string, groupName: string | string[]): void; - export function logEvent(event: string): void; - export function logEvent(event: string, data: Object): void; - export function logEvent(event: string, data: Object, callback: (httpCode: number, response: any) => void): void; + export function logEvent(event: string): void; + export function logEvent(event: string, data: Object): void; + export function logEvent(event: string, data: Object, callback: (httpCode: number, response: any) => void): void; - export var options: Config; + export var options: Config; }