Add back the analytics
property and add deprecation warning when used
This commit is contained in:
parent
6d91119b93
commit
99b07d4602
3 changed files with 31 additions and 6 deletions
|
@ -60,6 +60,10 @@ function getAdapter({
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface VercelServerlessConfig {
|
export interface VercelServerlessConfig {
|
||||||
|
/**
|
||||||
|
* @deprecated
|
||||||
|
*/
|
||||||
|
analytics?: boolean;
|
||||||
webAnalytics?: VercelWebAnalyticsConfig;
|
webAnalytics?: VercelWebAnalyticsConfig;
|
||||||
speedInsights?: VercelSpeedInsightsConfig;
|
speedInsights?: VercelSpeedInsightsConfig;
|
||||||
includeFiles?: string[];
|
includeFiles?: string[];
|
||||||
|
@ -71,6 +75,7 @@ export interface VercelServerlessConfig {
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function vercelServerless({
|
export default function vercelServerless({
|
||||||
|
analytics,
|
||||||
webAnalytics,
|
webAnalytics,
|
||||||
speedInsights,
|
speedInsights,
|
||||||
includeFiles,
|
includeFiles,
|
||||||
|
@ -117,12 +122,18 @@ export default function vercelServerless({
|
||||||
name: PACKAGE_NAME,
|
name: PACKAGE_NAME,
|
||||||
hooks: {
|
hooks: {
|
||||||
'astro:config:setup': async ({ command, config, updateConfig, injectScript, logger }) => {
|
'astro:config:setup': async ({ command, config, updateConfig, injectScript, logger }) => {
|
||||||
if (webAnalytics?.enabled) {
|
if (webAnalytics?.enabled || analytics) {
|
||||||
|
if (analytics) {
|
||||||
|
logger.warn(
|
||||||
|
`@astrojs/vercel: the \`analytics\` property is deprecated. Please use the new \`webAnalytics\` and \`speedInsights\` properties instead.`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
injectScript(
|
injectScript(
|
||||||
'page',
|
'page',
|
||||||
await getInjectableWebAnalyticsContent({
|
await getInjectableWebAnalyticsContent({
|
||||||
config: {
|
config: {
|
||||||
...webAnalytics.config,
|
...(webAnalytics?.config || {}),
|
||||||
mode: command === 'dev' ? 'development' : 'production',
|
mode: command === 'dev' ? 'development' : 'production',
|
||||||
},
|
},
|
||||||
astro: {
|
astro: {
|
||||||
|
@ -132,7 +143,7 @@ export default function vercelServerless({
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (command === 'build' && speedInsights?.enabled) {
|
if (command === 'build' && (speedInsights?.enabled || analytics)) {
|
||||||
injectScript('page', 'import "@astrojs/vercel/speed-insights"');
|
injectScript('page', 'import "@astrojs/vercel/speed-insights"');
|
||||||
}
|
}
|
||||||
const outDir = getVercelOutput(config.root);
|
const outDir = getVercelOutput(config.root);
|
||||||
|
|
|
@ -39,11 +39,14 @@ const sendToSpeedInsights = (metric: Metric, options: Options) => {
|
||||||
|
|
||||||
function collectWebVitals() {
|
function collectWebVitals() {
|
||||||
const analyticsId = (import.meta as any).env.PUBLIC_VERCEL_ANALYTICS_ID;
|
const analyticsId = (import.meta as any).env.PUBLIC_VERCEL_ANALYTICS_ID;
|
||||||
|
|
||||||
if (!analyticsId) {
|
if (!analyticsId) {
|
||||||
console.error('[Speed Insights] VERCEL_ANALYTICS_ID not found');
|
console.error('[Speed Insights] VERCEL_ANALYTICS_ID not found');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const options: Options = { path: window.location.pathname, analyticsId };
|
const options: Options = { path: window.location.pathname, analyticsId };
|
||||||
|
|
||||||
try {
|
try {
|
||||||
onFID((metric) => sendToSpeedInsights(metric, options));
|
onFID((metric) => sendToSpeedInsights(metric, options));
|
||||||
onTTFB((metric) => sendToSpeedInsights(metric, options));
|
onTTFB((metric) => sendToSpeedInsights(metric, options));
|
||||||
|
|
|
@ -20,6 +20,10 @@ function getAdapter(): AstroAdapter {
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface VercelStaticConfig {
|
export interface VercelStaticConfig {
|
||||||
|
/**
|
||||||
|
* @deprecated
|
||||||
|
*/
|
||||||
|
analytics?: boolean;
|
||||||
webAnalytics?: VercelWebAnalyticsConfig;
|
webAnalytics?: VercelWebAnalyticsConfig;
|
||||||
speedInsights?: VercelSpeedInsightsConfig;
|
speedInsights?: VercelSpeedInsightsConfig;
|
||||||
imageService?: boolean;
|
imageService?: boolean;
|
||||||
|
@ -27,6 +31,7 @@ export interface VercelStaticConfig {
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function vercelStatic({
|
export default function vercelStatic({
|
||||||
|
analytics,
|
||||||
webAnalytics,
|
webAnalytics,
|
||||||
speedInsights,
|
speedInsights,
|
||||||
imageService,
|
imageService,
|
||||||
|
@ -38,12 +43,18 @@ export default function vercelStatic({
|
||||||
name: '@astrojs/vercel',
|
name: '@astrojs/vercel',
|
||||||
hooks: {
|
hooks: {
|
||||||
'astro:config:setup': async ({ command, config, injectScript, updateConfig, logger }) => {
|
'astro:config:setup': async ({ command, config, injectScript, updateConfig, logger }) => {
|
||||||
if (webAnalytics?.enabled) {
|
if (webAnalytics?.enabled || analytics) {
|
||||||
|
if (analytics) {
|
||||||
|
logger.warn(
|
||||||
|
`@astrojs/vercel: the \`analytics\` property is deprecated. Please use the new \`webAnalytics\` and \`speedInsights\` properties instead.`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
injectScript(
|
injectScript(
|
||||||
'page',
|
'page',
|
||||||
await getInjectableWebAnalyticsContent({
|
await getInjectableWebAnalyticsContent({
|
||||||
config: {
|
config: {
|
||||||
...webAnalytics.config,
|
...(webAnalytics?.config || {}),
|
||||||
mode: command === 'dev' ? 'development' : 'production',
|
mode: command === 'dev' ? 'development' : 'production',
|
||||||
},
|
},
|
||||||
astro: {
|
astro: {
|
||||||
|
@ -53,7 +64,7 @@ export default function vercelStatic({
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (command === 'build' && speedInsights?.enabled) {
|
if (command === 'build' && (speedInsights?.enabled || analytics)) {
|
||||||
injectScript('page', 'import "@astrojs/vercel/speed-insights"');
|
injectScript('page', 'import "@astrojs/vercel/speed-insights"');
|
||||||
}
|
}
|
||||||
const outDir = new URL('./static/', getVercelOutput(config.root));
|
const outDir = new URL('./static/', getVercelOutput(config.root));
|
||||||
|
|
Loading…
Add table
Reference in a new issue