File tree 4 files changed +29
-14
lines changed
4 files changed +29
-14
lines changed Original file line number Diff line number Diff line change @@ -66,6 +66,7 @@ func main() {
66
66
googleSecret = fs .String ("google.secret" , "" , "Google OAuth2 secret." )
67
67
googleRedirect = fs .String ("google.redirect" , "" , "Google OAuth2 redirect URL." )
68
68
healthzToken = fs .String ("health.token" , "" , "Token for the health check endpoint" )
69
+ usePlausible = fs .Bool ("plausible" , false , "Use plausible.io for tracking statistics" )
69
70
devMode = fs .Bool ("dev" , false , "Run in development mode." )
70
71
_ = fs .String ("config" , "" , "Config file (optional)" )
71
72
)
@@ -119,6 +120,7 @@ func main() {
119
120
http .WithDatabase (db ),
120
121
http .WithStationService (stationService ),
121
122
http .WithDevMode (* devMode ),
123
+ http .WithPlausible (* usePlausible ),
122
124
)
123
125
124
126
// Initialize authentication handler.
Original file line number Diff line number Diff line change 21
21
22
22
// Handler serves various HTTP endpoints.
23
23
type Handler struct {
24
- mux * http.ServeMux
25
- devMode bool
24
+ mux * http.ServeMux
25
+ devMode bool
26
+ plausible bool
26
27
27
28
db browser.Database
28
29
stationService browser.StationService
@@ -96,6 +97,12 @@ func WithDevMode(mode bool) Option {
96
97
}
97
98
}
98
99
100
+ func WithPlausible (use bool ) Option {
101
+ return func (h * Handler ) {
102
+ h .plausible = use
103
+ }
104
+ }
105
+
99
106
func (h * Handler ) handleVersion (w http.ResponseWriter , r * http.Request ) {
100
107
w .Header ().Set ("Content-Type" , "text/plain" )
101
108
w .Write ([]byte (browser .Version ))
Original file line number Diff line number Diff line change 26
26
<script src="/assets/third_party/jquery/jquery-ui.min.js"></script>
27
27
<script src="/assets/third_party/bootstrap/js/bootstrap.min.js"></script>
28
28
<script src="/assets/third_party/cookies-eu-banner/js/cookies-eu-banner.js"></script>
29
- <script defer data-domain="browser.lter.eurac.edu" src="https://plausible.io/js/plausible.js"></script>
29
+ {{ if .Plausible }} <script defer data-domain="browser.lter.eurac.edu" src="https://plausible.io/js/plausible.js"></script>{{ end }}
30
30
<link rel="icon" type="image/png" sizes="32x32" href="/assets/favicon-32x32.png">
31
31
<link rel="icon" type="image/png" sizes="16x16" href="/assets/favicon-16x16.png">
32
32
<link rel="apple-touch-icon" href="/assets/favicon-196x196.png">
Original file line number Diff line number Diff line change @@ -65,6 +65,7 @@ func (h *Handler) handleIndex() http.HandlerFunc {
65
65
Token string
66
66
StartDate string
67
67
EndDate string
68
+ Plausible bool
68
69
}{
69
70
data ,
70
71
browser .GroupsByRole (user .Role ),
@@ -75,6 +76,7 @@ func (h *Handler) handleIndex() http.HandlerFunc {
75
76
middleware .XSRFTokenPlaceholder ,
76
77
time .Now ().AddDate (0 , - 6 , 0 ).Format ("2006-01-02" ),
77
78
time .Now ().Format ("2006-01-02" ),
79
+ h .plausible ,
78
80
})
79
81
if err != nil {
80
82
Error (w , err , http .StatusInternalServerError )
@@ -112,18 +114,20 @@ func (h *Handler) handleHello() http.HandlerFunc {
112
114
}
113
115
114
116
err = tmpl .Execute (w , struct {
115
- Data browser.Stations
116
- User * browser.User
117
- Language string
118
- Path string
119
- Token string
120
- Content template.HTML
117
+ Data browser.Stations
118
+ User * browser.User
119
+ Language string
120
+ Path string
121
+ Token string
122
+ Plausible bool
123
+ Content template.HTML
121
124
}{
122
125
data ,
123
126
user ,
124
127
lang ,
125
128
name ,
126
129
middleware .XSRFTokenPlaceholder ,
130
+ h .plausible ,
127
131
template .HTML (license ),
128
132
})
129
133
if err != nil {
@@ -175,16 +179,18 @@ func (h *Handler) handleStaticPage() http.HandlerFunc {
175
179
}
176
180
177
181
err = tmpl .Execute (w , struct {
178
- Data browser.Stations
179
- User * browser.User
180
- Language string
181
- Path string
182
- Content template.HTML
182
+ Data browser.Stations
183
+ User * browser.User
184
+ Language string
185
+ Path string
186
+ Plausible bool
187
+ Content template.HTML
183
188
}{
184
189
data ,
185
190
user ,
186
191
lang ,
187
192
name ,
193
+ h .plausible ,
188
194
template .HTML (p ),
189
195
})
190
196
if err != nil {
You can’t perform that action at this time.
0 commit comments