@arcblock/ux 2.10.45 → 2.10.46
Sign up to get free protection for your applications and to get access to all the features.
- 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/withTracker/README.md +16 -13
- package/src/withTracker/index.js +20 -33
@@ -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",
|
@@ -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
|
};
|