Skip to content
DocsGoals and custom events

Goals and custom events

A goal counts something you care about: a visit to a page, or a custom event your site sends, such as a signup. Each site can have up to 50 goals.

Send a custom event

Once the script has loaded, call window.mayfly with an event name and, if you like, a few properties:

Custom events
window.mayfly?.('signup', { plan: 'pro' });
window.mayfly?.('purchase', { plan: 'pro' }, { revenue: 4900, currency: 'USD' });

The optional chaining (?.) means nothing breaks if a blocker stopped the script. If your code can run before the deferred script has loaded, put this queue first instead; the script replays queued events when it arrives:

Queue events before the script loads
window.mayfly = window.mayfly || function () {
  (window.mayfly.q = window.mayfly.q || []).push(arguments);
};
window.mayfly("signup");
  • Event names can be up to 120 characters. Use the exact same name in the goal.
  • Property values can be text, numbers or true and false, with keys up to 64 characters.
  • Outbound link clicks and file downloads are recorded on their own; you don’t need events for them.

Create a goal

Open Goals for the site and choose what counts:

  • A page visit: an exact path, such as /thank-you, or a path ending in * or /** to match everything that starts with it, such as /blog/**. Paths start with / and have no domain, query or fragment.
  • A custom event: the exact event name your code sends.

Owners and admins can create, edit and delete goals. A goal applies to events already collected, so it shows results for the past as well as from now on.

Reading the results

  • Conversions on the Goals page count daily unique conversions: a visitor counts once per day, so a returning person can count again on another day.
  • Conversion rate is unique conversions divided by daily uniques in the same period.
  • Revenue is the total sent with matching events. See Revenue attribution.

Goal results can be downloaded as CSV or read through the API.

Funnels

A funnel is 2 to 6 steps, each matched the same way as a goal: a page path pattern or a custom event name. Each website holds up to 10 funnels, and owners and admins manage them in the Funnels section of Goals.

  • Order within one visit. A visit reaches step 2 only if it matched step 1 first, earlier in the same visit, and so on. One event never satisfies two steps, even when two patterns would both match it.
  • The selected range only. Events outside the date range do not count, so a visit that starts before the range contributes only the part inside it.
  • Revenue per step is all revenue recorded by the visits that reached that step, wherever in the visit it happened. It is not revenue earned by the step.

Funnels need the ClickHouse analytics backend; on the Postgres beta the definitions save but no results are computed.

Something here doesn’t match what you see? Write to kirylapps@gmail.com.