Capturing events
Send custom events for the actions that matter to your business, with properties you can filter and break down by.
The web snippet records pageviews, page leaves and interactions on its own. Custom events add the moments only your code knows about: a signup completed, a plan upgraded, a report exported. They are what most funnels, retention charts and dashboards are built on.
Capture an event
myjourney.capture("signup_completed", {
signup_method: "google",
plan: "starter",
});- The first argument is the event's name.
- The second is an object of properties that describe this occurrence.
- The event is tied to whoever the library thinks the visitor is right now, anonymous or identified.
Calls made before the library has finished loading are queued, so you can capture straight away.
Choose good names
Event names are how your team finds data later, so agree on a style before you start.
- Use an object and a verb in the past tense:
report_exported,invoice_paid,teammate_invited. - Keep one case style, such as lower case with underscores.
- Name the action, not the screen element:
plan_upgradedstays meaningful when the button changes. - Do not put changing values in the name.
checkout_step_3should becheckout_step_completedwith astep: 3property. - Names starting with
$are used by the library itself, such as$pageviewand$autocapture. Do not start your own names with$.
Add useful properties
Properties are what you filter and break down by, so add the ones you will want to ask questions about.
myjourney.capture("report_exported", {
format: "csv", // text
rows: 1200, // number
scheduled: false, // true or false
report_id: "rep_8812",
});- Send numbers as numbers and true or false as booleans, so you can use "greater than" filters and sums.
- Prefer a few consistent properties over many one-off ones.
- Leave out anything personal you do not need.
Every event also carries properties the library adds for you, such as the page address ($current_url), browser, operating system, device type and referrer.
To attach a property to every event from this browser, register it as a super property instead of adding it to each call.
Update the person at the same time
A capture call can also set person properties:
myjourney.capture(
"plan_upgraded",
{ from_plan: "starter", to_plan: "growth" },
{ $set: { plan: "growth" }, $set_once: { first_paid_plan: "growth" } },
);Check that it arrived
- Trigger the event on your site.
- In the app, open Activity and the Live tab, and look for your event's name.
- Open the event to see its properties.
Once an event has arrived, it is listed under Data → Event definitions, where you can describe it for your team; see Data management.
If an event never arrives, check Event ingestion warnings.
Capture from your server
Events that happen on your server, such as a payment confirmed by your payment provider, can be sent over HTTPS to your region's capture address. The request format is shown in Server-side Google Tag Manager, and the full reference is in the API docs.
To have server events count toward the same visitor as the browser, send the same distinct ID the browser uses; myjourney.get_distinct_id() returns it.
Related
- Autocapture
- Events
- Actions: group events, including autocaptured clicks, under one name.
Can't find what you need? Contact support