Skip to content

Commit

Permalink
run linter
Browse files Browse the repository at this point in the history
  • Loading branch information
jmsalcido committed Dec 27, 2023
1 parent 36b80fe commit af615d6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 25 deletions.
19 changes: 9 additions & 10 deletions src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@ import type { Metadata } from 'next'
import { Anton, Courier_Prime, Montserrat } from 'next/font/google'
import { ReactNode, Suspense } from 'react'

import {PHProvider, PostHogPageview} from '~/app/providers'
import { meta, Prices } from '~/lib/constants'

import { cx } from '../../styled-system/css'

import {PHProvider, PostHogPageview} from "~/app/providers";

const montserrat = Montserrat({
subsets: ['latin'],
variable: '--font-body',
Expand Down Expand Up @@ -55,14 +54,14 @@ export default function RootLayout ({
}) {
return (
<html lang="es" className={cx(anton.variable, courier.variable, montserrat.variable)}>
<Suspense>
<PostHogPageview/>
</Suspense>
<PHProvider>
<body>
{children}
</body>
</PHProvider>
<Suspense>
<PostHogPageview/>
</Suspense>
<PHProvider>
<body>
{children}
</body>
</PHProvider>
</html>
)
}
Expand Down
30 changes: 15 additions & 15 deletions src/app/providers.tsx
Original file line number Diff line number Diff line change
@@ -1,38 +1,38 @@
'use client'
import {usePathname, useSearchParams} from 'next/navigation'
import posthog from 'posthog-js'
import {PostHogProvider} from 'posthog-js/react'
import {usePathname, useSearchParams} from "next/navigation";
import {useEffect} from "react";
import {useEffect} from 'react'

if (typeof window !== 'undefined') {
posthog.init(process.env.NEXT_PUBLIC_POSTHOG_KEY!!, {
api_host: process.env.NEXT_PUBLIC_POSTHOG_HOST || 'https://app.posthog.com',
capture_pageview: false // Disable automatic pageview capture, as we capture manually
capture_pageview: false, // Disable automatic pageview capture, as we capture manually
})
}

export function PostHogPageview(): JSX.Element {
const pathname = usePathname();
const searchParams = useSearchParams();
export function PostHogPageview (): JSX.Element {
const pathname = usePathname()
const searchParams = useSearchParams()

useEffect(() => {
if (pathname) {
let url = window.origin + pathname;
let url = window.origin + pathname
if (searchParams && searchParams.toString()) {
url = url + `?${searchParams.toString()}`;
url = url + `?${searchParams.toString()}`
}
posthog.capture("$pageview", {
posthog.capture('$pageview', {
$current_url: url,
});
})
}
}, [pathname, searchParams]);
}, [pathname, searchParams])

return <></>;
return <></>
}

export function PHProvider({
children,
}: {
export function PHProvider ({
children,
}: {
children: React.ReactNode
}) {
return <PostHogProvider client={posthog}>{children}</PostHogProvider>
Expand Down

0 comments on commit af615d6

Please sign in to comment.