Skip to content

Commit

Permalink
[Issue #575] Remove web-vitals package and set debug to true for test…
Browse files Browse the repository at this point in the history
…ing in the preview environment.

Signed-off-by: Louis Fettet <[email protected]>
  • Loading branch information
LouisFettet committed Oct 9, 2024
1 parent e034b68 commit f8540e6
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 85 deletions.
1 change: 0 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ CONTENTFUL_IMAGE_API_ENDPOINT="https://images.ctfassets.net"
CONTENTFUL_MANAGEMENT_API_ENDPOINT="https://api.contentful.com"
KV_URL="redis://localhost"
VERCEL=""
VERCEL_ANALYTICS_ID=""
VERCEL_ENV=""
VERCEL_GIT_REPO_OWNER=""
VERCEL_GIT_REPO_SLUG=""
Expand Down
13 changes: 1 addition & 12 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@
"jpeg-js": "^0.4.4",
"lodash": "^4.17.21",
"redis": "^4.6.10",
"topojson-client": "^3.1.0",
"web-vitals": "^3.4.0"
"topojson-client": "^3.1.0"
}
}
62 changes: 0 additions & 62 deletions src/lib/vitals.ts

This file was deleted.

3 changes: 3 additions & 0 deletions src/routes/+layout.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ export const load = async ({
// * whether we should connect to Vercel Speed Insights
// * if we should set up GA in debug mode or prod mode
const isProd = VERCEL_ENV === "production";
const isPreview = VERCEL_ENV === "preview";
const speedInsightsEnabled = isProd || isPreview;

const clientCurrentUser: User | undefined = currentUser
? { name: currentUser.name, email: currentUser.email, avatarURL: currentUser.avatarURL }
Expand Down Expand Up @@ -95,6 +97,7 @@ export const load = async ({
return {
isProd,
previewAuthenticationError,
speedInsightsEnabled,
pageMetadataMap: pageMetadataMap,
pathsToIDs: pathsToIDs,
siteTitle: loadSiteTitle(),
Expand Down
20 changes: 12 additions & 8 deletions src/routes/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
export let data;
$: ({
isProd,
speedInsightsEnabled,
headerPrimaryNavItems,
headerSecondaryNavItems,
footerNavItems,
Expand All @@ -34,14 +35,17 @@
} = data);
// Vercel Speed Insights
$: if (browser) {
//&& isProd) {
injectSpeedInsights();
// webVitals({
// path: $page.url.pathname,
// params: $page.params,
// analyticsID,
// });
$: if (browser && speedInsightsEnabled) {
injectSpeedInsights({
// The percentage of events to send (between 0 and 1); default is 1.
// TODO: Decrease this to 0.75 for cost savings, if needed.
sampleRate: 1,
debug: true,
beforeSend: (data) => {
console.log("beforeSend", data);
return data;
},
});
}
setCurrentUserStore(data.currentUser);
Expand Down

0 comments on commit f8540e6

Please sign in to comment.