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, unlessevent.preventDefault()
was called.Form submissions – Triggered when a form with a valid
action
is submitted, unlessevent.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:
Open your Web Analytics report for your project.
Scroll to the Tracked events section and click New event.
Choose Pageview as the type and enter the exact page path you want to track.
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:
Open your Web Analytics report for your project.
Scroll to the Tracked events section and click New event.
Choose Custom event as the type and enter the exact event name you used in your HTML.
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');
}