@hyvor/design 1.1.22-beta.2 → 1.1.23
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.
|
@@ -2,13 +2,14 @@ interface InitOptions {
|
|
|
2
2
|
forceTrack?: boolean;
|
|
3
3
|
openPanelApiUrl?: string;
|
|
4
4
|
openPanelClientId?: string;
|
|
5
|
+
context?: Record<string, any>;
|
|
5
6
|
}
|
|
6
7
|
declare class Track {
|
|
7
8
|
private op;
|
|
8
9
|
private isProductionDomain;
|
|
9
|
-
init({ forceTrack, openPanelApiUrl, openPanelClientId }?: InitOptions): void;
|
|
10
|
-
private checkOp;
|
|
10
|
+
init({ forceTrack, openPanelApiUrl, openPanelClientId, context }?: InitOptions): void;
|
|
11
11
|
ready(): boolean;
|
|
12
|
+
private warnNoOp;
|
|
12
13
|
context(properties: Record<string, any>): void;
|
|
13
14
|
event(name: string, properties?: Record<string, any>): void;
|
|
14
15
|
identify(profileId: string, props: {
|
|
@@ -5,7 +5,7 @@ class Track {
|
|
|
5
5
|
const hostname = window.location.hostname;
|
|
6
6
|
return hostname === 'hyvor.com' || hostname.endsWith('.hyvor.com');
|
|
7
7
|
}
|
|
8
|
-
init({ forceTrack = false, openPanelApiUrl = 'https://op.hyvor.com/api', openPanelClientId = 'b11f6143-a6b0-4fa4-a86c-3969c01dbb1d' } = {}) {
|
|
8
|
+
init({ forceTrack = false, openPanelApiUrl = 'https://op.hyvor.com/api', openPanelClientId = 'b11f6143-a6b0-4fa4-a86c-3969c01dbb1d', context = {} } = {}) {
|
|
9
9
|
if (!forceTrack && !this.isProductionDomain()) {
|
|
10
10
|
console.log('Tracking is disabled in non-production domains.');
|
|
11
11
|
return;
|
|
@@ -17,39 +17,56 @@ class Track {
|
|
|
17
17
|
trackOutgoingLinks: true,
|
|
18
18
|
trackAttributes: true,
|
|
19
19
|
});
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
if (!this.op) {
|
|
23
|
-
throw new Error('OpenPanel is not initialized. Call track.init() first.');
|
|
20
|
+
if (Object.keys(context).length > 0) {
|
|
21
|
+
this.op.setGlobalProperties(context);
|
|
24
22
|
}
|
|
25
23
|
}
|
|
26
24
|
ready() {
|
|
27
25
|
return this.op !== undefined;
|
|
28
26
|
}
|
|
27
|
+
warnNoOp(message) {
|
|
28
|
+
console.warn(`[Track] Ignoring action: ${message} - OpenPanel is not initialized. Call track.init() first.`);
|
|
29
|
+
}
|
|
29
30
|
// set global context
|
|
30
31
|
context(properties) {
|
|
31
|
-
this.
|
|
32
|
-
|
|
32
|
+
if (this.op) {
|
|
33
|
+
this.op.setGlobalProperties(properties);
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
this.warnNoOp('set context');
|
|
37
|
+
}
|
|
33
38
|
}
|
|
34
39
|
// log an event
|
|
35
40
|
event(name, properties) {
|
|
36
|
-
this.
|
|
37
|
-
|
|
41
|
+
if (this.op) {
|
|
42
|
+
this.op.track(name, properties);
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
this.warnNoOp(`log event "${name}"`);
|
|
46
|
+
}
|
|
38
47
|
}
|
|
39
48
|
// identify user
|
|
40
49
|
identify(profileId, props) {
|
|
41
|
-
this.
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
50
|
+
if (this.op) {
|
|
51
|
+
this.op.identify({
|
|
52
|
+
profileId: profileId,
|
|
53
|
+
firstName: props.name,
|
|
54
|
+
avatar: props.avatar,
|
|
55
|
+
properties: props.properties
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
this.warnNoOp(`identify user "${profileId}"`);
|
|
60
|
+
}
|
|
48
61
|
}
|
|
49
62
|
// log out user (clear identity)
|
|
50
63
|
logout() {
|
|
51
|
-
this.
|
|
52
|
-
|
|
64
|
+
if (this.op) {
|
|
65
|
+
this.op.clear();
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
this.warnNoOp('logout user');
|
|
69
|
+
}
|
|
53
70
|
}
|
|
54
71
|
}
|
|
55
72
|
const track = new Track();
|
package/package.json
CHANGED