From 40497eddcee971d58897ed879e82c6b2e5b0f17b Mon Sep 17 00:00:00 2001 From: Rob Dominguez Date: Wed, 22 May 2024 17:25:45 -0500 Subject: [PATCH] Move posthog.init into useEffect --- src/theme/Navbar/index.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/theme/Navbar/index.js b/src/theme/Navbar/index.js index 1e05106c1..a4ed4dea8 100644 --- a/src/theme/Navbar/index.js +++ b/src/theme/Navbar/index.js @@ -2,20 +2,21 @@ import React, { useEffect } from 'react'; import NavbarLayout from '@theme/Navbar/Layout'; import NavbarContent from '@theme/Navbar/Content'; import fetchUser from '@theme/Navbar/FetchUser'; -// import posthog from 'posthog-js'; - -// // 🦔 config -// posthog.init('phc_MZpdcQLGf57lyfOUT0XA93R3jaCxGsqftVt4iI4MyUY', { -// api_host: 'https://analytics-posthog.hasura-app.io', -// }); +import posthog from 'posthog-js'; export default function Navbar() { useEffect(() => { + if (typeof window !== 'undefined') { + posthog.init('phc_MZpdcQLGf57lyfOUT0XA93R3jaCxGsqftVt4iI4MyUY', { + api_host: 'https://analytics-posthog.hasura-app.io', + }); + } + const getUser = async () => { try { const user = await fetchUser(); console.log('User fetched:', user); - // posthog.identify(user.data.users[0]?.id, { email: user.data.users[0]?.email }); + posthog.identify(user.data.users[0]?.id, { email: user.data.users[0]?.email }); } catch (error) { console.error('Error fetching user:', error); }