Skip to content

Commit

Permalink
fix: add removal of GA cross site tracking params in URL
Browse files Browse the repository at this point in the history
  • Loading branch information
spaenleh committed Jan 22, 2024
1 parent eaa5995 commit fec43dc
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 72 deletions.
65 changes: 13 additions & 52 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@
"plugin:react-hooks/recommended",
"eslint:recommended"
],
"plugins": [
"@typescript-eslint",
"react-hooks"
],
"plugins": ["@typescript-eslint", "react-hooks"],
"env": {
"browser": true,
"node": true,
Expand Down Expand Up @@ -43,9 +40,7 @@
"react/react-in-jsx-scope": "off",
// note you must disable the base rule as it can report incorrect errors
"no-use-before-define": "off",
"@typescript-eslint/no-use-before-define": [
"error"
],
"@typescript-eslint/no-use-before-define": ["error"],
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": [
"error",
Expand All @@ -64,12 +59,7 @@
"react/jsx-filename-extension": [
1,
{
"extensions": [
".js",
".jsx",
".ts",
".tsx"
]
"extensions": [".js", ".jsx", ".ts", ".tsx"]
}
],
"import/no-named-as-default": 0,
Expand All @@ -86,16 +76,11 @@
}
],
"no-restricted-syntax": "off",
"react/state-in-constructor": [
"error",
"never"
],
"react/state-in-constructor": ["error", "never"],
"no-console": [
1,
{
"allow": [
"error"
]
"allow": ["error", "info"]
}
],
"import/no-extraneous-dependencies": [
Expand All @@ -107,15 +92,12 @@
"react/prop-types": "off", // Since we do not use prop-types
"react/require-default-props": "off", // Since we do not use prop-types
// disable the rule for all files
"@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/explicit-function-return-type": "off"
},
"overrides": [
{
// enable the rule specifically for TypeScript files
"files": [
"*.ts",
"*.tsx"
],
"files": ["*.ts", "*.tsx"],
"rules": {
"@typescript-eslint/explicit-module-boundary-types": [
"error",
Expand All @@ -127,46 +109,25 @@
},
{
// enable the rule specifically for src files
"files": [
"src/**/*.js",
"src/**/*.tsx",
"src/**/*.ts"
],
"files": ["src/**/*.js", "src/**/*.tsx", "src/**/*.ts"],
"rules": {
"no-restricted-syntax": [
"error"
]
"no-restricted-syntax": ["error"]
}
}
],
"settings": {
"import/extensions": [
".js",
".jsx",
".ts",
".tsx"
],
"import/extensions": [".js", ".jsx", ".ts", ".tsx"],
"import/parsers": {
"@typescript-eslint/parser": [
".ts",
".tsx"
]
"@typescript-eslint/parser": [".ts", ".tsx"]
},
"import/resolver": {
"typescript": {
"alwaysTryTypes": true
},
"node": {
"extensions": [
".js",
".jsx",
".ts",
".tsx"
]
"extensions": [".js", ".jsx", ".ts", ".tsx"]
}
}
},
"ignorePatterns": [
"node_modules/*"
]
"ignorePatterns": ["node_modules/*"]
}
32 changes: 13 additions & 19 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { useEffect } from 'react';
import ReactGA from 'react-ga4';
import {
Navigate,
Route,
Expand All @@ -8,11 +7,11 @@ import {
useSearchParams,
} from 'react-router-dom';

import { hasAcceptedCookies, saveUrlForRedirection } from '@graasp/sdk';
import { saveUrlForRedirection } from '@graasp/sdk';
import { CustomInitialLoader, withAuthorization } from '@graasp/ui';

import { SIGN_IN_PATH } from '@/config/constants';
import { DOMAIN, GA_MEASUREMENT_ID } from '@/config/env';
import { DOMAIN } from '@/config/env';
import { HOME_PATH, buildMainPath } from '@/config/paths';
import { useCurrentMemberContext } from '@/contexts/CurrentMemberContext';
import HomePage from '@/modules/pages/HomePage';
Expand All @@ -23,22 +22,17 @@ export const App = (): JSX.Element => {
const [searchParams, setSearchParams] = useSearchParams();
const { data: currentMember, isLoading } = useCurrentMemberContext();

useEffect(() => {
// REACTGA
// Send pageview with a custom path
if (GA_MEASUREMENT_ID && hasAcceptedCookies()) {
ReactGA.initialize(GA_MEASUREMENT_ID);
ReactGA.send('pageview');
}

// remove cross domain tracking query params
// eslint-disable-next-line no-console
console.log('removing google cross site tracking params after load');
// eslint-disable-next-line no-console
console.log(searchParams);
searchParams.delete('_gl');
setSearchParams(searchParams);
}, [location]);
useEffect(
() => {
if (searchParams.get('_gl'))
// remove cross domain tracking query params
console.info('Removing cross site tracking params');
searchParams.delete('_gl');
setSearchParams(searchParams);
},
// eslint-disable-next-line react-hooks/exhaustive-deps
[searchParams],
);

if (isLoading) {
return <CustomInitialLoader />;
Expand Down
1 change: 0 additions & 1 deletion src/Root.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { useEffect } from 'react';
import { I18nextProvider } from 'react-i18next';
import { BrowserRouter as Router } from 'react-router-dom';
import { ToastContainer } from 'react-toastify';
Expand Down

0 comments on commit fec43dc

Please sign in to comment.