StatsRaven

Snippet

The snippet counts visits in the browser. It is about 2 KB compressed, sets no cookies and stores nothing on the device. Server logs already tell StatsRaven which pages were requested. The snippet adds what only a browser knows: that a person really looked at the page, for how long, and what they did there.

Add it to a site

Create a key for the site on your StatsRaven server. List every hostname that may send data, because beacons from other hosts are refused.

statsraven site-key --project shop --hosts shop.example,www.shop.example

Then add one line to the <head> of every page, with your server's address and the key it printed.

<script defer src="https://stats.example.com/s.js" data-site="pk_..."></script>

Single page apps need nothing more. The snippet counts a new page view whenever the address changes through pushState, replaceState or the back button.

What it sends

The page path without its query string, the referring site, UTM tags, the browser language, and when the page is left, how long it was visible and how far it was scrolled. From the request itself the server keeps the country, region and city as Cloudflare estimates them when StatsRaven sits behind Cloudflare (otherwise no location is kept), a coarse device type, browser family and operating system family. The IP address and user agent are used to make an anonymous visitor code that changes every day, and are not stored.

While a page is visible it also sends a small signal every 30 seconds, for up to two hours, so the Live page can show who is on the site right now. These signals are held in memory and never stored.

Nothing is sent when the browser asks for privacy with Global Privacy Control or Do Not Track, when the page runs on localhost, or when the browser says it is automated.

Goals and events

Call statsraven.track when something worth counting happens. Each event shows up as a goal on the Overview page with its conversion rate.

statsraven.track("signup");
statsraven.track("signup", { plan: "pro", seats: 3 });
statsraven.track("purchase", { plan: "pro" }, { amount: 49, currency: "EUR" });
PartRules
NameUp to 64 letters, digits and _ - . :
PropertiesUp to 10. Names use letters, digits and underscores, up to 32 characters. Values are kept as text, up to 100 characters
RevenueAn amount and a three letter currency code. USD when the code is missing

Properties can be asked about in chat and used in charts as prop.plan, prop.seats and so on. Never put emails, names or other personal data in a property.

Counted for you

Turn both off with data-auto="off" on the script tag.

Pages that are not found

Add statsraven.track("404") to your not-found page. Filter the Overview page by the 404 event and the pages list shows which paths people hit.

Options

AttributeWhat it does
data-siteThe site key. Required
data-auto="off"Stops counting outbound clicks and downloads
data-hash="on"Counts the part after # as part of the page, for apps that route with it

How visits are counted

A visit ends after 30 minutes without a page view or event. A bounce is a visit with one page, no event and less than 10 seconds on the page. Because the visitor code changes every day, someone who comes back on another day counts as a new visitor. When a site also sends server logs, StatsRaven checks whether each page request that looked like a browser also ran the snippet. Requests that never did are shown as likely scrapers.