Hubfly spaceDocs
Console

Custom events and goals

Web Analytics is coming soon

Web Analytics is not open for new sites yet, and nothing is charged for it. This guide describes how it works at launch; the prices are the launch prices.

The script exposes one function, window.hubfly(command, …args). Calls made before it loads are queued if you add the one-line stub. Every pageview and custom event, including automatic ones, is a billable event.

Track an event

JavaScript
document.querySelector("#signup").addEventListener("click", () => {
  hubfly("track", "Signup");
});

Event names are up to 120 characters and are case-sensitive: Signup and signup are different events. Use a few stable names and put the details in props.

Props

Props describe an event or a pageview, and every report can be filtered by them.

JavaScript
hubfly("track", "Signup", { props: { plan: "pro", source: "pricing-page" } });
  • Up to 30 props per event. Keys up to 64 characters; values are strings up to 512 characters, numbers or booleans, stored as text. Other values are dropped.
  • Do not put personal data such as email addresses or names in props.

Revenue

Attach an amount and a three-letter currency code to an event, and goals built on it report revenue:

JavaScript
hubfly("track", "Purchase", {
  props: { plan: "pro" },
  revenue: { amount: 29.99, currency: "USD" },
});

The amount must be greater than zero, with at most six decimals. Leave out currency, or pass a bare number such as revenue: 29.99, to use the site's currency. Reports sum revenue in the site's currency, set in Settings → General; events in other currencies are counted but their amounts are not added up or converted.

Automatic events

Turn these on in the site's Settings → Tracking; no code is needed.

SettingEvent nameProp
Outbound linksOutbound Link: Clickurl: the link target
File downloadsFile Downloadurl: the file URL, without its query string
Form submissionsForm: Submissionform: the form's id, name or action path
404 pages404path: the missing page

With 404 pages on, the script records pages served with status 404 by itself. When HubProxy adds the script to a page on a Hubfly space domain (automatic injection), it marks the tag of a 404 page with data-404, so this works in every browser. Where you add the tag yourself, on a site hosted elsewhere or on Hubfly space, the script relies on the browser to report the page's status, and only Chromium-based browsers do; call hubfly('404') from your not-found page to cover the other browsers. Single-page apps whose not-found route is served with status 200 always need that call.

Manual pageviews and 404s

The script records a pageview on load and on every client-side navigation (pushState, replaceState and back/forward), so single-page apps need no extra code. To record one yourself, for example for a virtual page in a modal flow:

JavaScript
hubfly("pageview", { url: "https://example.com/checkout/step-2", props: { variant: "b" } });

// On your not-found page:
hubfly("404");

Goals and funnels

A goal counts visitors who view a page or trigger a custom event. Pageview goals match a path pattern such as /thanks/**; event goals match an event name exactly. Goals are applied when reports run, so a new goal also covers past events still within the site's raw retention. A funnel is an ordered list of 2 to 8 pages and events, each of which must follow the previous one within a time window you choose, and shows how many visitors reach each step and where they leave. In cookieless mode the steps must happen within one visit; in persistent mode they can span visits.

Identify users

In the opt-in persistent mode, you can attach your own user id after sign-in, so you can find a user's visits:

JavaScript
hubfly("identify", "user_42");

Use an opaque id

The id is stored as given, up to 128 characters. Use an internal id, never an email address or another direct identifier you are not allowed to process. In the default cookieless mode, identify is ignored.
JavaScript
// Persistent mode with "Wait for consent": stays cookieless until granted.
hubfly("consent", true);   // the visitor agreed
hubfly("consent", false);  // withdrawn: the stored id is deleted

// Any mode: stop or resume collection in this browser.
hubfly("opt_out");
hubfly("opt_in");

The opt-out choice is kept in the browser's local storage for that site.

Command reference

CallWhat it does
hubfly('track', name, {props, revenue})Records a custom event. Billable.
hubfly('pageview', {url, props})Records a pageview for the given URL, or the current one. Billable.
hubfly('404')Records a 404 event for the current page. Billable.
hubfly('identify', userId)Attaches a user id. Persistent mode only.
hubfly('consent', true | false)Grants or withdraws consent for a persistent id.
hubfly('opt_out'), hubfly('opt_in')Stops or resumes all collection in this browser.

To send events from your backend instead, use the server-side events API.

Something unclear or out of date? Emailsupport@hubfly.spaceBack to top