diff --git a/.env.example b/.env.example index f3e1cdc..3a293fc 100644 --- a/.env.example +++ b/.env.example @@ -4,5 +4,11 @@ NEXT_PUBLIC_GA_ID=G-1234567890 NEXT_PUBLIC_GOOGLE_TAG_MANAGER_ID=G-1234567890 NEXT_PUBLIC_GOOGLE_SITE_VERIFICATION=klajsndfkjuhjkhbasldfbnlawieufbasd +# Feature: Clarity # Mocked: true NEXT_PUBLIC_MS_CLARITY_ID=1234567890 + +# Feature: Posthog +# Mocked: true +NEXT_PUBLIC_POSTHOG_KEY="paosidASDKJHUkasdMvV8JjDtZmAvYNiOAf4p9zcTNhDOt" +NEXT_PUBLIC_POSTHOG_HOST="https://us.i.posthog.com" diff --git a/src/components/BlogCard/BlogCard.tsx b/src/components/BlogCard/BlogCard.tsx index b80e795..e9685e9 100644 --- a/src/components/BlogCard/BlogCard.tsx +++ b/src/components/BlogCard/BlogCard.tsx @@ -6,6 +6,7 @@ import { HeartIcon as HeartIconSolid } from '@heroicons/react/24/solid' import Image from 'next/image' import Link from 'next/link' import { usePathname, useSearchParams } from 'next/navigation' +import posthog from 'posthog-js' import { useCallback, useRef, useState } from 'react' interface BlogCardProps { @@ -68,6 +69,10 @@ export const BlogCard = ({ { + posthog.capture('blog-card-clicked', { + href, + title, + }) window.umami.track('blog-card-clicked', { href, title, diff --git a/src/components/Footer/Footer.tsx b/src/components/Footer/Footer.tsx index 128f78c..007a757 100644 --- a/src/components/Footer/Footer.tsx +++ b/src/components/Footer/Footer.tsx @@ -1,5 +1,6 @@ import { nanoid } from 'nanoid' import Link from 'next/link' +import posthog from 'posthog-js' import { useMemo } from 'react' const sunIcon = ( @@ -58,6 +59,9 @@ const ThemeSwitcher = () => { type="button" aria-label="Use Dark Mode" onClick={() => { + posthog.capture('switch-theme', { + from: 'dark-to-light', + }) window.umami.track('switch-theme', { from: 'dark-to-light', }) @@ -73,6 +77,9 @@ const ThemeSwitcher = () => { type="button" aria-label="Use Light Mode" onClick={() => { + posthog.capture('switch-theme', { + from: 'light-to-dark', + }) window.umami.track('switch-theme', { from: 'light-to-dark', }) diff --git a/src/pages/_app.tsx b/src/pages/_app.tsx index 3f4de1c..ceeb693 100644 --- a/src/pages/_app.tsx +++ b/src/pages/_app.tsx @@ -6,11 +6,25 @@ import * as gtag from '@/lib/gtag' import * as gtm from '@/lib/gtm' import { MS_CLARITY_ID } from '@/lib/clarity' import { GOOGLE_SITE_VERIFICATION } from '@/lib/google-site-verification' +import { posthog } from 'posthog-js' +import { PostHogProvider } from 'posthog-js/react' import '@/styles/blog.css' import '@/styles/globals.css' import '@/styles/styles.css' +if (typeof window !== 'undefined' && process.env.NEXT_PUBLIC_POSTHOG_KEY) { + // checks that we are client-side + posthog.init(process.env.NEXT_PUBLIC_POSTHOG_KEY, { + api_host: + process.env.NEXT_PUBLIC_POSTHOG_HOST || 'https://us.i.posthog.com', + person_profiles: 'identified_only', // 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 CustomApp = ({ Component, pageProps }: AppProps) => ( <>
@@ -117,7 +131,9 @@ const CustomApp = ({ Component, pageProps }: AppProps) => ( `, }} /> -