astrolib's People
astrolib's Issues
Add support for additional twitter tags like title and description
analytics snippet showing as string on screen
analytics snippet showing as string on screen
Please add Vercel Analytics
I want to use vercel analytics in astro but I'd have to create a library for that I see that you have a nice set of Components that Allow the user to integrate analytics from other sites. I'm going to just give you the code for how to integrate Vercel Analytics if you want more info look into the docs.
You need to install web-vitals
in order to use the code below.
Code needed for Web Analytics
import { Metric, onCLS, onFCP, onFID, onLCP, onTTFB } from 'web-vitals';
const vitalsUrl = 'https://vitals.vercel-analytics.com/v1/vitals';
function getConnectionSpeed() {
return 'connection' in navigator
&& navigator['connection']
&& typeof navigator['connection'] === "object"
&& 'effectiveType' in navigator['connection']
? navigator['connection']['effectiveType']
: '';
}
type Options = { params: { [s: string]: any; } | ArrayLike<any>; path: string; analyticsId: string; debug: boolean; }
function sendToAnalytics(metric:Metric, options:Options) {
const page = Object.entries(options.params).reduce(
(acc, [key, value]) => acc.replace(value, `[${key}]`),
options.path,
);
const body = {
dsn: options.analyticsId, // qPgJqYH9LQX5o31Ormk8iWhCxZO
id: metric.id, // v2-1653884975443-1839479248192
page, // /blog/[slug]
href: location.href, // https://my-app.vercel.app/blog/my-test
event_name: metric.name, // TTFB
value: metric.value.toString(), // 60.20000000298023
speed: getConnectionSpeed(), // 4g
};
if (options.debug) {
console.log('[Analytics]', metric.name, JSON.stringify(body, null, 2));
}
const blob = new Blob([new URLSearchParams(body as Record<string, any>).toString()], {
// This content type is necessary for `sendBeacon`
type: 'application/x-www-form-urlencoded',
});
if (navigator.sendBeacon) {
navigator.sendBeacon(vitalsUrl, blob);
} else
fetch(vitalsUrl, {
body: blob,
method: 'POST',
credentials: 'omit',
keepalive: true,
});
}
export function webVitals(options:Options) {
try {
onFID((metric) => sendToAnalytics(metric, options));
onTTFB((metric) => sendToAnalytics(metric, options));
onLCP((metric) => sendToAnalytics(metric, options));
onCLS((metric) => sendToAnalytics(metric, options));
onFCP((metric) => sendToAnalytics(metric, options));
} catch (err) {
console.error('[Analytics]', err);
}
}
Astro Component
<script>
// Replace this with the one that comes from the file with the script that I have written above.
import { webVitals } from "~/utils/vitals";
const analyticsId = import.meta.env.PUBLIC_VERCEL_ANALYTICS_ID;
if (analyticsId) {
webVitals({
analyticsId,
path: location.pathname,
params: location.search,
debug: !import.meta.env.PROD,
});
}</script>
Cannot find module `./src/AstroSeo.astro` or its corresponding type declarations
I installed @astrolib/seo
v1.0.0-beta.4 in my TS project but when I run npx tsc --noEmit
I am getting the following errors:
node_modules/@astrolib/seo/index.ts:4:37 - error TS2307: Cannot find module './src/AstroSeo.astro' or its corresponding type declarations.
4 export { default as AstroSeo } from "./src/AstroSeo.astro";node_modules/@astrolib/seo/index.ts:5:15 - error TS2307: Cannot find module './src/AstroSeo.astro' or its corresponding type declarations.
5 export * from "./src/AstroSeo.astro";
I checked my code that imports from @astrolib/seo
and it looks like it offers 2 type definitons for the same root package (located in ./index.ts
and ./src/types.ts
):
How can I tell TS to use only one of the two? I am running on TypeScript Version 5.2.2.
Changelog
I can't find a changelog for the packages in this repo. Is there a changelog anywhere? If not, could one be added?
It helps to know what will break when upgrading.
Thanks!
adding analytics causes "Unknown file extension ".ts" error for "node_modules\@astrolib\analytics\index.ts"
astro add @astrolib/analytics
astro check
then errors with
Unknown file extension ".ts" for C:\Users\clida\Documents\Git\astro-vercel-astro\node_modules@astrolib\analytics\index.ts
Tags rendered before charset
Hi, as far as I can see all tags are rendered on top of head section. Afaik the <meta charset="" />
Tag should appear before other tags and e.g. lighthouse test will complain about this. Any possibility to avoid or change this behavior?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.