Skip to content

Commit

Permalink
add plausible analytics
Browse files Browse the repository at this point in the history
  • Loading branch information
troypoulter committed May 18, 2023
1 parent a43b3b4 commit 2e892e8
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 3 deletions.
15 changes: 12 additions & 3 deletions app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import "@/styles/globals.css"
import { Metadata } from "next"

import { Analytics } from '@vercel/analytics/react';
import { Analytics } from "@vercel/analytics/react"

import { siteConfig } from "@/config/site"
import { fontSans } from "@/lib/fonts"
import { cn } from "@/lib/utils"
import { SiteHeader } from "@/components/site-header"
import { TailwindIndicator } from "@/components/tailwind-indicator"
import { ThemeProvider } from "@/components/theme-provider"
import PlausibleScript from "@/components/plausible-script"

export const metadata: Metadata = {
title: {
Expand All @@ -35,7 +35,15 @@ export default function RootLayout({ children }: RootLayoutProps) {
return (
<>
<html lang="en" suppressHydrationWarning>
<head />
<head>
<script
async
defer
src="/stats/js/script.js"
data-api="/stats/api/event"
data-domain="base64.troypoulter.com"
></script>
</head>
<body
className={cn(
"min-h-screen bg-background font-sans antialiased",
Expand All @@ -48,6 +56,7 @@ export default function RootLayout({ children }: RootLayoutProps) {
<div className="flex-1">{children}</div>
</div>
<Analytics />
{process.env.NODE_ENV === "production" && <PlausibleScript />}
<TailwindIndicator />
</ThemeProvider>
</body>
Expand Down
15 changes: 15 additions & 0 deletions components/plausible-script.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import Head from "next/head";

const PlausibleScript = () => (
<Head>
<script
key="plausible-script"
src="/stats/js/script.js"
async
defer
data-api="/stats/api/event"
data-domain="base64.troypoulter.com"
/>
</Head>
);
export default PlausibleScript;
12 changes: 12 additions & 0 deletions vercel.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"rewrites": [
{
"source": "/stats/js/script.js",
"destination": "https://plausible.io/js/script.js"
},
{
"source": "/stats/api/event",
"destination": "https://plausible.io/api/event"
}
]
}

1 comment on commit 2e892e8

@vercel
Copy link

@vercel vercel bot commented on 2e892e8 May 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.