improve google analytics page title
parent
aebb2689bb
commit
678c7c235c
|
@ -10,7 +10,9 @@ function gtag() {
|
||||||
}
|
}
|
||||||
|
|
||||||
gtag('js', new Date())
|
gtag('js', new Date())
|
||||||
gtag('config', MEASUREMENT_ID)
|
gtag('config', MEASUREMENT_ID, {
|
||||||
|
page_title: meta('meta[property="og:title"]'),
|
||||||
|
})
|
||||||
|
|
||||||
const script = document.createElement('script')
|
const script = document.createElement('script')
|
||||||
script.async = true
|
script.async = true
|
||||||
|
@ -20,3 +22,7 @@ script.addEventListener('load', () => script.remove())
|
||||||
document.currentScript!.remove()
|
document.currentScript!.remove()
|
||||||
|
|
||||||
document.head.append(script)
|
document.head.append(script)
|
||||||
|
|
||||||
|
function meta(selector: string) {
|
||||||
|
return document.head.querySelector<HTMLMetaElement>(selector)?.content
|
||||||
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
{{- $defines := dict "MEASUREMENT_ID" (jsonify .Site.GoogleAnalytics) -}}
|
{{- $defines := dict "MEASUREMENT_ID" (jsonify .Site.GoogleAnalytics) -}}
|
||||||
|
{{- $page := . -}}
|
||||||
{{- with resources.Get "gtag.ts" | js.Build (dict "defines" $defines) | minify | fingerprint }}
|
{{- with resources.Get "gtag.ts" | js.Build (dict "defines" $defines) | minify | fingerprint }}
|
||||||
<script async defer src="{{ .Permalink }}"></script>
|
<script src="{{ .Permalink }}"></script>
|
||||||
{{- end }}
|
{{- end }}
|
Loading…
Reference in New Issue