Connecting My Astro Blog to Vercel Analytics: A Quick Guide

I recently decided to add web analytics to my Astro blog. And after some thought, I opted for Vercel Analytics instead of the usual Google Analytics. No particular reason, just felt like trying something new. I did, however, connect my site to Google Search Console for good measure.
Here’s the lowdown on what I learned while linking up Astro with Vercel Analytics:
Ignore the Default Instructions:
When you enable Vercel Analytics, they’ll give you a set of instructions to follow. My advice? Skip them if you’re using Astro. I made the mistake of following them, and it ended up confusing me more than helping.
Leverage Astro Integrations:
Astro actually has its own Vercel integration. Head over to Astro’s list of integrations and look for Vercel. Once you’ve found it, use the provided command to install it.
#using npm
npx astro add vercel
#using yarn
yarn astro add vercel
#using pnpm
pnpm astro add vercel
Configure Web Analytics:
Scroll down the page and you’ll find the web analytics configuration section. Insert the necessary codes into your astro.config.mjs file by following the provided instructions.
> //astro.config.mjs
import { defineConfig } from 'astro/config';
import vercel from '@astrojs/vercel/serverless';
export default defineConfig({
output: 'server',
adapter: vercel({
webAnalytics: {
enabled: true,
},
}),
});
Deploy and Enjoy:
With the integration set up and the codes in place, it’s time to deploy your site to Vercel. Once it’s live, boom! Your analytics should be up and running. Simple as pie, right?
This process might seem a bit daunting at first, but trust me, once you get the hang of it, it’s a breeze. Plus, using Vercel Analytics provides some neat insights without the fuss of more complex tools.
If you’re like me and prefer a more straightforward approach, this is definitely a great option. Now, go ahead and give it a shot! Your blog will be equipped with Vercel Analytics in no time.
PS. If you do add vercel to your astro blog, your posts will stop working. 😅 I will share the solution in my next post!
Happy blogging! 🚀