Skip to content

Commit 954271a

Browse files
authored
Merge pull request #1369 from AppQuality/develop
Release 20250630
2 parents ced070f + 175bf5d commit 954271a

178 files changed

Lines changed: 13345 additions & 10540 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@
33
"version": "1.4.0",
44
"private": true,
55
"dependencies": {
6+
"@analytics/google-tag-manager": "^0.6.0",
7+
"@analytics/segment": "^2.1.0",
68
"@appquality/languages": "1.4.3",
79
"@appquality/unguess-design-system": "4.0.42",
810
"@headwayapp/react-widget": "^0.0.4",
911
"@reduxjs/toolkit": "^1.8.0",
1012
"@sentry/react": "^8.32.0",
1113
"@zendeskgarden/svg-icons": "^7.2.0",
1214
"comuni-province-regioni": "^0.4.3",
15+
"analytics": "^0.8.16",
1316
"date-fns": "^2.28.0",
1417
"formik": "^2.2.9",
1518
"i18n-iso-countries": "^7.3.0",
@@ -20,7 +23,6 @@
2023
"query-string": "^7.1.1",
2124
"react": "^18.3.1",
2225
"react-dom": "^18.3.1",
23-
"react-gtm-module": "^2.0.11",
2426
"react-helmet": "^6.1.0",
2527
"react-i18next": "^15.0.2",
2628
"react-redux": "^7.2.6",
@@ -29,6 +31,7 @@
2931
"styled-components": "^6.1.1",
3032
"ts-node": "^10.9.2",
3133
"typescript": "^4.6.2",
34+
"use-analytics": "^1.1.0",
3235
"uuid": "^10.0.0",
3336
"web-vitals": "^2.1.4",
3437
"yup": "^0.32.11"
@@ -79,10 +82,10 @@
7982
"@types/qs": "^6.9.7",
8083
"@types/react": "^18.3.9",
8184
"@types/react-dom": "^18.3.0",
82-
"@types/react-gtm-module": "^2.0.1",
8385
"@types/react-helmet": "^6.1.5",
8486
"@types/react-scroll": "^1.8.10",
8587
"@types/react-transition-group": "^4.4.5",
88+
"@types/use-analytics": "^0.0.3",
8689
"@types/uuid": "^10.0.0",
8790
"@typescript-eslint/eslint-plugin": "^5.0.0",
8891
"@typescript-eslint/parser": "^5.0.0",
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
declare module '@analytics/google-tag-manager' {
2+
type AnalyticsPlugin = import('analytics').AnalyticsPlugin;
3+
4+
type GoogleTagManagerConfig = {
5+
auth?: string;
6+
containerId: string;
7+
customScriptSrc?: string;
8+
dataLayerName?: string;
9+
debug?: boolean;
10+
execution?: string;
11+
preview?: string;
12+
};
13+
14+
function googleTagManager(config: GoogleTagManagerConfig): AnalyticsPlugin;
15+
export default googleTagManager;
16+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
declare module '@analytics/segment' {
2+
type AnalyticsPlugin = import('analytics').AnalyticsPlugin;
3+
4+
type SegmentConfig = {
5+
/** Your segment write key */
6+
writeKey: string;
7+
flushAt?: number;
8+
/* Segment sdk config options. Docs https://segment.com/docs/connections/sources/catalog/libraries/server/node/#configuration */
9+
flushInterval?: number;
10+
/** Disable loading segment for anonymous visitors */
11+
disableAnonymousTraffic?: boolean;
12+
/** Override the Segment snippet url, for loading via custom CDN proxy */
13+
customScriptSrc?: boolean;
14+
/** Enable/disable segment destinations https://segment.com/docs/connections/sources/catalog/libraries/website/javascript/#managing-data-flow-with-the-integrations-object */
15+
integrations?: Record<string, boolean>;
16+
};
17+
18+
function segmentPlugin(config: SegmentConfig): AnalyticsPlugin;
19+
export default segmentPlugin;
20+
}

src/analytics.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import Analytics from 'analytics';
2+
import googleTagManager from '@analytics/google-tag-manager';
3+
import segmentPlugin from '@analytics/segment';
4+
import { isDev } from './common/isDevEnvironment';
5+
6+
const analytics = Analytics({
7+
app: 'unguess-react',
8+
plugins: [
9+
googleTagManager({
10+
containerId: process.env.REACT_APP_GTM_ID || 'GTM-WVXPS94',
11+
...(isDev() && {
12+
auth: 'HjeAxSQB9e685mi-_8YiDw',
13+
preview: 'env-4',
14+
}),
15+
}),
16+
segmentPlugin({
17+
writeKey: isDev()
18+
? 'AxHbacd31w50NwjDM8tadsP82hSwTz4Z'
19+
: 'oxd3W7coKxDdzq99F88doV5VvQrESbJh',
20+
}),
21+
],
22+
});
23+
24+
export default analytics;

src/app/App.tsx

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,40 +7,44 @@ import Helmet from 'react-helmet';
77
import { useTranslation } from 'react-i18next';
88
import { Provider } from 'react-redux';
99
import { appTheme } from 'src/app/theme';
10+
import { AnalyticsProvider } from 'use-analytics';
1011
import Pages from 'src/common/Pages';
12+
import analytics from 'src/analytics';
1113
import '../i18n';
1214
import { store } from './store';
1315

1416
const App = () => {
1517
const { t } = useTranslation();
1618
return (
1719
<Provider store={store}>
18-
<ThemeProvider theme={appTheme}>
19-
<GlobalStyle />
20-
<Helmet>
21-
<meta
22-
property="og:title"
23-
content={`UNGUESS - ${t('__APP_META_PAYOFF')}`}
24-
/>
25-
<title>UNGUESS - {t('__APP_META_PAYOFF')}</title>
26-
<meta name="description" content={t('__APP_META_DESCRIPTION')} />
27-
</Helmet>
28-
<ToastProvider
29-
limit={5}
30-
zIndex={500}
31-
placementProps={{
32-
top: {
33-
style: {
34-
top:
35-
parseInt(appTheme.components.chrome.header.height, 10) +
36-
appTheme.space.base * 4,
20+
<AnalyticsProvider instance={analytics}>
21+
<ThemeProvider theme={appTheme}>
22+
<GlobalStyle />
23+
<Helmet>
24+
<meta
25+
property="og:title"
26+
content={`UNGUESS - ${t('__APP_META_PAYOFF')}`}
27+
/>
28+
<title>UNGUESS - {t('__APP_META_PAYOFF')}</title>
29+
<meta name="description" content={t('__APP_META_DESCRIPTION')} />
30+
</Helmet>
31+
<ToastProvider
32+
limit={5}
33+
zIndex={500}
34+
placementProps={{
35+
top: {
36+
style: {
37+
top:
38+
parseInt(appTheme.components.chrome.header.height, 10) +
39+
appTheme.space.base * 4,
40+
},
3741
},
38-
},
39-
}}
40-
>
41-
<Pages />
42-
</ToastProvider>
43-
</ThemeProvider>
42+
}}
43+
>
44+
<Pages />
45+
</ToastProvider>
46+
</ThemeProvider>
47+
</AnalyticsProvider>
4448
</Provider>
4549
);
4650
};
Lines changed: 3 additions & 0 deletions
Loading
Lines changed: 4 additions & 0 deletions
Loading

src/assets/icons/home-internet.svg

Lines changed: 4 additions & 0 deletions
Loading
Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
import React, { useEffect } from 'react';
2-
import TagManager, { TagManagerArgs } from 'react-gtm-module';
32
import { Helmet } from 'react-helmet';
3+
import { useLocation } from 'react-router-dom';
44
import { useAppSelector } from 'src/app/hooks';
55
import { useActiveWorkspace } from 'src/hooks/useActiveWorkspace';
6-
import { isDev } from './isDevEnvironment';
6+
import { useAnalytics } from 'use-analytics';
77

8-
const tagManagerArgs: TagManagerArgs = {
9-
gtmId: process.env.REACT_APP_GTM_ID || 'GTM-WVXPS94',
10-
...(isDev() && {
11-
auth: 'HjeAxSQB9e685mi-_8YiDw',
12-
preview: 'env-4',
13-
}),
14-
events: {
15-
unguess_loaded: 'unguess_loaded',
16-
workspace_change: 'workspace_change',
17-
generic_error: 'generic_error',
18-
},
19-
};
20-
TagManager.initialize(tagManagerArgs);
8+
// const tagManagerArgs: TagManagerArgs = {
9+
// gtmId: process.env.REACT_APP_GTM_ID || 'GTM-WVXPS94',
10+
// ...(isDev() && {
11+
// auth: 'HjeAxSQB9e685mi-_8YiDw',
12+
// preview: 'env-4',
13+
// }),
14+
// events: {
15+
// unguess_loaded: 'unguess_loaded',
16+
// workspace_change: 'workspace_change',
17+
// generic_error: 'generic_error',
18+
// },
19+
// };
20+
// TagManager.initialize(tagManagerArgs);
2121

22-
export const GoogleTagManager = ({
22+
export const Track = ({
2323
title,
2424
children,
2525
}: {
@@ -28,6 +28,12 @@ export const GoogleTagManager = ({
2828
}) => {
2929
const { userData } = useAppSelector((state) => state.user);
3030
const { activeWorkspace } = useActiveWorkspace();
31+
const { track, identify, page } = useAnalytics();
32+
const location = useLocation();
33+
34+
useEffect(() => {
35+
page();
36+
}, [location]);
3137

3238
const helmet = () => (
3339
<Helmet>
@@ -39,19 +45,24 @@ export const GoogleTagManager = ({
3945

4046
useEffect(() => {
4147
if (userData?.role && activeWorkspace?.company) {
42-
const tagManagerDataLayer = {
48+
identify(`profile_${userData.profile_id}`, {
4349
role: userData.role,
4450
customer_role: userData.customer_role,
4551
wp_user_id: userData.tryber_wp_user_id,
4652
tester_id: userData.profile_id,
4753
name: userData.name,
4854
email: userData.email,
4955
company: activeWorkspace.company,
50-
event: 'unguess_loaded',
51-
};
56+
});
5257

53-
TagManager.dataLayer({
54-
dataLayer: tagManagerDataLayer,
58+
track('unguess_loaded', {
59+
role: userData.role,
60+
customer_role: userData.customer_role,
61+
wp_user_id: userData.tryber_wp_user_id,
62+
tester_id: userData.profile_id,
63+
name: userData.name,
64+
email: userData.email,
65+
company: activeWorkspace.company,
5566
});
5667
}
5768
}, [userData, activeWorkspace]);

src/common/components/ErrorBoundary/ErrorBoundaryPage.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
} from '@appquality/unguess-design-system';
1111
import { useTranslation } from 'react-i18next';
1212
import { ReactComponent as Illustration } from 'src/assets/errorBoundaryPage.svg';
13-
import { GoogleTagManager } from 'src/common/GoogleTagManager';
13+
import { Track } from 'src/common/Track';
1414
import { Logged } from 'src/features/templates/Logged';
1515
import styled from 'styled-components';
1616

@@ -26,7 +26,7 @@ const ErrorBoundaryPage = () => {
2626
const { t } = useTranslation();
2727

2828
return (
29-
<GoogleTagManager title={t('__ERROR_PAGE_TITLE')}>
29+
<Track title={t('__ERROR_PAGE_TITLE')}>
3030
<Logged route="">
3131
<Container id="error-container" style={{ height: '100%' }}>
3232
<Grid>
@@ -56,7 +56,7 @@ const ErrorBoundaryPage = () => {
5656
</Grid>
5757
</Container>
5858
</Logged>
59-
</GoogleTagManager>
59+
</Track>
6060
);
6161
};
6262

0 commit comments

Comments
 (0)