Skip to content

About

See visitors, pageviews and top pages from Privatus Analytics, the cookieless website analytics, inside Sanity Studio

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

sanity-plugin-privatus-analytics

See who reads your content, right inside Sanity Studio.

Your team writes and publishes in Sanity. But to see if anyone reads it, they have to leave the Studio and log in to another dashboard. Many analytics tools also need a cookie pop-up, and lots of visitors click "no" or leave. Bots then puff up the numbers that are left.

This plugin brings your Privatus Analytics numbers into Sanity Studio. Your editors see visitors, pageviews and top pages next to the content they manage, with no extra login. Privatus Analytics counts visits without cookies, so you need no cookie pop-up for it. It also leaves bots out, so the numbers are honest.

Free plan, no card: 10,000 events a month (an event is a page view or an action you track) on up to 3 sites. Start free at privatusanalytics.com.

The Privatus Analytics widget on a Sanity Studio dashboard

What you get

  • An Analytics tool in the Studio's top menu. It shows your full Privatus Analytics dashboard: visitors, pages, sources, countries, devices and more.
  • A dashboard widget for @sanity/dashboard. It shows visitors and pageviews for the period you pick, the change from the period before, and your top pages.

Use one or both. The plugin only reads your reports. It does not track anyone in the Studio.

Requirements

  • Sanity Studio 4, 5 or 6. The widget needs @sanity/dashboard.
  • A Privatus Analytics account with your website added as a site. There is a free plan.
  • The Privatus Analytics script on your website (the front end, not the Studio), so visits are counted. Put it in the <head> of your pages:
<script defer src="https://privatusstats.com/js/pa.js" data-site="pa_YOURSITEID"></script>

You find your site id (it starts with pa_) in Privatus Analytics under Site settings, Tracking.

Install

npm install sanity-plugin-privatus-analytics

Set up

1. Make a share link

  1. In Privatus Analytics, open your site, then Site settings, Sharing.
  2. Create a link of the kind Public or Embed. Pick the sections you want your editors to see.
  3. Copy the link. It looks like https://privatusanalytics.com/share/abc123.

Why a share link? Sanity puts your Studio settings into JavaScript that the browser downloads. A secret API key there would not stay secret. A share link is made to be seen, it only shows what you picked, and you can revoke it at any time.

2. Add the plugin to sanity.config.ts

import {defineConfig} from 'sanity'
import {dashboardTool} from '@sanity/dashboard'
import {privatusAnalytics, privatusWidget} from 'sanity-plugin-privatus-analytics'

const shareUrl = 'https://privatusanalytics.com/share/abc123'

export default defineConfig({
  // ...
  plugins: [
    // The Analytics tool in the top menu
    privatusAnalytics({shareUrl}),

    // The widget on the Studio dashboard
    dashboardTool({
      widgets: [privatusWidget({shareUrl, period: '30d'})],
    }),
  ],
})

Tip: keep the link in an environment variable such as SANITY_STUDIO_PRIVATUS_SHARE_URL and read it with process.env.SANITY_STUDIO_PRIVATUS_SHARE_URL.

Options

privatusAnalytics(options)

Option Default What it does
shareUrl (needed) Your public or embed share link
title Analytics The name in the top menu
name analytics The tool's address, as in /analytics

privatusWidget(options)

Option Default What it does
shareUrl (needed) Your public or embed share link
period 7d today, yesterday, 24h, 7d, 30d, 90d, mtd (month so far), last_month, ytd (year so far) or 12mo
topPages 5 How many top pages to list, from 0 to 10
title Privatus Analytics The widget heading
layout {width: 'medium'} The widget size on the dashboard

If the share link locks a period, the widget shows that period.

Questions

  • "This share link was not found." The link was revoked or mistyped. Make a new one in Site settings, Sharing.
  • "Could not reach Privatus Analytics." Password links and team-only links need a sign-in, so the Studio cannot read them. Use a Public or Embed link.

Privacy

The plugin only loads your share link from Privatus Analytics. It sends no data about your editors or your content anywhere.

More

Develop

npm ci
npm run typecheck
npm test
npm run build
./run-docker.sh   # builds a real Sanity Studio with this plugin in Docker

License

MIT, Two Phase LLC. See LICENSE.

About

See visitors, pageviews and top pages from Privatus Analytics, the cookieless website analytics, inside Sanity Studio

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages