---
title: Ahrefs Analytics
description: Cookieless web analytics from Ahrefs with a prebuilt helper that wires the project key into a c15t-managed script.
lastModified: 2026-05-10
icon: ahrefs
---
Ahrefs Web Analytics is a cookieless analytics product configured with a single project key. The `ahrefsAnalytics()` helper wires that key into the `data-key` attribute that Ahrefs' loader reads at startup.

## Integrate with c15t

**React**

```tsx
import { type ReactNode } from 'react';
import { ConsentManagerProvider } from '@c15t/react';
import { ahrefsAnalytics } from '@c15t/scripts/ahrefs-analytics';

const scripts = [
  ahrefsAnalytics({
    key: 'your-ahrefs-project-key',
  }),
];

export function ConsentProvider({ children }: { children: ReactNode }) {
  return (
    <ConsentManagerProvider
      options={{
        mode: 'hosted',
        backendURL: 'https://your-instance.c15t.dev',
        scripts,
      }}
    >
      {children}
    </ConsentManagerProvider>
  );
}
```

**Next.js**

```tsx
'use client';

import { type ReactNode } from 'react';
import { ConsentManagerProvider } from '@c15t/nextjs';
import { ahrefsAnalytics } from '@c15t/scripts/ahrefs-analytics';

const scripts = [
  ahrefsAnalytics({
    key: 'your-ahrefs-project-key',
  }),
];

export function ConsentProvider({ children }: { children: ReactNode }) {
  return (
    <ConsentManagerProvider
      options={{
        mode: 'hosted',
        backendURL: '/api/c15t',
        scripts,
      }}
    >
      {children}
    </ConsentManagerProvider>
  );
}
```

**JavaScript**

```ts
import { getOrCreateConsentRuntime } from 'c15t';
import { ahrefsAnalytics } from '@c15t/scripts/ahrefs-analytics';

getOrCreateConsentRuntime({
  mode: 'hosted',
  backendURL: 'https://your-instance.c15t.dev',
  scripts: [
    ahrefsAnalytics({
      key: 'your-ahrefs-project-key',
    }),
  ],
});
```

## How c15t loads it

* **Category:** `measurement` (Analytics)
* **Loads when:** measurement consent is granted
* **On revocation:** unloaded — c15t removes the script element from the DOM. Ahrefs Web Analytics is cookieless, so no client-side state needs clearing.

To run from a custom loader URL (for example a self-hosted proxy):

```ts
ahrefsAnalytics({
  key: 'your-ahrefs-project-key',
  scriptUrl: 'https://analytics.example.com/analytics.js',
})
```

Once loaded, Ahrefs exposes its runtime API on `window.AhrefsAnalytics`. The c15t helper only models the serializable script configuration — calls to `window.AhrefsAnalytics.sendEvent(...)` happen in your application code as needed.

## Tracking events in your app

c15t gates the Ahrefs Analytics script from loading until `measurement` consent is granted. Your application code that calls Ahrefs' runtime API (`window.AhrefsAnalytics.sendEvent`) is **not** automatically gated — `window.AhrefsAnalytics` does not exist until the script is loaded, so unguarded calls before consent throw.

Guard event calls by checking consent state. From React:

```tsx
import { useCallback } from 'react';
import { useConsentManager } from '@c15t/react';

function SignupExample() {
  const { has } = useConsentManager();

  const trackSignup = useCallback(() => {
    if (has('measurement')) {
      window.AhrefsAnalytics?.sendEvent('signup');
    }
  }, [has]);

  // Call trackSignup() from an event handler after signup succeeds.
}
```

From plain JavaScript:

```ts
import { getOrCreateConsentRuntime } from 'c15t';

const { consentStore } = getOrCreateConsentRuntime();

if (consentStore.getState().has('measurement')) {
  window.AhrefsAnalytics?.sendEvent('signup');
}
```

## Types

### AhrefsAnalyticsOptions

| Property    | Value                                                            |
| :---------- | :--------------------------------------------------------------- |
| Type Name   | \`AhrefsAnalyticsOptions\`                                       |
| Source Path | \`./packages/scripts/src/vendors/analytics/ahrefs-analytics.ts\` |

\*AutoTypeTable: Could not extract \`AhrefsAnalyticsOptions\` from \`./packages/scripts/src/vendors/analytics/ahrefs-analytics.ts\`. Verify the path/name and that the file is included by your tsconfig.\*

### Script

| Property    | Value                                               |
| :---------- | :-------------------------------------------------- |
| Type Name   | \`Script\`                                          |
| Source Path | \`./packages/core/src/libs/script-loader/types.ts\` |

\*AutoTypeTable: Could not extract \`Script\` from \`./packages/core/src/libs/script-loader/types.ts\`. Verify the path/name and that the file is included by your tsconfig.\*
