add gtag
parent
870f508b54
commit
2c3f71079a
|
@ -0,0 +1,25 @@
|
|||
Reflect.set(self, "dataLayer", Reflect.get(self, "dataLayer") || []);
|
||||
|
||||
gtag("js", new Date());
|
||||
gtag("config", "G-HRBGCQKEY6");
|
||||
loadScript("https://www.googletagmanager.com/gtag/js?id=G-HRBGCQKEY6");
|
||||
|
||||
export function gtag(name: "js", value: Date): void;
|
||||
export function gtag(name: "config", value: string): void;
|
||||
export function gtag(name: "event", action: string, params: object): void;
|
||||
export function gtag(): void {
|
||||
Reflect.get(self, "dataLayer").push(arguments);
|
||||
}
|
||||
|
||||
function loadScript(url: string) {
|
||||
return new Promise<void>((resolve, reject) => {
|
||||
const element = document.createElement("script");
|
||||
element.src = url;
|
||||
element.addEventListener("load", () => {
|
||||
resolve();
|
||||
element.remove();
|
||||
});
|
||||
element.addEventListener("error", reject);
|
||||
document.head.appendChild(element);
|
||||
});
|
||||
}
|
|
@ -2,5 +2,11 @@
|
|||
<hr>
|
||||
<p>本文仅供学习所用,严禁转载或商业加工,任何需求请联系译者 (<a href="mailto:nao@sakuras.jp">佐倉 奈緒</a>)</p>
|
||||
</article>
|
||||
{{ $customize_js := resources.Get "customize.js" | js.Build | resources.Minify | resources.Fingerprint "sha512" }}
|
||||
<script src="{{ $customize_js.Permalink }}" integrity="{{ $customize_js.Data.Integrity }}"></script>
|
||||
{{- with resources.Get "customize.js" | js.Build | minify | fingerprint }}
|
||||
<script src="{{ .Permalink }}" integrity="{{ .Data.Integrity }}"></script>
|
||||
{{- end }}
|
||||
{{- if hugo.IsProduction }}
|
||||
{{- with resources.Get "gtag.ts" | js.Build | minify | fingerprint }}
|
||||
<script src="{{ .Permalink }}" integrity="{{ .Data.Integrity }}"></script>
|
||||
{{- end }}
|
||||
{{- end }}
|
Loading…
Reference in New Issue