Skip to content

Commit

Permalink
enable analytics
Browse files Browse the repository at this point in the history
  • Loading branch information
raymonstah committed Apr 2, 2024
1 parent 9b4cf45 commit d957161
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 12 deletions.
2 changes: 2 additions & 0 deletions functions/api/server/public/templates/about.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
<link href="/output.css" rel="stylesheet" />
<script src="/1.9.10.htmx.min.js"></script>

{{ template "rollbar.html" . }}
{{ template "google-analytics.html" . }}
{{ template "dark-mode.html" . }}

</head>
Expand Down
2 changes: 2 additions & 0 deletions functions/api/server/public/templates/error.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
<link href="/output.css" rel="stylesheet" />
<script src="/1.9.10.htmx.min.js"></script>

{{ template "rollbar.html" . }}
{{ template "google-analytics.html" . }}
{{ template "google-ads.html" . }}
{{ template "dark-mode.html" . }}

Expand Down
12 changes: 12 additions & 0 deletions functions/api/server/public/templates/google-analytics.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!-- For Google Analytics -->
{{ if .EnableAnalytics }}
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-DNWC1SD6ZZ"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());

gtag('config', 'G-DNWC1SD6ZZ');
</script>
{{ end }}
1 change: 1 addition & 0 deletions functions/api/server/public/templates/humans-id.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<link rel="icon" href="/favicon.ico" type="image/x-icon" />
<link href="/output.css" rel="stylesheet" />
{{ template "rollbar.html" . }}
{{ template "google-analytics.html" . }}
<script src="/1.9.10.htmx.min.js"></script>

{{ template "google-ads.html" . }}
Expand Down
1 change: 1 addition & 0 deletions functions/api/server/public/templates/humans.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="icon" href="/favicon.ico" type="image/x-icon" />
{{ template "rollbar.html" . }}
{{ template "google-analytics.html" . }}
<link href="/output.css" rel="stylesheet" />
<script src="/1.9.10.htmx.min.js"></script>

Expand Down
1 change: 1 addition & 0 deletions functions/api/server/public/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="icon" href="/favicon.ico" type="image/x-icon" />
{{ template "rollbar.html" . }}
{{ template "google-analytics.html" . }}
<link href="/output.css" rel="stylesheet" />
<script src="/1.9.10.htmx.min.js"></script>

Expand Down
26 changes: 14 additions & 12 deletions functions/api/server/server-html.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,11 @@ func (s *ServerHTML) HandlerError(w http.ResponseWriter, r *http.Request, e Erro
}

type Base struct {
Local bool
EnableAds bool
RollbarToken string
Admin bool
Local bool
EnableAds bool
EnableAnalytics bool
RollbarToken string
Admin bool
}

type HTMLResponseHumans struct {
Expand Down Expand Up @@ -338,9 +339,10 @@ func (s *ServerHTML) HandlerHumans(w http.ResponseWriter, r *http.Request) error

response := HTMLResponseHumans{
Base: Base{
Local: s.local,
EnableAds: !s.local,
RollbarToken: s.rollbarToken,
Local: s.local,
EnableAds: !s.local,
EnableAnalytics: !s.local,
RollbarToken: s.rollbarToken,
},
Count: len(humans),
Humans: humans,
Expand Down Expand Up @@ -404,7 +406,7 @@ func (s *ServerHTML) HandlerHuman(w http.ResponseWriter, r *http.Request) error
return NewNotFoundError(fmt.Errorf("%w: %v", humandao.ErrHumanNotFound, path))
}

base := Base{EnableAds: !s.local, Admin: admin, RollbarToken: s.rollbarToken, Local: s.local}
base := Base{EnableAds: !s.local, EnableAnalytics: !s.local, Admin: admin, RollbarToken: s.rollbarToken, Local: s.local}
response := HTMLResponseHuman{Human: human, Base: base}
if err := s.template.ExecuteTemplate(w, "humans-id.html", response); err != nil {
s.logger.Error().Err(err).Msg("unable to execute humans-id template")
Expand Down Expand Up @@ -449,7 +451,7 @@ func (s *ServerHTML) HandlerHumanEdit(w http.ResponseWriter, r *http.Request) er
return err
}

base := Base{EnableAds: !s.local, Admin: admin, RollbarToken: s.rollbarToken, Local: s.local}
base := Base{EnableAds: !s.local, EnableAnalytics: !s.local, Admin: admin, RollbarToken: s.rollbarToken, Local: s.local}
response := HTMLResponseHuman{Human: human, Base: base}
if err := s.template.ExecuteTemplate(w, "humans-id-edit.html", response); err != nil {
s.logger.Error().Err(err).Msg("unable to execute humans-id-edit.html template")
Expand Down Expand Up @@ -495,7 +497,7 @@ func (s *ServerHTML) HandlerHumanUpdate(w http.ResponseWriter, r *http.Request)
return err
}

base := Base{EnableAds: !s.local, Admin: s.local, RollbarToken: s.rollbarToken, Local: s.local}
base := Base{EnableAds: !s.local, EnableAnalytics: !s.local, Admin: s.local, RollbarToken: s.rollbarToken, Local: s.local}
response := HTMLResponseHuman{Human: human, Base: base}
if err := s.template.ExecuteTemplate(w, "humans-id.html", response); err != nil {
s.logger.Error().Err(err).Msg("unable to execute humans-id template")
Expand Down Expand Up @@ -543,12 +545,12 @@ func (s *ServerHTML) HandlerLogin(w http.ResponseWriter, r *http.Request) error
referer = "/admin"
}

w.Header().Add("HX-Redirect", referer) // not needed, but just in case I decide to switch to htmx.ajax()
w.Header().Add("HX-Redirect", referer)
http.Redirect(w, r, referer, http.StatusFound)
return nil
}

base := Base{EnableAds: !s.local, Admin: s.local, RollbarToken: s.rollbarToken, Local: s.local}
base := Base{EnableAds: !s.local, EnableAnalytics: !s.local, Admin: s.local, RollbarToken: s.rollbarToken, Local: s.local}
response := HTMLResponseLogin{Base: base}
if err := s.template.ExecuteTemplate(w, "login.html", response); err != nil {
s.logger.Error().Err(err).Msg("unable to execute login template")
Expand Down

0 comments on commit d957161

Please sign in to comment.