Skip to content
✨ Publier v1 is live — a polished docs platform built for the open web.
On this page

Analytics

What Publier adds to your pages when you configure analytics, what stays with your analytics provider, and what you handle yourself.

Publier does one thing for analytics: it adds your provider’s script to your pages. The provider’s script then runs in the reader’s browser, and the provider collects, stores and reports the data. This page covers what Publier adds and where, what config errors look like, and the parts you own: a privacy notice, a Content-Security-Policy and checking that it works. The YAML for each provider is in Integrations.

What Publier adds

Publier reads the analytics: block of publier.config.yaml and supports these keys:

KeyFieldsWhat the page loads
ga4measurementIdhttps://www.googletagmanager.com/gtag/js?id=<measurementId>, plus an inline gtag setup that calls gtag('config', …)
posthogapiKey, optional host (default https://app.posthog.com)PostHog’s inline loader, which fetches <host>/static/array.js, then calls posthog.init
plausibledomain, optional selfHostedhttps://plausible.io/js/script.js, or <selfHosted>/js/script.js with any trailing / removed; the tag carries defer and data-domain
fathomsiteIdhttps://cdn.usefathom.com/script.js with defer and data-site
umamiwebsiteId, srcThe script at src, with async and data-website-id
scriptsa list of custom entriesEach entry as configured; see Custom scripts

Any combination works. The snippets are emitted in the order above, then your custom head scripts in the order you list them.

How the snippet reaches the page

Publier does not write the provider’s <script> tag into each built HTML file. It registers one inline script with Astro’s injectScript() at the head-inline stage, which Astro documents as “Injected into a script tag in the <head> of every page”. When a page loads, that script turns the snippet HTML into elements and appends them to document.head. This has four consequences:

  • Every page gets it. Publier has no per-page, per-collection or per-route switch for analytics. Draft status and noindex are not consulted.
  • It needs JavaScript. A reader whose browser does not run scripts sends nothing, because the provider’s tag never gets created.
  • No development switch. Publier applies the same registration whether you run astro dev or astro build. If a provider counts your local visits, use a separate property or ID for development, or leave analytics: out of your local config.
  • The tag is inside a string. In the built HTML you will find the provider’s URL as text inside an inline script, not as a <script src> element. See Check that it works.

Config errors

docsShell() validates analytics: when Astro loads the config. Any error stops astro dev and astro build with Invalid publier.config.yaml: followed by one [code] path: message line per problem.

ProblemCodePath
analytics is not a mappingwrong-typeanalytics
A provider key is not a mappingwrong-typeanalytics.ga4, analytics.posthog, and so on
A required field is missing or not a stringmissing-requiredanalytics.ga4.measurementId, analytics.posthog.apiKey, analytics.plausible.domain, analytics.fathom.siteId, analytics.umami.websiteId, analytics.umami.src
scripts is not a listwrong-typeanalytics.scripts
A scripts entry is not a mappingwrong-typeanalytics.scripts[0]
placement is not head or bodyinvalid-enumanalytics.scripts[0].placement
A scripts entry has no non-empty src or contentmissing-requiredanalytics.scripts[0]

Some mistakes pass validation and do nothing, so a missing tracker is not always an error:

  • A misspelt key is ignored. docsShell() reads only the keys it knows and does not report unknown top-level keys, so analytic: or analytics.googleAnalytics is dropped without a message. The same holds for an unknown field inside a provider.
  • An empty string skips the provider. measurementId: "" passes validation, but no snippet is emitted for it.
  • A wrong-typed optional value is ignored. async: "true" (a string) leaves async off, and a non-string host or selfHosted falls back to the default.

Where Publier stops

Publier injects the snippet. The provider’s script and servers do everything after that: collecting, storing, reporting, retention and any cookies or identifiers the script sets.

In the current release, Publier ships none of the following, so a Publier site has them only if you add them:

  • A dashboard or report. Read your numbers in the provider’s own interface.
  • First-party event collection or an events API. Custom events come from the provider’s script, called from your own code.
  • A consent banner, a consent-gated loader, or Do-Not-Track handling. Once you configure a provider, its script is added to every page load.

What you do yourself

Whether you must tell readers about analytics, or ask first, depends on the provider, how you configure it, and the law where your readers live. That is your decision, and this page is not legal advice. Publier gives you nothing to show a notice or to gate the script.

If you need the provider’s script to wait for consent, write that logic yourself. A scripts entry with content runs your code verbatim on every page, so it can hold your consent check and load the provider’s tag only afterwards. In that case leave the provider’s own key out of analytics:, or the script loads once unconditionally and once after consent.

Content-Security-Policy

Publier does not set a Content-Security-Policy. The dist/_headers file it writes holds X-Content-Type-Options, Referrer-Policy, X-Frame-Options, Strict-Transport-Security and Cross-Origin-Opener-Policy, plus cache rules. If your host or CDN adds a policy, two things need to be allowed:

  1. The inline script. The snippet is added by an inline <script> in <head>, and Publier injects other inline scripts there too. A script-src without 'unsafe-inline' or a matching hash blocks them; see MDN’s script-src reference. Publier does not add nonces. A scripts entry with content is another inline script and needs the same allowance.
  2. The provider’s script origin. These come from the snippets:
ProviderScript origin
ga4https://www.googletagmanager.com
posthogYour host, or https://app.posthog.com
plausiblehttps://plausible.io, or your selfHosted origin
fathomhttps://cdn.usefathom.com
umamiThe origin of your src
scriptsThe origin of each src

The provider’s script then sends data somewhere, and a policy can block that too (connect-src, img-src). Those origins are the provider’s behaviour, not something in Publier’s source, so take them from the provider’s documentation. Google lists script-src-elem https://www.googletagmanager.com together with img-src and connect-src entries in its CSP guide for Google tags, and PostHog documents script-src and connect-src needs in its content security policy guide.

Check that it works

  1. In the built HTML. After astro build, search dist/ for the provider’s host. Every page rendered through your layouts carries the inline script, so the second command lists only HTML files without it, such as a redirect page:

    terminal
    grep -rl "cdn.usefathom.com" dist --include='*.html' | wc -l
    grep -rL "cdn.usefathom.com" dist --include='*.html'

    Use googletagmanager.com, plausible.io, your selfHosted host, or your Umami src host for the other providers. A PostHog snippet contains your host and /static/array.js.

  2. In the browser. Open a deployed page, then look at the Network tab for a request to the provider’s script, and at the Elements panel for the <script> in <head>. A blocked request there usually means a CSP or an ad blocker.

  3. At the provider. Visit the page and watch the provider’s real-time view. Hits can take longer to appear in its standard reports. How long is up to the provider.

Custom scripts

The scripts list takes any script, not only analytics.

publier.config.yaml
analytics:
scripts:
- src: https://my-cdn.example.com/my-tag.js
async: true
- content: "window.dataLayer = window.dataLayer || [];"
placement: head
FieldRule
srcExternal script URL, HTML-escaped into the src attribute.
contentInline JavaScript. Publier does not escape or change it. It runs on every page with the page’s privileges, so treat it as your own code.
async, deferAdd the attribute when true. Only YAML booleans count.
placementhead (the default) or body.

An entry needs a non-empty src or content, or the build fails. If you set both, Publier uses src and drops content.

Scripts with placement: head are written into each page’s <head> and scripts with placement: body at the end of <body>, just before </body>. Both keep the order they have in the config and appear in the built HTML of every page, so you can check them with “view source”. publier dev loads head scripts at runtime instead.

  • Integrations has the YAML for each provider.
  • Search says that Publier records no search terms.
  • Accessibility says to test third-party additions such as analytics, and Publier does not guarantee a Lighthouse score; measure your pages after adding a provider.