mirror of
https://github.com/Frooodle/Stirling-PDF.git
synced 2026-04-16 23:08:38 +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:
17
frontend/package-lock.json
generated
17
frontend/package-lock.json
generated
@@ -44,6 +44,7 @@
|
||||
"@mantine/hooks": "^8.3.1",
|
||||
"@mui/icons-material": "^7.3.2",
|
||||
"@mui/material": "^7.3.2",
|
||||
"@posthog/react": "^1.8.2",
|
||||
"@reactour/tour": "^3.8.0",
|
||||
"@stripe/react-stripe-js": "^4.0.2",
|
||||
"@stripe/stripe-js": "^7.9.0",
|
||||
@@ -2871,6 +2872,22 @@
|
||||
"cross-spawn": "^7.0.6"
|
||||
}
|
||||
},
|
||||
"node_modules/@posthog/react": {
|
||||
"version": "1.8.2",
|
||||
"resolved": "https://registry.npmjs.org/@posthog/react/-/react-1.8.2.tgz",
|
||||
"integrity": "sha512-KzUuXIcAR8fAjU7IeDq+XfEcUTNvzgEGB381WRrFUUsu7jFTcKZZ6crx/ukHRCzTnoEuy5EJDkL7b7sJecPlCg==",
|
||||
"license": "MIT",
|
||||
"peerDependencies": {
|
||||
"@types/react": ">=16.8.0",
|
||||
"posthog-js": ">=1.257.2",
|
||||
"react": ">=16.8.0"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"@types/react": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/@posthog/types": {
|
||||
"version": "1.354.0",
|
||||
"resolved": "https://registry.npmjs.org/@posthog/types/-/types-1.354.0.tgz",
|
||||
|
||||
@@ -61,6 +61,7 @@
|
||||
"license-report": "^6.8.0",
|
||||
"pdfjs-dist": "^5.4.149",
|
||||
"peerjs": "^1.5.5",
|
||||
"@posthog/react": "^1.8.2",
|
||||
"posthog-js": "^1.268.0",
|
||||
"qrcode.react": "^4.2.0",
|
||||
"react": "^19.1.1",
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
@@ -10,9 +10,6 @@
|
||||
],
|
||||
"@proprietary/*": [
|
||||
"src/core/*"
|
||||
],
|
||||
"posthog-js/react": [
|
||||
"node_modules/posthog-js/react/dist/types/index.d.ts"
|
||||
]
|
||||
}
|
||||
},
|
||||
@@ -23,4 +20,4 @@
|
||||
"src/*.tsx",
|
||||
"src/core"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,9 +12,6 @@
|
||||
],
|
||||
"@core/*": [
|
||||
"src/core/*"
|
||||
],
|
||||
"posthog-js/react": [
|
||||
"node_modules/posthog-js/react/dist/types/index.d.ts"
|
||||
]
|
||||
}
|
||||
},
|
||||
@@ -26,4 +23,4 @@
|
||||
"src/core/setupTests.ts",
|
||||
"src/desktop"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,9 +11,6 @@
|
||||
],
|
||||
"@proprietary/*": [
|
||||
"src/proprietary/*"
|
||||
],
|
||||
"posthog-js/react": [
|
||||
"node_modules/posthog-js/react/dist/types/index.d.ts"
|
||||
]
|
||||
}
|
||||
},
|
||||
@@ -25,4 +22,4 @@
|
||||
"src/core/setupTests.ts",
|
||||
"src/proprietary"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user