About this resource
Check the Domain Rating (DR) of websites directly in Google Sheets using Google Apps Script and the Ahrefs API. This script adds a custom spreadsheet function that retrieves available Domain Rating data, helping SEO professionals, link builders, digital marketers, and website owners evaluate domains more efficiently.
Use it to organize website metrics, research backlink opportunities, review publisher websites, and analyze competitor domains—all from your spreadsheet.
Key Features
-
Automated DR Checks: Retrieve a website's Ahrefs Domain Rating using a custom Google Sheets formula.
-
Bulk Spreadsheet Workflow: Apply the formula across multiple rows to check multiple domains.
-
Simple Custom Function: Use
=AHREFS_DR(A2)to check the domain entered in cell A2. -
API Error Handling: Identify unsuccessful API requests and missing DR data.
-
Easy Setup: Run the script directly inside Google Sheets using Google Apps Script.
-
SEO Research: Support backlink prospecting, website evaluation, publisher analysis, and competitor research.
Requirements
Before installing the script, ensure you have:
-
A Google account with access to Google Sheets.
-
An Ahrefs API key authorized to access the endpoint used by the script.
-
Basic familiarity with Google Sheets and the Apps Script editor.
-
Internet access for API requests.
Important: Ahrefs API availability, permissions, usage limits, and charges depend on your account and applicable plan. Verify access to the required endpoint before using the script.
Installation Guide
Step 1: Open Google Apps Script
Open your Google Sheet and select Extensions → Apps Script from the menu.
Step 2: Add the Script
Paste the supplied Ahrefs DR Checker code into the Apps Script editor. If your project is dedicated to this checker, you can replace the default code. Otherwise, add the function to your existing project, ensuring there are no conflicting function or constant names.
Step 3: Configure Your API Key
Locate this line in the script:
const;
Replace the placeholder with your own authorized Ahrefs API key. Do not publish the key or share it with unauthorized users.
Step 4: Save the Project
Click Save and give the project a name, such as Ahrefs DR Checker.
Step 5: Enter Your Domains
Return to Google Sheets and enter the website domains in column A.
| A — Domain | B — Domain Rating |
|---|---|
| example.com | =AHREFS_DR(A2) |
| example.org | =AHREFS_DR(A3) |
| example.net | =AHREFS_DR(A4) |
These are illustrative examples. The returned values depend on the data available from the Ahrefs API.
Step 6: Run the Formula
Enter the following formula in cell B2:
=AHREFS_DR(A2)
The function requests Domain Rating data for the domain in cell A2. If the API responds successfully with the expected data structure, the function returns the DR value.
Fill the formula down column B to process additional domains. Each formula may trigger an API request, so large spreadsheets can encounter API usage limits or Google Apps Script execution constraints.
How to Use the DR Checker
Once configured, use:
=AHREFS_DR(A2)
Here, A2 contains the domain you want to check. The supplied script accepts domains with or without an HTTP or HTTPS prefix.
Example workflow:
-
Enter
example.comin cell A2. -
Enter
=AHREFS_DR(A2)in cell B2. -
Wait for the API response.
-
Review the returned Domain Rating or any error message.
-
Repeat for additional domains by filling the formula down.
Troubleshooting
API ERROR 401 — Unauthorized
The API key may be invalid, missing, or unauthorized. Verify the key and confirm that it is configured correctly in Apps Script.
API ERROR 403 — Forbidden
Your account or API key may not have permission to access the endpoint. Review the relevant API access requirements for your Ahrefs account.
API ERROR 429 — Rate Limit or Usage Limit
The request may have exceeded an applicable limit. Review your API usage and reduce the frequency of requests where necessary.
NO DR DATA
The API response did not contain the expected domain_rating.domain_rating field. The domain may not have available data, or the response structure may differ from what the script expects.
Other Errors
Check the API key, endpoint access, script configuration, and error message. The function returns an HTTP status error for unsuccessful responses and an exception message when a request or parsing operation fails.
Security and Usage Best Practices
-
Protect your API key: Never publish real credentials in a public repository or publicly shared script.
-
Verify API permissions: Confirm that your account can access the endpoint used in the script.
-
Monitor usage: Check applicable API limits and charges before processing large lists.
-
Test first: Start with a few domains before running the checker across a large spreadsheet.
-
Avoid excessive requests: Large numbers of simultaneous formulas can cause slowdowns, rate limits, or execution failures.
For thousands of domains, consider a batch-processing implementation with caching and controlled request intervals rather than making an individual request for every cell.
Who Should Use This Script?
This resource is useful for:
-
SEO Professionals: Review Domain Rating while evaluating websites.
-
Link Builders: Research publisher sites and backlink opportunities.
-
SEO Agencies: Organize and assess domain metrics for client campaigns.
-
Digital Marketers: Analyze competitor websites and potential publishing partners.
-
Website Owners: Maintain domain research and SEO metrics in Google Sheets.
Final Thoughts
The Ahrefs DR Checker for Google Sheets provides a convenient way to retrieve available Domain Rating data within an existing spreadsheet workflow. Configure your authorized API key, enter your domains, and use the custom function to support your SEO research.
Disclaimer: This is an independent community resource. It is not affiliated with, endorsed by, or an official product of Ahrefs. Domain Rating is an Ahrefs metric, and the results depend on data available through the authorized API.
How to use it
- Review the requirements and confirm the resource fits your use case.
- Download or copy the resource using the button on this page.
- Configure your own credentials and settings; never paste secrets into public code.
- Test with sample data before using it in a production environment.
Review code and permissions before running. Third-party services may have usage limits or costs.