Skip to content

Commit

Permalink
LMD-0003: Migrate to google analytics 4 (#39)
Browse files Browse the repository at this point in the history
* LMD-0003: Migrate to google analytics 4

* LMD-0003: Fetch the tag manager id from params
  • Loading branch information
DivLoic authored May 12, 2024
1 parent 089f67c commit a2273a5
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 13 deletions.
2 changes: 1 addition & 1 deletion config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ summarylength: 50

# Google Analytics
googleAnalytics: "UA-155287871-1"
tagManagerId: "GTM-KXQLGWGM"

# Syntax highlighting
pygmentsCodefences: true
Expand Down Expand Up @@ -46,6 +45,7 @@ params:
project_tagline: "Event Streams and Monads in the Cloud"
author:
name: "Loïc DIVAD"
tagManagerId: "GTM-KXQLGWGM"
mainSections: "posts"
socials:
linkedin: "https://www.linkedin.com/in/lo%C3%AFc-divad-3a5a9893/"
Expand Down
2 changes: 1 addition & 1 deletion layouts/_default/baseof.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
<html lang="{{ .Site.Language.Lang }}">
{{ partial "head.html" . }}
<body>
{{ partial "google-analytics4-body.html" . }}
{{ partial "header-nav.html" . }}
<section class="main-content">
{{ block "main" . }}{{ end }}
{{ partial "footer.html" . }}
</section>
</body>
{{ partial "google-analytics-async.html" . }}
{{- range .Site.Params.extra_js }}<script src="{{ . | absURL }}"></script>{{- end }}
{{- range .Params.extra_js }}<script src="{{ . | absURL }}"></script>{{- end }}
</html>
11 changes: 0 additions & 11 deletions layouts/partials/google-analytics-async.html

This file was deleted.

6 changes: 6 additions & 0 deletions layouts/partials/google-analytics4-body.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{{ if not $.Site.IsServer }}
{{ with $.Site.Params.TagManagerId }}<!-- Google Tag Manager (noscript) -->
<noscript><iframe src="https://www.googletagmanager.com/ns.html?id={{ . }}"
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<!-- End Google Tag Manager (noscript) -->{{ end }}
{{ end }}
9 changes: 9 additions & 0 deletions layouts/partials/google-analytics4-head.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{{ if not $.Site.IsServer }}
{{ with $.Site.Params.TagManagerId }}<!-- Google Tag Manager -->
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','{{ . }}');</script>
<!-- End Google Tag Manager -->{{ end }}
{{ end }}
1 change: 1 addition & 0 deletions layouts/partials/head.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<head>
{{ partial "google-analytics4-head.html" . }}
{{ $og_image := (cond (ne (.Param "thumbnail") nil) (.Param "thumbnail") (.Param "post_banner") ) }}
{{ $og_desc := (cond (ne (.Param "title") nil) (.Param "title" | printf ": %s") (", Event Streams and Monads in the Cloud") ) }}
<meta charset="utf-8">
Expand Down

0 comments on commit a2273a5

Please sign in to comment.