Netlify Plugin
Auto-inject JustAnalytics tracking scripts and track deployments with the Netlify Build plugin
Netlify Plugin
The netlify-plugin-justanalytics Build plugin automatically injects the JustAnalytics tracking and monitoring scripts into your HTML files during build. It also supports automatic release tracking on every deploy.
Prerequisites#
- A JustAnalytics account with a Site ID
- A Netlify site with a build step that outputs HTML files
Installation#
Install the plugin
npm install netlify-plugin-justanalytics --save-dev
Configure in netlify.toml
Add the plugin to your netlify.toml:
[[plugins]]
package = "netlify-plugin-justanalytics"
[plugins.inputs]
siteId = "your-justanalytics-site-id"
Replace your-justanalytics-site-id with your actual Site ID from the JustAnalytics dashboard.
Deploy
Push your changes and Netlify will automatically:
- Run your build command
- Inject JustAnalytics scripts into all HTML files
- Deploy the modified files
Configuration Options#
All options are set under [plugins.inputs] in netlify.toml:
[[plugins]]
package = "netlify-plugin-justanalytics"
[plugins.inputs]
# Required: Your JustAnalytics Site ID
siteId = "your-site-id"
# Optional: API key for release tracking
apiKey = "ja_sk_..."
# Optional: Include monitoring script (error tracking + Web Vitals)
# Default: true
includeMonitor = true
# Optional: Where to inject scripts ("head" or "body")
# Default: "head"
injectPosition = "head"
# Optional: Track deployments as releases
# Default: true (requires apiKey)
trackReleases = true
Using Environment Variables#
For sensitive values like API keys, use Netlify environment variables:
[[plugins]]
package = "netlify-plugin-justanalytics"
[plugins.inputs]
siteId = "your-site-id"
apiKey = "$JUSTANALYTICS_API_KEY"
Then set JUSTANALYTICS_API_KEY in your Netlify site's Site settings > Environment variables.
What Gets Injected#
The plugin adds the following before the </head> tag in every HTML file:
<!-- JustAnalytics -->
<script defer data-site-id="your-site-id" src="https://justanalytics.app/tracker.js"></script>
<script defer data-site-id="your-site-id" src="https://justanalytics.app/monitor.js"></script>
<!-- /JustAnalytics -->
- tracker.js — Pageviews, clicks, scroll depth, custom events
- monitor.js — Error tracking, Web Vitals, session replay
Files that already contain <!-- JustAnalytics --> are skipped to prevent duplicate injection.
Release Tracking#
When trackReleases is enabled and an apiKey is provided, the plugin sends a release notification to JustAnalytics after every successful deployment. This includes:
- Commit SHA and message (from Netlify build environment)
- Branch name to determine environment (main/master = production, others = preview)
- Deploy timestamp
- Repository URL
View releases in the JustAnalytics dashboard under Monitoring > Releases.
Server-Side SDK (Optional)#
For server-rendered Netlify sites (e.g., Next.js on Netlify, SvelteKit, Nuxt), you can also install the Node.js SDK for APM and error tracking:
npm install @justanalyticsapp/node
Set environment variables in Netlify:
| Variable | Value |
|----------|-------|
| JUSTANALYTICS_SITE_ID | Your site ID |
| JUSTANALYTICS_API_KEY | ja_sk_... |
| JUSTANALYTICS_ENDPOINT | https://justanalytics.app |
Frameworks#
The plugin works with any static site generator or framework that outputs HTML files:
| Framework | Publish Directory | Notes |
|-----------|------------------|-------|
| Next.js (static export) | out | Use output: 'export' in next.config.js |
| Gatsby | public | Works out of the box |
| Hugo | public | Works out of the box |
| Astro | dist | Works out of the box |
| 11ty | _site | Works out of the box |
| Vite / React | dist | Works out of the box |
| Svelte | build | Works out of the box |
For SSR frameworks on Netlify (Next.js SSR, SvelteKit), use the tracking script in your layout template instead of the build plugin.
Troubleshooting#
Scripts not appearing in HTML#
- Verify the
siteIdis set correctly innetlify.toml - Check the Netlify build log for
[JustAnalytics]messages - Ensure your build outputs
.htmlfiles to the publish directory
No data in JustAnalytics dashboard#
- Open your deployed site and check the browser Network tab for requests to
justanalytics.app - Verify the Site ID matches your JustAnalytics dashboard
- Check for Content Security Policy headers blocking the script
Release tracking not working#
- Ensure
apiKeyis set and valid - Check the Netlify deploy log for
[JustAnalytics] Release notification sent - Verify the API key has
ingestpermissions