virling Docs
v0.3.0 virling.com GitHub Start free
virling Docs

Script attributes and API

The tracking script is served at /v.js by every Virling server. It is about 2 KB gzipped, and its source is assets/v.src.js.

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

Attributes

AttributeWhat it does
data-siteRequiredThe site’s domain as added to Virling. Without it the script does nothing.
data-apiOptionalFull URL to send events to. Default: /api/event on the host the script was loaded from.
data-cookielessOptionalNever set the virling_vid cookie. A cookie set after consent is still read. See Cookieless mode.
data-respect-gpcOptionalSend nothing when navigator.globalPrivacyControl is on.
data-devOptionalAlso track on localhost, 127.* and [::1], which are skipped by default.

Boolean attributes only need to be present: data-cookieless, not data-cookieless="true".

JavaScript API

virling("goal", name)

Sends a goal. See Goals.

virling("goal", "signup");

virling("consent")

On a site set to Until consent, sets the virling_vid cookie to the ID the current visit is already counted under, so the visit continues. Call it from your consent tool once the visitor accepts. It does nothing on other sites or when the cookie is already set. See Cookieless until consent.

virling.vid()

Returns the visitor ID, or null in cookieless mode until a page loads with the consent cookie. Pass it into checkout. See Link checkout to visits.

Call it as window.virling?.vid?.(), which returns nothing instead of throwing when the script is blocked or has not loaded yet:

const id = window.virling?.vid?.();
if (id) { /* pass it into checkout */ }

virling.q

Calls queued in window.virling.q before the script loads are replayed in order. See Calling before the script loads.

NameValueLifetimeFlags
virling_vidv followed by a timestamp and random characters1 year, renewed on each visitDomain is the registrable domain, so subdomains share it; Path /, SameSite=Lax, Secure on HTTPS

virling_ignore is set to 1 for a year only when you open the site with #virling-ignore; while it is set the script sends nothing. Opening #virling-track removes it.

The server accepts visitor IDs of 8 to 64 letters, digits and dashes. Anything else is replaced with the daily cookieless hash.

Automatic behavior

  • A pageview on load, and on history.pushState, history.replaceState and popstate when the path or query changes. See Single-page apps.
  • Links to buy.stripe.com get client_reference_id, links to buy.polar.sh get reference_id, links to checkout.dodopayments.com get metadata_virling_vid, and links to *.lemonsqueezy.com get checkout[custom][virling_vid], set to the visitor ID, on page load and on click. See Checkout links need no code.

Caching

/v.js is served with Cache-Control: public, max-age=3600 and Access-Control-Allow-Origin: *. After an upgrade, browsers pick up the new script within an hour.

Connect your payment provider and see revenue by channel.

Start free
Was this page helpful?No Edit this page on GitHub