Analytics

Track conversions and custom JS events with goals

Define what counts as a conversion, measure your completion rate per period, and fire custom events straight from your site's JavaScript.

AstrinaEditorial July 12, 2026 3 min read EN RU UK

Pageviews tell you that people showed up. Goals tell you whether they did the thing you actually care about. With conversion goals and custom events, you decide what counts as a conversion and watch the completion rate move over time.

What a conversion goal measures

A goal is a definition of success. Once you set one, Astrina tracks its completion rate per period, so you can compare periods rather than staring at a raw count.

The rate is simple:

Rate = converting visits ÷ total visits

Because it is a ratio of visits, the number stays meaningful whether your traffic is up or down. You are always looking at the share of visits that reached your goal, not just how many did.

Four ways to define a goal

You can describe what counts as a conversion in four different ways, depending on what "success" means for your site:

  • Destination URL — the visit reaches a page whose address contains your text. For example, a page that contains /thank-you.
  • Pages per visit — the visit views at least N pages.
  • Visit duration — the visit lasts at least N seconds.
  • Custom event — an event you fire yourself from JavaScript.

The first three need no code changes at all — they are built from data Astrina already reconstructs from a visit. The fourth is for everything that does not map neatly to a URL or a threshold.

Custom events, fired from your JavaScript

Some conversions do not have their own page. A purchase, a signup, an add-to-cart, or a button click can all happen without a navigation. For those, you fire a custom event yourself.

The tracker exposes window.AstrinaGoal. Call it with an event name and, optionally, a small JSON props object:

AstrinaGoal("signup", {plan:"pro"})

A few rules to keep in mind:

  • Event names use the characters [a-z0-9._-] and can be up to 80 characters long.
  • You may attach a small JSON props object, like {plan:"pro"}, alongside the name.
  • A custom-event goal matches a visit when that visit fired an event with the exact name you configured.

If your tracker loads asynchronously, you do not have to worry about timing. There is a preload queue at window._astrq, so events you queue before the async script finishes loading still fire once it is ready.

Events land in the same visit as page views

A custom event is not a separate, disconnected data point. Each event ties to the same pseudonymous visitor and lands in the same reconstructed visit as that visitor's page views.

That means a signup event and the pages the visitor looked at before it all belong to one visit — which is exactly what makes the conversion rate add up correctly.

How to get started

Setting up your first goal takes two steps:

  1. Open /my/goals.php and create a goal. Pick one of the four types: a destination URL, pages per visit, visit duration, or a custom event.
  2. If you chose a custom event, add the matching call in your site's JavaScript at the moment the conversion happens — for example on a purchase, signup, add-to-cart, or button click:
    AstrinaGoal("signup", {plan:"pro"})

Use the same event name in your code that you configured on the goals page, since matching is by exact name. From there, Astrina takes care of tying the event to the right visit and reporting your completion rate per period.

Decide what a conversion means for you, define it once, and let the rate tell you whether it is trending the right way.

Try it on your site

The core counter is free. Add your site and explore every feature.

← All articles

What this page answers

  • analytics
  • analytics guide
  • Track conversions and custom JS events with goals
  • Track conversions and custom JS events with goals guide
  • Track conversions and custom JS events with goals explained
  • Track conversions and custom JS events with goals tutorial
  • getting started with Track conversions and custom JS events with goals
  • Track conversions and custom JS events with goals best practices
  • Track conversions and custom JS events with goals step by step
  • what is Track conversions and custom JS events with goals
  • Track conversions and custom JS events with goals for beginners
  • Track conversions and custom JS events with goals checklist
  • Track conversions and custom JS events with goals examples
  • why Track conversions and custom JS events with goals matters