Skip to content

Commit

Permalink
feat: add analytics
Browse files Browse the repository at this point in the history
  • Loading branch information
arian81 committed Jun 21, 2024
1 parent dc33fa6 commit 2e631ec
Show file tree
Hide file tree
Showing 5 changed files with 151 additions and 102 deletions.
13 changes: 13 additions & 0 deletions next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,18 @@ const config = {
},
],
},
async rewrites() {
return [
{
source: "/ingest/static/:path*",
destination: "https://us-assets.i.posthog.com/static/:path*",
},
{
source: "/ingest/:path*",
destination: "https://us.i.posthog.com/:path*",
},
];
},
skipTrailingSlashRedirect: true,
};
export default config;
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"next": "^14.1.1",
"next-sanity": "^7.0.10",
"next-themes": "^0.2.1",
"posthog-js": "^1.139.6",
"react": "18.2.0",
"react-dom": "18.2.0",
"react-markdown": "^9.0.1",
Expand Down
21 changes: 21 additions & 0 deletions pnpm-lock.yaml

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

8 changes: 6 additions & 2 deletions src/env.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ const client = z.object({
// NEXT_PUBLIC_CLIENTVAR: z.string().min(1),
NEXT_PUBLIC_LASTFM_USERNAME: z.string(),
NEXT_PUBLIC_LASTFM_TOKEN: z.string(),
NEXT_PUBLIC_POSTHOG_KEY: z.string(),
NEXT_PUBLIC_POSTHOG_HOST: z.string(),
});

/**
Expand All @@ -29,6 +31,8 @@ const processEnv = {
// NEXT_PUBLIC_CLIENTVAR: process.env.NEXT_PUBLIC_CLIENTVAR,
NEXT_PUBLIC_LASTFM_USERNAME: process.env.NEXT_PUBLIC_LASTFM_USERNAME,
NEXT_PUBLIC_LASTFM_TOKEN: process.env.NEXT_PUBLIC_LASTFM_TOKEN,
NEXT_PUBLIC_POSTHOG_KEY: process.env.NEXT_PUBLIC_POSTHOG_KEY,
NEXT_PUBLIC_POSTHOG_HOST: process.env.NEXT_PUBLIC_POSTHOG_HOST,
};

// Don't touch the part below
Expand All @@ -54,7 +58,7 @@ if (!!process.env.SKIP_ENV_VALIDATION == false) {
if (parsed.success === false) {
console.error(
"❌ Invalid environment variables:",
parsed.error.flatten().fieldErrors
parsed.error.flatten().fieldErrors,
);
throw new Error("Invalid environment variables");
}
Expand All @@ -68,7 +72,7 @@ if (!!process.env.SKIP_ENV_VALIDATION == false) {
throw new Error(
process.env.NODE_ENV === "production"
? "❌ Attempted to access a server-side environment variable on the client"
: `❌ Attempted to access server-side environment variable '${prop}' on the client`
: `❌ Attempted to access server-side environment variable '${prop}' on the client`,
);
return target[/** @type {keyof typeof target} */ (prop)];
},
Expand Down
210 changes: 110 additions & 100 deletions src/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,26 @@ import "~/styles/globals.css";
import { NextPage } from "next";
import { AppProps } from "next/app";
import "easymde/dist/easymde.min.css";
// import "../styles/github-dark.css";
// import "../styles/isbl-editor-dark.css";
import "../styles/catppuccin-frape.css";
import "../styles/callout-style.css";

const outfit = Outfit({ subsets: ["latin"] });
import posthog from "posthog-js";
import { PostHogProvider } from "posthog-js/react";
import { env } from "~/env.mjs";

if (typeof window !== "undefined") {
// checks that we are client-side
posthog.init(env.NEXT_PUBLIC_POSTHOG_KEY, {
api_host: "/ingest",
ui_host: env.NEXT_PUBLIC_POSTHOG_HOST || "https://us.i.posthog.com",
person_profiles: "always", // or 'always' to create profiles for anonymous users as well
loaded: (posthog) => {
if (process.env.NODE_ENV === "development") posthog.debug(); // debug mode in development
},
});
}

const outfit = Outfit({ subsets: ["latin"] });
const open = Open_Sans({ weight: ["400", "500", "700"], subsets: ["latin"] });

export type NextPageWithLayout<P = {}, IP = P> = NextPage<P, IP> & {
Expand All @@ -36,106 +49,103 @@ const MyApp: AppType = ({ Component, pageProps }: AppPropsWithLayout) => {
return (
<QueryClientProvider client={queryClient}>
<ThemeProvider attribute="class">
<Head>
{/* <script
async
crossOrigin="anonymous"
src="https://pep.dev/pep.js#Tu9mVg8m"
></script> */}
<meta
name="description"
content="Hey this is Arian Ahmadinejad. Software engineer from Canada, pursuing computer science to hack into the Matrix."
/>
<PostHogProvider client={posthog}>
<Head>
<meta
name="description"
content="Hey this is Arian Ahmadinejad. Software engineer from Canada, pursuing computer science to hack into the Matrix."
/>

{/* <!-- Facebook Meta Tags --> */}
<meta property="og:url" content="https://arian.gg" />
<meta property="og:type" content="website" />
<meta
property="og:title"
content="Arian Ahmadinejad | Software Engineer"
/>
<meta
property="og:description"
content="Hey this is Arian Ahmadinejad. Software engineer from Canada, pursuing computer science to hack into the Matrix."
/>
<meta
property="og:image"
content="https://arian.gg/assets/meta.png"
/>
{/* <!-- Facebook Meta Tags --> */}
<meta property="og:url" content="https://arian.gg" />
<meta property="og:type" content="website" />
<meta
property="og:title"
content="Arian Ahmadinejad | Software Engineer"
/>
<meta
property="og:description"
content="Hey this is Arian Ahmadinejad. Software engineer from Canada, pursuing computer science to hack into the Matrix."
/>
<meta
property="og:image"
content="https://arian.gg/assets/meta.png"
/>

{/* <!-- Twitter Meta Tags --> */}
<meta name="twitter:card" content="summary_large_image" />
<meta property="twitter:domain" content="arian.gg" />
<meta property="twitter:url" content="https://arian.gg" />
<meta
name="twitter:title"
content="Arian Ahmadinejad | Software Engineer"
/>
<meta
name="twitter:description"
content="Hey this is Arian Ahmadinejad. Software engineer from Canada, pursuing computer science to hack into the Matrix."
/>
<meta
name="twitter:image"
content="https://arian.gg/assets/meta.png"
/>
<meta charSet="utf-8" />
{/* <!-- Icons for everything --> */}
<link
rel="apple-touch-icon"
sizes="180x180"
href="/assets/apple-touch-icon.png"
/>
<link
rel="icon"
type="image/png"
sizes="32x32"
href="/assets/favicon-32x32.png"
/>
<link
rel="icon"
type="image/png"
sizes="16x16"
href="/assets/favicon-16x16.png"
/>
<link rel="manifest" href="/assets/site.webmanifest" />
<link
rel="mask-icon"
href="/assets/safari-pinned-tab.svg"
color="#592406"
/>
<link rel="shortcut icon" href="/assets/favicon.ico" />
<meta name="msapplication-TileColor" content="#603cba" />
<meta
name="msapplication-config"
content="/assets/browserconfig.xml"
/>
<meta
name="theme-color"
content="#fed7aa"
media="(prefers-color-scheme: light)"
/>
<meta
name="theme-color"
content="#161616"
media="(prefers-color-scheme: dark)"
/>
{/* <!-- Twitter Meta Tags --> */}
<meta name="twitter:card" content="summary_large_image" />
<meta property="twitter:domain" content="arian.gg" />
<meta property="twitter:url" content="https://arian.gg" />
<meta
name="twitter:title"
content="Arian Ahmadinejad | Software Engineer"
/>
<meta
name="twitter:description"
content="Hey this is Arian Ahmadinejad. Software engineer from Canada, pursuing computer science to hack into the Matrix."
/>
<meta
name="twitter:image"
content="https://arian.gg/assets/meta.png"
/>
<meta charSet="utf-8" />
{/* <!-- Icons for everything --> */}
<link
rel="apple-touch-icon"
sizes="180x180"
href="/assets/apple-touch-icon.png"
/>
<link
rel="icon"
type="image/png"
sizes="32x32"
href="/assets/favicon-32x32.png"
/>
<link
rel="icon"
type="image/png"
sizes="16x16"
href="/assets/favicon-16x16.png"
/>
<link rel="manifest" href="/assets/site.webmanifest" />
<link
rel="mask-icon"
href="/assets/safari-pinned-tab.svg"
color="#592406"
/>
<link rel="shortcut icon" href="/assets/favicon.ico" />
<meta name="msapplication-TileColor" content="#603cba" />
<meta
name="msapplication-config"
content="/assets/browserconfig.xml"
/>
<meta
name="theme-color"
content="#fed7aa"
media="(prefers-color-scheme: light)"
/>
<meta
name="theme-color"
content="#161616"
media="(prefers-color-scheme: dark)"
/>

<link rel="canonical" href="https://arian.gg" />
<meta
name="viewport"
content="width=device-width initial-scale=1.0 maximum-scale=1.0 user-scalable=0"
/>
<title>Arian Ahmadinejad</title>
</Head>
<style jsx global>{`
html {
font-family: ${outfit.style.fontFamily};
}
`}</style>
{getLayout(<Component {...pageProps} />)}
<Analytics />
<SpeedInsights />
<link rel="canonical" href="https://arian.gg" />
<meta
name="viewport"
content="width=device-width initial-scale=1.0 maximum-scale=1.0 user-scalable=0"
/>
<title>Arian Ahmadinejad</title>
</Head>
<style jsx global>{`
html {
font-family: ${outfit.style.fontFamily};
}
`}</style>
{getLayout(<Component {...pageProps} />)}
<Analytics />
<SpeedInsights />
</PostHogProvider>
</ThemeProvider>
</QueryClientProvider>
);
Expand Down

0 comments on commit 2e631ec

Please sign in to comment.