Skip to content

Commit

Permalink
chore: add google Analytics
Browse files Browse the repository at this point in the history
  • Loading branch information
mildronize committed May 23, 2024
1 parent 7d1b468 commit 4eaef3d
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions docs/.vitepress/shared.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { defineConfig } from "vitepress";
import { defineConfig, type HeadConfig } from "vitepress";
import { transformerTwoslash } from "@shikijs/vitepress-twoslash";
import { Sidebar } from "../../utils/utils";

Expand All @@ -22,22 +22,32 @@ export const shared = defineConfig({
},
},

head: [
head: [...googleFonts(), ...googleAnalytics("G-LWNNLXVF0K")],
});

function googleAnalytics(tagManagerId: string): HeadConfig[] {
return [
["script", { async: "", src: `https://www.googletagmanager.com/gtag/js?id=${tagManagerId}` }],
[
"script",
{},
`window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', '${tagManagerId}');`,
],
];
}

function googleFonts(): HeadConfig[] {
return [
["link", { rel: "preconnect", href: "https://fonts.googleapis.com" }],
["link", { rel: "preconnect", href: "https://fonts.gstatic.com", crossorigin: "" }],
[
"link",
{ href: "https://fonts.googleapis.com/css2?family=Noto+Sans+Thai:[email protected]&display=swap", rel: "stylesheet" },
],
],
});

interface SidebarOptions {
isCollapsed?: boolean;
/**
* @default '' (Means en for English)
*/
locale?: string;
];
}

export const baseSidebar = new Sidebar({
Expand Down

0 comments on commit 4eaef3d

Please sign in to comment.