Introduction
Tracked events let you measure specific actions visitors take on your website.
You can track two types of events:
Pageview events – Triggered when someone visits a specific page (e.g. a thank-you or checkout page).
Custom events – Triggered when someone interacts with an element on your site (e.g. clicks a button or submits a form).
What’s tracked automatically
Ahrefs Analytics tracks the following events automatically:
Pageviews – Triggered on page load and during client-side navigation (according to browser’s history API)
Link clicks – Triggered when a user clicks a link with a valid
href
, unlessevent.preventDefault()
was called.Form submissions – Triggered when a form with a valid action is submitted,
unless event.preventDefault()
was called.
These built-in events appear in your dashboard automatically. You can also add your own tracked events manually to measure specific actions that matter to your site.
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.
Click “New event” and enter the exact page path you want to track.
Name the event to make it easier to recognize in reports and click “Create”.
Once a visitor loads that page, the event will show up in your dashboard.
Custom events
Custom events are useful for tracking interactions like button clicks or form submissions 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.
Triggering custom events via JavaScript
In addition to configuring events via HTML, you can also send custom events programmatically using JavaScript.
This is useful for tracking actions that don’t involve links or forms — such as button clicks, modal views, or API responses.
Trigger a custom event:
if (window.AhrefsAnalytics != null) {
window.AhrefsAnalytics.sendEvent('signup');
}
Note: Events triggered before the tracker script loads will be ignored. Make sure to call sendEvent
after the page has fully loaded or the script is confirmed to be available.