-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[@astrojs/vercel] Individually enable Speed Insights and Web Analytics (
#8021) * Individually enable Speed Insights and Web Analytics * Update pnpm-lock.yaml * Remove .only on tests * Fix build * Move `beforeSend` out of config * Address feedback from review * Update README.md * Add back the `analytics` property and add deprecation warning when used * Add migration guide for the deprecated `analytics` property * Update packages/integrations/vercel/README.md Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca> * Update README.md * Fix external dependency issue * Simplify plugin and reduce scope * Update .changeset/sixty-teachers-tap.md Co-authored-by: Emanuele Stoppa <my.burning@gmail.com> * Apply feedback from review * Move exposeEnv to speed-insights since it's only used there --------- Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca> Co-authored-by: Matthew Phillips <matthew@skypack.dev> Co-authored-by: Emanuele Stoppa <my.burning@gmail.com>
- Loading branch information
1 parent
7522bb4
commit 2e8726f
Showing
24 changed files
with
402 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
--- | ||
'@astrojs/vercel': minor | ||
--- | ||
|
||
Enable Vercel Speed Insights and Vercel Web Analytics individually. | ||
Deprecates the `analytics` property in `astro.config.mjs` in favor of `speedInsights` and `webAnalytics`. | ||
|
||
If you're using the `analytics` property, you'll need to update your config to use the new properties: | ||
|
||
```diff | ||
// astro.config.mjs | ||
export default defineConfig({ | ||
adapter: vercel({ | ||
- analytics: true, | ||
+ webAnalytics: { | ||
+ enabled: true | ||
+ }, | ||
+ speedInsights: { | ||
+ enabled: true | ||
+ } | ||
}) | ||
}); | ||
``` | ||
|
||
Allow configuration of Web Analytics with all available configuration options. | ||
Bumps @vercel/analytics package to the latest version. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
packages/integrations/vercel/src/lib/env.ts → ...grations/vercel/src/lib/speed-insights.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
export type VercelWebAnalyticsConfig = { | ||
enabled: boolean; | ||
}; | ||
|
||
export async function getInjectableWebAnalyticsContent({ | ||
mode, | ||
}: { | ||
mode: 'development' | 'production'; | ||
}) { | ||
const base = `window.va = window.va || function () { (window.vaq = window.vaq || []).push(arguments); };`; | ||
|
||
if (mode === 'development') { | ||
return ` | ||
${base} | ||
var script = document.createElement('script'); | ||
script.defer = true; | ||
script.src = 'https://cdn.vercel-insights.com/v1/script.debug.js'; | ||
var head = document.querySelector('head'); | ||
head.appendChild(script); | ||
`; | ||
} | ||
|
||
return `${base} | ||
var script = document.createElement('script'); | ||
script.defer = true; | ||
script.src = '/_vercel/insights/script.js'; | ||
var head = document.querySelector('head'); | ||
head.appendChild(script); | ||
`; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import type { AnalyticsProps } from '@vercel/analytics'; | ||
|
||
export type VercelWebAnalyticsBeforeSend = AnalyticsProps['beforeSend']; |
10 changes: 10 additions & 0 deletions
10
...ations/vercel/test/fixtures/with-speed-insights-enabled/output-as-server/astro.config.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { defineConfig } from 'astro/config'; | ||
import vercel from '@astrojs/vercel/serverless'; | ||
|
||
export default defineConfig({ | ||
adapter: vercel({ | ||
speedInsights: { | ||
enabled: true | ||
} | ||
}) | ||
}); |
Oops, something went wrong.