mirror of
https://github.com/Frooodle/Stirling-PDF.git
synced 2026-04-22 23:08:53 +02:00
Posthog-fixes (#5901)
PostHog is now initialized with persistence: 'memory' so no cookies are
written on first load. Consent is handled in a PostHogConsentSync
component that switches to localStorage+cookie persistence only when the
user accepts, using the official @posthog/react package (cherry-picked
from 14aaf64)
---------
Co-authored-by: James Brunton <james@stirlingpdf.com>
This commit is contained in:
12
frontend/src/global.d.ts
vendored
12
frontend/src/global.d.ts
vendored
@@ -26,16 +26,4 @@ declare module 'axios' {
|
||||
}
|
||||
}
|
||||
|
||||
declare module 'posthog-js/react' {
|
||||
import { ReactNode } from 'react';
|
||||
import posthogJs, { PostHogConfig } from 'posthog-js';
|
||||
|
||||
export const PostHogProvider: React.FC<{
|
||||
client?: typeof posthogJs;
|
||||
options?: Partial<PostHogConfig>;
|
||||
apiKey?: string;
|
||||
children?: ReactNode;
|
||||
}>;
|
||||
}
|
||||
|
||||
export { };
|
||||
|
||||
@@ -9,7 +9,7 @@ import { BrowserRouter } from 'react-router-dom';
|
||||
import App from '@app/App';
|
||||
import '@app/i18n'; // Initialize i18next
|
||||
import posthog from 'posthog-js';
|
||||
import { PostHogProvider } from 'posthog-js/react';
|
||||
import { PostHogProvider } from '@posthog/react';
|
||||
import { BASE_PATH } from '@app/constants/app';
|
||||
|
||||
posthog.init('phc_VOdeYnlevc2T63m3myFGjeBlRcIusRgmhfx6XL5a1iz', {
|
||||
@@ -18,18 +18,19 @@ posthog.init('phc_VOdeYnlevc2T63m3myFGjeBlRcIusRgmhfx6XL5a1iz', {
|
||||
capture_exceptions: true, // This enables capturing exceptions using Error Tracking, set to false if you don't want this
|
||||
debug: false,
|
||||
opt_out_capturing_by_default: true, // Opt-out by default, controlled by cookie consent
|
||||
persistence: 'memory', // No cookies/localStorage written until user opts in
|
||||
cross_subdomain_cookie: false,
|
||||
});
|
||||
|
||||
function updatePosthogConsent(){
|
||||
if(typeof(posthog) == "undefined" || !posthog.__loaded) {
|
||||
return;
|
||||
}
|
||||
function updatePosthogConsent() {
|
||||
if (!posthog.__loaded) return;
|
||||
const optIn = (window.CookieConsent as any)?.acceptedService?.('posthog', 'analytics') || false;
|
||||
if (optIn) {
|
||||
posthog.set_config({ persistence: 'localStorage+cookie' });
|
||||
posthog.opt_in_capturing();
|
||||
} else {
|
||||
posthog.opt_out_capturing();
|
||||
posthog.set_config({ persistence: 'memory' });
|
||||
}
|
||||
console.log("Updated PostHog consent: ", optIn ? "opted in" : "opted out");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user