Custom events and goals
Web Analytics is coming soon
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
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.
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:
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.
| Setting | Event name | Prop |
|---|---|---|
| Outbound links | Outbound Link: Click | url: the link target |
| File downloads | File Download | url: the file URL, without its query string |
| Form submissions | Form: Submission | form: the form's id, name or action path |
| 404 pages | 404 | path: 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:
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:
hubfly("identify", "user_42");Use an opaque id
identify is ignored.Consent and opt-out
// 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
| Call | What 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.