add gtag
parent
289e923111
commit
0d32150f91
|
@ -0,0 +1,45 @@
|
|||
export {};
|
||||
|
||||
declare global {
|
||||
interface Window {
|
||||
dataLayer: IArguments[];
|
||||
}
|
||||
}
|
||||
|
||||
const IDENTIFY = "G-N24RP9JT2Q";
|
||||
|
||||
self.dataLayer = self.dataLayer || [];
|
||||
|
||||
gtag("js", new Date());
|
||||
gtag("config", IDENTIFY);
|
||||
restoreClientID();
|
||||
|
||||
loadScript("https://www.googletagmanager.com/gtag/js?id=" + IDENTIFY);
|
||||
|
||||
function gtag(method: string, ...params: unknown[]): void {
|
||||
self.dataLayer.push(arguments);
|
||||
}
|
||||
|
||||
function restoreClientID() {
|
||||
const KEY = "GA:CLIENT-ID";
|
||||
const clientId = sessionStorage.getItem(KEY);
|
||||
if (clientId) {
|
||||
gtag("set", "client_id", clientId);
|
||||
} else {
|
||||
gtag("get", IDENTIFY, "client_id", (client_id: string) => {
|
||||
sessionStorage.setItem(KEY, client_id);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function loadScript(src: string) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const element = document.createElement("script");
|
||||
element.src = src;
|
||||
element.async = true;
|
||||
element.defer = true;
|
||||
element.addEventListener("load", resolve);
|
||||
element.addEventListener("error", reject);
|
||||
document.head.appendChild(element);
|
||||
});
|
||||
}
|
|
@ -2,6 +2,5 @@
|
|||
{{ partial "main/header.html" . }}
|
||||
{{ end }}
|
||||
{{ define "main" }}
|
||||
{{ $section_to_display := .Pages }}
|
||||
{{ partial "main/list.html" (dict "context" . "section_to_display" $section_to_display) }}
|
||||
{{ partial "main/list.html" (dict "context" . "section_to_display" .Pages) }}
|
||||
{{ end }}
|
|
@ -0,0 +1,8 @@
|
|||
{{- if ne .Site.BaseURL "https://mtf.wiki" }}
|
||||
<meta name="robots" content="noindex, nofollow">
|
||||
{{- end }}
|
||||
{{- if hugo.IsProduction }}
|
||||
{{- with resources.Get "gtag.ts" | js.Build | minify | fingerprint }}
|
||||
<script src="{{ .Permalink }}" async defer></script>
|
||||
{{- end }}
|
||||
{{- end }}
|
|
@ -1,8 +1,6 @@
|
|||
User-agent: *
|
||||
{{- if eq .Site.BaseURL "https://mtf.wiki" }}
|
||||
{{- range $.Site.Home.AllTranslations }}
|
||||
Sitemap: {{ .RelPermalink }}sitemap.xml
|
||||
{{- end }}
|
||||
Sitemap: {{ absURL "sitemap.xml" }}
|
||||
{{- else }}
|
||||
Disallow: /
|
||||
{{- end }}
|
Loading…
Reference in New Issue