@arcblock/ux 2.10.45 → 2.10.46

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.
@@ -1,13 +1,13 @@
1
1
  # withTracker
2
2
 
3
- Add arcblock analytics, google analytics and sentry error reporting to your application.
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 react-ga @arcblock/analytics-js @sentry/browser @arcblock/ux
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
- function App() {
23
- return <p>My awesome application</p>;
24
- }
22
+ const App = () => <p>My awesome application</p>;
23
+ const TrackedApp = withTracker(App);
25
24
 
26
- const Wrapped = withTracker(App, {
27
- appName: 'my-awesome-app',
28
- appVersion: '0.1.0',
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
- ReactDOM.render(<Wrapped />, document.getElementById('root'));
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, options?: {}): (props: any) => import("react/jsx-runtime").JSX.Element;
1
+ declare function _default(WrappedComponent: any): (props: any) => import("react/jsx-runtime").JSX.Element;
2
2
  export default _default;
@@ -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 ErrorBoundary from './error_boundary';
8
- export default (WrappedComponent, options = {}) => {
9
- const {
10
- appVersion,
11
- gaAccount,
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 (gaAccount) {
29
- ReactGA.set({
11
+ if (trackingId) {
12
+ ReactGA.send({
13
+ hitType: 'pageview',
30
14
  page,
31
- ...options
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.45",
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": "f4387cd434dcdf0bab88973b014575613dcb3611",
67
+ "gitHead": "ae503a7f61a29ddfe9fdc5a1b0e040fa5890dc75",
68
68
  "dependencies": {
69
69
  "@arcblock/did-motif": "^1.1.13",
70
- "@arcblock/icons": "^2.10.45",
71
- "@arcblock/nft-display": "^2.10.45",
72
- "@arcblock/react-hooks": "^2.10.45",
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 arcblock analytics, google analytics and sentry error reporting to your application.
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 react-ga @arcblock/analytics-js @sentry/browser @arcblock/ux
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
- function App() {
23
- return <p>My awesome application</p>;
24
- }
22
+ const App = () => <p>My awesome application</p>;
23
+ const TrackedApp = withTracker(App);
25
24
 
26
- const Wrapped = withTracker(App, {
27
- appName: 'my-awesome-app',
28
- appVersion: '0.1.0',
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
- ReactDOM.render(<Wrapped />, document.getElementById('root'));
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,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
- import ErrorBoundary from './error_boundary';
9
-
10
- export default (WrappedComponent, options = {}) => {
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 (gaAccount) {
30
- ReactGA.set({ page, ...options });
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
  };