mirror of
https://github.com/withastro/astro.git
synced 2025-01-27 22:19:04 -05:00
31 lines
779 B
TypeScript
31 lines
779 B
TypeScript
|
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);
|
||
|
`;
|
||
|
}
|