Skip to content

Commit

Permalink
Move posthog.init into useEffect
Browse files Browse the repository at this point in the history
  • Loading branch information
robertjdominguez committed May 22, 2024
1 parent 7da7b7e commit 40497ed
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/theme/Navbar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 40497ed

Please sign in to comment.