LightNet v4 is here! Learn how to upgrade your site
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. You can also use another analytics provider by adding its script to the document head.
Set up Plausible
Section titled “Set up Plausible”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.
- Create a Plausible account.
- In Plausible, add your LightNet site as a new website.
- Select the NPM installation instructions.
- In your LightNet project, add the Plausible integration:
Confirm the prompts. Astro installs
Terminal window npm 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.com",integrations: [lightnet({/* Your LightNet configuration */}),plausibleAnalytics()],}); - Deploy your site.
- Open Plausible and verify that visits are being recorded.
Use another provider
Section titled “Use another provider”You can use another analytics provider by adding 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.com",integrations: [lightnet({headComponent: "src/CustomHead.astro",}),],}); - Deploy your site and verify the installation in your analytics provider.