Skip to main content

Tracked events in Ahrefs Web Analytics

Learn how to track specific user actions on your site with pageviews and custom events.

Andrey Kirillov avatar
Written by Andrey Kirillov
Updated over 2 weeks ago

Tracked events let you measure specific actions visitors take on your website, such as clicking a button, submitting a form, or any other interaction you care about.

What's tracked automatically

Ahrefs Web Analytics tracks the following events automatically:

  • Outbound link clicks – Triggered when a user clicks a link with a valid href that leads outside the project's scope, unless event.preventDefault() was called.

  • Form submissions – Triggered when a form with a valid action is submitted, unless event.preventDefault() was called.

These events don't require any setup and will appear in your report by default. You can also add your own tracked events to measure other specific actions that matter to your site.

Types of tracked events

You can track two types of events:

  • Pageview events – Triggered when someone visits a specific page, such as a thank-you or checkout page.

  • Custom events – Triggered when someone interacts with an element on your site, like clicking a button, submitting a form, or opening a modal.

Pageview events

Pageview events are useful for tracking visits to key pages, like confirmation or success pages. If your site has dedicated URLs for completed actions, like /thank-you or /checkout/success, you can set those as tracked events.

To set up a pageview event:

  1. Open your Web Analytics report for your project.

  2. Scroll to the Tracked events section and click New event.

  3. Choose Pageview as the type and enter the exact page path you want to track.

  4. Name the event to make it easier to recognize and click Create.

Custom events

Custom events are useful for tracking interactions like button clicks, form submissions, or other actions that don't load a new page. You can configure them by adding special class names to your HTML.

The simplest way to set them up is by adding a class in the format AhrefsAnalytics-event-EventName to your HTML.

Example:

<a class="AhrefsAnalytics-event-signup" href="#">Sign up</a>

This will track an event called signup when the link is clicked.

The same works for forms:

<form class="AhrefsAnalytics-event-signup" action="/submit">
...
</form>

This will trigger a custom event called signup when the form is submitted.

To start seeing the custom event in your report, you also need to add it there:

  1. Open your Web Analytics report for your project.

  2. Scroll to the Tracked events section and click New event.

  3. Choose Custom event as the type and enter the exact event name you used in your HTML.

  4. Name the event to make it easier to recognize and click Create.

Triggering custom events via JavaScript

For more precise tracking, you can send custom events using JavaScript. This gives you more control over when the event is triggered

The snippet below illustrates how to do this:

if (window.AhrefsAnalytics != null) {
window.AhrefsAnalytics.sendEvent('signup');
}
Did this answer your question?