File tree Expand file tree Collapse file tree 4 files changed +50
-1
lines changed Expand file tree Collapse file tree 4 files changed +50
-1
lines changed Original file line number Diff line number Diff line change 29
29
work correctly both with client-side routing and a non-root public URL.
30
30
Learn how to configure a non-root public URL by running `npm run build`.
31
31
-->
32
+ <!-- Global site tag (gtag.js) - Google Analytics -->
33
+ < script async src ="https://www.googletagmanager.com/gtag/js?id=UA-125599395-1 "> </ script >
34
+ < script >
35
+ window . dataLayer = window . dataLayer || [ ] ;
36
+ function gtag ( ) { dataLayer . push ( arguments ) ; }
37
+ gtag ( 'js' , new Date ( ) ) ;
38
+
39
+ gtag ( 'config' , 'UA-125599395-1' ) ;
40
+ </ script >
41
+
32
42
< title > React App</ title >
33
43
</ head >
34
44
< body >
Original file line number Diff line number Diff line change 1
- import * as React from 'react' ;
1
+ import React , { useEffect } from 'react' ;
2
2
import { connect } from 'react-redux' ;
3
3
import OpaqueLayer from '../../components/common/OpaqueLayer' ;
4
4
import AuthModalContainer from '../auth/AuthModalContainer' ;
@@ -8,6 +8,8 @@ import useUserLoader from './hooks/useUserLoader';
8
8
import GlobalStyles from '../../GlobalStyles' ;
9
9
import { ToastContainer , Flip } from 'react-toastify' ;
10
10
import 'react-toastify/dist/ReactToastify.css' ;
11
+ import { useHistory } from 'react-router-dom' ;
12
+ import gtag from '../../lib/gtag' ;
11
13
12
14
interface OwnProps { }
13
15
interface StateProps {
@@ -19,6 +21,24 @@ type CoreProps = OwnProps & StateProps & DispatchProps;
19
21
const Core : React . FC < CoreProps > = ( { layer } ) => {
20
22
useUserLoader ( ) ;
21
23
24
+ const history = useHistory ( ) ;
25
+
26
+ useEffect ( ( ) => {
27
+ const unregister = history . listen ( location => {
28
+ // adds setTimeout for page title sync
29
+ // is there any better solution?
30
+ setTimeout ( ( ) => {
31
+ gtag ( 'config' , 'UA-125599395-1' , {
32
+ page_path : location . pathname + location . search ,
33
+ } ) ;
34
+ } , 1000 ) ;
35
+ } ) ;
36
+
37
+ return ( ) => {
38
+ unregister ( ) ;
39
+ } ;
40
+ } , [ history ] ) ;
41
+
22
42
return (
23
43
< >
24
44
< OpaqueLayer visible = { layer } />
Original file line number Diff line number Diff line change
1
+ export default function gtag ( ...params : any [ ] ) {
2
+ if ( typeof window === 'undefined' ) return ;
3
+ const { gtag } = window as any ;
4
+ if ( ! gtag ) return ;
5
+ gtag ( ...params ) ;
6
+ }
Original file line number Diff line number Diff line change @@ -65,6 +65,19 @@ function Html({
65
65
/>
66
66
) ) }
67
67
< meta name = "viewport" content = "width=device-width, initial-scale=1" />
68
+ < script
69
+ async
70
+ src = "https://www.googletagmanager.com/gtag/js?id=UA-125599395-1"
71
+ > </ script >
72
+ < script
73
+ dangerouslySetInnerHTML = { {
74
+ __html : `window.dataLayer = window.dataLayer || [];
75
+ function gtag(){dataLayer.push(arguments);}
76
+ gtag('js', new Date());
77
+
78
+ gtag('config', 'UA-125599395-1');` ,
79
+ } }
80
+ > </ script >
68
81
</ head >
69
82
< body >
70
83
< div id = "root" dangerouslySetInnerHTML = { { __html : content } } > </ div >
You can’t perform that action at this time.
0 commit comments