Skip to content

Commit

Permalink
feat: add page track of segmentio
Browse files Browse the repository at this point in the history
  • Loading branch information
JimmyLv committed Mar 6, 2023
1 parent 097c165 commit b8e5cd1
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 8 deletions.
11 changes: 4 additions & 7 deletions pages/_app.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
import { Inter as FontSans } from "@next/font/google";
import {
createBrowserSupabaseClient,
Session,
} from "@supabase/auth-helpers-nextjs";

import { createBrowserSupabaseClient, Session } from "@supabase/auth-helpers-nextjs";
import { SessionContextProvider } from "@supabase/auth-helpers-react";
import { Analytics } from "@vercel/analytics/react";
import { ThemeProvider } from "next-themes";
import type { AppProps } from "next/app";
import React, { useState } from "react";
import CommandMenu from "~/components/CommandMenu";
import { AnalyticsProvider } from "~/components/context/analytics";
import { TailwindIndicator } from "~/components/tailwind-indicator";
import { Toaster } from "~/components/ui/toaster";
import { TooltipProvider } from "~/components/ui/tooltip";
import { cn } from "~/lib/utils";
import Footer from "../components/Footer";
import Header from "../components/Header";
import "../styles/globals.css";
import { ThemeProvider } from "next-themes";
import { TooltipProvider } from "~/components/ui/tooltip";

const fontSans = FontSans({
subsets: ["latin"],
Expand All @@ -32,6 +28,7 @@ function MyApp({
}>) {
// Create a new supabase browser client on every first render.
const [supabaseClient] = useState(() => createBrowserSupabaseClient());

return (
<AnalyticsProvider>
<SessionContextProvider
Expand Down
29 changes: 28 additions & 1 deletion pages/index.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,30 @@
import Home from "./[...slug]";
import { AnalyticsBrowser } from "@segment/analytics-next";
import { Analytics as AnalyticsType } from "@segment/analytics-next/dist/types/core/analytics";
import React, { useEffect, useState } from "react";
import { useAnalytics } from "~/components/context/analytics";
import SlugPage from "./[...slug]";

function Home(): React.ReactElement {
const [analytics, setAnalytics] = useState<AnalyticsType | undefined>(
undefined
);

const { analytics: analyticsBrowser } = useAnalytics();
useEffect(() => {
async function handleAnalyticsLoading(browser: AnalyticsBrowser) {
try {
const [response, ctx] = await browser;
setAnalytics(response);
// @ts-ignore
window.analytics = response;
window.analytics?.identify("'hello world' from segmentio analytics");
} catch (err) {
console.error(err);
setAnalytics(undefined);
}
}
handleAnalyticsLoading(analyticsBrowser).catch(console.error);
}, [analyticsBrowser]);
return <SlugPage />;
}
export default Home;

1 comment on commit b8e5cd1

@vercel
Copy link

@vercel vercel bot commented on b8e5cd1 Mar 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.