Git Product home page Git Product logo

astrolib's People

Contributors

andersk avatar prototypa avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

astrolib's Issues

analytics snippet showing as string on screen

<script async src="https://www.googletagmanager.com/gtag/js?id=##########"></script><script>{let id = "###########"; window.dataLayer = window.dataLayer || []; function gtag() { window.dataLayer.push(arguments); } gtag("js", new Date()); gtag("config", id); }</script>

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):

image

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!

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 photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.