Files
formbricks-formbricks/apps/web/app/PostHogClient.tsx
Dhruwang Jariwala 21f393f402 feat: Add Google Sheets Integration (#735)
* added intro and surveySelect page

* added home page and  wrapper component

* added spreadsheet select

* added data write functionality and added integration schema model

* improved UX

* reworked UI

* added google sheet integration

* removed some unused code

* added user email

* UI tweaks

* fixed build issues and made added question to top of spreadsheets

* adds refreshSheets and added empty survey/spreadsheets text

* restored pnpm-lock

* added duplicate sheet warning

* move process.env to t3env

* move migration

* update docs link, add note to show that sheets integration is not configured

* Add simple docs page for google-sheets

* added session check

* restored pnpm-lock

* Merge branch 'main' of github.com:formbricks/formbricks into Integration/Google-sheet

* added google sheet  env variables to runtimeEnv

---------

Co-authored-by: Johannes <johannes@formbricks.com>
Co-authored-by: Matthias Nannt <mail@matthiasnannt.com>
2023-09-19 22:29:11 +09:00

41 lines
1.1 KiB
TypeScript

"use client";
import { env } from "@/env.mjs";
import { usePathname, useSearchParams } from "next/navigation";
import posthog from "posthog-js";
import { PostHogProvider } from "posthog-js/react";
import { useEffect } from "react";
const posthogEnabled = env.NEXT_PUBLIC_POSTHOG_API_KEY && env.NEXT_PUBLIC_POSTHOG_API_HOST;
if (typeof window !== "undefined") {
if (posthogEnabled) {
posthog.init(env.NEXT_PUBLIC_POSTHOG_API_KEY!, {
api_host: env.NEXT_PUBLIC_POSTHOG_API_HOST,
});
}
}
export function PostHogPageview(): JSX.Element {
const pathname = usePathname();
const searchParams = useSearchParams();
useEffect(() => {
if (posthogEnabled && pathname) {
let url = window.origin + pathname;
if (searchParams && searchParams.toString()) {
url = url + `?${searchParams.toString()}`;
}
posthog.capture("$pageview", {
$current_url: url,
});
}
}, [pathname, searchParams]);
return <></>;
}
export function PHProvider({ children }: { children: React.ReactNode }) {
return posthogEnabled ? <PostHogProvider client={posthog}>{children}</PostHogProvider> : children;
}