Analytics and Cookies
Depending on your needs, you may want to add analytics to your website, or manage cookies if you’re not using privacy focused analytics.
Analytics
If you wish to add analytics to your website, this is typically done by adding code to the <head>
of the site. You can do this within the file ./src/layouts/BaseHead.astro
. This file is included in all pages, and is where you can add / remove anything from the <head>
of the site.
The below links have more info to walk you through setting up analytics with Astro.
- Blog post on setting up Google Analytics 4 and Google Tag Manager with Astro.
- How to bypass ad-blockers with analytics rewrites.
Cookies!
If you’re using Google Analytics, you’ll need to manage cookies to be compliant with GDPR.
I have a blog post on implementing a basic cookie request modal that will help you set this up with GA4 here.