Skip to content
This repository has been archived by the owner on Nov 21, 2024. It is now read-only.

fix: add ga code #59

Merged
merged 1 commit into from
Jan 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"qs": "6.11.0",
"react": "18.2.0",
"react-dom": "18.2.0",
"react-ga4": "1.4.1",
"react-i18next": "11.16.9",
"react-router": "6.3.0",
"react-router-dom": "6.3.0",
Expand Down
3 changes: 3 additions & 0 deletions src/config/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ const {
REACT_APP_DOMAIN: ENV_DOMAIN,
} = env;

export const { REACT_APP_GA_MEASUREMENT_ID: GA_MEASUREMENT_ID, NODE_ENV } =
process.env;

export const DOMAIN = ENV_DOMAIN || process.env.REACT_APP_DOMAIN;

export const APP_NAME = 'Graasp Authentication';
Expand Down
9 changes: 9 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
import React from 'react';
import { createRoot } from 'react-dom/client';
import ReactGA from 'react-ga4';

import { hasAcceptedCookies } from '@graasp/sdk';

import Root from './components/Root';
import { GA_MEASUREMENT_ID, NODE_ENV } from './config/constants';
import './index.css';
import * as serviceWorker from './serviceWorker';

if (GA_MEASUREMENT_ID && hasAcceptedCookies() && NODE_ENV !== 'test') {
ReactGA.initialize(GA_MEASUREMENT_ID);
ReactGA.send('pageview');
}

const container = document.getElementById('root');
const root = createRoot(container); // createRoot(container!) if you use TypeScript
root.render(<Root />);
Expand Down
8 changes: 8 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9208,6 +9208,7 @@ __metadata:
qs: 6.11.0
react: 18.2.0
react-dom: 18.2.0
react-ga4: 1.4.1
react-i18next: 11.16.9
react-router: 6.3.0
react-router-dom: 6.3.0
Expand Down Expand Up @@ -14412,6 +14413,13 @@ __metadata:
languageName: node
linkType: hard

"react-ga4@npm:1.4.1":
version: 1.4.1
resolution: "react-ga4@npm:1.4.1"
checksum: 4c33ecb47dfc26c241a6af8e2b08b29b6c059f40e456e93d1c2b65c995edce18f32d9777295774ec992d968d7c5efdd105eb62398972d85ff2e2b6dad8646a26
languageName: node
linkType: hard

"react-i18next@npm:11.16.9":
version: 11.16.9
resolution: "react-i18next@npm:11.16.9"
Expand Down