Landing : les événements émis avant l'init de PostHog sont mis en file

Depuis le chargement différé de PostHog, page_viewed partait au premier
rendu, avant init(), et était jeté au lieu d'attendre dans la file.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
IliesAllaliandClaude Opus 5.5 committed 2026-09-24 14:11:55 +02:00
1 parent 73db745a04
commit 4c0d281919
1 file changed
+4 -5
+4 -5
View File
@@ -4,9 +4,10 @@
* Events are silently dropped when the key is absent.
*/
const KEY = import.meta.env.VITE_POSTHOG_KEY
let ph = null
let initStarted = false
let enabled = false
let enabled = Boolean(KEY)
const queuedEvents = []
const MAX_QUEUED_EVENTS = 100
@@ -23,13 +24,11 @@ export const analytics = {
if (initStarted) return
initStarted = true
const key = import.meta.env.VITE_POSTHOG_KEY
if (!key) return
if (!KEY) return
enabled = true
import('posthog-js')
.then(({ default: posthog }) => {
posthog.init(key, {
posthog.init(KEY, {
api_host: import.meta.env.VITE_POSTHOG_HOST || 'https://us.i.posthog.com',
cross_subdomain_cookie: true,
defaults: '2026-01-30',