Skip to content

webstats() commands

One function, on the page as soon as the pixel loads.

webstats(command, ...args);
CommandSignatureDoes
eventwebstats('event', name, props?)Records a custom event
pageviewwebstats('pageview')Records a pageview by hand
contentwebstats('content', declaration | null)Names the title the page is about
videowebstats('video', target?, info?)Names a player
configwebstats('config', { contentNav })Sets how URL changes map to pages
flushwebstats('flush')Sends the buffer immediately

An unknown command is ignored, and no command throws once the pixel has loaded.

The pixel is deferred, so window.webstats does not exist until p.js executes. There is no queue stub: a call made before then throws webstats is not defined and is lost.

From an inline <script> in your HTML, make it type="module". Module scripts are deferred too, and run in document order, so one placed after the snippet is guaranteed to be safe.

From app or framework code, guard the call unless you can be certain your bundle executes after p.js:

if (window.webstats) webstats('content', { type: 'movie', ids: { tmdb: '278' } });

A bundle loaded with async, a script placed above the snippet, or a component that renders before the pixel lands will otherwise throw.

<script defer src="https://10.vidstats.top/js/p.js?s=YOUR_TAG_KEY"></script>
<script type="module">
webstats('content', { type: 'movie', ids: { tmdb: '278' } });
</script>
webstats('event', 'signup');
webstats('event', 'purchase', { plan: 'annual', price: 290, currency: 'EUR' });
ArgumentTypeLimit
namestring, required1 to 64 characters. A longer or empty name drops the whole event
propsobject, optionalSee below

Props limits:

RuleLimit
Value typesText, finite numbers, true/false. No arrays, no nested objects
Keys32 per event
Key length64 characters, trimmed beyond
Value length1024 characters, trimmed beyond

An over-length key or value is truncated. An unusable value (a nested object, an array, NaN) drops that one key. Keys past the 32nd are dropped. In all of those the event still records.

The one hard failure is the event name: over 64 characters or empty and the whole event is discarded. See Send events.

webstats('pageview');

Records a pageview for the current URL. You rarely need this: the pixel records the first load and every pushState, replaceState, popstate, and hash change on its own. Use it only for a router that changes views without touching the URL. See React, Vue, and SPAs.

webstats('content', {
type: 'movie',
ids: { tmdb: '278' },
title: 'The Shawshank Redemption',
episode: { ids: { tmdb: '63056' }, season: 1, number: 1, title: 'Winter Is Coming' },
});

A declaration is not clearable. webstats('content', null) does nothing at all, so on a single-page app declare the new title on every route change rather than trying to clear the old one.

KeyTypeRequired
typeone of the 12 content typesyes
idsobject of provider: idyes, at least one entry
titlestring, 256 charactersno
episode{ ids?, season?, number?, title? }no

Limits: 12 id providers, provider names 24 characters, id values 128 characters.

A declaration with an empty ids object, or a type outside the list, is dropped with no error. Those are the two things to check first when a title does not appear. See Content types and ids.

webstats('video', '#player', { id: 'tmdb-278', title: 'The Shawshank Redemption', tmdb: '278' });
webstats('video', videoElement, { id: 'tmdb-278' });
webstats('video', { id: 'tmdb-278' }); // applies to every video on the page
ArgumentAccepts
targetA CSS selector, a DOM element, or omitted to match every video on the page
infoid and title are the identity. Any other key (tmdb, imdb, series, season, episode, type, or your own) is metadata

A selector rule applies to videos that already exist and to any that appear later, so you can call it before your player mounts. If id is absent the pixel derives one from the video file name, then falls back to its position on the page.

You do not need this command to measure video. It only controls how a player is named. See Track video.

webstats('config', { contentNav: 'query' });

contentNav decides which part of the URL counts as a new page.

ValueA new page when
path (default)The pathname changes. ?tab= toggles do not split a video view
queryThe pathname or query string changes
fragmentThe pathname or hash changes. For hash routers

The same thing can be set on the script tag, which takes effect earlier:

<script defer src="https://10.vidstats.top/js/p.js?s=YOUR_TAG_KEY" data-content-nav="fragment"></script>

Set it once, before your first pageview. The data-content-nav attribute is the reliable way to do that, because it is read as the pixel initialises.

webstats('flush');

Sends anything buffered right now. Events are batched and flushed automatically, including when the page is hidden or closed, so this is only useful just before you navigate away by hand.