vercel / speed-insights

Vercel Speed Insights package
https://vercel.com/docs/speed-insights
Apache License 2.0
57 stars 9 forks source link

feat: Astro support #29

Closed feugy closed 9 months ago

feugy commented 10 months ago

๐Ÿ““ What's in there?

This is an initial draft for Astro first-class support.

beforeSend is supported by using speedInsightsBeforeSend as global window function

<script is:inline>
  function speedInsightsBeforeSend(data){
    console.log("Capured event!")
    return data;
  }
</script>

TODO list:

๐Ÿงช How to test?

There's a new example app, based on the Astro official blog template

โ— Notes to reviewers

vercel[bot] commented 10 months ago

The latest updates on your projects. Learn more about Vercel for Git โ†—๏ธŽ

Name Status Preview Comments Updated (UTC)
speed-insights-nextjs โœ… Ready (Inspect) Visit Preview ๐Ÿ’ฌ Add feedback Dec 13, 2023 1:11pm
speed-insights-nuxt โœ… Ready (Inspect) Visit Preview ๐Ÿ’ฌ Add feedback Dec 13, 2023 1:11pm
speed-insights-remix โœ… Ready (Inspect) Visit Preview ๐Ÿ’ฌ Add feedback Dec 13, 2023 1:11pm
speed-insights-sveltekit โœ… Ready (Inspect) Visit Preview ๐Ÿ’ฌ Add feedback Dec 13, 2023 1:11pm
speed-insights-vue โœ… Ready (Inspect) Visit Preview ๐Ÿ’ฌ Add feedback Dec 13, 2023 1:11pm
MoustaphaDev commented 9 months ago

Agreed that using a component is better DX!

I'm exploring an alternative approach to address the beforeSend as props limitation that might be more suitable than excluding that future (in my opinion), although not ideal.

Here's how it would work and how it would be documented:

Note: Because of some limitations (blah blah), if you want to use the beforeSend feature, you can define a speedInsightsBeforeSend function in an inline script in your Astro page or layout:

<script is:inline>
  function speedInsightsBeforeSend(data){
    console.log("Capured event!")
    return data;
  }
</script>

Here's how the function will be used internally:

// ...
const beforeSend = window.speedInsightsBeforeSend;
injectSpeedInsights({ route, ...props, framework: 'astro', beforeSend });
// ...

Let me know what you think ๐Ÿ™‚

tobiaslins commented 9 months ago

@MoustaphaDev thanks for the review! Thats a great idea. I just updated the code to look for window.speedInsightsBeforeSend to support that!

tobiaslins commented 9 months ago

Updated to latest versions :) Thanks all :lfg-intense: