Skip to content

Commit acae6c6

Browse files
PatrickfBrazchriscollins3456
authored andcommitted
feat(web-react): adds the possibility to track events through GA4 (datahub-project#8231)
Co-authored-by: Chris Collins <[email protected]>
1 parent 6a4cca6 commit acae6c6

File tree

5 files changed

+22
-272
lines changed

5 files changed

+22
-272
lines changed

datahub-web-react/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"private": true,
55
"dependencies": {
66
"@analytics/amplitude": "0.0.3",
7-
"@analytics/google-analytics": "^0.5.2",
7+
"@analytics/google-analytics": "^1.0.7",
88
"@analytics/mixpanel": "^0.3.1",
99
"@ant-design/colors": "^5.0.0",
1010
"@ant-design/icons": "^4.3.0",

datahub-web-react/src/app/analytics/README.md

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,20 +48,17 @@ const config: any = {
4848

4949
### Google Analytics
5050

51-
**Disclaimers**
52-
53-
- This plugin requires use of Universal Analytics and does not yet support GA4. To create a Universal Analytics Property, follow [this guide](https://www.analyticsmania.com/other-posts/how-to-create-a-universal-analytics-property/).
54-
- Google Analytics lacks robust support for custom event properties. For that reason many of the DataHub events discussed above will not be fully populated. Instead, we map certain fields of the DataHub event to the standard `category`, `action`, `label` fields required by GA.
55-
5651
1. Open `datahub-web-react/src/conf/analytics.ts`
57-
2. Uncomment the `googleAnalytics` field within the `config` object.
58-
3. Replace the sample `trackingId` with the one provided by Google Analytics.
52+
2. Uncomment the `googleAnalytics` field within the `config`.
53+
3. Replace the sample `measurementIds` with the one provided by Google Analytics.
5954
4. Rebuild & redeploy `datahub-frontend-react` to start tracking.
6055

56+
Example:
57+
6158
```typescript
6259
const config: any = {
6360
googleAnalytics: {
64-
trackingId: 'UA-24123123-01',
61+
measurementIds: ['G-ATV123'],
6562
},
6663
};
6764
```

datahub-web-react/src/app/analytics/plugin/googleAnalytics.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import googleAnalytics from '@analytics/google-analytics';
22
import { Event, EventType } from '../event';
33
import analyticsConfig from '../../../conf/analytics';
44

5-
const gaConfigs = analyticsConfig.googleAnalytics;
6-
const isEnabled: boolean = gaConfigs || false;
7-
const trackingId = isEnabled ? gaConfigs.trackingId : undefined;
5+
const ga4Configs = analyticsConfig.googleAnalytics;
6+
const isEnabled: boolean = ga4Configs || false;
7+
const measurementIds = isEnabled ? ga4Configs.measurementIds : undefined;
88

99
const getLabelFromEvent = (event: Event) => {
1010
switch (event.type) {
@@ -21,11 +21,7 @@ const getLabelFromEvent = (event: Event) => {
2121

2222
let wrappedGoogleAnalyticsPlugin;
2323
if (isEnabled) {
24-
/**
25-
* Init default GA plugin
26-
*/
27-
const googleAnalyticsPlugin = googleAnalytics({ trackingId });
28-
24+
const googleAnalyticsPlugin = googleAnalytics({ measurementIds });
2925
/**
3026
* Lightweight wrapper on top of the default google analytics plugin
3127
* to transform DataHub Analytics Events into the Google Analytics event

datahub-web-react/src/conf/analytics.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const config: any = {
22
// Uncomment below to configure analytics.
33
// googleAnalytics: {
4-
// trackingId: 'UA-24123123-01',
4+
// measurementIds: ['G-RTEGER123'],
55
// },
66
// mixpanel: {
77
// token: 'fad1285da4e618b618973cacf6565e61',

0 commit comments

Comments
 (0)