@patternfly/chatbot 2.2.0-prerelease.43 → 2.2.0-prerelease.44

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/dist/cjs/tracking/console_tracking_provider.d.ts +4 -5
  2. package/dist/cjs/tracking/console_tracking_provider.js +22 -15
  3. package/dist/cjs/tracking/posthog_tracking_provider.d.ts +2 -2
  4. package/dist/cjs/tracking/posthog_tracking_provider.js +21 -12
  5. package/dist/cjs/tracking/segment_tracking_provider.d.ts +2 -2
  6. package/dist/cjs/tracking/segment_tracking_provider.js +21 -12
  7. package/dist/cjs/tracking/trackingProviderProxy.d.ts +1 -1
  8. package/dist/cjs/tracking/trackingProviderProxy.js +2 -2
  9. package/dist/cjs/tracking/tracking_api.d.ts +1 -1
  10. package/dist/cjs/tracking/tracking_registry.js +46 -12
  11. package/dist/cjs/tracking/tracking_spi.d.ts +15 -5
  12. package/dist/cjs/tracking/tracking_spi.js +9 -0
  13. package/dist/cjs/tracking/umami_tracking_provider.d.ts +6 -2
  14. package/dist/cjs/tracking/umami_tracking_provider.js +66 -22
  15. package/dist/esm/tracking/console_tracking_provider.d.ts +4 -5
  16. package/dist/esm/tracking/console_tracking_provider.js +22 -15
  17. package/dist/esm/tracking/posthog_tracking_provider.d.ts +2 -2
  18. package/dist/esm/tracking/posthog_tracking_provider.js +21 -12
  19. package/dist/esm/tracking/segment_tracking_provider.d.ts +2 -2
  20. package/dist/esm/tracking/segment_tracking_provider.js +21 -12
  21. package/dist/esm/tracking/trackingProviderProxy.d.ts +1 -1
  22. package/dist/esm/tracking/trackingProviderProxy.js +2 -2
  23. package/dist/esm/tracking/tracking_api.d.ts +1 -1
  24. package/dist/esm/tracking/tracking_registry.js +46 -12
  25. package/dist/esm/tracking/tracking_spi.d.ts +15 -5
  26. package/dist/esm/tracking/tracking_spi.js +8 -1
  27. package/dist/esm/tracking/umami_tracking_provider.d.ts +6 -2
  28. package/dist/esm/tracking/umami_tracking_provider.js +66 -22
  29. package/package.json +1 -1
  30. package/patternfly-docs/content/extensions/chatbot/examples/Analytics/Analytics.md +18 -14
  31. package/patternfly-docs/content/extensions/chatbot/examples/demos/Chatbot.tsx +4 -3
  32. package/src/tracking/console_tracking_provider.ts +21 -17
  33. package/src/tracking/posthog_tracking_provider.ts +20 -13
  34. package/src/tracking/segment_tracking_provider.ts +20 -13
  35. package/src/tracking/trackingProviderProxy.ts +2 -2
  36. package/src/tracking/tracking_api.ts +1 -1
  37. package/src/tracking/tracking_registry.ts +46 -13
  38. package/src/tracking/tracking_spi.ts +18 -7
  39. package/src/tracking/umami_tracking_provider.ts +76 -20
@@ -1,10 +1,9 @@
1
- import { TrackingSpi } from './tracking_spi';
1
+ import { InitProps, TrackingSpi } from './tracking_spi';
2
2
  import { TrackingApi, TrackingEventProperties } from './tracking_api';
3
3
  export declare class ConsoleTrackingProvider implements TrackingSpi, TrackingApi {
4
+ private verbose;
4
5
  trackPageView(url: string | undefined): void;
5
- registerProvider(): void;
6
- initialize(): void;
7
- identify(userID: string): void;
6
+ initialize(props: InitProps): void;
7
+ identify(userID: string, userProperties?: TrackingEventProperties): void;
8
8
  trackSingleItem(item: string, properties?: TrackingEventProperties): void;
9
- getKey(): string;
10
9
  }
@@ -2,26 +2,33 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ConsoleTrackingProvider = void 0;
4
4
  class ConsoleTrackingProvider {
5
+ constructor() {
6
+ this.verbose = false;
7
+ }
5
8
  trackPageView(url) {
6
- // eslint-disable-next-line no-console
7
- console.log('ConsoleProvider pageView', url);
9
+ if (this.verbose) {
10
+ // eslint-disable-next-line no-console
11
+ console.log('ConsoleProvider pageView ', url);
12
+ }
8
13
  }
9
- // eslint-disable-next-line @typescript-eslint/no-empty-function
10
- registerProvider() { }
11
- initialize() {
12
- // eslint-disable-next-line no-console
13
- console.log('ConsoleProvider initialize');
14
+ initialize(props) {
15
+ this.verbose = props.verbose;
16
+ if (this.verbose) {
17
+ // eslint-disable-next-line no-console
18
+ console.log('ConsoleProvider initialize');
19
+ }
14
20
  }
15
- identify(userID) {
16
- // eslint-disable-next-line no-console
17
- console.log('ConsoleProvider identify', userID);
21
+ identify(userID, userProperties = {}) {
22
+ if (this.verbose) {
23
+ // eslint-disable-next-line no-console
24
+ console.log('ConsoleProvider identify ', userID, userProperties);
25
+ }
18
26
  }
19
27
  trackSingleItem(item, properties) {
20
- // eslint-disable-next-line no-console
21
- console.log('ConsoleProvider: ' + item, properties);
22
- }
23
- getKey() {
24
- return 'console';
28
+ if (this.verbose) {
29
+ // eslint-disable-next-line no-console
30
+ console.log('ConsoleProvider: ' + item, properties);
31
+ }
25
32
  }
26
33
  }
27
34
  exports.ConsoleTrackingProvider = ConsoleTrackingProvider;
@@ -1,9 +1,9 @@
1
1
  import { TrackingApi, TrackingEventProperties } from './tracking_api';
2
2
  import { InitProps, TrackingSpi } from './tracking_spi';
3
3
  export declare class PosthogTrackingProvider implements TrackingSpi, TrackingApi {
4
- getKey(): string;
4
+ private verbose;
5
5
  initialize(props: InitProps): void;
6
- identify(userID: string): void;
6
+ identify(userID: string, userProperties?: TrackingEventProperties): void;
7
7
  trackPageView(url: string | undefined): void;
8
8
  trackSingleItem(item: string, properties?: TrackingEventProperties): void;
9
9
  }
@@ -3,12 +3,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PosthogTrackingProvider = void 0;
4
4
  const posthog_js_1 = require("posthog-js");
5
5
  class PosthogTrackingProvider {
6
- getKey() {
7
- return 'posthogKey';
6
+ constructor() {
7
+ this.verbose = false;
8
8
  }
9
9
  initialize(props) {
10
- // eslint-disable-next-line no-console
11
- console.log('PosthogProvider initialize');
10
+ this.verbose = props.verbose;
11
+ if (this.verbose) {
12
+ // eslint-disable-next-line no-console
13
+ console.log('PosthogProvider initialize');
14
+ }
12
15
  const posthogKey = props.posthogKey;
13
16
  posthog_js_1.posthog.init(posthogKey, {
14
17
  // eslint-disable-next-line camelcase
@@ -17,20 +20,26 @@ class PosthogTrackingProvider {
17
20
  person_profiles: 'identified_only' // or 'always' to create profiles for anonymous users as well
18
21
  });
19
22
  }
20
- identify(userID) {
21
- // eslint-disable-next-line no-console
22
- console.log('PosthogProvider userID: ' + userID);
23
- posthog_js_1.posthog.identify(userID);
23
+ identify(userID, userProperties = {}) {
24
+ if (this.verbose) {
25
+ // eslint-disable-next-line no-console
26
+ console.log('PosthogProvider userID: ' + userID);
27
+ }
28
+ posthog_js_1.posthog.identify(userID, userProperties);
24
29
  }
25
30
  trackPageView(url) {
26
- // eslint-disable-next-line no-console
27
- console.log('PostHogProvider url', url);
31
+ if (this.verbose) {
32
+ // eslint-disable-next-line no-console
33
+ console.log('PostHogProvider url ', url);
34
+ }
28
35
  // TODO posthog seems to record that automatically.
29
36
  // How to not clash with this here? Just leave as no-op?
30
37
  }
31
38
  trackSingleItem(item, properties) {
32
- // eslint-disable-next-line no-console
33
- console.log('PosthogProvider: trackSingleItem' + item, properties);
39
+ if (this.verbose) {
40
+ // eslint-disable-next-line no-console
41
+ console.log('PosthogProvider: trackSingleItem ' + item, properties);
42
+ }
34
43
  posthog_js_1.posthog.capture(item, { properties });
35
44
  }
36
45
  }
@@ -2,9 +2,9 @@ import { TrackingApi, TrackingEventProperties } from './tracking_api';
2
2
  import { InitProps, TrackingSpi } from './tracking_spi';
3
3
  export declare class SegmentTrackingProvider implements TrackingSpi, TrackingApi {
4
4
  private analytics;
5
- getKey(): string;
5
+ private verbose;
6
6
  initialize(props: InitProps): void;
7
- identify(userID: string): void;
7
+ identify(userID: string, userProperties?: TrackingEventProperties): void;
8
8
  trackPageView(url: string | undefined): void;
9
9
  trackSingleItem(item: string, properties?: TrackingEventProperties): void;
10
10
  }
@@ -3,12 +3,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SegmentTrackingProvider = void 0;
4
4
  const analytics_next_1 = require("@segment/analytics-next");
5
5
  class SegmentTrackingProvider {
6
- getKey() {
7
- return 'segmentKey';
6
+ constructor() {
7
+ this.verbose = false;
8
8
  }
9
9
  initialize(props) {
10
- // eslint-disable-next-line no-console
11
- console.log('SegmentProvider initialize');
10
+ this.verbose = props.verbose;
11
+ if (this.verbose) {
12
+ // eslint-disable-next-line no-console
13
+ console.log('SegmentProvider initialize');
14
+ }
12
15
  const segmentKey = props.segmentKey;
13
16
  // We need to create an object here, as ts lint is unhappy otherwise
14
17
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -20,16 +23,20 @@ class SegmentTrackingProvider {
20
23
  integrations: Object.assign({}, integrations)
21
24
  });
22
25
  }
23
- identify(userID) {
24
- // eslint-disable-next-line no-console
25
- console.log('SegmentProvider userID: ' + userID);
26
+ identify(userID, userProperties = {}) {
27
+ if (this.verbose) {
28
+ // eslint-disable-next-line no-console
29
+ console.log('SegmentProvider userID: ' + userID);
30
+ }
26
31
  if (this.analytics) {
27
- this.analytics.identify(userID);
32
+ this.analytics.identify(userID, userProperties);
28
33
  }
29
34
  }
30
35
  trackPageView(url) {
31
- // eslint-disable-next-line no-console
32
- console.log('SegmentProvider url', url);
36
+ if (this.verbose) {
37
+ // eslint-disable-next-line no-console
38
+ console.log('SegmentProvider url ', url);
39
+ }
33
40
  if (this.analytics) {
34
41
  if (url) {
35
42
  this.analytics.page(url);
@@ -40,8 +47,10 @@ class SegmentTrackingProvider {
40
47
  }
41
48
  }
42
49
  trackSingleItem(item, properties) {
43
- // eslint-disable-next-line no-console
44
- console.log('SegmentProvider: trackSingleItem' + item, properties);
50
+ if (this.verbose) {
51
+ // eslint-disable-next-line no-console
52
+ console.log('SegmentProvider: trackSingleItem ' + item, properties);
53
+ }
45
54
  if (this.analytics) {
46
55
  this.analytics.track(item, { properties });
47
56
  }
@@ -2,7 +2,7 @@ import { TrackingApi, TrackingEventProperties } from './tracking_api';
2
2
  declare class TrackingProviderProxy implements TrackingApi {
3
3
  providers: TrackingApi[];
4
4
  constructor(providers: TrackingApi[]);
5
- identify(userID: string): void;
5
+ identify(userID: string, userProperties?: TrackingEventProperties): void;
6
6
  trackSingleItem(eventName: string, properties?: TrackingEventProperties): void;
7
7
  trackPageView(url: string | undefined): void;
8
8
  }
@@ -5,9 +5,9 @@ class TrackingProviderProxy {
5
5
  this.providers = [];
6
6
  this.providers = providers;
7
7
  }
8
- identify(userID) {
8
+ identify(userID, userProperties = {}) {
9
9
  for (const provider of this.providers) {
10
- provider.identify(userID);
10
+ provider.identify(userID, userProperties);
11
11
  }
12
12
  }
13
13
  trackSingleItem(eventName, properties) {
@@ -2,7 +2,7 @@ export interface TrackingEventProperties {
2
2
  [key: string]: string | number | boolean | undefined;
3
3
  }
4
4
  export interface TrackingApi {
5
- identify: (userID: string) => void;
5
+ identify: (userID: string, userProperties: TrackingEventProperties) => void;
6
6
  trackPageView: (url: string | undefined) => void;
7
7
  trackSingleItem: (eventName: string, properties: TrackingEventProperties | undefined) => void;
8
8
  }
@@ -4,6 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.getTrackingProviders = void 0;
7
+ const tracking_spi_1 = require("./tracking_spi");
7
8
  const trackingProviderProxy_1 = __importDefault(require("./trackingProviderProxy"));
8
9
  const console_tracking_provider_1 = require("./console_tracking_provider");
9
10
  const segment_tracking_provider_1 = require("./segment_tracking_provider");
@@ -11,23 +12,56 @@ const posthog_tracking_provider_1 = require("./posthog_tracking_provider");
11
12
  const umami_tracking_provider_1 = require("./umami_tracking_provider");
12
13
  const getTrackingProviders = (initProps) => {
13
14
  const providers = [];
14
- providers.push(new segment_tracking_provider_1.SegmentTrackingProvider());
15
- providers.push(new posthog_tracking_provider_1.PosthogTrackingProvider());
16
- providers.push(new umami_tracking_provider_1.UmamiTrackingProvider());
17
- // TODO dynamically find and register providers
15
+ if (initProps.activeProviders) {
16
+ let tmpProps = initProps.activeProviders;
17
+ // Theoretically we get an array of provider names, but it could also be a CSV string...
18
+ if (!Array.isArray(initProps.activeProviders)) {
19
+ const tmpString = initProps.activeProviders;
20
+ if (tmpString && tmpString.indexOf(',') !== -1) {
21
+ tmpProps = tmpString.split(',');
22
+ }
23
+ else {
24
+ tmpProps = [tmpString];
25
+ }
26
+ }
27
+ tmpProps.forEach((provider) => {
28
+ switch (tracking_spi_1.Providers[provider]) {
29
+ case tracking_spi_1.Providers.Segment:
30
+ providers.push(new segment_tracking_provider_1.SegmentTrackingProvider());
31
+ break;
32
+ case tracking_spi_1.Providers.Umami:
33
+ providers.push(new umami_tracking_provider_1.UmamiTrackingProvider());
34
+ break;
35
+ case tracking_spi_1.Providers.Posthog:
36
+ providers.push(new posthog_tracking_provider_1.PosthogTrackingProvider());
37
+ break;
38
+ case tracking_spi_1.Providers.Console:
39
+ providers.push(new console_tracking_provider_1.ConsoleTrackingProvider());
40
+ break;
41
+ case tracking_spi_1.Providers.None: // Do nothing, just a placeholder
42
+ break;
43
+ default:
44
+ if (providers.length > 1) {
45
+ if (initProps.verbose) {
46
+ // eslint-disable-next-line no-console
47
+ console.error("Unknown provider '" + provider);
48
+ }
49
+ }
50
+ break;
51
+ }
52
+ });
53
+ }
18
54
  // Initialize them
19
- const enabledProviders = [];
20
55
  for (const provider of providers) {
21
- const key = provider.getKey();
22
- if (Object.keys(initProps).indexOf(key) > -1) {
56
+ try {
23
57
  provider.initialize(initProps);
24
- enabledProviders.push(provider);
58
+ }
59
+ catch (e) {
60
+ // eslint-disable-next-line no-console
61
+ console.error(e);
25
62
  }
26
63
  }
27
- // Add the console provider
28
- const consoleTrackingProvider = new console_tracking_provider_1.ConsoleTrackingProvider();
29
- enabledProviders.push(consoleTrackingProvider); // TODO noop- provider?
30
- return new trackingProviderProxy_1.default(enabledProviders);
64
+ return new trackingProviderProxy_1.default(providers);
31
65
  };
32
66
  exports.getTrackingProviders = getTrackingProviders;
33
67
  exports.default = exports.getTrackingProviders;
@@ -1,9 +1,19 @@
1
- import { TrackingApi, TrackingEventProperties } from './tracking_api';
2
- export interface InitProps {
3
- [key: string]: string | number | boolean;
1
+ import { TrackingApi } from './tracking_api';
2
+ export declare enum Providers {
3
+ None = 0,
4
+ Segment = 1,
5
+ Umami = 2,
6
+ Posthog = 3,
7
+ Console = 4
8
+ }
9
+ export type ProviderAsString = keyof typeof Providers;
10
+ export interface BaseProps {
11
+ verbose: boolean;
12
+ activeProviders: [ProviderAsString];
4
13
  }
14
+ export type InitProps = {
15
+ [key: string]: string | number | boolean;
16
+ } & BaseProps;
5
17
  export interface TrackingSpi extends TrackingApi {
6
- getKey: () => string;
7
18
  initialize: (props: InitProps) => void;
8
- trackSingleItem: (item: string, properties?: TrackingEventProperties) => void;
9
19
  }
@@ -1,2 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Providers = void 0;
4
+ var Providers;
5
+ (function (Providers) {
6
+ Providers[Providers["None"] = 0] = "None";
7
+ Providers[Providers["Segment"] = 1] = "Segment";
8
+ Providers[Providers["Umami"] = 2] = "Umami";
9
+ Providers[Providers["Posthog"] = 3] = "Posthog";
10
+ Providers[Providers["Console"] = 4] = "Console";
11
+ })(Providers || (exports.Providers = Providers = {}));
@@ -6,9 +6,13 @@ declare global {
6
6
  }
7
7
  }
8
8
  export declare class UmamiTrackingProvider implements TrackingSpi, TrackingApi {
9
- getKey(): string;
9
+ private verbose;
10
+ private websiteId;
11
+ private queue;
10
12
  initialize(props: InitProps): void;
11
- identify(userID: string): void;
13
+ identify(userID: string, userProperties?: TrackingEventProperties): void;
12
14
  trackPageView(url: string | undefined): void;
13
15
  trackSingleItem(item: string, properties?: TrackingEventProperties): void;
16
+ flushQueue(): void;
17
+ log(msg: string): void;
14
18
  }
@@ -2,43 +2,87 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.UmamiTrackingProvider = void 0;
4
4
  class UmamiTrackingProvider {
5
- getKey() {
6
- return 'umamiKey';
5
+ constructor() {
6
+ this.verbose = false;
7
+ this.queue = [];
7
8
  }
8
9
  initialize(props) {
9
- // eslint-disable-next-line no-console
10
- console.log('UmamiProvider initialize');
11
- const umamiKey = props.umamiKey;
10
+ this.verbose = props.verbose;
11
+ this.log('UmamiProvider initialize');
12
+ this.websiteId = props.umamiKey;
12
13
  const hostUrl = props.umamiHostUrl;
13
14
  const script = document.createElement('script');
14
15
  script.src = hostUrl + '/script.js';
15
16
  script.async = true;
16
17
  script.defer = true;
17
18
  // Configure Umami properties
18
- script.setAttribute('data-website-id', umamiKey);
19
- script.setAttribute('data-domains', 'localhost'); // TODO ?
19
+ script.setAttribute('data-website-id', this.websiteId);
20
+ script.setAttribute('data-host-url', hostUrl);
20
21
  script.setAttribute('data-auto-track', 'false');
21
- script.setAttribute('data-host-url', hostUrl); // TODO ?
22
- script.setAttribute('data-exclude-search', 'false'); // TODO ?
22
+ script.setAttribute('data-exclude-search', 'false');
23
+ // Now get from config, which may override some of the above.
24
+ const UMAMI_PREFIX = 'umami-';
25
+ for (const prop in props) {
26
+ if (prop.startsWith(UMAMI_PREFIX)) {
27
+ const att = 'data-' + prop.substring(UMAMI_PREFIX.length);
28
+ const val = props[prop];
29
+ script.setAttribute(att, String(val));
30
+ }
31
+ }
32
+ script.onload = () => {
33
+ this.log('UmamiProvider script loaded');
34
+ this.flushQueue();
35
+ };
23
36
  document.body.appendChild(script);
24
37
  }
25
- identify(userID) {
26
- var _a;
27
- // eslint-disable-next-line no-console
28
- console.log('UmamiProvider userID: ' + userID);
29
- (_a = window.umami) === null || _a === void 0 ? void 0 : _a.identify({ userID });
38
+ identify(userID, userProperties = {}) {
39
+ this.log('UmamiProvider userID: ' + userID + ' => ' + JSON.stringify(userProperties));
40
+ if (window.umami) {
41
+ window.umami.identify({ userID, userProperties });
42
+ }
43
+ else {
44
+ this.queue.push({ what: 'i', name: userID, payload: userProperties });
45
+ }
30
46
  }
31
47
  trackPageView(url) {
32
- var _a;
33
- // eslint-disable-next-line no-console
34
- console.log('UmamiProvider url', url);
35
- (_a = window.umami) === null || _a === void 0 ? void 0 : _a.track({ url });
48
+ this.log('UmamiProvider url ' + url);
49
+ if (window.umami) {
50
+ window.umami.track({ url, website: this.websiteId });
51
+ }
52
+ else {
53
+ this.queue.push({ what: 'p', name: String(url) });
54
+ }
36
55
  }
37
56
  trackSingleItem(item, properties) {
38
- var _a;
39
- // eslint-disable-next-line no-console
40
- console.log('UmamiProvider: trackSingleItem' + item, properties);
41
- (_a = window.umami) === null || _a === void 0 ? void 0 : _a.track(item, properties);
57
+ this.log('UmamiProvider: trackSingleItem ' + item + JSON.stringify(properties));
58
+ if (window.umami) {
59
+ window.umami.track(item, properties);
60
+ }
61
+ else {
62
+ this.queue.push({ what: 't', name: item, payload: properties });
63
+ }
64
+ }
65
+ flushQueue() {
66
+ for (const item of this.queue) {
67
+ this.log('Queue flush ' + JSON.stringify(item));
68
+ switch (item.what) {
69
+ case 'i':
70
+ this.identify(item.name, item.payload);
71
+ break;
72
+ case 't':
73
+ this.trackSingleItem(item.name, item.payload);
74
+ break;
75
+ case 'p':
76
+ this.trackPageView(item.name);
77
+ break;
78
+ }
79
+ }
80
+ }
81
+ log(msg) {
82
+ if (this.verbose) {
83
+ // eslint-disable-next-line no-console
84
+ console.debug('UmamiProvider: ', msg);
85
+ }
42
86
  }
43
87
  }
44
88
  exports.UmamiTrackingProvider = UmamiTrackingProvider;
@@ -1,10 +1,9 @@
1
- import { TrackingSpi } from './tracking_spi';
1
+ import { InitProps, TrackingSpi } from './tracking_spi';
2
2
  import { TrackingApi, TrackingEventProperties } from './tracking_api';
3
3
  export declare class ConsoleTrackingProvider implements TrackingSpi, TrackingApi {
4
+ private verbose;
4
5
  trackPageView(url: string | undefined): void;
5
- registerProvider(): void;
6
- initialize(): void;
7
- identify(userID: string): void;
6
+ initialize(props: InitProps): void;
7
+ identify(userID: string, userProperties?: TrackingEventProperties): void;
8
8
  trackSingleItem(item: string, properties?: TrackingEventProperties): void;
9
- getKey(): string;
10
9
  }
@@ -1,23 +1,30 @@
1
1
  export class ConsoleTrackingProvider {
2
+ constructor() {
3
+ this.verbose = false;
4
+ }
2
5
  trackPageView(url) {
3
- // eslint-disable-next-line no-console
4
- console.log('ConsoleProvider pageView', url);
6
+ if (this.verbose) {
7
+ // eslint-disable-next-line no-console
8
+ console.log('ConsoleProvider pageView ', url);
9
+ }
5
10
  }
6
- // eslint-disable-next-line @typescript-eslint/no-empty-function
7
- registerProvider() { }
8
- initialize() {
9
- // eslint-disable-next-line no-console
10
- console.log('ConsoleProvider initialize');
11
+ initialize(props) {
12
+ this.verbose = props.verbose;
13
+ if (this.verbose) {
14
+ // eslint-disable-next-line no-console
15
+ console.log('ConsoleProvider initialize');
16
+ }
11
17
  }
12
- identify(userID) {
13
- // eslint-disable-next-line no-console
14
- console.log('ConsoleProvider identify', userID);
18
+ identify(userID, userProperties = {}) {
19
+ if (this.verbose) {
20
+ // eslint-disable-next-line no-console
21
+ console.log('ConsoleProvider identify ', userID, userProperties);
22
+ }
15
23
  }
16
24
  trackSingleItem(item, properties) {
17
- // eslint-disable-next-line no-console
18
- console.log('ConsoleProvider: ' + item, properties);
19
- }
20
- getKey() {
21
- return 'console';
25
+ if (this.verbose) {
26
+ // eslint-disable-next-line no-console
27
+ console.log('ConsoleProvider: ' + item, properties);
28
+ }
22
29
  }
23
30
  }
@@ -1,9 +1,9 @@
1
1
  import { TrackingApi, TrackingEventProperties } from './tracking_api';
2
2
  import { InitProps, TrackingSpi } from './tracking_spi';
3
3
  export declare class PosthogTrackingProvider implements TrackingSpi, TrackingApi {
4
- getKey(): string;
4
+ private verbose;
5
5
  initialize(props: InitProps): void;
6
- identify(userID: string): void;
6
+ identify(userID: string, userProperties?: TrackingEventProperties): void;
7
7
  trackPageView(url: string | undefined): void;
8
8
  trackSingleItem(item: string, properties?: TrackingEventProperties): void;
9
9
  }
@@ -1,11 +1,14 @@
1
1
  import { posthog } from 'posthog-js';
2
2
  export class PosthogTrackingProvider {
3
- getKey() {
4
- return 'posthogKey';
3
+ constructor() {
4
+ this.verbose = false;
5
5
  }
6
6
  initialize(props) {
7
- // eslint-disable-next-line no-console
8
- console.log('PosthogProvider initialize');
7
+ this.verbose = props.verbose;
8
+ if (this.verbose) {
9
+ // eslint-disable-next-line no-console
10
+ console.log('PosthogProvider initialize');
11
+ }
9
12
  const posthogKey = props.posthogKey;
10
13
  posthog.init(posthogKey, {
11
14
  // eslint-disable-next-line camelcase
@@ -14,20 +17,26 @@ export class PosthogTrackingProvider {
14
17
  person_profiles: 'identified_only' // or 'always' to create profiles for anonymous users as well
15
18
  });
16
19
  }
17
- identify(userID) {
18
- // eslint-disable-next-line no-console
19
- console.log('PosthogProvider userID: ' + userID);
20
- posthog.identify(userID);
20
+ identify(userID, userProperties = {}) {
21
+ if (this.verbose) {
22
+ // eslint-disable-next-line no-console
23
+ console.log('PosthogProvider userID: ' + userID);
24
+ }
25
+ posthog.identify(userID, userProperties);
21
26
  }
22
27
  trackPageView(url) {
23
- // eslint-disable-next-line no-console
24
- console.log('PostHogProvider url', url);
28
+ if (this.verbose) {
29
+ // eslint-disable-next-line no-console
30
+ console.log('PostHogProvider url ', url);
31
+ }
25
32
  // TODO posthog seems to record that automatically.
26
33
  // How to not clash with this here? Just leave as no-op?
27
34
  }
28
35
  trackSingleItem(item, properties) {
29
- // eslint-disable-next-line no-console
30
- console.log('PosthogProvider: trackSingleItem' + item, properties);
36
+ if (this.verbose) {
37
+ // eslint-disable-next-line no-console
38
+ console.log('PosthogProvider: trackSingleItem ' + item, properties);
39
+ }
31
40
  posthog.capture(item, { properties });
32
41
  }
33
42
  }
@@ -2,9 +2,9 @@ import { TrackingApi, TrackingEventProperties } from './tracking_api';
2
2
  import { InitProps, TrackingSpi } from './tracking_spi';
3
3
  export declare class SegmentTrackingProvider implements TrackingSpi, TrackingApi {
4
4
  private analytics;
5
- getKey(): string;
5
+ private verbose;
6
6
  initialize(props: InitProps): void;
7
- identify(userID: string): void;
7
+ identify(userID: string, userProperties?: TrackingEventProperties): void;
8
8
  trackPageView(url: string | undefined): void;
9
9
  trackSingleItem(item: string, properties?: TrackingEventProperties): void;
10
10
  }