Skip to content

Commit c652948

Browse files
Merge pull request #1257 from guardian/cc/remove-ga
Removing Google Analytics
2 parents 918b818 + 70da59f commit c652948

File tree

9 files changed

+11
-164
lines changed

9 files changed

+11
-164
lines changed

client/components/mma/cancel/CancellationReasonReview.tsx

-10
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import type {
1616
} from '../../../../shared/productTypes';
1717
import { sans } from '../../../styles/fonts';
1818
import { measure } from '../../../styles/typography';
19-
import { trackEvent } from '../../../utilities/analytics';
2019
import { useFetch } from '../../../utilities/hooks/useFetch';
2120
import { CallCentreNumbers } from '../../shared/CallCentreNumbers';
2221
import { GenericErrorScreen } from '../../shared/GenericErrorScreen';
@@ -51,12 +50,6 @@ const getPatchUpdateCaseFunc =
5150
Subject: 'Online Cancellation Query',
5251
});
5352

54-
const gaTrackFeedback = (actionString: string) =>
55-
trackEvent({
56-
eventCategory: 'feedback',
57-
eventAction: actionString,
58-
});
59-
6053
const ContactUs = (reason: CancellationReason) =>
6154
reason.hideContactUs ? (
6255
<></>
@@ -117,7 +110,6 @@ const FeedbackFormAndContactUs = (props: FeedbackFormProps) => {
117110
const submitFeedback = () => {
118111
if (feedback.length) {
119112
setHasHitSubmit(true);
120-
gaTrackFeedback('submitted');
121113
}
122114
setFeedbackValidationErrorState(!feedback.length);
123115
};
@@ -209,7 +201,6 @@ const FeedbackFormAndContactUs = (props: FeedbackFormProps) => {
209201
props.caseId,
210202
feedback,
211203
)();
212-
gaTrackFeedback('submitted silently');
213204
}
214205
}}
215206
/>
@@ -368,7 +359,6 @@ export const CancellationReasonReview = () => {
368359
reason: routerState.selectedReasonId,
369360
product: productType.cancellation.sfCaseProduct,
370361
subscriptionName: productDetail.subscription.subscriptionId,
371-
gaData: '' + JSON.stringify(window.gaData),
372362
}),
373363
headers: {
374364
'Content-Type': 'application/json',

client/components/mma/cancel/cancellationSaves/membership/ConfirmMembershipCancellation.tsx

-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ export const ConfirmMembershipCancellation = () => {
5050
reason: selectedReasonId,
5151
product: productType.cancellation.sfCaseProduct,
5252
subscriptionName: productDetail.subscription.subscriptionId,
53-
gaData: '' + JSON.stringify(window.gaData),
5453
}),
5554
headers: {
5655
'Content-Type': 'application/json',

client/components/mma/cancel/cancellationSaves/membership/SelectReason.tsx

-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,6 @@ function cancellationCaseFetch(
144144
reason: selectedReasonId,
145145
product: productType.cancellation.sfCaseProduct,
146146
subscriptionName: productDetail.subscription.subscriptionId,
147-
gaData: '' + JSON.stringify(window.gaData),
148147
}),
149148
headers: {
150149
'Content-Type': 'application/json',

client/utilities/analytics.ts

+9-16
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,13 @@ interface Event {
1515

1616
export const MMA_AB_TEST_DIMENSION_VALUE = ''; // this can be used for a/b testing
1717

18-
export const trackEvent = (
19-
{ eventCategory, eventAction, product, eventLabel, eventValue }: Event,
20-
alsoTrackInGA = true,
21-
) => {
22-
if (alsoTrackInGA && window.ga) {
23-
window.ga(
24-
'send',
25-
'event',
26-
eventCategory,
27-
eventAction,
28-
eventLabel,
29-
eventValue,
30-
);
31-
}
18+
export const trackEvent = ({
19+
eventCategory,
20+
eventAction,
21+
product,
22+
eventLabel,
23+
eventValue,
24+
}: Event) => {
3225
if (window.guardian && window.guardian.ophan) {
3326
const ophanProduct: OphanProduct | undefined =
3427
product &&
@@ -58,10 +51,10 @@ export const trackEvent = (
5851
}
5952
};
6053

61-
export const trackEventInOphanOnly = (event: Event) => trackEvent(event, false);
54+
export const trackEventInOphanOnly = (event: Event) => trackEvent(event);
6255

6356
export const applyAnyOptimiseExperiments = () => {
64-
if (typeof window !== 'undefined' && window.ga && window.dataLayer) {
57+
if (typeof window !== 'undefined' && window.dataLayer) {
6558
window.dataLayer.push({ event: 'optimize.activate' });
6659
}
6760
};

client/utilities/gaStub.ts

-25
This file was deleted.

client/utilities/hooks/useAnalytics.ts

+1-89
Original file line numberDiff line numberDiff line change
@@ -2,84 +2,18 @@ import { loadScript } from '@guardian/libs';
22
import * as Sentry from '@sentry/browser';
33
import { useEffect, useState } from 'react';
44
import { useLocation } from 'react-router-dom';
5-
import parse from 'url-parse';
6-
import {
7-
applyAnyOptimiseExperiments,
8-
MMA_AB_TEST_DIMENSION_VALUE,
9-
} from '../analytics';
10-
import { runGaStub } from '../gaStub';
115

126
declare global {
137
interface Window {
14-
ga?: any;
15-
gaData?: string;
168
dataLayer?: any;
179
}
1810
}
1911

20-
const GA_AVAILABLE = false;
21-
const GA_UA = 'UA-51507017-5';
22-
2312
export const useAnalytics = () => {
2413
const location = useLocation();
2514
const [cmpIsInitialised, setCmpIsInitialised] = useState<boolean>(false);
26-
const [gaIsInitialised, setGaIsInitialised] = useState<boolean>(false);
2715
const [qmIsInitialised, setQmIsInitialised] = useState<boolean>(false);
2816

29-
const initialiseGa = () => {
30-
// Run self evoking GA script
31-
runGaStub();
32-
33-
if (typeof window !== 'undefined' && window.ga) {
34-
const queryParams = parse(window.location.href, true).query;
35-
36-
const INTCMP = queryParams.INTCMP;
37-
38-
if (window.guardian) {
39-
// tslint:disable-next-line:no-object-mutation
40-
window.guardian.INTCMP = INTCMP;
41-
42-
const abName = queryParams.abName;
43-
const abVariant = queryParams.abVariant;
44-
45-
if (abName && abVariant) {
46-
// tslint:disable-next-line:no-object-mutation
47-
window.guardian.abTest = {
48-
name: abName,
49-
variant: abVariant,
50-
};
51-
}
52-
}
53-
54-
if (window.dataLayer === undefined) {
55-
// tslint:disable-next-line:no-object-mutation
56-
window.dataLayer = [];
57-
}
58-
59-
window.ga('create', GA_UA, 'auto');
60-
window.ga('require', 'GTM-M985W29');
61-
window.ga('set', 'transport', 'beacon');
62-
if (INTCMP) {
63-
window.ga('set', 'dimension12', INTCMP);
64-
}
65-
window.ga('set', 'dimension29', MMA_AB_TEST_DIMENSION_VALUE);
66-
67-
new MutationObserver(applyAnyOptimiseExperiments).observe(
68-
document.body,
69-
{
70-
attributes: false,
71-
characterData: false,
72-
childList: true,
73-
subtree: true,
74-
attributeOldValue: false,
75-
characterDataOldValue: false,
76-
},
77-
);
78-
}
79-
80-
setGaIsInitialised(true);
81-
};
82-
8317
const initialiseQm = () => {
8418
loadScript(
8519
'https://cdn.quantummetric.com/instrumentation/new-worker-gnm-sri/quantum-gnm.js',
@@ -102,20 +36,8 @@ export const useAnalytics = () => {
10236
import('@guardian/consent-management-platform').then(
10337
({ onConsentChange, getConsentFor }) => {
10438
onConsentChange((consentState) => {
105-
const gaConsentState = getConsentFor(
106-
'google-analytics',
107-
consentState,
108-
);
109-
11039
const qmConsentState = getConsentFor('qm', consentState);
11140

112-
// @ts-expect-error: Suppressing "element implicitly has an 'any' type because index expression is not of type 'number'."
113-
window[`ga-disable-${GA_UA}`] = !gaConsentState;
114-
115-
if (GA_AVAILABLE && gaConsentState && !gaIsInitialised) {
116-
initialiseGa();
117-
}
118-
11941
if (qmConsentState && !qmIsInitialised) {
12042
initialiseQm();
12143
}
@@ -143,15 +65,5 @@ export const useAnalytics = () => {
14365
window.guardian.spaTransition = true;
14466
}
14567
}
146-
147-
if (gaIsInitialised && window.ga) {
148-
window.ga('send', 'pageview', {
149-
location: window.location.href,
150-
page: window.location.pathname + window.location.search,
151-
dimension12: window.guardian.INTCMP,
152-
dimension29: MMA_AB_TEST_DIMENSION_VALUE,
153-
});
154-
applyAnyOptimiseExperiments();
155-
}
156-
}, [location, cmpIsInitialised, gaIsInitialised]);
68+
}, [location, cmpIsInitialised]);
15769
};

package.json

-3
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@
8181
"@types/cookie-parser": "1.4.1",
8282
"@types/csurf": "1.9.35",
8383
"@types/express": "4.16.1",
84-
"@types/google.analytics": "0.0.39",
8584
"@types/helmet": "0.0.37",
8685
"@types/jest": "29.5.6",
8786
"@types/js-cookie": "2.2.3",
@@ -94,7 +93,6 @@
9493
"@types/react-dom": "18.2.1",
9594
"@types/react-test-renderer": "18.0.0",
9695
"@types/ua-parser-js": "0.7.36",
97-
"@types/url-parse": "1.4.3",
9896
"@types/uuid": "8.3.4",
9997
"@types/webpack": "5.28.0",
10098
"@types/webpack-node-externals": "2.5.3",
@@ -183,7 +181,6 @@
183181
"stylis-pxtorem": "0.0.2",
184182
"tslib": "2.6.2",
185183
"ua-parser-js": "1.0.34",
186-
"url-parse": "1.5.9",
187184
"winston": "3.2.1",
188185
"yup": "0.28.5"
189186
},

server/middleware/identityMiddleware.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ const authenticateWithIdapi: (statusCodeOverride?: number) => RequestHandler =
210210
// If the request to manage contains sign-in token query parameters,
211211
// but they are not needed because the user is already signed in,
212212
// redirect them to the same url, but with the sign-in token query parameters removed.
213-
// This ensures the sensitive query parameters will not be recorded by GA or Ophan,
213+
// This ensures the sensitive query parameters will not be recorded by Ophan,
214214
// in addition to the url the user sees in the browser being simpler.
215215
if (containsSignInTokenQueryParameters(req)) {
216216
// Note it is vital that updateManageUrl() removes the auto sign-in query parameters,

yarn.lock

-18
Original file line numberDiff line numberDiff line change
@@ -5027,11 +5027,6 @@
50275027
resolved "https://registry.yarnpkg.com/@types/find-cache-dir/-/find-cache-dir-3.2.1.tgz#7b959a4b9643a1e6a1a5fe49032693cc36773501"
50285028
integrity sha512-frsJrz2t/CeGifcu/6uRo4b+SzAwT4NYCVPu1GN8IB9XTzrpPkGuV0tmh9mN+/L0PklAlsC3u5Fxt0ju00LXIw==
50295029

5030-
5031-
version "0.0.39"
5032-
resolved "https://registry.yarnpkg.com/@types/google.analytics/-/google.analytics-0.0.39.tgz#19a952003dbf3c7373d655a5c3203b4726b8b802"
5033-
integrity sha512-AwVtVYACQg26MJz+752H6uskn53BR7eilCOHksUGkzobZNKc7O3RFTJrbD3yKAluXy6favVdynnr9btijjcakQ==
5034-
50355030
"@types/graceful-fs@^4.1.3":
50365031
version "4.1.8"
50375032
resolved "https://registry.yarnpkg.com/@types/graceful-fs/-/graceful-fs-4.1.8.tgz#417e461e4dc79d957dc3107f45fe4973b09c2915"
@@ -5431,11 +5426,6 @@
54315426
resolved "https://registry.yarnpkg.com/@types/unist/-/unist-2.0.9.tgz#72e164381659a49557b0a078b28308f2c6a3e1ce"
54325427
integrity sha512-zC0iXxAv1C1ERURduJueYzkzZ2zaGyc+P2c95hgkikHPr3z8EdUZOlgEQ5X0DRmwDZn+hekycQnoeiiRVrmilQ==
54335428

5434-
5435-
version "1.4.3"
5436-
resolved "https://registry.yarnpkg.com/@types/url-parse/-/url-parse-1.4.3.tgz#fba49d90f834951cb000a674efee3d6f20968329"
5437-
integrity sha512-4kHAkbV/OfW2kb5BLVUuUMoumB3CP8rHqlw48aHvFy5tf9ER0AfOonBlX29l/DD68G70DmyhRlSYfQPSYpC5Vw==
5438-
54395429
54405430
version "8.3.4"
54415431
resolved "https://registry.yarnpkg.com/@types/uuid/-/uuid-8.3.4.tgz#bd86a43617df0594787d38b735f55c805becf1bc"
@@ -16050,14 +16040,6 @@ url-parse-lax@^3.0.0:
1605016040
dependencies:
1605116041
prepend-http "^2.0.0"
1605216042

16053-
16054-
version "1.5.9"
16055-
resolved "https://registry.yarnpkg.com/url-parse/-/url-parse-1.5.9.tgz#05ff26484a0b5e4040ac64dcee4177223d74675e"
16056-
integrity sha512-HpOvhKBvre8wYez+QhHcYiVvVmeF6DVnuSOOPhe3cTum3BnqHhvKaZm8FU5yTiOu/Jut2ZpB2rA/SbBA1JIGlQ==
16057-
dependencies:
16058-
querystringify "^2.1.1"
16059-
requires-port "^1.0.0"
16060-
1606116043
url-parse@^1.5.3:
1606216044
version "1.5.10"
1606316045
resolved "https://registry.yarnpkg.com/url-parse/-/url-parse-1.5.10.tgz#9d3c2f736c1d75dd3bd2be507dcc111f1e2ea9c1"

0 commit comments

Comments
 (0)