Skip to content

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.

For full set up instructions, see Plausible Analytics’ Get Started documentation.

  1. Create a Plausible account.
  2. In Plausible, add your production domain as a new website, for example your-site.example.
  3. Select the NPM installation instructions.
  4. In your LightNet project, add the Plausible integration:
    Terminal window
    pnpm astro add @lightnet/plausible-analytics
    Confirm the prompts. Astro installs @lightnet/plausible-analytics and adds it to the integrations array in astro.config.mjs.
  5. Make sure the top-level Astro site option in astro.config.mjs is 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()
    ],
    });
  6. Deploy your site, then visit the deployed site.
  7. Open Plausible and verify that visits are being recorded. If you need help verifying the installation, see Plausible’s troubleshooting guide.

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.

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.

  1. Create a component in your LightNet project, for example src/CustomHead.astro.
  2. Add your provider’s tracking script to the component. This example uses Fathom Analytics:
    src/CustomHead.astro
    ---
    ---
    <script
    src="https://cdn.usefathom.com/script.js"
    data-site="YOUR-SITE-ID"
    defer>
    </script>
  3. 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",
    }),
    ],
    });
  4. Deploy your site and verify the installation in your analytics provider.