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
hrefthat leads outside the project's scope, unlessevent.preventDefault()was called.Form submissions – Triggered when a form with a valid
actionis 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');
}
Event properties (optional)
Event properties let you attach extra details to a tracked event.
They’re useful when you want to break the same event down by variants, plans or other dimensions.
Examples:
A
signupevent with properties likeplan = standard,duration = monthlyA
cta_clickevent with properties likebutton = header,variant = BA
purchaseevent with properties likecategory = shoes,size = 42
You’ll see these properties later in the Event properties reports.
Note: Property names and values are treated as strings. When using attributes or class names below, property names can’t contain dashes (-), because dashes are used as delimiters.
How to attach event properties
There are three ways to attach properties to your events:
Add properties to every event via the tracking script.
Add properties to a single custom event via CSS classes.
Add properties via JavaScript (JS API).
1. Attach properties to every event (tracking script)
You can attach a property to all events by adding data-prop-NAME="VALUE" attributes to your tracking <script> tag:
<script
src="https://analytics.ahrefs.com/analytics.js"
data-key="YOUR_DATA_KEY"
data-prop-plan="standard"
data-prop-duration="monthly">
</script>
This will add plan = "standard" and duration = "monthly" to every event sent from this page.
Note: NAME cannot contain dashes (-).
2. Attach properties to a single custom event (CSS classes)
You can attach properties to a specific custom event by using special CSS class names on the element that triggers it.
Example – a button that triggers a signup event with a plan property:
<div
class="
AhrefsAnalytics-event-signup
AhrefsAnalytics-prop-plan-standard
">
Sign up for Standard
</div>
Here:
AhrefsAnalytics-event-signuptells the Ahrefs Web Analytics script to send asignupevent when this element is clicked.AhrefsAnalytics-prop-plan-standardadds a propertyplan = "standard"only to this event.
Note: Property names in AhrefsAnalytics-prop-… also cannot contain dashes (-).
3. Attach properties via JavaScript (JS API)
If you’re triggering events via JavaScript, you can attach properties by passing an object as the second argument to sendEvent:
if (window.AhrefsAnalytics != null) {
window.AhrefsAnalytics.sendEvent(
'signup',
{
props: {
plan: 'standard',
duration: 'monthly'
}
}
);
}
This is the most flexible option if you need to set properties based on your app’s state like logged-in user, A/B test variant, etc.
Using event properties in reports
Event properties don’t show up automatically. Once you start sending them, you need to add them to your reports.
Event properties report
Use this when you want a breakdown by property values.
Open your Web Analytics report for the project.
Go to the Event properties report.
Click New property.
Choose the event property, give it a name and click Create.
This lets you see visitors and events split by each property value, for example signups by plan, button variant, or country.
Filtering by event properties
You can also use event properties to segment other reports.
Click Add filter and select Event property.
Choose the property and value(s) you want to filter by.
This lets you narrow down any report to, for example, plan is standard or variant is B. You can add multiple property filters to refine the segment further.


