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.

Time to data: 3 minutes

Prerequisites#


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:

  1. Run your build command
  2. Inject JustAnalytics scripts into all HTML files
  3. 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#

  1. Verify the siteId is set correctly in netlify.toml
  2. Check the Netlify build log for [JustAnalytics] messages
  3. Ensure your build outputs .html files to the publish directory

No data in JustAnalytics dashboard#

  1. Open your deployed site and check the browser Network tab for requests to justanalytics.app
  2. Verify the Site ID matches your JustAnalytics dashboard
  3. Check for Content Security Policy headers blocking the script

Release tracking not working#

  1. Ensure apiKey is set and valid
  2. Check the Netlify deploy log for [JustAnalytics] Release notification sent
  3. Verify the API key has ingest permissions