webstats() commands
One function, on the page as soon as the pixel loads.
webstats(command, ...args);| Command | Signature | Does |
|---|---|---|
event | webstats('event', name, props?) | Records a custom event |
pageview | webstats('pageview') | Records a pageview by hand |
content | webstats('content', declaration | null) | Names the title the page is about |
video | webstats('video', target?, info?) | Names a player |
config | webstats('config', { contentNav }) | Sets how URL changes map to pages |
flush | webstats('flush') | Sends the buffer immediately |
An unknown command is ignored, and no command throws once the pixel has loaded.
Calling webstats() from your page
Section titled “Calling webstats() from your page”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' });| Argument | Type | Limit |
|---|---|---|
name | string, required | 1 to 64 characters. A longer or empty name drops the whole event |
props | object, optional | See below |
Props limits:
| Rule | Limit |
|---|---|
| Value types | Text, finite numbers, true/false. No arrays, no nested objects |
| Keys | 32 per event |
| Key length | 64 characters, trimmed beyond |
| Value length | 1024 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.
pageview
Section titled “pageview”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.
content
Section titled “content”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.
| Key | Type | Required |
|---|---|---|
type | one of the 12 content types | yes |
ids | object of provider: id | yes, at least one entry |
title | string, 256 characters | no |
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| Argument | Accepts |
|---|---|
target | A CSS selector, a DOM element, or omitted to match every video on the page |
info | id 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.
config
Section titled “config”webstats('config', { contentNav: 'query' });contentNav decides which part of the URL counts as a new page.
| Value | A new page when |
|---|---|
path (default) | The pathname changes. ?tab= toggles do not split a video view |
query | The pathname or query string changes |
fragment | The 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.