@@ -2,84 +2,18 @@ import { loadScript } from '@guardian/libs';
2
2
import * as Sentry from '@sentry/browser' ;
3
3
import { useEffect , useState } from 'react' ;
4
4
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' ;
11
5
12
6
declare global {
13
7
interface Window {
14
- ga ?: any ;
15
- gaData ?: string ;
16
8
dataLayer ?: any ;
17
9
}
18
10
}
19
11
20
- const GA_AVAILABLE = false ;
21
- const GA_UA = 'UA-51507017-5' ;
22
-
23
12
export const useAnalytics = ( ) => {
24
13
const location = useLocation ( ) ;
25
14
const [ cmpIsInitialised , setCmpIsInitialised ] = useState < boolean > ( false ) ;
26
- const [ gaIsInitialised , setGaIsInitialised ] = useState < boolean > ( false ) ;
27
15
const [ qmIsInitialised , setQmIsInitialised ] = useState < boolean > ( false ) ;
28
16
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
-
83
17
const initialiseQm = ( ) => {
84
18
loadScript (
85
19
'https://cdn.quantummetric.com/instrumentation/new-worker-gnm-sri/quantum-gnm.js' ,
@@ -102,20 +36,8 @@ export const useAnalytics = () => {
102
36
import ( '@guardian/consent-management-platform' ) . then (
103
37
( { onConsentChange, getConsentFor } ) => {
104
38
onConsentChange ( ( consentState ) => {
105
- const gaConsentState = getConsentFor (
106
- 'google-analytics' ,
107
- consentState ,
108
- ) ;
109
-
110
39
const qmConsentState = getConsentFor ( 'qm' , consentState ) ;
111
40
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
-
119
41
if ( qmConsentState && ! qmIsInitialised ) {
120
42
initialiseQm ( ) ;
121
43
}
@@ -143,15 +65,5 @@ export const useAnalytics = () => {
143
65
window . guardian . spaTransition = true ;
144
66
}
145
67
}
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 ] ) ;
157
69
} ;
0 commit comments