Skip to content

Instantly share code, notes, and snippets.

@pmeyerdk
Last active September 3, 2022 17:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pmeyerdk/46b0bb2fcbee184be041a5d309d31dc3 to your computer and use it in GitHub Desktop.
Save pmeyerdk/46b0bb2fcbee184be041a5d309d31dc3 to your computer and use it in GitHub Desktop.
pmeyer.dk: Converting my Wordpress blog to Hugo
<noscript><iframe src="//www.googletagmanager.com/ns.html?id={{ .Site.Params.gtm_id }}" height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<script>
window.dataLayer = window.dataLayer || [];
window.dataLayer.push({
'page_title': '{{ .LinkTitle }}',
{{- if eq .Kind "page"}}
'page_id': '{{ with .File }}{{ .UniqueID }}{{ end }}',
{{- end}}
'page_permalink': '{{ .Permalink }}',
'page_kind': '{{ .Kind }}',
'page_type': '{{ .Type }}',
{{- if .Params.categories}}
'page_categories': '{{ delimit .Params.categories "|" }}',
{{- end }}
{{- if .Params.tags}}
'page_tags': '{{ delimit .Params.tags "|" }}',
{{- end }}
{{- if .ExpiryDate }}
'page_expiry_date': '{{.ExpiryDate.format "2006-01-02"}}',
{{- end }}
{{- if not (eq (.PublishDate.Format "2006-01-02") "0001-01-01")}}
'page_publish_date': '{{.PublishDate.Format "2006-01-02"}}',
'page_modified_date': '{{.Lastmod.Format "2006-01-02"}}',
{{- end }}
{{- if .ReadingTime }}
'page_reading_time_minutes':{{ .ReadingTime }},
'page_reading_time_seconds':{{- $readTime := mul (div (countwords .Content) 220.0) 60}}{{- math.Round $readTime}},
{{- end }}
{{- if not (eq .WordCount 0)}}
'page_word_count':{{ .WordCount }},
'page_fuzzy_word_count':{{ .FuzzyWordCount }},
{{- end }}
'page_author': '{{ if .Params.author -}}{{ .Params.author }}{{- else if .Site.Author.name -}}{{ .Site.Author.name }}{{- end }}',
'page_language': '{{ .Language }}',
'page_translated':{{ .IsTranslated }}
});
</script>
<link href="https://www.googletagmanager.com" rel="preconnect" crossorigin>
<link rel="dns-prefetch" href="https://www.googletagmanager.com">
<!-- 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','{{ .Site.Params.gtm_id }}');</script>
<!-- End Google Tag Manager -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment