Analytics
Integrate Google Analytics and Yandex Metrica with Unloyd.
Unloyd supports Google Analytics (GA4) and Yandex Metrica out of the box. Set the environment variable and deploy — no code changes needed.
Google Analytics (GA4)
-
Get Your Measurement ID
- Go to Google Analytics
- Navigate to Admin → Data Streams → select or create a web stream
- Copy the Measurement ID (format:
G-XXXXXXXXXX)
-
Add to Environment Variables
PUBLIC_ANALYTICS_GOOGLE=G-XXXXXXXXXX -
Deploy
The script loads automatically on build. No further setup needed.
Yandex Metrica
-
Get Your Counter ID
- Go to Yandex Metrica
- Create a new counter and copy the Counter ID (numeric value)
-
Add to Environment Variables
PUBLIC_ANALYTICS_YANDEX=XXXXXXXXX -
Deploy
The script loads automatically on build. No further setup needed.
How It Works
Both scripts are conditionally loaded in Head.astro — they only render if the corresponding environment variable is set. This keeps your site lightweight when analytics are not configured.
Privacy Considerations
Both services collect user data. Make sure your site has:
- A Privacy Policy page
- The built-in cookie consent system enabled
- Clear notice to users about data collection