Add Analytics
Analytics can help you understand how people use your media library, which pages are popular, and whether changes are helping. You can collect those insights without using cookies or building visitor profiles.
We recommend Plausible for LightNet sites because it is privacy-friendly and easy to add.
Plausible does not use cookies and does not require a cookie banner for standard pageview analytics. It is a paid service, which means your visitors do not pay with their personal data.
Set up Plausible
Section titled “Set up Plausible”For full set up instructions, see Plausible Analytics’ Get Started documentation.
- Create a Plausible account.
- In Plausible, add your production domain as a new website, for example
your-site.example. - Select the NPM installation instructions.
- In your LightNet project, add the Plausible integration:
Confirm the prompts. Astro installs
Terminal window pnpm astro add @lightnet/plausible-analytics@lightnet/plausible-analyticsand adds it to theintegrationsarray inastro.config.mjs. - Make sure the top-level Astro
siteoption inastro.config.mjsis set to your production URL:astro.config.mjs import { defineConfig } from "astro/config";import lightnet from "lightnet";import plausibleAnalytics from "@lightnet/plausible-analytics"export default defineConfig({site: "https://your-site.example",integrations: [lightnet({/* Your LightNet configuration */}),plausibleAnalytics()],}); - Deploy your site, then visit the deployed site.
- Open Plausible and verify that visits are being recorded. If you need help verifying the installation, see Plausible’s troubleshooting guide.
Other analytics approaches
Section titled “Other analytics approaches”We recommend using a simple client-side analytics integration for most LightNet sites, especially Plausible.
Server-side approaches are also possible, including edge functions, workers, or custom logging pipelines, but they are usually more complex to implement and maintain. They are outside the scope of this guide.
Use a different client-side provider
Section titled “Use a different client-side provider”If you prefer a different client-side analytics provider, you can add its script with LightNet’s headComponent config option.
This adds a custom Astro component to the HTML <head> of every page.
- Create a component in your LightNet project, for example
src/CustomHead.astro. - Add your provider’s tracking script to the component. This example uses Fathom Analytics:
src/CustomHead.astro ------<scriptsrc="https://cdn.usefathom.com/script.js"data-site="YOUR-SITE-ID"defer></script> - Configure LightNet to use the component:
astro.config.mjs import { defineConfig } from "astro/config";import lightnet from "lightnet";export default defineConfig({site: "https://your-site.example",integrations: [lightnet({headComponent: "src/CustomHead.astro",}),],}); - Deploy your site and verify the installation in your analytics provider.