@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.
- package/dist/cjs/tracking/console_tracking_provider.d.ts +4 -5
- package/dist/cjs/tracking/console_tracking_provider.js +22 -15
- package/dist/cjs/tracking/posthog_tracking_provider.d.ts +2 -2
- package/dist/cjs/tracking/posthog_tracking_provider.js +21 -12
- package/dist/cjs/tracking/segment_tracking_provider.d.ts +2 -2
- package/dist/cjs/tracking/segment_tracking_provider.js +21 -12
- package/dist/cjs/tracking/trackingProviderProxy.d.ts +1 -1
- package/dist/cjs/tracking/trackingProviderProxy.js +2 -2
- package/dist/cjs/tracking/tracking_api.d.ts +1 -1
- package/dist/cjs/tracking/tracking_registry.js +46 -12
- package/dist/cjs/tracking/tracking_spi.d.ts +15 -5
- package/dist/cjs/tracking/tracking_spi.js +9 -0
- package/dist/cjs/tracking/umami_tracking_provider.d.ts +6 -2
- package/dist/cjs/tracking/umami_tracking_provider.js +66 -22
- package/dist/esm/tracking/console_tracking_provider.d.ts +4 -5
- package/dist/esm/tracking/console_tracking_provider.js +22 -15
- package/dist/esm/tracking/posthog_tracking_provider.d.ts +2 -2
- package/dist/esm/tracking/posthog_tracking_provider.js +21 -12
- package/dist/esm/tracking/segment_tracking_provider.d.ts +2 -2
- package/dist/esm/tracking/segment_tracking_provider.js +21 -12
- package/dist/esm/tracking/trackingProviderProxy.d.ts +1 -1
- package/dist/esm/tracking/trackingProviderProxy.js +2 -2
- package/dist/esm/tracking/tracking_api.d.ts +1 -1
- package/dist/esm/tracking/tracking_registry.js +46 -12
- package/dist/esm/tracking/tracking_spi.d.ts +15 -5
- package/dist/esm/tracking/tracking_spi.js +8 -1
- package/dist/esm/tracking/umami_tracking_provider.d.ts +6 -2
- package/dist/esm/tracking/umami_tracking_provider.js +66 -22
- package/package.json +1 -1
- package/patternfly-docs/content/extensions/chatbot/examples/Analytics/Analytics.md +18 -14
- package/patternfly-docs/content/extensions/chatbot/examples/demos/Chatbot.tsx +4 -3
- package/src/tracking/console_tracking_provider.ts +21 -17
- package/src/tracking/posthog_tracking_provider.ts +20 -13
- package/src/tracking/segment_tracking_provider.ts +20 -13
- package/src/tracking/trackingProviderProxy.ts +2 -2
- package/src/tracking/tracking_api.ts +1 -1
- package/src/tracking/tracking_registry.ts +46 -13
- package/src/tracking/tracking_spi.ts +18 -7
- package/src/tracking/umami_tracking_provider.ts +76 -20
@@ -1,11 +1,14 @@
|
|
1
1
|
import { AnalyticsBrowser } from '@segment/analytics-next';
|
2
2
|
export class SegmentTrackingProvider {
|
3
|
-
|
4
|
-
|
3
|
+
constructor() {
|
4
|
+
this.verbose = false;
|
5
5
|
}
|
6
6
|
initialize(props) {
|
7
|
-
|
8
|
-
|
7
|
+
this.verbose = props.verbose;
|
8
|
+
if (this.verbose) {
|
9
|
+
// eslint-disable-next-line no-console
|
10
|
+
console.log('SegmentProvider initialize');
|
11
|
+
}
|
9
12
|
const segmentKey = props.segmentKey;
|
10
13
|
// We need to create an object here, as ts lint is unhappy otherwise
|
11
14
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
@@ -17,16 +20,20 @@ export class SegmentTrackingProvider {
|
|
17
20
|
integrations: Object.assign({}, integrations)
|
18
21
|
});
|
19
22
|
}
|
20
|
-
identify(userID) {
|
21
|
-
|
22
|
-
|
23
|
+
identify(userID, userProperties = {}) {
|
24
|
+
if (this.verbose) {
|
25
|
+
// eslint-disable-next-line no-console
|
26
|
+
console.log('SegmentProvider userID: ' + userID);
|
27
|
+
}
|
23
28
|
if (this.analytics) {
|
24
|
-
this.analytics.identify(userID);
|
29
|
+
this.analytics.identify(userID, userProperties);
|
25
30
|
}
|
26
31
|
}
|
27
32
|
trackPageView(url) {
|
28
|
-
|
29
|
-
|
33
|
+
if (this.verbose) {
|
34
|
+
// eslint-disable-next-line no-console
|
35
|
+
console.log('SegmentProvider url ', url);
|
36
|
+
}
|
30
37
|
if (this.analytics) {
|
31
38
|
if (url) {
|
32
39
|
this.analytics.page(url);
|
@@ -37,8 +44,10 @@ export class SegmentTrackingProvider {
|
|
37
44
|
}
|
38
45
|
}
|
39
46
|
trackSingleItem(item, properties) {
|
40
|
-
|
41
|
-
|
47
|
+
if (this.verbose) {
|
48
|
+
// eslint-disable-next-line no-console
|
49
|
+
console.log('SegmentProvider: trackSingleItem ' + item, properties);
|
50
|
+
}
|
42
51
|
if (this.analytics) {
|
43
52
|
this.analytics.track(item, { properties });
|
44
53
|
}
|
@@ -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
|
}
|
@@ -3,9 +3,9 @@ class TrackingProviderProxy {
|
|
3
3
|
this.providers = [];
|
4
4
|
this.providers = providers;
|
5
5
|
}
|
6
|
-
identify(userID) {
|
6
|
+
identify(userID, userProperties = {}) {
|
7
7
|
for (const provider of this.providers) {
|
8
|
-
provider.identify(userID);
|
8
|
+
provider.identify(userID, userProperties);
|
9
9
|
}
|
10
10
|
}
|
11
11
|
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
|
}
|
@@ -1,3 +1,4 @@
|
|
1
|
+
import { Providers } from './tracking_spi';
|
1
2
|
import TrackingProviderProxy from './trackingProviderProxy';
|
2
3
|
import { ConsoleTrackingProvider } from './console_tracking_provider';
|
3
4
|
import { SegmentTrackingProvider } from './segment_tracking_provider';
|
@@ -5,22 +6,55 @@ import { PosthogTrackingProvider } from './posthog_tracking_provider';
|
|
5
6
|
import { UmamiTrackingProvider } from './umami_tracking_provider';
|
6
7
|
export const getTrackingProviders = (initProps) => {
|
7
8
|
const providers = [];
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
if (initProps.activeProviders) {
|
10
|
+
let tmpProps = initProps.activeProviders;
|
11
|
+
// Theoretically we get an array of provider names, but it could also be a CSV string...
|
12
|
+
if (!Array.isArray(initProps.activeProviders)) {
|
13
|
+
const tmpString = initProps.activeProviders;
|
14
|
+
if (tmpString && tmpString.indexOf(',') !== -1) {
|
15
|
+
tmpProps = tmpString.split(',');
|
16
|
+
}
|
17
|
+
else {
|
18
|
+
tmpProps = [tmpString];
|
19
|
+
}
|
20
|
+
}
|
21
|
+
tmpProps.forEach((provider) => {
|
22
|
+
switch (Providers[provider]) {
|
23
|
+
case Providers.Segment:
|
24
|
+
providers.push(new SegmentTrackingProvider());
|
25
|
+
break;
|
26
|
+
case Providers.Umami:
|
27
|
+
providers.push(new UmamiTrackingProvider());
|
28
|
+
break;
|
29
|
+
case Providers.Posthog:
|
30
|
+
providers.push(new PosthogTrackingProvider());
|
31
|
+
break;
|
32
|
+
case Providers.Console:
|
33
|
+
providers.push(new ConsoleTrackingProvider());
|
34
|
+
break;
|
35
|
+
case Providers.None: // Do nothing, just a placeholder
|
36
|
+
break;
|
37
|
+
default:
|
38
|
+
if (providers.length > 1) {
|
39
|
+
if (initProps.verbose) {
|
40
|
+
// eslint-disable-next-line no-console
|
41
|
+
console.error("Unknown provider '" + provider);
|
42
|
+
}
|
43
|
+
}
|
44
|
+
break;
|
45
|
+
}
|
46
|
+
});
|
47
|
+
}
|
12
48
|
// Initialize them
|
13
|
-
const enabledProviders = [];
|
14
49
|
for (const provider of providers) {
|
15
|
-
|
16
|
-
if (Object.keys(initProps).indexOf(key) > -1) {
|
50
|
+
try {
|
17
51
|
provider.initialize(initProps);
|
18
|
-
|
52
|
+
}
|
53
|
+
catch (e) {
|
54
|
+
// eslint-disable-next-line no-console
|
55
|
+
console.error(e);
|
19
56
|
}
|
20
57
|
}
|
21
|
-
|
22
|
-
const consoleTrackingProvider = new ConsoleTrackingProvider();
|
23
|
-
enabledProviders.push(consoleTrackingProvider); // TODO noop- provider?
|
24
|
-
return new TrackingProviderProxy(enabledProviders);
|
58
|
+
return new TrackingProviderProxy(providers);
|
25
59
|
};
|
26
60
|
export default getTrackingProviders;
|
@@ -1,9 +1,19 @@
|
|
1
|
-
import { TrackingApi
|
2
|
-
export
|
3
|
-
|
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 +1,8 @@
|
|
1
|
-
export
|
1
|
+
export var Providers;
|
2
|
+
(function (Providers) {
|
3
|
+
Providers[Providers["None"] = 0] = "None";
|
4
|
+
Providers[Providers["Segment"] = 1] = "Segment";
|
5
|
+
Providers[Providers["Umami"] = 2] = "Umami";
|
6
|
+
Providers[Providers["Posthog"] = 3] = "Posthog";
|
7
|
+
Providers[Providers["Console"] = 4] = "Console";
|
8
|
+
})(Providers || (Providers = {}));
|
@@ -6,9 +6,13 @@ declare global {
|
|
6
6
|
}
|
7
7
|
}
|
8
8
|
export declare class UmamiTrackingProvider implements TrackingSpi, TrackingApi {
|
9
|
-
|
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
|
}
|
@@ -1,40 +1,84 @@
|
|
1
1
|
export class UmamiTrackingProvider {
|
2
|
-
|
3
|
-
|
2
|
+
constructor() {
|
3
|
+
this.verbose = false;
|
4
|
+
this.queue = [];
|
4
5
|
}
|
5
6
|
initialize(props) {
|
6
|
-
|
7
|
-
|
8
|
-
|
7
|
+
this.verbose = props.verbose;
|
8
|
+
this.log('UmamiProvider initialize');
|
9
|
+
this.websiteId = props.umamiKey;
|
9
10
|
const hostUrl = props.umamiHostUrl;
|
10
11
|
const script = document.createElement('script');
|
11
12
|
script.src = hostUrl + '/script.js';
|
12
13
|
script.async = true;
|
13
14
|
script.defer = true;
|
14
15
|
// Configure Umami properties
|
15
|
-
script.setAttribute('data-website-id',
|
16
|
-
script.setAttribute('data-
|
16
|
+
script.setAttribute('data-website-id', this.websiteId);
|
17
|
+
script.setAttribute('data-host-url', hostUrl);
|
17
18
|
script.setAttribute('data-auto-track', 'false');
|
18
|
-
script.setAttribute('data-
|
19
|
-
|
19
|
+
script.setAttribute('data-exclude-search', 'false');
|
20
|
+
// Now get from config, which may override some of the above.
|
21
|
+
const UMAMI_PREFIX = 'umami-';
|
22
|
+
for (const prop in props) {
|
23
|
+
if (prop.startsWith(UMAMI_PREFIX)) {
|
24
|
+
const att = 'data-' + prop.substring(UMAMI_PREFIX.length);
|
25
|
+
const val = props[prop];
|
26
|
+
script.setAttribute(att, String(val));
|
27
|
+
}
|
28
|
+
}
|
29
|
+
script.onload = () => {
|
30
|
+
this.log('UmamiProvider script loaded');
|
31
|
+
this.flushQueue();
|
32
|
+
};
|
20
33
|
document.body.appendChild(script);
|
21
34
|
}
|
22
|
-
identify(userID) {
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
35
|
+
identify(userID, userProperties = {}) {
|
36
|
+
this.log('UmamiProvider userID: ' + userID + ' => ' + JSON.stringify(userProperties));
|
37
|
+
if (window.umami) {
|
38
|
+
window.umami.identify({ userID, userProperties });
|
39
|
+
}
|
40
|
+
else {
|
41
|
+
this.queue.push({ what: 'i', name: userID, payload: userProperties });
|
42
|
+
}
|
27
43
|
}
|
28
44
|
trackPageView(url) {
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
45
|
+
this.log('UmamiProvider url ' + url);
|
46
|
+
if (window.umami) {
|
47
|
+
window.umami.track({ url, website: this.websiteId });
|
48
|
+
}
|
49
|
+
else {
|
50
|
+
this.queue.push({ what: 'p', name: String(url) });
|
51
|
+
}
|
33
52
|
}
|
34
53
|
trackSingleItem(item, properties) {
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
54
|
+
this.log('UmamiProvider: trackSingleItem ' + item + JSON.stringify(properties));
|
55
|
+
if (window.umami) {
|
56
|
+
window.umami.track(item, properties);
|
57
|
+
}
|
58
|
+
else {
|
59
|
+
this.queue.push({ what: 't', name: item, payload: properties });
|
60
|
+
}
|
61
|
+
}
|
62
|
+
flushQueue() {
|
63
|
+
for (const item of this.queue) {
|
64
|
+
this.log('Queue flush ' + JSON.stringify(item));
|
65
|
+
switch (item.what) {
|
66
|
+
case 'i':
|
67
|
+
this.identify(item.name, item.payload);
|
68
|
+
break;
|
69
|
+
case 't':
|
70
|
+
this.trackSingleItem(item.name, item.payload);
|
71
|
+
break;
|
72
|
+
case 'p':
|
73
|
+
this.trackPageView(item.name);
|
74
|
+
break;
|
75
|
+
}
|
76
|
+
}
|
77
|
+
}
|
78
|
+
log(msg) {
|
79
|
+
if (this.verbose) {
|
80
|
+
// eslint-disable-next-line no-console
|
81
|
+
console.debug('UmamiProvider: ', msg);
|
82
|
+
}
|
39
83
|
}
|
40
84
|
}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@patternfly/chatbot",
|
3
|
-
"version": "2.2.0-prerelease.
|
3
|
+
"version": "2.2.0-prerelease.44",
|
4
4
|
"description": "This library provides React components based on PatternFly 6 that can be used to build chatbots.",
|
5
5
|
"main": "dist/cjs/index.js",
|
6
6
|
"module": "dist/esm/index.js",
|
@@ -36,10 +36,12 @@ Note that user code only interacts with:
|
|
36
36
|
|
37
37
|
### Setup
|
38
38
|
|
39
|
-
1. Before you can use the `trackingAPI`, you must first supply the API keys of the respective providers.
|
39
|
+
1. Before you can use the `trackingAPI`, you must first supply the API keys of the respective providers. To enable a provider, it must be added to the `activeProviders` property:
|
40
40
|
|
41
41
|
```nolive
|
42
42
|
const initProps: InitProps = {
|
43
|
+
verbose: false,
|
44
|
+
activeProviders: ['Segment', 'Umami', 'Posthog', 'Console' ],
|
43
45
|
segmentKey: 'TODO-key', // TODO add your key here
|
44
46
|
// segmentCdn: 'https://my.org/cdn', // Set up segment cdn (optional)
|
45
47
|
// segmentIntegrations: { // Provide Segment integrations (optional)
|
@@ -50,13 +52,15 @@ const initProps: InitProps = {
|
|
50
52
|
},
|
51
53
|
|
52
54
|
posthogKey: 'TODO-key',
|
53
|
-
umamiKey: 'TODO-key',
|
55
|
+
umamiKey: 'TODO-umami-key',
|
54
56
|
umamiHostUrl: 'http://localhost:3000', // TODO where is your JS provider?
|
57
|
+
'umami-data-domains': 'TODO umami data domain',
|
55
58
|
something: 'test',
|
56
|
-
console: 'true' // Console provider
|
57
59
|
};
|
58
60
|
```
|
59
61
|
|
62
|
+
- **Note:** To enable output debugging via the web-browser console, set the `verbose` key to `true`. By default, this is set to `false`.
|
63
|
+
|
60
64
|
1. Once this is done, you can create an instance of the `trackingAPI` and start sending events.
|
61
65
|
|
62
66
|
```nolive
|
@@ -76,22 +80,20 @@ trackingAPI.trackSingleItem("MyEvent", { response: 'Good response' })
|
|
76
80
|
|
77
81
|
#### Tracking providers
|
78
82
|
|
79
|
-
Only providers with a matching
|
83
|
+
Only providers with a matching entry in the `InitProps.activeProviders` array will be started and used.
|
84
|
+
|
85
|
+
Possible values are:
|
86
|
+
* Umami
|
87
|
+
* Posthog
|
88
|
+
* Segment
|
89
|
+
* Console
|
80
90
|
|
81
|
-
```nolive
|
82
|
-
const initProps: InitProps = {
|
83
|
-
segmentKey: 'TODO-key', // TODO add your key here
|
84
|
-
posthogKey: 'TODO-key',
|
85
|
-
umamiKey: 'TODO-key',
|
86
|
-
umamiHostUrl: 'http://localhost:3000', // TODO where is your JS provider?
|
87
|
-
console: true
|
88
|
-
```
|
89
91
|
|
90
92
|
##### Modifying providers
|
91
93
|
|
92
94
|
If you know upfront that you only want to use 1 of the supported providers, you can modify `getTrackingProviders()` and remove all other providers in the providers array.
|
93
95
|
|
94
|
-
When using the providers you need to add additional dependencies to your package.json file:
|
96
|
+
When using the providers, you might need to add additional dependencies to your package.json file:
|
95
97
|
|
96
98
|
```nolive
|
97
99
|
"dependencies": {
|
@@ -99,12 +101,14 @@ When using the providers you need to add additional dependencies to your package
|
|
99
101
|
"posthog-js": "^1.194.4"
|
100
102
|
```
|
101
103
|
|
104
|
+
Depending on your local setup, this might not be necessary. For example, if you pull the ChatBot codebase as a dependency into your project, you don't need to add it as an additional dependency in your package.json.
|
105
|
+
|
102
106
|
##### Adding providers
|
103
107
|
|
104
108
|
To add another analytics provider, you need to implement 2 interfaces, `TrackingSpi` and `trackingApi`.
|
105
109
|
|
106
110
|
1. It is easiest to start by copying the `ConsoleTrackingProvider`
|
107
|
-
1.
|
111
|
+
1. Add an entry for your new provider to the `Providers` enum in `tracking_spi.ts`
|
108
112
|
1. Once you are happy enough with the implementation, add it to the array of providers in `getTrackingProviders()`
|
109
113
|
|
110
114
|
### Page flow tracking
|
@@ -98,17 +98,18 @@ export default MessageLoading;
|
|
98
98
|
const date = new Date();
|
99
99
|
|
100
100
|
const initProps: InitProps = {
|
101
|
+
verbose: false,
|
101
102
|
segmentKey: 'TODO-key', // TODO add your key here
|
102
103
|
posthogKey: 'TODO-key',
|
103
104
|
umamiKey: 'TODO-key',
|
104
|
-
umamiHostUrl: 'http://localhost:3000', // TODO where is your
|
105
|
+
umamiHostUrl: 'http://localhost:3000', // TODO where is your Umami installation?
|
105
106
|
console: true,
|
106
107
|
something: 'test'
|
107
108
|
};
|
108
109
|
|
109
110
|
const tracking = getTrackingProviders(initProps);
|
110
|
-
tracking.identify('user-123'); // TODO get real user id
|
111
|
-
tracking.trackPageView(window.
|
111
|
+
tracking.identify('user-123', { superUser: true }); // TODO get real user id + properties
|
112
|
+
tracking.trackPageView(window.location.href);
|
112
113
|
|
113
114
|
const actionEventName = 'MessageAction';
|
114
115
|
const initialMessages: MessageProps[] = [
|
@@ -1,30 +1,34 @@
|
|
1
|
-
import { TrackingSpi } from './tracking_spi';
|
1
|
+
import { InitProps, TrackingSpi } from './tracking_spi';
|
2
2
|
import { TrackingApi, TrackingEventProperties } from './tracking_api';
|
3
3
|
|
4
4
|
export class ConsoleTrackingProvider implements TrackingSpi, TrackingApi {
|
5
|
+
private verbose = false;
|
5
6
|
trackPageView(url: string | undefined) {
|
6
|
-
|
7
|
-
|
7
|
+
if (this.verbose) {
|
8
|
+
// eslint-disable-next-line no-console
|
9
|
+
console.log('ConsoleProvider pageView ', url);
|
10
|
+
}
|
8
11
|
}
|
9
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
10
|
-
registerProvider(): void {}
|
11
12
|
|
12
|
-
initialize(): void {
|
13
|
-
|
14
|
-
|
13
|
+
initialize(props: InitProps): void {
|
14
|
+
this.verbose = props.verbose;
|
15
|
+
if (this.verbose) {
|
16
|
+
// eslint-disable-next-line no-console
|
17
|
+
console.log('ConsoleProvider initialize');
|
18
|
+
}
|
15
19
|
}
|
16
20
|
|
17
|
-
identify(userID: string): void {
|
18
|
-
|
19
|
-
|
21
|
+
identify(userID: string, userProperties: TrackingEventProperties = {}): void {
|
22
|
+
if (this.verbose) {
|
23
|
+
// eslint-disable-next-line no-console
|
24
|
+
console.log('ConsoleProvider identify ', userID, userProperties);
|
25
|
+
}
|
20
26
|
}
|
21
27
|
|
22
28
|
trackSingleItem(item: string, properties?: TrackingEventProperties): void {
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
getKey(): string {
|
28
|
-
return 'console';
|
29
|
+
if (this.verbose) {
|
30
|
+
// eslint-disable-next-line no-console
|
31
|
+
console.log('ConsoleProvider: ' + item, properties);
|
32
|
+
}
|
29
33
|
}
|
30
34
|
}
|
@@ -4,13 +4,14 @@ import { TrackingApi, TrackingEventProperties } from './tracking_api';
|
|
4
4
|
import { InitProps, TrackingSpi } from './tracking_spi';
|
5
5
|
|
6
6
|
export class PosthogTrackingProvider implements TrackingSpi, TrackingApi {
|
7
|
-
|
8
|
-
return 'posthogKey';
|
9
|
-
}
|
7
|
+
private verbose = false;
|
10
8
|
|
11
9
|
initialize(props: InitProps): void {
|
12
|
-
|
13
|
-
|
10
|
+
this.verbose = props.verbose;
|
11
|
+
if (this.verbose) {
|
12
|
+
// eslint-disable-next-line no-console
|
13
|
+
console.log('PosthogProvider initialize');
|
14
|
+
}
|
14
15
|
const posthogKey = props.posthogKey as string;
|
15
16
|
|
16
17
|
posthog.init(posthogKey, {
|
@@ -21,22 +22,28 @@ export class PosthogTrackingProvider implements TrackingSpi, TrackingApi {
|
|
21
22
|
});
|
22
23
|
}
|
23
24
|
|
24
|
-
identify(userID: string): void {
|
25
|
-
|
26
|
-
|
27
|
-
|
25
|
+
identify(userID: string, userProperties: TrackingEventProperties = {}): void {
|
26
|
+
if (this.verbose) {
|
27
|
+
// eslint-disable-next-line no-console
|
28
|
+
console.log('PosthogProvider userID: ' + userID);
|
29
|
+
}
|
30
|
+
posthog.identify(userID, userProperties);
|
28
31
|
}
|
29
32
|
|
30
33
|
trackPageView(url: string | undefined): void {
|
31
|
-
|
32
|
-
|
34
|
+
if (this.verbose) {
|
35
|
+
// eslint-disable-next-line no-console
|
36
|
+
console.log('PostHogProvider url ', url);
|
37
|
+
}
|
33
38
|
// TODO posthog seems to record that automatically.
|
34
39
|
// How to not clash with this here? Just leave as no-op?
|
35
40
|
}
|
36
41
|
|
37
42
|
trackSingleItem(item: string, properties?: TrackingEventProperties): void {
|
38
|
-
|
39
|
-
|
43
|
+
if (this.verbose) {
|
44
|
+
// eslint-disable-next-line no-console
|
45
|
+
console.log('PosthogProvider: trackSingleItem ' + item, properties);
|
46
|
+
}
|
40
47
|
posthog.capture(item, { properties });
|
41
48
|
}
|
42
49
|
}
|
@@ -5,13 +5,14 @@ import { InitProps, TrackingSpi } from './tracking_spi';
|
|
5
5
|
|
6
6
|
export class SegmentTrackingProvider implements TrackingSpi, TrackingApi {
|
7
7
|
private analytics: AnalyticsBrowser | undefined;
|
8
|
-
|
9
|
-
return 'segmentKey';
|
10
|
-
}
|
8
|
+
private verbose = false;
|
11
9
|
|
12
10
|
initialize(props: InitProps): void {
|
13
|
-
|
14
|
-
|
11
|
+
this.verbose = props.verbose;
|
12
|
+
if (this.verbose) {
|
13
|
+
// eslint-disable-next-line no-console
|
14
|
+
console.log('SegmentProvider initialize');
|
15
|
+
}
|
15
16
|
const segmentKey = props.segmentKey as string;
|
16
17
|
|
17
18
|
// We need to create an object here, as ts lint is unhappy otherwise
|
@@ -32,17 +33,21 @@ export class SegmentTrackingProvider implements TrackingSpi, TrackingApi {
|
|
32
33
|
);
|
33
34
|
}
|
34
35
|
|
35
|
-
identify(userID: string): void {
|
36
|
-
|
37
|
-
|
36
|
+
identify(userID: string, userProperties: TrackingEventProperties = {}): void {
|
37
|
+
if (this.verbose) {
|
38
|
+
// eslint-disable-next-line no-console
|
39
|
+
console.log('SegmentProvider userID: ' + userID);
|
40
|
+
}
|
38
41
|
if (this.analytics) {
|
39
|
-
this.analytics.identify(userID);
|
42
|
+
this.analytics.identify(userID, userProperties);
|
40
43
|
}
|
41
44
|
}
|
42
45
|
|
43
46
|
trackPageView(url: string | undefined): void {
|
44
|
-
|
45
|
-
|
47
|
+
if (this.verbose) {
|
48
|
+
// eslint-disable-next-line no-console
|
49
|
+
console.log('SegmentProvider url ', url);
|
50
|
+
}
|
46
51
|
if (this.analytics) {
|
47
52
|
if (url) {
|
48
53
|
this.analytics.page(url);
|
@@ -53,8 +58,10 @@ export class SegmentTrackingProvider implements TrackingSpi, TrackingApi {
|
|
53
58
|
}
|
54
59
|
|
55
60
|
trackSingleItem(item: string, properties?: TrackingEventProperties): void {
|
56
|
-
|
57
|
-
|
61
|
+
if (this.verbose) {
|
62
|
+
// eslint-disable-next-line no-console
|
63
|
+
console.log('SegmentProvider: trackSingleItem ' + item, properties);
|
64
|
+
}
|
58
65
|
if (this.analytics) {
|
59
66
|
this.analytics.track(item, { properties });
|
60
67
|
}
|
@@ -6,9 +6,9 @@ class TrackingProviderProxy implements TrackingApi {
|
|
6
6
|
this.providers = providers;
|
7
7
|
}
|
8
8
|
|
9
|
-
identify(userID: string): void {
|
9
|
+
identify(userID: string, userProperties: TrackingEventProperties = {}): void {
|
10
10
|
for (const provider of this.providers) {
|
11
|
-
provider.identify(userID);
|
11
|
+
provider.identify(userID, userProperties);
|
12
12
|
}
|
13
13
|
}
|
14
14
|
|