Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

📈 App Router - added app insights telemetry for app components #3151

Merged
merged 25 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
83ef4fe
📈 Added app insights telemetry for app components
Sep 23, 2024
6479acd
🚨 Cleaned up linting errors
Sep 23, 2024
1f81b73
Merge branch 'main' into fix-app-insights
Sep 23, 2024
7913bd9
removed fallback text from suspense boundary
Sep 23, 2024
482d195
🐛 Fixed screen rendering blank while query params resolve
Sep 23, 2024
dbbf5ed
♻️ Removed unnecessary suspense boundary
Sep 23, 2024
4aa5ee7
⚡ Removed unnecessary suspense boundary from app router layout component
Sep 23, 2024
153a48e
⚡ Added telemetry provider to template.tsx
Sep 24, 2024
e247a28
🚨 Fixed useReportWebVitals being called conditionally
Sep 24, 2024
f7a8df9
🚨 Removed unused imports from layout.tsx
Sep 24, 2024
293da9a
Merge branch 'main' into fix-app-insights
Sep 24, 2024
6d5d040
Added template to layout properly
Sep 24, 2024
971478d
🐛 Fixed TelemetryProvider not receiving appInsights from context prov…
Sep 24, 2024
2af610b
🚨 Removed unused import
Sep 24, 2024
02d3a0c
Adding web vitals as client component
amankumarrr Sep 24, 2024
1b8055a
cleaning up redundant components
amankumarrr Sep 24, 2024
08c0bab
handling undefined for appInsight
amankumarrr Sep 24, 2024
1916471
Fixing rewards URL
amankumarrr Sep 24, 2024
fdbd863
removing console log
amankumarrr Sep 24, 2024
072c1c6
Adding ISR
amankumarrr Sep 24, 2024
609c6ac
Adding placeholder for the countdown
amankumarrr Sep 24, 2024
868b57d
Removing unused MenuData variable
amankumarrr Sep 24, 2024
d269981
Merge branch 'main' into fix-app-insights
amankumarrr Sep 24, 2024
6712157
removing unused import
amankumarrr Sep 24, 2024
e0e3e58
Wrapping web vitals with AppInsight
amankumarrr Sep 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions app/components/web-vitals.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"use client";

import { useAppInsightsContext } from "@microsoft/applicationinsights-react-js";
import { usePathname } from "next/navigation";
import { useReportWebVitals } from "next/web-vitals";

export const WebVitals = () => {
const appInsights = useAppInsightsContext();
const pathname = usePathname();

useReportWebVitals((metric) => {
switch (metric.name) {
case "TTFB":
case "FCP":
case "LCP":
case "FID":
case "CLS":
case "INP":
appInsights?.trackMetric(
{ name: metric.name, average: metric.value },
{ page: `${pathname}` }
);
break;
}
});
return <></>;
};
31 changes: 16 additions & 15 deletions app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,24 @@
import "styles.css";

// import { CustomLink } from "@/components/customLink";
// import { Footer } from "@/components/layout/footer";
import classNames from "classnames";
import { Open_Sans } from "next/font/google";
// import Head from "next/head";
// import { Theme } from "../components/layout/theme";
import { Footer } from "@/components/layout/footer/footer";
import { MegaMenuWrapper } from "@/components/server/MegaMenuWrapper";
import ChatBaseBot from "@/components/zendeskButton/chatBaseBot";
import { Metadata, Viewport } from "next";

import { AppInsightsProvider } from "@/context/app-insight-client";
import { EventInfoStatic } from "@/services/server/events";
import { GoogleTagManager } from "@next/third-parties/google";
import classNames from "classnames";
import dayjs from "dayjs";
import advancedFormat from "dayjs/plugin/advancedFormat";
import isBetween from "dayjs/plugin/isBetween";
import relativeTime from "dayjs/plugin/relativeTime";
import timezone from "dayjs/plugin/timezone";
import utc from "dayjs/plugin/utc";
import { Suspense } from "react";
import { Metadata, Viewport } from "next";
import { Open_Sans } from "next/font/google";
import client from "../tina/__generated__/client";
import { MenuWrapper } from "./components/MenuWrapper";
import { WebVitals } from "./components/web-vitals";
import { LiveStream } from "./live-steam-banner/live-stream";
import { DEFAULT } from "./meta-data/default";
import { getMegamenu } from "./utils/get-mega-menu";
Expand All @@ -47,6 +44,8 @@ export const viewport: Viewport = {
initialScale: 1,
};

export const revalidate = 3600;

export default async function RootLayout({
children,
}: {
Expand Down Expand Up @@ -75,19 +74,21 @@ export default async function RootLayout({
>
<header className="no-print">
{liveStreamData ? (
<Suspense>
<LiveStream event={liveStreamData}>
<MegaMenuWrapper menu={menuData.data.megamenu.menuGroups} />
</LiveStream>
</Suspense>
<LiveStream event={liveStreamData}>
<MegaMenuWrapper menu={menuData.data.megamenu.menuGroups} />
</LiveStream>
) : (
<MenuWrapper>
<MegaMenuWrapper menu={menuData.data.megamenu.menuGroups} />
</MenuWrapper>
)}
</header>
<main className="grow bg-white">{children}</main>

<main className="grow bg-white">
<AppInsightsProvider>
<WebVitals />
{children}
</AppInsightsProvider>
</main>
<Footer />
</div>
{/* </Theme> */}
Expand Down
8 changes: 4 additions & 4 deletions app/live-steam-banner/live-stream.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
EventInfoStatic,
formatDates,
} from "@/services/server/events";
import { useSearchParams } from "next/navigation";
import { ReadonlyURLSearchParams, useSearchParams } from "next/navigation";
import { PropsWithChildren, useEffect, useState } from "react";
dayjs.extend(relativeTime);
dayjs.extend(timezone);
Expand Down Expand Up @@ -47,7 +47,7 @@ interface LiveStreamProps extends PropsWithChildren {
}

export function LiveStream({ event, children }: LiveStreamProps) {
const params = useSearchParams();
const params: ReadonlyURLSearchParams = useSearchParams();
const [countdownMins, setCountdownMins] = useState<number>();
const [liveStreamDelayMinutes, setLiveStreamDelayMinutes] = useState(0);

Expand Down Expand Up @@ -104,15 +104,15 @@ export function LiveStream({ event, children }: LiveStreamProps) {

return (
<>
{(showBanner || params.get("liveBanner")) && (
{(showBanner || params?.get("liveBanner")) && (
<LiveStreamBanner
countdownMins={countdownMins}
liveStreamData={eventDynamic}
isLive={!!isLive}
/>
)}
<MenuWrapper>
{(isLive || params.get("liveStream")) && (
{(isLive || params?.get("liveStream")) && (
<LiveStreamWidget
{...{ eventDynamic, liveStreamDelayMinutes }}
event={eventDynamic}
Expand Down
2 changes: 1 addition & 1 deletion components/liveStream/liveStreamBanner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const LiveStreamBanner = ({
<h1 className="m-0 py-0 text-xl font-light text-gray-300">{title}</h1>
<p className="py-0 text-xs text-white">
<span className="block text-sswRed">
{isLive ? liveText : countdownText}
{(isLive ? liveText : countdownText) || "Calculating..."}
</span>
{!isLive && scheduledTimeText(dayjs(startDateTime))}
</p>
Expand Down
2 changes: 1 addition & 1 deletion content/products/index/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
},
{
"name": "SSW Rewards",
"url": "https://www.ssw.com.au/products/rewards",
"url": "/products/rewards",
"description": "Scan SSW QR codes, earn SSW Points, claim rewards, and win prizes!",
"logo": "/images/products/ssw-rewards.jpeg"
},
Expand Down
Loading