blog.json to the script as a data-* attribute, so you can ignore pages, collect extra query parameters and limit the metrics Simple Analytics collects without writing a custom script.
With the c15t cookie banner on, Simple Analytics loads through c15t instead, only after a visitor allows the measurement category, and keeps every option below.
1
Add your website in Simple Analytics
In Simple Analytics, add your site’s domain as a website, like
blog.acme.com. Simple Analytics identifies websites by their domain, so you don’t need an ID or an API key.2
Add it to Notra
Open Studio → Sites, select your site, open Integrations and click Add Simple Analytics. Enter the same domain under Domain, and if you set up a custom subdomain to bypass ad blockers, enter its script URL under Script URL as well. When you click Save, Notra opens a pull request with the change. To configure it in your repository instead, add it to
blog.json:blog.json
3
Merge and verify
After you merge the change and the production deployment finishes, visit your live site and check the dashboard of your website in Simple Analytics.
Options
The dashboard covers the domain, the script URL and Do Not Track. You set every other option inblog.json, and editing the integration in the dashboard keeps those options as they are.
The function and namespace options take a JavaScript identifier, like
rewritePath.
Notra adds the origin of the script to script-src and the host that receives events to connect-src in the Content-Security-Policy. That host is https://queue.simpleanalyticscdn.com for the default script and the origin of scriptUrl when you set one.
Bypass ad blockers
Some ad blockers block the Simple Analytics domains. To avoid that, add a CNAME record for a subdomain likeapi.acme.com that points to simpleanalyticsexternal.com, save the subdomain in your website settings in Simple Analytics as its bypass guide describes and set scriptUrl to https://api.acme.com/latest.js. The script then loads from your subdomain and sends its events back to it.
Custom events
To track clicks in your own components and MDX, adddata-simple-event to an element. Simple Analytics then sends an event with that name when a visitor clicks it, or submits it if the element is a form, and uses the element’s data-simple-event-* attributes as metadata:
sa_event("pricing_clicked"), or use your namespace or saGlobal if you set one, as the events docs of Simple Analytics describe. Custom scripts can run before Simple Analytics loads, and with the c15t banner on it only loads after a visitor allows measurement, so define a queue first. Simple Analytics sends the queued events once it loads and drops them if it never does:
script.js
Privacy
Simple Analytics sets no cookies and stores nothing in the browser’s local or session storage, and it collects no personal data. It skips visitors who turned on Do Not Track unless you setcollectDnt to true, so turning on Do Not Track in your own browser also stops it from counting your visits.