Compare commits

...

1 Commits

Author SHA1 Message Date
09bae1126f BLOG-112 refactor: simplify Google Analytics script initialization and remove gtag declaration from Window interface
All checks were successful
PR Title Check / pr-title-check (pull_request) Successful in 13s
Frontend CI / build (push) Successful in 1m13s
2025-08-04 07:22:48 +08:00
2 changed files with 6 additions and 7 deletions

View File

@ -18,7 +18,6 @@ declare global {
interface Window {
dataLayer: unknown[];
gtag: (command: 'config' | 'set' | 'js' | 'event', ...args: unknown[]) => void;
}
}

View File

@ -1,4 +1,4 @@
<script lang="ts">
<script lang>
import { Environment } from '$lib/environment';
import { onMount } from 'svelte';
@ -19,10 +19,10 @@
document.head.appendChild(gaScript);
window.dataLayer = window.dataLayer || [];
window.gtag = (command: 'config' | 'set' | 'js' | 'event', ...args: unknown[]) => {
window.dataLayer.push(command, ...args);
};
window.gtag('js', new Date());
window.gtag('config', gaMeasurementId);
function gtag() {
window.dataLayer.push(arguments);
}
gtag('js', new Date());
gtag('config', gaMeasurementId);
});
</script>