diff --git a/README.md b/README.md index 7bc1f08..b5f6317 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ [![Coverage Status](https://coveralls.io/repos/github/CrossLead/crosslytics/badge.svg?branch=master)](https://coveralls.io/github/CrossLead/crosslytics?branch=master) [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0) -Tired of writing repetitive code to send the same analytics data to all your different tracking services? Or formatting the same data slightly differently for each service, like using ["eventAction"](https://developers.google.com/analytics/devguides/collection/analyticsjs/field-reference#eventAction) for Google Analytics but ["event_name"](https://developers.intercom.com/reference#event-model) for Intercom? +Tired of writing repetitive code to send the same analytics data to all your different tracking services? Or formatting the same data slightly differently for each service, like using [`eventAction`](https://developers.google.com/analytics/devguides/collection/analyticsjs/field-reference#eventAction) for Google Analytics but [`event_name`](https://developers.intercom.com/reference#event-model) for Intercom? Use Crosslytics for a unified event definition and analytics reporting API: Define events once and report them to all your analytics services with a single call. We've also abstracted the services themselves into a pluggable [Tracker](#trackers) architecture so you can use only the services you need and quickly add support for new ones. @@ -21,7 +21,7 @@ type DashboardPanelEventArgs = { 'Panel Name'?: string }; -export class DashboardPanelCreated extends TrackedEvent { +export class DashboardPanelCreated implements TrackedEvent { readonly name = 'DashboardPanel Created'; readonly category = 'Dashboard'; readonly argPriority: (keyof DashboardPanelEventArgs)[] = [ diff --git a/src/core/crosslytics.spec.ts b/src/core/crosslytics.spec.ts index 886ae8a..9fcadf5 100644 --- a/src/core/crosslytics.spec.ts +++ b/src/core/crosslytics.spec.ts @@ -9,11 +9,11 @@ interface TestEventArgs { 'Color': string; } -class TestEvent extends TrackedEvent { +class TestEvent implements TrackedEvent { public name = 'Test Event'; public category = 'Test Category'; - public organizationId = 'abc123'; - public argPriority = new Array(); + public argPriority: Array = ['Color']; + constructor(public args: TestEventArgs) {} } // tslint:disable-next-line:max-classes-per-file diff --git a/src/core/crosslytics.ts b/src/core/crosslytics.ts index 5ff0540..0c9efe7 100644 --- a/src/core/crosslytics.ts +++ b/src/core/crosslytics.ts @@ -13,9 +13,9 @@ export class Crosslytics { * Helper method equivalent to calling .track() on all registered trackers */ public async track(event: TrackedEvent) { - const promises = Array - .from(this.trackers.values()) - .map(t => t.track(event)); + const promises = Array.from(this.trackers.values()).map(t => + t.track(event) + ); return Promise.all(promises); } @@ -25,9 +25,7 @@ export class Crosslytics { public async page(page: Page | string) { const p: Page = typeof page === 'string' ? { url: page } : page; - const promises = Array - .from(this.trackers.values()) - .map(t => t.page(p)); + const promises = Array.from(this.trackers.values()).map(t => t.page(p)); return Promise.all(promises); } diff --git a/src/core/trackedEvent.ts b/src/core/trackedEvent.ts index c6a0683..414f3de 100644 --- a/src/core/trackedEvent.ts +++ b/src/core/trackedEvent.ts @@ -8,7 +8,7 @@ * 'Panel Type'?: number, * 'Panel Name'?: string * }; - * class DashboardPanelCreated extends TrackedEvent { + * class DashboardPanelCreated implements TrackedEvent { * readonly name = 'DashboardPanel Created'; * readonly category = 'Dashboard'; * readonly argPriority: (keyof DashboardPanelEventArgs)[] = [ @@ -17,16 +17,19 @@ * 'Panel Name', * 'Panel Color' * ]; + * constructor(public args: DashboardPanelEventArgs) {}; * } * @see {@link https://segment.com/docs/spec/track/#event} */ -export abstract class TrackedEvent { +export interface TrackedEvent { /** * We suggest human readable names consisting of noun + past tense verb. * @see {@link https://segment.com/academy/collecting-data/naming-conventions-for-clean-data/} */ - public abstract readonly name: string; - public abstract readonly category: string; + readonly name: string; + readonly category: string; + + args: T; /** * Many trackers only support a limited number of arguments. For example, @@ -36,7 +39,5 @@ export abstract class TrackedEvent { * the Google Analytics case, the tracker will submit the first string match * as the Label and the first integer match as the Value. */ - public abstract readonly argPriority: Array; - - constructor(public args: T) {} + readonly argPriority: Array; }