@@ -2,6 +2,7 @@ import React, { useState, useEffect } from 'react';
2
2
import { useSelector , useDispatch } from 'react-redux' ;
3
3
import Cookies from 'js-cookie' ;
4
4
import styled from 'styled-components' ;
5
+ import ReactGA from 'react-ga' ;
5
6
import getConfig from '../../../utils/getConfig' ;
6
7
import { setUserCookieConsent } from '../actions' ;
7
8
import { remSize , prop } from '../../../theme' ;
@@ -61,7 +62,6 @@ function CookieConsent() {
61
62
function acceptAllCookies ( ) {
62
63
if ( user . authenticated ) {
63
64
dispatch ( setUserCookieConsent ( 'all' ) ) ;
64
- return ;
65
65
}
66
66
setBrowserCookieConsent ( 'all' ) ;
67
67
Cookies . set ( 'p5-cookie-consent' , 'all' , { expires : 365 } ) ;
@@ -70,10 +70,12 @@ function CookieConsent() {
70
70
function acceptEssentialCookies ( ) {
71
71
if ( user . authenticated ) {
72
72
dispatch ( setUserCookieConsent ( 'essential' ) ) ;
73
- return ;
74
73
}
75
74
setBrowserCookieConsent ( 'essential' ) ;
76
75
Cookies . set ( 'p5-cookie-consent' , 'essential' , { expires : 365 } ) ;
76
+ Cookies . remove ( '_ga' ) ;
77
+ Cookies . remove ( '_gat' ) ;
78
+ Cookies . remove ( '_gid' ) ;
77
79
}
78
80
79
81
function mergeCookieConsent ( ) {
@@ -94,18 +96,30 @@ function CookieConsent() {
94
96
} else {
95
97
initializeCookieConsent ( ) ;
96
98
}
99
+
100
+ if ( p5CookieConsent === 'essential' ) {
101
+ ReactGA . initialize ( getConfig ( 'GA_MEASUREMENT_ID' ) , {
102
+ gaOptions : {
103
+ storage : 'none'
104
+ }
105
+ } ) ;
106
+ } else {
107
+ ReactGA . initialize ( getConfig ( 'GA_MEASUREMENT_ID' ) ) ;
108
+ }
109
+ ReactGA . pageview ( window . location . pathname + window . location . search ) ;
97
110
} , [ ] ) ;
98
111
99
112
useEffect ( ( ) => {
100
113
mergeCookieConsent ( ) ;
101
114
} , [ user . authenticated ] ) ;
102
115
103
116
// Turn off Google Analytics
104
- useEffect ( ( ) => {
105
- if ( cookieConsent === 'essential' || user . cookieConsent === 'essential' ) {
106
- window [ `ga-disable-${ getConfig ( 'GA_MEASUREMENT_ID' ) } ` ] = true ;
107
- }
108
- } , [ cookieConsent , user . cookieConsent ] ) ;
117
+ // useEffect(() => {
118
+ // if (cookieConsent === 'all' || user.cookieConsent === 'all') {
119
+ // ReactGA.initialize(getConfig('GA_MEASUREMENT_ID'));
120
+ // ReactGA.pageview(window.location.pathname + window.location.search);
121
+ // }
122
+ // }, [cookieConsent, user.cookieConsent]);
109
123
110
124
const showCookieConsent =
111
125
( user . authenticated && user . cookieConsent === 'none' ) ||
0 commit comments