@arcblock/ux 2.10.44 → 2.10.46
Sign up to get free protection for your applications and to get access to all the features.
- package/lib/DID/index.js +45 -27
- package/lib/withTracker/README.md +16 -13
- package/lib/withTracker/index.d.ts +1 -1
- package/lib/withTracker/index.js +25 -33
- package/package.json +6 -5
- package/src/DID/index.tsx +48 -21
- package/src/withTracker/README.md +16 -13
- package/src/withTracker/index.js +20 -33
package/lib/DID/index.js
CHANGED
@@ -1,25 +1,26 @@
|
|
1
1
|
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
2
2
|
import { getDIDMotifInfo } from '@arcblock/did-motif';
|
3
|
-
import
|
3
|
+
import { types } from '@ocap/mcrypto';
|
4
|
+
import QRCode from 'qrcode.react';
|
4
5
|
import { Icon } from '@iconify/react';
|
5
|
-
import
|
6
|
+
import IconQrCode from '@iconify-icons/material-symbols/qr-code-rounded';
|
7
|
+
import { Box, Dialog, DialogContent, Typography } from '@mui/material';
|
6
8
|
import { useCreation, useMemoizedFn } from 'ahooks';
|
7
|
-
import QRCode from 'qrcode.react';
|
8
9
|
import React, { forwardRef, useImperativeHandle, useRef, useState } from 'react';
|
9
10
|
import Address from '../Address';
|
10
11
|
import Avatar from '../Avatar';
|
11
12
|
import { temp as colors } from '../Colors';
|
12
13
|
import { DID_PREFIX } from '../Util/constant';
|
13
14
|
import { translate } from '../Locale/util';
|
14
|
-
import { getDIDColor,
|
15
|
+
import { getDIDColor, isEthereumDid } from '../Util';
|
15
16
|
const translations = {
|
16
17
|
en: {
|
17
|
-
scanQrcode: 'Scan with DID Wallet to
|
18
|
+
scanQrcode: 'Scan with DID Wallet to view this {role}',
|
18
19
|
download: 'Download',
|
19
20
|
downloadTips: "Don't have DID Wallet ?"
|
20
21
|
},
|
21
22
|
zh: {
|
22
|
-
scanQrcode: '
|
23
|
+
scanQrcode: '使用 DID Wallet 扫码查看该 {role}',
|
23
24
|
download: '下载',
|
24
25
|
downloadTips: '没有 DID Wallet ?'
|
25
26
|
}
|
@@ -45,6 +46,16 @@ const isSquareMotif = roleType => {
|
|
45
46
|
};
|
46
47
|
return !roles[roleType];
|
47
48
|
};
|
49
|
+
const getRoleName = roleType => {
|
50
|
+
const [roleName] = Object.entries(types.RoleType).find(item => item[1] === roleType) || [];
|
51
|
+
if (roleName) {
|
52
|
+
// UpperCase first word, example:
|
53
|
+
// ROLE_ACCOUNT -> Account
|
54
|
+
// ROLE_APPLICATION -> Application
|
55
|
+
return roleName.toLowerCase().replace(/role_(\S)/g, (_, $1) => $1.toUpperCase());
|
56
|
+
}
|
57
|
+
return 'Address';
|
58
|
+
};
|
48
59
|
const getAvatarSize = (didMotifInfo, isEthDid, size) => {
|
49
60
|
if (isEthDid) {
|
50
61
|
return size * 0.75;
|
@@ -104,24 +115,19 @@ const DID = /*#__PURE__*/forwardRef((props, ref) => {
|
|
104
115
|
const [open, setOpen] = useState(false);
|
105
116
|
const isEthDid = isEthereumDid(did);
|
106
117
|
const didMotifInfo = isEthDid ? undefined : getDIDMotifInfo(did);
|
107
|
-
const
|
108
|
-
const prepend = [/*#__PURE__*/_jsx("span", {
|
118
|
+
const getPrepend = avatarSize => [/*#__PURE__*/_jsx("span", {
|
109
119
|
style: {
|
110
120
|
flex: '0 0 auto',
|
111
|
-
fontSize,
|
112
121
|
color: getFontColor(did, didMotifInfo, isEthDid)
|
113
122
|
},
|
114
123
|
children: "DID:"
|
115
124
|
}, "prefix-did"), /*#__PURE__*/_jsx("span", {
|
116
125
|
className: "did-address-text",
|
117
|
-
style: {
|
118
|
-
fontSize
|
119
|
-
},
|
120
126
|
children: "ABT:"
|
121
127
|
}, "prefix-abt"), showAvatar && /*#__PURE__*/_jsx(Avatar, {
|
122
128
|
src: "",
|
123
129
|
did: did,
|
124
|
-
size: getAvatarSize(didMotifInfo, isEthDid,
|
130
|
+
size: getAvatarSize(didMotifInfo, isEthDid, avatarSize || 18),
|
125
131
|
style: {
|
126
132
|
display: 'inline-flex',
|
127
133
|
alignItems: 'center',
|
@@ -179,7 +185,7 @@ const DID = /*#__PURE__*/forwardRef((props, ref) => {
|
|
179
185
|
content: `${DID_PREFIX}${did}`,
|
180
186
|
...rest,
|
181
187
|
ref: addressRef,
|
182
|
-
prepend:
|
188
|
+
prepend: getPrepend(rest.size),
|
183
189
|
append: /*#__PURE__*/_jsxs(_Fragment, {
|
184
190
|
children: [showQrcode ? /*#__PURE__*/_jsx(Box, {
|
185
191
|
id: "did-qrcode-button",
|
@@ -195,20 +201,31 @@ const DID = /*#__PURE__*/forwardRef((props, ref) => {
|
|
195
201
|
}) : null, rest.append]
|
196
202
|
}),
|
197
203
|
children: did
|
198
|
-
}), /*#__PURE__*/
|
204
|
+
}), /*#__PURE__*/_jsx(Dialog, {
|
199
205
|
open: open,
|
200
206
|
onClose: closeQrCode,
|
201
207
|
maxWidth: "sm",
|
202
|
-
|
208
|
+
PaperProps: {
|
209
|
+
sx: {
|
210
|
+
boxShadow: 'none',
|
211
|
+
borderRadius: '12px'
|
212
|
+
}
|
213
|
+
},
|
214
|
+
children: /*#__PURE__*/_jsxs(DialogContent, {
|
203
215
|
align: "center",
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
216
|
+
sx: {
|
217
|
+
p: 3
|
218
|
+
},
|
219
|
+
children: [/*#__PURE__*/_jsx(Typography, {
|
220
|
+
sx: {
|
221
|
+
mb: 2,
|
222
|
+
fontWeight: 500,
|
223
|
+
fontSize: 18
|
224
|
+
},
|
225
|
+
children: t('scanQrcode', {
|
226
|
+
role: getRoleName(didMotifInfo?.roleType)
|
227
|
+
})
|
228
|
+
}), /*#__PURE__*/_jsx(QRCode
|
212
229
|
// eslint-disable-next-line max-len
|
213
230
|
, {
|
214
231
|
value: `abt://abtwallet.io/i?did=${DID_PREFIX}${did}&action=didRecognize&chainID=${chainId || DEFAULT_CHAIN_ID}`,
|
@@ -217,14 +234,15 @@ const DID = /*#__PURE__*/forwardRef((props, ref) => {
|
|
217
234
|
level: "M"
|
218
235
|
}), /*#__PURE__*/_jsx(Box, {
|
219
236
|
sx: {
|
220
|
-
|
237
|
+
mt: 1.5,
|
221
238
|
textAlign: 'center'
|
222
239
|
},
|
223
240
|
children: /*#__PURE__*/_jsx(Address, {
|
224
241
|
locale: locale,
|
225
242
|
content: `${DID_PREFIX}${did}`,
|
226
|
-
prepend:
|
243
|
+
prepend: getPrepend(16),
|
227
244
|
...rest,
|
245
|
+
size: 16,
|
228
246
|
copyable: true,
|
229
247
|
children: did
|
230
248
|
})
|
@@ -237,7 +255,7 @@ const DID = /*#__PURE__*/forwardRef((props, ref) => {
|
|
237
255
|
},
|
238
256
|
children: downloadTips
|
239
257
|
})]
|
240
|
-
})
|
258
|
+
})
|
241
259
|
})]
|
242
260
|
});
|
243
261
|
});
|
@@ -1,13 +1,13 @@
|
|
1
1
|
# withTracker
|
2
2
|
|
3
|
-
Add
|
3
|
+
Add google analytics reporting to your application.
|
4
4
|
|
5
5
|
## Usage
|
6
6
|
|
7
7
|
### Installation
|
8
8
|
|
9
9
|
```bash
|
10
|
-
yarn add
|
10
|
+
yarn add @arcblock/ux
|
11
11
|
```
|
12
12
|
|
13
13
|
### Configuration & Usage
|
@@ -16,19 +16,22 @@ In your application entry file
|
|
16
16
|
|
17
17
|
```javascript
|
18
18
|
import React from 'react';
|
19
|
-
import ReactDOM from 'react-dom';
|
20
19
|
import withTracker from '@arcblock/ux/lib/withTracker';
|
20
|
+
import { BrowserRouter as Router } from 'react-router-dom';
|
21
21
|
|
22
|
-
|
23
|
-
|
24
|
-
}
|
22
|
+
const App = () => <p>My awesome application</p>;
|
23
|
+
const TrackedApp = withTracker(App);
|
25
24
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
gaAccount: '',
|
30
|
-
sentryDSN: '',
|
31
|
-
});
|
25
|
+
export default function WrappedApp() {
|
26
|
+
// While the blocklet is deploy to a sub path, this will be work properly.
|
27
|
+
const basename = window?.blocklet?.prefix || '/';
|
32
28
|
|
33
|
-
|
29
|
+
return (
|
30
|
+
<Router basename={basename}>
|
31
|
+
<TrackedApp />
|
32
|
+
</Router>
|
33
|
+
);
|
34
|
+
}
|
34
35
|
```
|
36
|
+
|
37
|
+
Then you can use `window.trackPage(path, title)` and `window.trackEvent(category, action, label, value)` to track page views and events.
|
@@ -1,2 +1,2 @@
|
|
1
|
-
declare function _default(WrappedComponent: any
|
1
|
+
declare function _default(WrappedComponent: any): (props: any) => import("react/jsx-runtime").JSX.Element;
|
2
2
|
export default _default;
|
package/lib/withTracker/index.js
CHANGED
@@ -1,38 +1,37 @@
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
2
|
-
/* eslint-disable import/no-unresolved */
|
3
|
-
import ReactGA from 'react-ga';
|
4
|
-
import * as Sentry from '@sentry/browser';
|
5
|
-
import { useMount, useDeepCompareEffect } from 'ahooks';
|
6
2
|
import { useLocation } from 'react-router-dom';
|
7
|
-
import
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
sentryDSN
|
13
|
-
} = options;
|
14
|
-
if (gaAccount) {
|
15
|
-
ReactGA.initialize(gaAccount);
|
16
|
-
}
|
17
|
-
if (sentryDSN) {
|
18
|
-
Sentry.init({
|
19
|
-
dsn: sentryDSN,
|
20
|
-
release: appVersion || 'unknown',
|
21
|
-
environment: process.env.NODE_ENV || 'development'
|
22
|
-
});
|
23
|
-
}
|
24
|
-
const trackPage = page => {
|
3
|
+
import { useMount, useDeepCompareEffect } from 'ahooks';
|
4
|
+
import ReactGA from 'react-ga4';
|
5
|
+
export default WrappedComponent => {
|
6
|
+
const trackingId = window.blocklet?.GA_MEASUREMENT_ID || '';
|
7
|
+
const trackPage = (page, title = document.title) => {
|
25
8
|
if (!process.env.NODE_ENV || process.env.NODE_ENV === 'development') {
|
26
9
|
return;
|
27
10
|
}
|
28
|
-
if (
|
29
|
-
ReactGA.
|
11
|
+
if (trackingId) {
|
12
|
+
ReactGA.send({
|
13
|
+
hitType: 'pageview',
|
30
14
|
page,
|
31
|
-
|
15
|
+
title
|
32
16
|
});
|
33
|
-
ReactGA.pageview(page);
|
34
17
|
}
|
35
18
|
};
|
19
|
+
const trackEvent = (category, action, label, value) => {
|
20
|
+
if (trackingId) {
|
21
|
+
ReactGA.event({
|
22
|
+
category,
|
23
|
+
action,
|
24
|
+
label,
|
25
|
+
value,
|
26
|
+
transport: 'beacon'
|
27
|
+
});
|
28
|
+
}
|
29
|
+
};
|
30
|
+
if (trackingId) {
|
31
|
+
ReactGA.initialize(trackingId);
|
32
|
+
}
|
33
|
+
window.trackPage = trackPage;
|
34
|
+
window.trackEvent = trackEvent;
|
36
35
|
return function TrackedComponent(props) {
|
37
36
|
const location = useLocation();
|
38
37
|
useMount(() => {
|
@@ -41,13 +40,6 @@ export default (WrappedComponent, options = {}) => {
|
|
41
40
|
useDeepCompareEffect(() => {
|
42
41
|
trackPage(location.pathname);
|
43
42
|
}, [location.pathname]);
|
44
|
-
if (process.env.NODE_ENV === 'production') {
|
45
|
-
return /*#__PURE__*/_jsx(ErrorBoundary, {
|
46
|
-
children: /*#__PURE__*/_jsx(WrappedComponent, {
|
47
|
-
...props
|
48
|
-
})
|
49
|
-
});
|
50
|
-
}
|
51
43
|
return /*#__PURE__*/_jsx(WrappedComponent, {
|
52
44
|
...props
|
53
45
|
});
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@arcblock/ux",
|
3
|
-
"version": "2.10.
|
3
|
+
"version": "2.10.46",
|
4
4
|
"description": "Common used react components for arcblock products",
|
5
5
|
"keywords": [
|
6
6
|
"react",
|
@@ -64,12 +64,12 @@
|
|
64
64
|
"react": ">=18.2.0",
|
65
65
|
"react-router-dom": ">=6.22.3"
|
66
66
|
},
|
67
|
-
"gitHead": "
|
67
|
+
"gitHead": "ae503a7f61a29ddfe9fdc5a1b0e040fa5890dc75",
|
68
68
|
"dependencies": {
|
69
69
|
"@arcblock/did-motif": "^1.1.13",
|
70
|
-
"@arcblock/icons": "^2.10.
|
71
|
-
"@arcblock/nft-display": "^2.10.
|
72
|
-
"@arcblock/react-hooks": "^2.10.
|
70
|
+
"@arcblock/icons": "^2.10.46",
|
71
|
+
"@arcblock/nft-display": "^2.10.46",
|
72
|
+
"@arcblock/react-hooks": "^2.10.46",
|
73
73
|
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
|
74
74
|
"@fontsource/inter": "^5.0.16",
|
75
75
|
"@fontsource/ubuntu-mono": "^5.0.18",
|
@@ -101,6 +101,7 @@
|
|
101
101
|
"qrcode.react": "^3.1.0",
|
102
102
|
"react-cookie-consent": "^6.4.1",
|
103
103
|
"react-error-boundary": "^3.1.4",
|
104
|
+
"react-ga4": "^2.1.0",
|
104
105
|
"react-helmet": "^6.1.0",
|
105
106
|
"react-intersection-observer": "^8.34.0",
|
106
107
|
"react-lottie-player": "^1.4.3",
|
package/src/DID/index.tsx
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
import { getDIDMotifInfo } from '@arcblock/did-motif';
|
2
|
-
import
|
2
|
+
import { types } from '@ocap/mcrypto';
|
3
|
+
import QRCode from 'qrcode.react';
|
3
4
|
import { Icon } from '@iconify/react';
|
4
|
-
import
|
5
|
+
import IconQrCode from '@iconify-icons/material-symbols/qr-code-rounded';
|
6
|
+
import { Box, Dialog, DialogContent, Typography } from '@mui/material';
|
5
7
|
import { useCreation, useMemoizedFn } from 'ahooks';
|
6
|
-
import QRCode from 'qrcode.react';
|
7
8
|
import React, { forwardRef, useImperativeHandle, useRef, useState } from 'react';
|
8
9
|
|
9
10
|
import Address, { IDidAddressWrapper } from '../Address';
|
@@ -13,16 +14,16 @@ import { DID_PREFIX } from '../Util/constant';
|
|
13
14
|
|
14
15
|
import { HTMLDidAddressElement } from '../Address/did-address';
|
15
16
|
import { translate } from '../Locale/util';
|
16
|
-
import { getDIDColor,
|
17
|
+
import { getDIDColor, isEthereumDid } from '../Util';
|
17
18
|
|
18
19
|
const translations = {
|
19
20
|
en: {
|
20
|
-
scanQrcode: 'Scan with DID Wallet to
|
21
|
+
scanQrcode: 'Scan with DID Wallet to view this {role}',
|
21
22
|
download: 'Download',
|
22
23
|
downloadTips: "Don't have DID Wallet ?",
|
23
24
|
},
|
24
25
|
zh: {
|
25
|
-
scanQrcode: '
|
26
|
+
scanQrcode: '使用 DID Wallet 扫码查看该 {role}',
|
26
27
|
download: '下载',
|
27
28
|
downloadTips: '没有 DID Wallet ?',
|
28
29
|
},
|
@@ -70,6 +71,19 @@ const isSquareMotif = (roleType: number) => {
|
|
70
71
|
return !roles[roleType];
|
71
72
|
};
|
72
73
|
|
74
|
+
const getRoleName = (roleType: number) => {
|
75
|
+
const [roleName] = Object.entries(types.RoleType).find((item) => item[1] === roleType) || [];
|
76
|
+
|
77
|
+
if (roleName) {
|
78
|
+
// UpperCase first word, example:
|
79
|
+
// ROLE_ACCOUNT -> Account
|
80
|
+
// ROLE_APPLICATION -> Application
|
81
|
+
return roleName.toLowerCase().replace(/role_(\S)/g, (_, $1) => $1.toUpperCase());
|
82
|
+
}
|
83
|
+
|
84
|
+
return 'Address';
|
85
|
+
};
|
86
|
+
|
73
87
|
const getAvatarSize = (didMotifInfo: any, isEthDid: boolean, size: number) => {
|
74
88
|
if (isEthDid) {
|
75
89
|
return size * 0.75;
|
@@ -139,12 +153,12 @@ const DID = forwardRef<HTMLDIDElement, IDIDPropTypes>((props, ref) => {
|
|
139
153
|
const [open, setOpen] = useState(false);
|
140
154
|
const isEthDid = isEthereumDid(did);
|
141
155
|
const didMotifInfo = isEthDid ? undefined : getDIDMotifInfo(did);
|
142
|
-
|
143
|
-
const
|
144
|
-
<span key="prefix-did" style={{ flex: '0 0 auto',
|
156
|
+
|
157
|
+
const getPrepend = (avatarSize: number) => [
|
158
|
+
<span key="prefix-did" style={{ flex: '0 0 auto', color: getFontColor(did, didMotifInfo, isEthDid) }}>
|
145
159
|
DID:
|
146
160
|
</span>,
|
147
|
-
<span key="prefix-abt" className="did-address-text"
|
161
|
+
<span key="prefix-abt" className="did-address-text">
|
148
162
|
ABT:
|
149
163
|
</span>,
|
150
164
|
showAvatar && (
|
@@ -152,7 +166,7 @@ const DID = forwardRef<HTMLDIDElement, IDIDPropTypes>((props, ref) => {
|
|
152
166
|
key="avatar"
|
153
167
|
src=""
|
154
168
|
did={did}
|
155
|
-
size={getAvatarSize(didMotifInfo, isEthDid,
|
169
|
+
size={getAvatarSize(didMotifInfo, isEthDid, avatarSize || 18)}
|
156
170
|
style={{ display: 'inline-flex', alignItems: 'center', marginLeft: 2, marginRight: 4 }}
|
157
171
|
blockiesPadding={false}
|
158
172
|
className="did-address-avatar"
|
@@ -218,7 +232,7 @@ const DID = forwardRef<HTMLDIDElement, IDIDPropTypes>((props, ref) => {
|
|
218
232
|
content={`${DID_PREFIX}${did}`}
|
219
233
|
{...rest}
|
220
234
|
ref={addressRef}
|
221
|
-
prepend={
|
235
|
+
prepend={getPrepend(rest.size)}
|
222
236
|
append={
|
223
237
|
<>
|
224
238
|
{showQrcode ? (
|
@@ -241,14 +255,21 @@ const DID = forwardRef<HTMLDIDElement, IDIDPropTypes>((props, ref) => {
|
|
241
255
|
{did}
|
242
256
|
</Address>
|
243
257
|
|
244
|
-
<Dialog
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
258
|
+
<Dialog
|
259
|
+
open={open}
|
260
|
+
onClose={closeQrCode}
|
261
|
+
maxWidth="sm"
|
262
|
+
PaperProps={{
|
263
|
+
sx: {
|
264
|
+
boxShadow: 'none',
|
265
|
+
borderRadius: '12px',
|
266
|
+
},
|
267
|
+
}}>
|
250
268
|
{/* @ts-ignore */}
|
251
|
-
<DialogContent align=
|
269
|
+
<DialogContent align="center" sx={{ p: 3 }}>
|
270
|
+
<Typography sx={{ mb: 2, fontWeight: 500, fontSize: 18 }}>
|
271
|
+
{t('scanQrcode', { role: getRoleName(didMotifInfo?.roleType) })}
|
272
|
+
</Typography>
|
252
273
|
<QRCode
|
253
274
|
// eslint-disable-next-line max-len
|
254
275
|
value={`abt://abtwallet.io/i?did=${DID_PREFIX}${did}&action=didRecognize&chainID=${
|
@@ -258,8 +279,14 @@ const DID = forwardRef<HTMLDIDElement, IDIDPropTypes>((props, ref) => {
|
|
258
279
|
renderAs="svg"
|
259
280
|
level="M"
|
260
281
|
/>
|
261
|
-
<Box sx={{
|
262
|
-
<Address
|
282
|
+
<Box sx={{ mt: 1.5, textAlign: 'center' }}>
|
283
|
+
<Address
|
284
|
+
locale={locale}
|
285
|
+
content={`${DID_PREFIX}${did}`}
|
286
|
+
prepend={getPrepend(16)}
|
287
|
+
{...rest}
|
288
|
+
size={16}
|
289
|
+
copyable>
|
263
290
|
{did}
|
264
291
|
</Address>
|
265
292
|
</Box>
|
@@ -1,13 +1,13 @@
|
|
1
1
|
# withTracker
|
2
2
|
|
3
|
-
Add
|
3
|
+
Add google analytics reporting to your application.
|
4
4
|
|
5
5
|
## Usage
|
6
6
|
|
7
7
|
### Installation
|
8
8
|
|
9
9
|
```bash
|
10
|
-
yarn add
|
10
|
+
yarn add @arcblock/ux
|
11
11
|
```
|
12
12
|
|
13
13
|
### Configuration & Usage
|
@@ -16,19 +16,22 @@ In your application entry file
|
|
16
16
|
|
17
17
|
```javascript
|
18
18
|
import React from 'react';
|
19
|
-
import ReactDOM from 'react-dom';
|
20
19
|
import withTracker from '@arcblock/ux/lib/withTracker';
|
20
|
+
import { BrowserRouter as Router } from 'react-router-dom';
|
21
21
|
|
22
|
-
|
23
|
-
|
24
|
-
}
|
22
|
+
const App = () => <p>My awesome application</p>;
|
23
|
+
const TrackedApp = withTracker(App);
|
25
24
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
gaAccount: '',
|
30
|
-
sentryDSN: '',
|
31
|
-
});
|
25
|
+
export default function WrappedApp() {
|
26
|
+
// While the blocklet is deploy to a sub path, this will be work properly.
|
27
|
+
const basename = window?.blocklet?.prefix || '/';
|
32
28
|
|
33
|
-
|
29
|
+
return (
|
30
|
+
<Router basename={basename}>
|
31
|
+
<TrackedApp />
|
32
|
+
</Router>
|
33
|
+
);
|
34
|
+
}
|
34
35
|
```
|
36
|
+
|
37
|
+
Then you can use `window.trackPage(path, title)` and `window.trackEvent(category, action, label, value)` to track page views and events.
|
package/src/withTracker/index.js
CHANGED
@@ -1,37 +1,32 @@
|
|
1
|
-
/* eslint-disable import/no-unresolved */
|
2
|
-
import ReactGA from 'react-ga';
|
3
|
-
import * as Sentry from '@sentry/browser';
|
4
|
-
|
5
|
-
import { useMount, useDeepCompareEffect } from 'ahooks';
|
6
1
|
import { useLocation } from 'react-router-dom';
|
2
|
+
import { useMount, useDeepCompareEffect } from 'ahooks';
|
3
|
+
import ReactGA from 'react-ga4';
|
7
4
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
const { appVersion, gaAccount, sentryDSN } = options;
|
12
|
-
|
13
|
-
if (gaAccount) {
|
14
|
-
ReactGA.initialize(gaAccount);
|
15
|
-
}
|
16
|
-
if (sentryDSN) {
|
17
|
-
Sentry.init({
|
18
|
-
dsn: sentryDSN,
|
19
|
-
release: appVersion || 'unknown',
|
20
|
-
environment: process.env.NODE_ENV || 'development',
|
21
|
-
});
|
22
|
-
}
|
23
|
-
|
24
|
-
const trackPage = (page) => {
|
5
|
+
export default (WrappedComponent) => {
|
6
|
+
const trackingId = window.blocklet?.GA_MEASUREMENT_ID || '';
|
7
|
+
const trackPage = (page, title = document.title) => {
|
25
8
|
if (!process.env.NODE_ENV || process.env.NODE_ENV === 'development') {
|
26
9
|
return;
|
27
10
|
}
|
28
11
|
|
29
|
-
if (
|
30
|
-
ReactGA.
|
31
|
-
ReactGA.pageview(page);
|
12
|
+
if (trackingId) {
|
13
|
+
ReactGA.send({ hitType: 'pageview', page, title });
|
32
14
|
}
|
33
15
|
};
|
34
16
|
|
17
|
+
const trackEvent = (category, action, label, value) => {
|
18
|
+
if (trackingId) {
|
19
|
+
ReactGA.event({ category, action, label, value, transport: 'beacon' });
|
20
|
+
}
|
21
|
+
};
|
22
|
+
|
23
|
+
if (trackingId) {
|
24
|
+
ReactGA.initialize(trackingId);
|
25
|
+
}
|
26
|
+
|
27
|
+
window.trackPage = trackPage;
|
28
|
+
window.trackEvent = trackEvent;
|
29
|
+
|
35
30
|
return function TrackedComponent(props) {
|
36
31
|
const location = useLocation();
|
37
32
|
|
@@ -43,14 +38,6 @@ export default (WrappedComponent, options = {}) => {
|
|
43
38
|
trackPage(location.pathname);
|
44
39
|
}, [location.pathname]);
|
45
40
|
|
46
|
-
if (process.env.NODE_ENV === 'production') {
|
47
|
-
return (
|
48
|
-
<ErrorBoundary>
|
49
|
-
<WrappedComponent {...props} />
|
50
|
-
</ErrorBoundary>
|
51
|
-
);
|
52
|
-
}
|
53
|
-
|
54
41
|
return <WrappedComponent {...props} />;
|
55
42
|
};
|
56
43
|
};
|