-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(analytics): adjust cookies modal and posthog setup, implement GA …
…custom events for feed search and sidebar
- Loading branch information
Showing
9 changed files
with
149 additions
and
46 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,27 @@ | ||
"use client"; | ||
import posthog from "posthog-js"; | ||
import { PostHogProvider } from "posthog-js/react"; | ||
import { useEffect } from "react"; | ||
|
||
import { getAnalyticsCookieConsentGiven } from "@/app/(main)/components/cookies_banner"; | ||
|
||
export function CSPostHogProvider({ children }: { children: any }) { | ||
if (typeof window !== "undefined" && process.env.NEXT_PUBLIC_POSTHOG_KEY) { | ||
posthog.init(process.env.NEXT_PUBLIC_POSTHOG_KEY, { | ||
api_host: process.env.NEXT_PUBLIC_POSTHOG_HOST, | ||
// set to 'always' to create profiles for anonymous users as well | ||
person_profiles: "identified_only", | ||
// TODO: uncomment once we want to support cookies configuration | ||
// persistence: | ||
// getAnalyticsCookieConsentGiven() === "yes" | ||
// ? "localStorage+cookie" | ||
// : "memory", | ||
}); | ||
} | ||
useEffect(() => { | ||
if (process.env.NEXT_PUBLIC_POSTHOG_KEY) { | ||
posthog.init(process.env.NEXT_PUBLIC_POSTHOG_KEY, { | ||
api_host: process.env.NEXT_PUBLIC_POSTHOG_HOST, | ||
// set to 'always' to create profiles for anonymous users as well | ||
person_profiles: "identified_only", | ||
// Disable automatic pageview capture, as we capture manually | ||
capture_pageview: false, | ||
disable_session_recording: true, | ||
persistence: | ||
getAnalyticsCookieConsentGiven() === "yes" | ||
? "localStorage+cookie" | ||
: "memory", | ||
}); | ||
} | ||
}, []); | ||
|
||
return <PostHogProvider client={posthog}>{children}</PostHogProvider>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
"use client"; | ||
|
||
import { usePathname, useSearchParams } from "next/navigation"; | ||
import { usePostHog } from "posthog-js/react"; | ||
import { useEffect } from "react"; | ||
|
||
export default function PostHogPageView() { | ||
const pathname = usePathname(); | ||
const searchParams = useSearchParams(); | ||
const posthog = usePostHog(); | ||
useEffect(() => { | ||
if (pathname && posthog) { | ||
let url = window.origin + pathname; | ||
if (searchParams.toString()) { | ||
url = url + `?${searchParams.toString()}`; | ||
} | ||
posthog.capture("$pageview", { | ||
$current_url: url, | ||
}); | ||
} | ||
}, [pathname, searchParams, posthog]); | ||
|
||
return null; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters