GuidesWeb

Astro analytics with Privytics, cookieless and EU-hosted

Cookieless analytics for Astro, hosted in the EU.

Privytics gives your Astro site page views, custom events and funnels without setting a single cookie. You add one component to your root layout, point it at the Privytics API, and every page rendered through that layout is tracked. It works the same whether your site is fully static, server-rendered, or a mix of both.

Why Astro teams use Privytics

One component covers every page

Astro sites almost always share a single root layout. Drop OpenPanelComponent into that layout's <head> once and every route inherits tracking. There is no per-page wiring and no provider tree to thread through.

Works with static output

The component renders a plain <script> tag plus a small inline init snippet, so it survives `astro build` to fully static HTML on a CDN. You do not need an SSR adapter or a server runtime just to collect analytics.

Track clicks without shipping an island

Astro ships zero JavaScript by default and adding a React or Vue island just to fire an event defeats that. With trackAttributes enabled you put data-track on ordinary markup, or call window.op inline, and no framework component is involved.

No cookie banner for the analytics itself

Astro is built for content and marketing sites, where a consent dialog is the first thing a visitor meets. Privytics is cookieless and writes nothing to the visitor's device, so the analytics does not add a reason to show one. You are still the controller and decide what your site needs overall.

Set it up

About five minutes, on the free plan, without a credit card.

  1. Install the SDK

    The Astro package is published by OpenPanel under the @openpanel scope. Privytics is built on the open-source OpenPanel engine, so you use the upstream package name.

    pnpm install @openpanel/astro
  2. Add the component to your root layout

    Put it in the <head> of the layout every page uses. apiUrl is required: leave it out and the component falls back to OpenPanel's own host, so your events never reach Privytics. clientId identifies your project. scriptUrl is optional. The component defaults to https://openpanel.dev/op1.js and works fine that way, but we point it at https://privytics.com/op1.js so the tracker is served from a domain we control rather than a third party. The tracking options all default to false, so enable the ones you want.

    ---
    import { OpenPanelComponent } from '@openpanel/astro';
    ---
    
    <html>
      <head>
        <OpenPanelComponent
          apiUrl="https://api.privytics.com"
          scriptUrl="https://privytics.com/op1.js"
          clientId="YOUR_CLIENT_ID"
          trackScreenViews={true}
          trackOutgoingLinks={true}
          trackAttributes={true}
        />
      </head>
      <body>
        <slot />
      </body>
    </html>
  3. Track a custom event

    Call the global op function inline, or use data attributes. The data-track form requires trackAttributes={true} from the previous step. Extra data-* attributes on the same element are sent as event properties.

    <button onclick="window.op('track', 'signup_clicked')">Sign up</button>
    
    <button data-track="pricing_viewed" data-plan="pro">See pricing</button>
  4. Identify a signed-in user

    Optional. Render IdentifyComponent on pages where you know who the visitor is to link sessions into one profile. This is opt-in and you need your own lawful basis for it.

    ---
    import { IdentifyComponent } from '@openpanel/astro';
    ---
    
    <IdentifyComponent
      profileId="123"
      firstName="Joe"
      lastName="Doe"
      email="joe@doe.com"
      properties={{
        tier: 'premium',
      }}
    />

Privytics runs the open-source OpenPanel engine, so the upstream Astro SDK reference applies here too. Point apiUrl at Privytics and the data lands in your Privytics project.

Questions

Does this work with a fully static Astro site?

Yes. The component outputs the tracker script tag and its init snippet during the build, so the generated HTML carries the tracker and no server runtime is required. Static hosting on any CDN is fine.

Do I need a cookie banner to use analytics on my Astro site?

Privytics is cookieless and stores nothing on the device, so the analytics itself does not create that requirement. You remain the data controller and other parts of your site may still need consent, so check your own situation.

How do I track page views in Astro?

Set trackScreenViews={true} on OpenPanelComponent. Page views are then recorded automatically and you do not need to call anything per route.

Can I track a button click without adding a React or Vue island?

Yes. Enable trackAttributes and add data-track to any plain element, or call window.op('track', 'event_name') from an inline onclick. Neither approach loads a framework.