Skip to content

Commit ba7888e

Browse files
committed
optional Google Analytics tag support
1 parent abb9d5b commit ba7888e

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ UI := ./web
33
TARGET := ./target
44
LISTEN_ADDR := 0.0.0.0:8000
55
DEBUG ?= true
6+
GTAG ?= # Set GTAG to enable Google Analytics
67

78
.PHONY:all
89
all: build
@@ -16,5 +17,5 @@ run:
1617

1718
.PHONY:ui
1819
ui:
19-
@cd $(UI) && REACT_APP_LANG_SERVER=http://$(LISTEN_ADDR) REACT_APP_VERSION=testing yarn start
20+
@cd $(UI) && REACT_APP_LANG_SERVER=http://$(LISTEN_ADDR) REACT_APP_GTAG=$(GTAG) REACT_APP_VERSION=testing yarn start
2021

web/public/index.html

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
66
<meta name="viewport" content="width=device-width, initial-scale=1" />
77
<meta name="theme-color" content="#000000" />
8+
<meta name="x-gtag" content="%REACT_APP_GTAG%" />
89
<meta
910
name="description"
1011
content="Better Go Playground with syntax highlight support"
@@ -29,5 +30,22 @@
2930
<body>
3031
<noscript>You need to enable JavaScript to run this app.</noscript>
3132
<div id="root"></div>
33+
<script>
34+
(function(d){
35+
var e = d.querySelector('meta[name=x-gtag]');
36+
if (!e || !e.content) return;
37+
var s = d.createElement('script');
38+
s.async = true; s.src = "https://www.googletagmanager.com/gtag/js?id=" + e.content;
39+
s.onload = function() {
40+
console.log('GA load done');
41+
window.dataLayer = window.dataLayer || [];
42+
function gtag(){dataLayer.push(arguments);}
43+
gtag('js', new Date());
44+
45+
gtag('config', 'UA-164070125-1');
46+
};
47+
d.body.appendChild(s);
48+
})(document)
49+
</script>
3250
</body>
3351
</html>

0 commit comments

Comments
 (0)