@arcblock/ux 3.1.30 → 3.1.31
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/lib/SessionUser/components/logged-in.js +41 -39
- package/lib/package.json.js +1 -1
- package/lib/withTracker/action/bind-wallet.d.ts +14 -0
- package/lib/withTracker/action/bind-wallet.js +1 -0
- package/lib/withTracker/action/login.d.ts +15 -0
- package/lib/withTracker/action/login.js +1 -0
- package/lib/withTracker/action/pay.d.ts +12 -0
- package/lib/withTracker/action/pay.js +1 -0
- package/lib/withTracker/action/switch-passport.d.ts +18 -0
- package/lib/withTracker/action/switch-passport.js +1 -0
- package/lib/withTracker/constant/index.d.ts +3 -0
- package/lib/withTracker/constant/index.js +6 -0
- package/lib/withTracker/env.d.ts +1 -0
- package/lib/withTracker/env.js +4 -0
- package/lib/withTracker/index.d.ts +2 -0
- package/lib/withTracker/index.js +21 -17
- package/package.json +7 -7
- package/src/SessionUser/components/logged-in.tsx +2 -0
- package/src/withTracker/action/bind-wallet.tsx +17 -0
- package/src/withTracker/action/login.tsx +18 -0
- package/src/withTracker/action/pay.tsx +14 -0
- package/src/withTracker/action/switch-passport.tsx +20 -0
- package/src/withTracker/constant/index.tsx +3 -0
- package/src/withTracker/env.tsx +1 -0
- package/src/withTracker/index.tsx +8 -11
@@ -1,8 +1,8 @@
|
|
1
1
|
import { jsxs as s, jsx as r, Fragment as W } from "react/jsx-runtime";
|
2
|
-
import { useRef as z, useEffect as
|
3
|
-
import { useMemoizedFn as n, useCreation as
|
2
|
+
import { useRef as z, useEffect as T } from "react";
|
3
|
+
import { useMemoizedFn as n, useCreation as _, useReactive as j } from "ahooks";
|
4
4
|
import f from "@arcblock/bridge";
|
5
|
-
import { Box as
|
5
|
+
import { Box as k, IconButton as G, Popper as H, ClickAwayListener as N, Fade as Q, Paper as V, Divider as S, MenuList as q, MenuItem as J } from "@mui/material";
|
6
6
|
import { Icon as K } from "@iconify/react";
|
7
7
|
import X from "@iconify-icons/material-symbols/person-outline-rounded";
|
8
8
|
import Y from "@iconify-icons/material-symbols/filter-vintage-outline-rounded";
|
@@ -15,33 +15,35 @@ import te from "../../Avatar/index.js";
|
|
15
15
|
import { getUserAvatar as oe } from "../../Util/index.js";
|
16
16
|
import ie from "./user-info.js";
|
17
17
|
import { DASHBOARD_URL as ne, PROFILE_URL as ce } from "../../Util/constant.js";
|
18
|
-
import
|
19
|
-
import { translations as
|
18
|
+
import le from "../../SessionPermission/index.js";
|
19
|
+
import { translations as ae } from "../libs/translation.js";
|
20
20
|
import { translate as se } from "../../Locale/util.js";
|
21
21
|
import pe from "./did-space.js";
|
22
22
|
import { mergeSx as ue } from "../../Util/style.js";
|
23
23
|
import { createDebug as de } from "../../Util/logger.js";
|
24
|
-
|
24
|
+
import { GA_LAST_ROLE as me } from "../../withTracker/constant/index.js";
|
25
|
+
const fe = (e) => {
|
25
26
|
const c = new URL(window.location.href);
|
26
27
|
return c.searchParams.set("inviter", e), c.toString();
|
27
28
|
}, g = de("did-connect");
|
28
|
-
function
|
29
|
+
function Te({
|
29
30
|
session: e,
|
30
31
|
onBindWallet: c = h,
|
31
|
-
isBlocklet:
|
32
|
+
isBlocklet: l = !0,
|
32
33
|
locale: u = "en",
|
33
34
|
size: b = 24,
|
34
35
|
popperType: I = "click",
|
35
36
|
sx: y,
|
36
37
|
...R
|
37
38
|
}) {
|
38
|
-
const
|
39
|
+
const a = n((t, o = {}) => se(ae, t, u, "en", o)), C = _(() => !!globalThis?.blocklet?.settings?.invite?.enabled, []), P = z(null), d = j({
|
39
40
|
open: !1
|
40
41
|
}), i = n((t = !d.open) => {
|
41
42
|
d.open = t;
|
42
|
-
}),
|
43
|
+
}), L = I === "hover" ? { onMouseEnter: () => i(!0), onMouseLeave: () => i(!1) } : { onClick: () => i() }, B = oe(e.user?.avatar?.replace(/\s/g, encodeURIComponent(" "))), D = e.useOAuth(), O = typeof e.usePasskey == "function" ? e.usePasskey() : null, v = n(({ inArcSphere: t = !1 } = {}) => {
|
44
|
+
localStorage.setItem(me, e?.user?.role);
|
43
45
|
const o = {};
|
44
|
-
t && e?.user?.sourceAppPid && (o.sourceAppPid = e.user.sourceAppPid), i(!1), e?.user?.sourceProvider === "passkey" ? O.switchPassport(e.user) : ["google", "apple", "email", "github"].includes(e?.user?.sourceProvider) ?
|
46
|
+
t && e?.user?.sourceAppPid && (o.sourceAppPid = e.user.sourceAppPid), i(!1), e?.user?.sourceProvider === "passkey" ? O.switchPassport(e.user) : ["google", "apple", "email", "github"].includes(e?.user?.sourceProvider) ? D.switchOAuthPassport(e.user) : e.switchPassport(h, o);
|
45
47
|
}), x = n(({ userSession: t, inArcSphere: o = !1 } = {}) => new Promise((F) => {
|
46
48
|
const A = {};
|
47
49
|
o && e.user.sourceAppPid && (A.sourceAppPid = e.user.sourceAppPid);
|
@@ -56,16 +58,16 @@ function We({
|
|
56
58
|
})), w = n(({ inArcSphere: t = !1 } = {}) => {
|
57
59
|
const o = {};
|
58
60
|
t && e.user.sourceAppPid && (o.sourceAppPid = e.user.sourceAppPid), i(!1), e.switchProfile(h, o);
|
59
|
-
}), M = n(() => {
|
60
|
-
i(!1), e.logout();
|
61
61
|
}), E = n(() => {
|
62
|
+
i(!1), e.logout();
|
63
|
+
}), M = n(() => {
|
62
64
|
i(!1), e.bindWallet(c);
|
63
65
|
}), U = n(() => {
|
64
66
|
i(!1);
|
65
|
-
const t =
|
66
|
-
ee(t), re.success(
|
67
|
+
const t = fe(e.user.did);
|
68
|
+
ee(t), re.success(a("inviteCopied"));
|
67
69
|
});
|
68
|
-
return
|
70
|
+
return T(() => {
|
69
71
|
f.registerBlocklet("callSwitchPassport", () => {
|
70
72
|
g("bridge registerBlocklet: callSwitchPassport"), v({ inArcSphere: !0 });
|
71
73
|
}), f.registerBlocklet("callSwitchDid", () => {
|
@@ -74,7 +76,7 @@ function We({
|
|
74
76
|
g("bridge registerBlocklet: callSwitchProfile"), w({ inArcSphere: !0 });
|
75
77
|
});
|
76
78
|
}, []), /* @__PURE__ */ s(
|
77
|
-
|
79
|
+
k,
|
78
80
|
{
|
79
81
|
sx: ue(
|
80
82
|
{
|
@@ -88,19 +90,19 @@ function We({
|
|
88
90
|
...R,
|
89
91
|
children: [
|
90
92
|
/* @__PURE__ */ r(
|
91
|
-
|
93
|
+
G,
|
92
94
|
{
|
93
95
|
ref: P,
|
94
96
|
size: "medium",
|
95
97
|
"data-cy": "sessionManager-logout-popup",
|
96
98
|
className: "arc-session-user-logged-in",
|
97
99
|
"aria-label": "User info button",
|
98
|
-
...
|
99
|
-
children: /* @__PURE__ */ r(te, { variant: "circle", did: e.user.did, src:
|
100
|
+
...L,
|
101
|
+
children: /* @__PURE__ */ r(te, { variant: "circle", did: e.user.did, src: B, size: b, shape: "circle" })
|
100
102
|
}
|
101
103
|
),
|
102
104
|
/* @__PURE__ */ r(
|
103
|
-
|
105
|
+
H,
|
104
106
|
{
|
105
107
|
open: d.open,
|
106
108
|
anchorEl: P.current,
|
@@ -110,13 +112,13 @@ function We({
|
|
110
112
|
zIndex: 1600
|
111
113
|
},
|
112
114
|
children: ({ TransitionProps: t }) => /* @__PURE__ */ r(
|
113
|
-
|
115
|
+
N,
|
114
116
|
{
|
115
117
|
onClickAway: (o) => {
|
116
118
|
o.preventDefault(), o.stopPropagation(), i(!1);
|
117
119
|
},
|
118
|
-
children: /* @__PURE__ */ r(
|
119
|
-
|
120
|
+
children: /* @__PURE__ */ r(Q, { ...t, timeout: 350, children: /* @__PURE__ */ s(
|
121
|
+
V,
|
120
122
|
{
|
121
123
|
variant: "outlined",
|
122
124
|
sx: {
|
@@ -129,22 +131,22 @@ function We({
|
|
129
131
|
ie,
|
130
132
|
{
|
131
133
|
locale: u,
|
132
|
-
isBlocklet:
|
134
|
+
isBlocklet: l,
|
133
135
|
session: e,
|
134
136
|
onSwitchPassport: v,
|
135
137
|
onSwitchAccount: x,
|
136
138
|
onSwitchProfile: w,
|
137
|
-
onBindWallet:
|
139
|
+
onBindWallet: M
|
138
140
|
}
|
139
141
|
),
|
140
|
-
/* @__PURE__ */ r(
|
141
|
-
/* @__PURE__ */ s(
|
142
|
-
|
143
|
-
/* @__PURE__ */ r(
|
142
|
+
/* @__PURE__ */ r(S, { sx: { m: "0 !important" } }),
|
143
|
+
/* @__PURE__ */ s(q, { sx: { p: 0 }, children: [
|
144
|
+
l ? /* @__PURE__ */ s(W, { children: [
|
145
|
+
/* @__PURE__ */ r(le, { session: e, children: /* @__PURE__ */ r(
|
144
146
|
p,
|
145
147
|
{
|
146
148
|
icon: Y,
|
147
|
-
title:
|
149
|
+
title: a("dashboard"),
|
148
150
|
component: "a",
|
149
151
|
href: ne,
|
150
152
|
sx: { display: "block", textDecoration: "none", color: "inherit" }
|
@@ -154,7 +156,7 @@ function We({
|
|
154
156
|
p,
|
155
157
|
{
|
156
158
|
icon: X,
|
157
|
-
title:
|
159
|
+
title: a("profile"),
|
158
160
|
component: "a",
|
159
161
|
href: ce,
|
160
162
|
sx: { display: "block", textDecoration: "none", color: "inherit" }
|
@@ -164,23 +166,23 @@ function We({
|
|
164
166
|
p,
|
165
167
|
{
|
166
168
|
icon: $,
|
167
|
-
title:
|
169
|
+
title: a("invite"),
|
168
170
|
component: "div",
|
169
171
|
onClick: U,
|
170
172
|
sx: { display: "block", color: "inherit" }
|
171
173
|
}
|
172
174
|
),
|
173
|
-
/* @__PURE__ */ r(
|
175
|
+
/* @__PURE__ */ r(S, { sx: { m: "0 !important" } }),
|
174
176
|
/* @__PURE__ */ r(pe, { session: e, locale: u })
|
175
177
|
] }) : null,
|
176
178
|
/* @__PURE__ */ r(
|
177
179
|
p,
|
178
180
|
{
|
179
181
|
icon: Z,
|
180
|
-
title:
|
182
|
+
title: a("logout"),
|
181
183
|
component: "div",
|
182
184
|
sx: { color: "error.main" },
|
183
|
-
onClick:
|
185
|
+
onClick: E,
|
184
186
|
"data-cy": "sessionManager-logout-trigger"
|
185
187
|
}
|
186
188
|
)
|
@@ -199,9 +201,9 @@ function We({
|
|
199
201
|
function p({
|
200
202
|
icon: e,
|
201
203
|
title: c,
|
202
|
-
...
|
204
|
+
...l
|
203
205
|
}) {
|
204
|
-
return /* @__PURE__ */ r(
|
206
|
+
return /* @__PURE__ */ r(k, { ...l, sx: { p: 0.5, ...l?.sx }, children: /* @__PURE__ */ s(
|
205
207
|
J,
|
206
208
|
{
|
207
209
|
sx: {
|
@@ -222,5 +224,5 @@ function p({
|
|
222
224
|
) });
|
223
225
|
}
|
224
226
|
export {
|
225
|
-
|
227
|
+
Te as default
|
226
228
|
};
|
package/lib/package.json.js
CHANGED
@@ -0,0 +1,14 @@
|
|
1
|
+
import { LiteralUnion } from 'type-fest';
|
2
|
+
export interface BindWalletEvent {
|
3
|
+
action: 'bindWalletSuccess' | 'bindWalletFailed';
|
4
|
+
provider: LiteralUnion<'wallet' | 'apple' | 'github' | 'google' | 'email' | 'twitter' | 'passkey', string>;
|
5
|
+
}
|
6
|
+
export interface BindWalletSuccessEvent extends BindWalletEvent {
|
7
|
+
action: 'bindWalletSuccess';
|
8
|
+
success: true;
|
9
|
+
}
|
10
|
+
export interface BindWalletFailedEvent extends BindWalletEvent {
|
11
|
+
action: 'bindWalletFailed';
|
12
|
+
success: false;
|
13
|
+
errorMessage: string;
|
14
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
|
@@ -0,0 +1,15 @@
|
|
1
|
+
import { LiteralUnion } from 'type-fest';
|
2
|
+
export interface LoginEvent {
|
3
|
+
action: 'loginSuccess' | 'loginFailed';
|
4
|
+
provider: LiteralUnion<'wallet' | 'apple' | 'github' | 'google' | 'email' | 'twitter' | 'passkey', string>;
|
5
|
+
success: boolean;
|
6
|
+
}
|
7
|
+
export interface LoginSuccessEvent extends LoginEvent {
|
8
|
+
action: 'loginSuccess';
|
9
|
+
success: true;
|
10
|
+
}
|
11
|
+
export interface LoginFailedEvent extends LoginEvent {
|
12
|
+
action: 'loginFailed';
|
13
|
+
success: false;
|
14
|
+
errorMessage: string;
|
15
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
|
@@ -0,0 +1,12 @@
|
|
1
|
+
export interface PayEvent {
|
2
|
+
action: 'paySuccess' | 'payFailed';
|
3
|
+
checkoutSessionMode: string;
|
4
|
+
success: boolean;
|
5
|
+
}
|
6
|
+
export interface PaySuccessEvent extends PayEvent {
|
7
|
+
success: true;
|
8
|
+
}
|
9
|
+
export interface PayFailedEvent extends PayEvent {
|
10
|
+
success: false;
|
11
|
+
errorMessage: string;
|
12
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
|
@@ -0,0 +1,18 @@
|
|
1
|
+
export interface SwitchPassportEvent {
|
2
|
+
action: 'switchPassportSuccess' | 'switchPassportFailed';
|
3
|
+
success: boolean;
|
4
|
+
}
|
5
|
+
export interface SwitchPassportSuccessEvent extends SwitchPassportEvent {
|
6
|
+
success: true;
|
7
|
+
/**
|
8
|
+
*
|
9
|
+
* @example guest -> admin
|
10
|
+
* @type {string}
|
11
|
+
* @memberof SwitchPassportEvent
|
12
|
+
*/
|
13
|
+
change: string;
|
14
|
+
}
|
15
|
+
export interface SwitchPassportFailedEvent extends SwitchPassportEvent {
|
16
|
+
success: false;
|
17
|
+
errorMessage: string;
|
18
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
|
@@ -0,0 +1 @@
|
|
1
|
+
export declare const googleAnalyticsMeasurementId: string;
|
package/lib/withTracker/index.js
CHANGED
@@ -1,22 +1,26 @@
|
|
1
|
-
import { jsx as
|
2
|
-
import { useLocation as
|
3
|
-
import { useMount as
|
4
|
-
import
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
1
|
+
import { jsx as p } from "react/jsx-runtime";
|
2
|
+
import { useLocation as f } from "react-router-dom";
|
3
|
+
import { useMount as s, useDeepCompareEffect as u } from "ahooks";
|
4
|
+
import r from "react-ga4";
|
5
|
+
import { default as A } from "react-ga4";
|
6
|
+
import { googleAnalyticsMeasurementId as n } from "./env.js";
|
7
|
+
n && r.initialize(n);
|
8
|
+
const h = (i) => {
|
9
|
+
const a = (o, t = document.title) => {
|
10
|
+
n && r.send({ hitType: "pageview", page: o, title: t });
|
11
|
+
}, c = (o, t, e, m) => {
|
12
|
+
n && r.event({ category: o, action: t, label: e, value: m, transport: "beacon" });
|
10
13
|
};
|
11
|
-
return
|
12
|
-
const
|
13
|
-
return
|
14
|
-
|
15
|
-
}),
|
16
|
-
|
17
|
-
}, [
|
14
|
+
return window.trackPage = a, window.trackEvent = c, function(t) {
|
15
|
+
const e = f();
|
16
|
+
return s(() => {
|
17
|
+
a(e.pathname);
|
18
|
+
}), u(() => {
|
19
|
+
a(e.pathname);
|
20
|
+
}, [e.pathname]), /* @__PURE__ */ p(i, { ...t });
|
18
21
|
};
|
19
22
|
};
|
20
23
|
export {
|
21
|
-
|
24
|
+
A as ReactGA,
|
25
|
+
h as default
|
22
26
|
};
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@arcblock/ux",
|
3
|
-
"version": "3.1.
|
3
|
+
"version": "3.1.31",
|
4
4
|
"description": "Common used react components for arcblock products",
|
5
5
|
"keywords": [
|
6
6
|
"react",
|
@@ -68,16 +68,16 @@
|
|
68
68
|
"react": "^19.0.0",
|
69
69
|
"react-router-dom": "^6.22.3"
|
70
70
|
},
|
71
|
-
"gitHead": "
|
71
|
+
"gitHead": "a904bcfb38156f7cdff5b2134c126b19d528f4b2",
|
72
72
|
"dependencies": {
|
73
|
-
"@arcblock/bridge": "3.1.
|
73
|
+
"@arcblock/bridge": "3.1.31",
|
74
74
|
"@arcblock/did": "^1.21.3",
|
75
75
|
"@arcblock/did-motif": "^1.1.14",
|
76
|
-
"@arcblock/icons": "3.1.
|
77
|
-
"@arcblock/nft-display": "3.1.
|
78
|
-
"@arcblock/react-hooks": "3.1.
|
76
|
+
"@arcblock/icons": "3.1.31",
|
77
|
+
"@arcblock/nft-display": "3.1.31",
|
78
|
+
"@arcblock/react-hooks": "3.1.31",
|
79
79
|
"@blocklet/js-sdk": "^1.16.49-beta-20250823-082650-626c1473",
|
80
|
-
"@blocklet/theme": "3.1.
|
80
|
+
"@blocklet/theme": "3.1.31",
|
81
81
|
"@fontsource/roboto": "~5.1.1",
|
82
82
|
"@fontsource/ubuntu-mono": "^5.2.6",
|
83
83
|
"@iconify-icons/logos": "^1.2.36",
|
@@ -33,6 +33,7 @@ import type { Locale, Session } from '../../type';
|
|
33
33
|
import DidSpace from './did-space';
|
34
34
|
import { mergeSx } from '../../Util/style';
|
35
35
|
import { createDebug } from '../../Util/logger';
|
36
|
+
import { GA_LAST_ROLE } from '../../withTracker/constant';
|
36
37
|
|
37
38
|
const getInviteLink = (inviter: string) => {
|
38
39
|
const url = new URL(window.location.href);
|
@@ -86,6 +87,7 @@ export default function LoggedIn({
|
|
86
87
|
const oauth = session.useOAuth();
|
87
88
|
const passkey = typeof session.usePasskey === 'function' ? session.usePasskey() : null;
|
88
89
|
const handleSwitchPassport = useMemoizedFn(({ inArcSphere = false } = {}) => {
|
90
|
+
localStorage.setItem(GA_LAST_ROLE, session?.user?.role);
|
89
91
|
const extraParams: Record<string, any> = {};
|
90
92
|
if (inArcSphere) {
|
91
93
|
if (session?.user?.sourceAppPid) {
|
@@ -0,0 +1,17 @@
|
|
1
|
+
import type { LiteralUnion } from 'type-fest';
|
2
|
+
|
3
|
+
export interface BindWalletEvent {
|
4
|
+
action: 'bindWalletSuccess' | 'bindWalletFailed';
|
5
|
+
provider: LiteralUnion<'wallet' | 'apple' | 'github' | 'google' | 'email' | 'twitter' | 'passkey', string>;
|
6
|
+
}
|
7
|
+
|
8
|
+
export interface BindWalletSuccessEvent extends BindWalletEvent {
|
9
|
+
action: 'bindWalletSuccess';
|
10
|
+
success: true;
|
11
|
+
}
|
12
|
+
|
13
|
+
export interface BindWalletFailedEvent extends BindWalletEvent {
|
14
|
+
action: 'bindWalletFailed';
|
15
|
+
success: false;
|
16
|
+
errorMessage: string;
|
17
|
+
}
|
@@ -0,0 +1,18 @@
|
|
1
|
+
import type { LiteralUnion } from 'type-fest';
|
2
|
+
|
3
|
+
export interface LoginEvent {
|
4
|
+
action: 'loginSuccess' | 'loginFailed';
|
5
|
+
provider: LiteralUnion<'wallet' | 'apple' | 'github' | 'google' | 'email' | 'twitter' | 'passkey', string>;
|
6
|
+
success: boolean;
|
7
|
+
}
|
8
|
+
|
9
|
+
export interface LoginSuccessEvent extends LoginEvent {
|
10
|
+
action: 'loginSuccess';
|
11
|
+
success: true;
|
12
|
+
}
|
13
|
+
|
14
|
+
export interface LoginFailedEvent extends LoginEvent {
|
15
|
+
action: 'loginFailed';
|
16
|
+
success: false;
|
17
|
+
errorMessage: string;
|
18
|
+
}
|
@@ -0,0 +1,14 @@
|
|
1
|
+
export interface PayEvent {
|
2
|
+
action: 'paySuccess' | 'payFailed';
|
3
|
+
checkoutSessionMode: string;
|
4
|
+
success: boolean;
|
5
|
+
}
|
6
|
+
|
7
|
+
export interface PaySuccessEvent extends PayEvent {
|
8
|
+
success: true;
|
9
|
+
}
|
10
|
+
|
11
|
+
export interface PayFailedEvent extends PayEvent {
|
12
|
+
success: false;
|
13
|
+
errorMessage: string;
|
14
|
+
}
|
@@ -0,0 +1,20 @@
|
|
1
|
+
export interface SwitchPassportEvent {
|
2
|
+
action: 'switchPassportSuccess' | 'switchPassportFailed';
|
3
|
+
success: boolean;
|
4
|
+
}
|
5
|
+
|
6
|
+
export interface SwitchPassportSuccessEvent extends SwitchPassportEvent {
|
7
|
+
success: true;
|
8
|
+
/**
|
9
|
+
*
|
10
|
+
* @example guest -> admin
|
11
|
+
* @type {string}
|
12
|
+
* @memberof SwitchPassportEvent
|
13
|
+
*/
|
14
|
+
change: string;
|
15
|
+
}
|
16
|
+
|
17
|
+
export interface SwitchPassportFailedEvent extends SwitchPassportEvent {
|
18
|
+
success: false;
|
19
|
+
errorMessage: string;
|
20
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
export const googleAnalyticsMeasurementId: string = window.blocklet?.GA_MEASUREMENT_ID || '';
|
@@ -1,29 +1,26 @@
|
|
1
1
|
import { useLocation } from 'react-router-dom';
|
2
2
|
import { useMount, useDeepCompareEffect } from 'ahooks';
|
3
3
|
import ReactGA from 'react-ga4';
|
4
|
+
import { googleAnalyticsMeasurementId } from './env';
|
4
5
|
|
6
|
+
if (googleAnalyticsMeasurementId) {
|
7
|
+
ReactGA.initialize(googleAnalyticsMeasurementId);
|
8
|
+
}
|
9
|
+
|
10
|
+
export { ReactGA };
|
5
11
|
export default <P extends object>(WrappedComponent: React.ComponentType<P>) => {
|
6
|
-
const trackingId = window.blocklet?.GA_MEASUREMENT_ID || '';
|
7
12
|
const trackPage = (page: string, title = document.title) => {
|
8
|
-
if (
|
9
|
-
return;
|
10
|
-
}
|
11
|
-
|
12
|
-
if (trackingId) {
|
13
|
+
if (googleAnalyticsMeasurementId) {
|
13
14
|
ReactGA.send({ hitType: 'pageview', page, title });
|
14
15
|
}
|
15
16
|
};
|
16
17
|
|
17
18
|
const trackEvent = (category: string, action: string, label: string, value: number) => {
|
18
|
-
if (
|
19
|
+
if (googleAnalyticsMeasurementId) {
|
19
20
|
ReactGA.event({ category, action, label, value, transport: 'beacon' });
|
20
21
|
}
|
21
22
|
};
|
22
23
|
|
23
|
-
if (trackingId) {
|
24
|
-
ReactGA.initialize(trackingId);
|
25
|
-
}
|
26
|
-
|
27
24
|
// @ts-ignore
|
28
25
|
window.trackPage = trackPage;
|
29
26
|
// @ts-ignore
|