Skip to content

Commit

Permalink
Merge pull request #15 from xandemon/analytics
Browse files Browse the repository at this point in the history
Integrate basic analytics with GA4
  • Loading branch information
xandemon committed Nov 6, 2024
2 parents eedd2f3 + 0cc39b0 commit 156057c
Show file tree
Hide file tree
Showing 15 changed files with 88 additions and 18 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/astro.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ env:
jobs:
build:
name: Build
env:
PUBLIC_GA_MEASUREMENT_ID: ${{ secrets.PUBLIC_GA_MEASUREMENT_ID }}
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand Down
1 change: 0 additions & 1 deletion docs/.env

This file was deleted.

1 change: 1 addition & 0 deletions docs/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ yarn-error.log*
pnpm-debug.log*

# environment variables
.env
.env.production

# macOS-specific files
Expand Down
17 changes: 9 additions & 8 deletions docs/astro.config.mjs
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import { defineConfig } from "astro/config";
import react from "@astrojs/react";

import tailwind from "@astrojs/tailwind";
import partytown from "@astrojs/partytown";

// https://astro.build/config
export default defineConfig({
site: "https://xandemon.github.io",
base: "/developer-icons/docs",
publicDir: "./assets",
integrations: [
react(),
tailwind({
applyBaseStyles: false,
}),
],
});
integrations: [react(), tailwind({
applyBaseStyles: false,
}), partytown({
config: {
forward: ['dataLayer.push']
}
})],
});
23 changes: 23 additions & 0 deletions docs/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
},
"dependencies": {
"@astrojs/check": "^0.6.0",
"@astrojs/partytown": "^2.1.2",
"@astrojs/react": "^3.3.4",
"@astrojs/tailwind": "^5.1.0",
"@fontsource-variable/noto-sans": "^5.0.5",
Expand Down
2 changes: 1 addition & 1 deletion docs/src/components/HeroSection.astro
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { ArrowUpRight } from "lucide-react";
import { Badge } from "./ui/badge";
import { Button } from "./ui/button";
import { publicBaseUrl } from "@/lib/utils";
import { publicBaseUrl } from "@/config";
---

<div class="flex items-center justify-between gap-4 w-full py-4">
Expand Down
2 changes: 1 addition & 1 deletion docs/src/components/Navbar.astro
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
import { GitHubDarkIcon, NPMIcon } from "developer-icons";
import Container from "./Container.astro";
import { publicBaseUrl } from "@/lib/utils";
import { publicBaseUrl } from "@/config";
---

<div class="navbar bg-zinc-900">
Expand Down
2 changes: 1 addition & 1 deletion docs/src/components/UnderDevelopment.astro
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
import { Button } from "./ui/button";
import { publicBaseUrl } from "@/lib/utils";
import { publicBaseUrl } from "@/config";
---

<div class="w-full flex flex-col items-center justify-center gap-6">
Expand Down
3 changes: 2 additions & 1 deletion docs/src/components/ui/iconCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import type { IconDataType } from "../../../../lib/iconsData";
import { generateIconCompName } from "../../../../lib/utils";
import { Badge } from "./badge";
import { Loader } from "./loader";
import { downloader, publicBaseUrl } from "@/lib/utils";
import { downloader } from "@/lib/utils";
import { publicBaseUrl } from "@/config";

export const IconCard = ({ icon }: { icon: IconDataType }) => {
const [downloadLoading, setDownloadLoading] = useState(false);
Expand Down
5 changes: 5 additions & 0 deletions docs/src/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const publicBaseUrl = import.meta.env.PROD
? "/developer-icons"
: "/developer-icons/docs";

export { publicBaseUrl };
21 changes: 20 additions & 1 deletion docs/src/layouts/DocsLayout.astro
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
---
import Container from "@/components/Container.astro";
import Navbar from "@/components/Navbar.astro";
import { cn, publicBaseUrl } from "@/lib/utils";
import { cn } from "@/lib/utils";
import { publicBaseUrl } from "@/config";
import "@fontsource-variable/noto-sans";
import "../styles/globals.css";
import "../styles/docs.css";
Expand Down Expand Up @@ -42,6 +43,24 @@ flattenedDocs.sort((a, b) => a.frontmatter.order - b.frontmatter.order);
<meta name="generator" content={Astro.generator} />

<title>{props.frontmatter.title}</title>

<!-- Google tag (gtag.js) -->
<script
type="text/partytown"
src="https://www.googletagmanager.com/gtag/js?id=G-ELYLP3JJDR"></script>
<script
type="text/partytown"
define:vars={{ measurementId: import.meta.env.PUBLIC_GA_MEASUREMENT_ID }}
>
{
`window.dataLayer = window.dataLayer || [];
function gtag() {
dataLayer.push(arguments);
}
gtag("js", new Date());
gtag("config", "${measurementId}");`;
}
</script>
</head>
<body class="text-zinc-300 bg-zinc-900 min-h-screen">
<Navbar />
Expand Down
21 changes: 20 additions & 1 deletion docs/src/layouts/Layout.astro
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
import Container from "@/components/Container.astro";
import Navbar from "@/components/Navbar.astro";
import { publicBaseUrl } from "@/lib/utils";
import { publicBaseUrl } from "@/config";
import "@fontsource-variable/noto-sans";
import "../styles/globals.css";
Expand All @@ -28,6 +28,25 @@ const { title } = Astro.props;
/>
<meta name="generator" content={Astro.generator} />
<title>{title}</title>

<!-- Google tag (gtag.js) -->
<script
type="text/partytown"
src="https://www.googletagmanager.com/gtag/js?id=G-ELYLP3JJDR"></script>
<script
type="text/partytown"
define:vars={{ measurementId: import.meta.env.PUBLIC_GA_MEASUREMENT_ID }}
>
{
`window.dataLayer = window.dataLayer || [];
function gtag() {
dataLayer.push(arguments);
}
gtag("js", new Date());
gtag("config", "${measurementId}");`;
}
console.log(measurementId);
</script>
</head>
<body class="text-zinc-300 bg-zinc-900 min-h-screen">
<Navbar />
Expand Down
2 changes: 0 additions & 2 deletions docs/src/lib/utils.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { type ClassValue, clsx } from "clsx";
import { twMerge } from "tailwind-merge";

export const publicBaseUrl = import.meta.env.VITE_PUBLIC_BASE_URL;

export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs));
}
Expand Down
3 changes: 2 additions & 1 deletion docs/src/pages/icons/[category].astro
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import Layout from "@/layouts/Layout.astro";
import { IconsList } from "@/components/iconsList";
import { categoriesData, iconsData } from "../../../../lib/iconsData";
import type { Category as CategoryType } from "../../../../lib/iconsData";
import { cn, publicBaseUrl } from "@/lib/utils";
import { cn } from "@/lib/utils";
import { publicBaseUrl } from "@/config";
export function getStaticPaths() {
return ["All", ...categoriesData].map((category) => ({
Expand Down

0 comments on commit 156057c

Please sign in to comment.