文档
浏览文档

The Privatus Analytics integration for Vercel

Install the Privatus Analytics integration on Vercel to set your site id as an environment variable on your projects, then use it in the tracking script.

查看 Markdown

Warning: The integration is not listed on the Vercel Marketplace. Don't install an integration called Privatus Analytics from the marketplace: it is not ours, whoever published it. Set the variable yourself in your project's settings until this page says the integration is listed.

The integration does one thing: it sets your Privatus Analytics site id as an environment variable on the Vercel projects you pick. Your code then reads it in the tracking script, so the id is not typed into the code and each environment can use the same one. It does not add a log drain or forward anything from Vercel: visits are still counted only by the tracking script.

Install#

  1. Start the install from the integration's page on Vercel and pick the team and the projects it may see.
  2. A Privatus Analytics window opens. Log in, or sign up and add your site first.
  3. Pick the site and the projects, then click Save. You return to Vercel.

The integration sets two variables on each project, for production, preview and development:

Variable Use it in
NEXT_PUBLIC_PRIVATUS_SITE_ID Next.js, where only NEXT_PUBLIC_ variables reach the browser
PRIVATUS_SITE_ID Every other framework, and server code

They take effect on each project's next deployment. Open Configure on the integration in Vercel to change the site or the projects. Only the Privatus Analytics account that installed the integration can change them.

Use the variable#

In Next.js, put the variable in the script tag of the root layout (see Next.js):

tsx
<Script defer src="https://privatusstats.com/js/pa.js"
        data-site={process.env.NEXT_PUBLIC_PRIVATUS_SITE_ID}
        strategy="afterInteractive" />

In other frameworks, read PRIVATUS_SITE_ID where your build fills in environment variables (for example import.meta.env in Astro) and print it in data-site.

Removing the integration#

Remove it in Vercel (Integrations → Privatus Analytics → Manage → Remove). We delete the integration's Vercel token at once. The two variables stay on your projects until you delete them in each project's settings.

What the integration can do#

It asks Vercel for read access to projects and read and write access to the environment variables it creates. It keeps Vercel's token for the installation (encrypted), the Vercel team id, the site you picked and the names of the projects it set the variables on.