Page views and clicks

datacub records page views, time on page, clicks and form submits by itself.

Page views

EventWhen
$pageviewon the first load, on every route change in a single page app, and when the browser restores a page from its back and forward cache
$pageleavewhen the user moves to the next page or hides the tab. Carries foreground time and how far they scrolled, in steps of 10%

Route changes are detected through the History API (pushState, replaceState, back and forward), 100 ms after the router updates the URL. A route that only rewrites the same path is not counted twice. Hash routers need hashRouting: true (frameworks).

URLs are cleaned on the device: fragments are removed, query values are kept only when they read as codes, never what someone typed or anything sensitive (see what the SDK collects), IDs in paths become :id, :uuid, :hash or :token, and anything that looks like personal data becomes :redacted. UTM parameters and which ad network sent the visit (gclid, fbclid and others, never their values) are kept for the source reports.

Clicks

Clicks on links, buttons, summary, submit inputs and elements with an ARIA role of button, link, menu item or tab are captured as $click. The visible text of buttons and links is captured (scrubbed, at most 100 characters; details). Give important ones a readable name with data-datacub-name:

<button data-datacub-name="upgrade_plan">ترقية الباقة</button>
<a href="/pricing" data-datacub-name="see_pricing">Pricing</a>

The name is what reports show, in any language your UI uses. Do not put user data in it: it is scrubbed like any other value.

Form submits

$form_submit records that a form was submitted: its data-datacub-name, its action path and how many fields it has. Never field names, values or labels.

<form data-datacub-name="signup" action="/signup">...</form>

A click is not an outcome

A click on "Pay" is a click, and a form submit is an attempt. Neither says the payment went through. Track the outcome where your code knows it worked, so funnels stay right when a card is declined or a form shows an error:

async function pay(planId: string) {
  const res = await fetch('/api/checkout', { method: 'POST', body: JSON.stringify({ planId }) })
  if (res.ok) datacub.track('checkout_completed', { plan: planId })
}

Leaving parts of the page out

Add class="datacub-no-capture" or data-datacub-no-capture to an element and nothing inside it is captured, clicks or submits:

<section class="datacub-no-capture">
  <!-- an admin panel, a support chat, anything you would rather not measure -->
</section>

To turn off clicks and form submits everywhere, keeping page views:

datacub.init('pk_live_YOUR_PROJECT_KEY', { autocapture: false })

In mobile apps

Apps have screens instead of pages, and no automatic clicks. See screens.