Google Analytics Plugin
The Google Analytics plugin allows you to integrate Google Analytics tracking into your Scully-generated static site using the Global Site Tag (gtag) method.Overview
- Type: Post-Render Plugin
- Function: Injects Google Analytics tracking script into HTML
- Method: Global Site Tag (analytics.js)
Installation
Install the plugin as a dev dependency:Configuration
Configure the plugin in your Scully configuration file:Usage
Basic Setup
- Get your Google Analytics tracking ID from the Google Analytics Dashboard
- Configure the plugin with your tracking ID
- Run Scully in production mode
Production-Only Tracking
It’s recommended to only include Google Analytics in production builds:Route-Specific Configuration
Apply the plugin to specific routes:Configuration Options
globalSiteTag (required)
Your Google Analytics tracking ID.- Go to Admin > Property > Tracking Info > Tracking Code
- Copy the Tracking ID (format:
UA-XXXXXXXXX-X)
How It Works
The plugin injects the following script into the<head> section of each rendered HTML page:
sk attribute prevents Scully from removing the script during the build process.
Environment Variables
For security, use environment variables for your tracking ID:Verification
After building your site with Scully:- Open a generated HTML file from the
dist/staticdirectory - Verify the Google Analytics script is present in the
<head>section - Deploy your site and check the Google Analytics Real-Time reports to confirm tracking is working
Testing
To test the plugin without waiting for real traffic:-
Build and serve your static site:
- Open your site in a browser
- Check the Google Analytics Real-Time view
- You should see your visit tracked
Migrating to GA4
This plugin uses Universal Analytics (analytics.js). For Google Analytics 4 (GA4), you may need to:- Create a custom plugin using the gtag.js format
- Or manually add the GA4 tracking code to your Angular app’s
index.html
Troubleshooting
Scripts Removed from HTML
If Google Analytics scripts are missing from the output:- Ensure you’re running Scully in production mode (
--prod) - Check that the plugin is in the
defaultPostRenderersor route-specificpostRenderers - Verify the
skattribute is present on the script tags
No Tracking Data
- Verify your tracking ID is correct
- Check browser console for errors
- Confirm you’re not blocking analytics with ad blockers
- Review Google Analytics Real-Time reports
Multiple Tracking Scripts
If you have analytics in both your Angular app and Scully:- Remove analytics from your Angular
index.html - Let Scully inject it via this plugin
- Or configure analytics only in your Angular app and skip this plugin
Repository
- Package:
@scullyio/scully-plugin-google-analytics - Repository: GitHub
- Author: Israel Guzman
See Also
- Sentry Plugin - Error tracking
- Post-Render Plugins
- Google Analytics Documentation

