Skip to content

Commit f19a94b

Browse files
committed
tweak
1 parent 8d37a1f commit f19a94b

File tree

3 files changed

+24
-6
lines changed

3 files changed

+24
-6
lines changed

src/global.d.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Google Analyticsのgtag関数の型定義
2+
interface Gtag {
3+
(command: 'config', targetId: string, config?: Record<string, any>): void;
4+
(
5+
command: 'event',
6+
eventName: string,
7+
eventParams?: {
8+
event_category?: string;
9+
event_label?: string;
10+
value?: number;
11+
[key: string]: any;
12+
}
13+
): void;
14+
}
15+
16+
// グローバルにgtagを宣言
17+
declare var gtag: Gtag;
18+
19+
export {};

src/lib/ga.svelte

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
<script lang="ts">
2-
import { page } from '$app/stores'
2+
import { onMount } from 'svelte';
33
4-
$: {
4+
onMount(() => {
55
if (typeof gtag !== 'undefined') {
66
gtag('config', 'G-MB7JWEJ8K7', {
77
page_title: document.title,
8-
page_path: $page.url.pathname,
9-
})
8+
page_path: window.location.pathname,
9+
});
1010
}
11-
}
11+
});
1212
</script>
1313

1414
<svelte:head>

src/routes/+layout.svelte

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import Analytics from '$lib/ga.svelte'
88
99
let title = "ゆーちゃん's Gists Portfolio";
1010
let description = 'ゆーちゃんのGitHub Gistsを集めたポートフォリオサイトです。';
11-
1211
</script>
1312

1413
<svelte:head>

0 commit comments

Comments
 (0)