How to Get a Website's Global Rank in PHP
You need a reliable way to fetch a website’s global rank in PHP so you can gate risky inventory, enrich signups, or audit where your ads run. By the end of this guide, you’ll call Klazify’s domain traffic intelligence endpoint, parse global_rank (plus country and category ranks), and plug those fields into your workflow with caching, batching, and fallback logic.
Why Klazify is the right API for website ranking and classification
When you’re deciding whether to trust, block, or prioritize a domain, you need two things: current traffic signals and accurate content classification. Klazify combines both via simple endpoints you can call from PHP (or any backend) and ship to production quickly.
- Accurate website categorization using AI: Klazify analyzes full page content, so when you retrieve a site’s traffic rank you can also map the site to IAB categories for brand safety and policy controls.
- Global coverage: Global_rank and top_countries fields help you rank and route domains from anywhere, while categorization works across multiple languages and regions.
- Real-time classification: Instead of stale lookups, Klazify’s classification and traffic insights reflect current site content and signals.
- Industry-level categories: IAB taxonomy makes it straightforward to segment news, finance, sports, or other categories for ad targeting and filtering.
- Simple API integration: Developer-friendly REST endpoints with Bearer auth let you POST a URL and immediately receive traffic ranks and engagement breakdowns.
- Compliance and filtering: Rely on category_rank and IAB mapping to block, allow, or throttle delivery pipelines based on policy.
If you’re building a scoring pipeline, moderation layer, or ad placement engine, Klazify’s combination of traffic rank and classification removes guesswork and reduces manual curation. Explore the platform at klazify.com and create a free account to start integrating within minutes.
What you will build: Get a site’s global rank in PHP and act on it
We’ll use Klazify’s traffic intelligence endpoint to fetch:
- global_rank: Position relative to all sites globally.
- country_rank: Best rank in a specific country.
- category_rank: Position within the site’s primary category.
- monthly_visits: Estimated total monthly visits to the site.
- engagement: Signals like average visit duration, pages per visit, and bounce rate.
- traffic_sources: Breakdown of sources such as search, direct, social, and referrals.
- top_countries: Countries contributing the most traffic with share percentages.
Then we’ll layer category data from the categorization endpoint to reinforce brand safety and routing. You’ll end with a practical pattern: fetch ranks and categories, cache per domain, and plug the values into your risk and enrichment logic.
Endpoint and authentication
Traffic intelligence endpoint:
- Method: POST
- URL: https://www.klazify.com/api/domain_traffic_intelligence
- Auth: Bearer token in the Authorization header
- Body: JSON with a url field
Website categorization endpoint (for IAB mapping and related data):
- Method: POST
- URL: https://www.klazify.com/api/categorize
- Auth: Bearer token in the Authorization header
- Body: JSON with a url field
Note: Failed or unreachable calls are not billed. Starter is $39.99/mo with a 7-day trial. Refer to the Documentation for additional request/response details.
cURL: Fetch traffic intelligence for a domain
Use this exact request structure to retrieve global_rank and related fields for a URL:
curl -X POST "https://www.klazify.com/api/domain_traffic_intelligence" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"url":"https://cbsnews.com"}'
Replace YOUR_API_KEY with your actual secret key. The response includes global_rank, country_rank, category_rank, monthly_visits, engagement, traffic_sources, and top_countries.
PHP: Get a website’s global rank and enforce rules
The snippet below posts a URL, parses traffic fields, and demonstrates a basic allow/block rule based on rank thresholds. Adjust thresholds to your policy.
<?php
$apiKey = "YOUR_API_KEY";
$endpoint = "https://www.klazify.com/api/domain_traffic_intelligence";
$payload = json_encode([
"url" => "https://example.com"
]);
$ch = curl_init($endpoint);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
"Authorization: Bearer " . $apiKey,
"Content-Type: application/json"
]);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 20);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$err = curl_error($ch);
curl_close($ch);
if ($err) {
// Not billed for unreachable calls; consider a retry or fallback cache
error_log("Klazify request error: " . $err);
exit(1);
}
if ($httpCode < 200 || $httpCode >= 300) {
error_log("Klazify HTTP error: " . $httpCode . " - " . $response);
exit(1);
}
$data = json_decode($response, true);
// Example parsing (keys depend on response shape documented for traffic intelligence)
$globalRank = $data["global_rank"] ?? null;
$countryRank = $data["country_rank"] ?? null;
$categoryRank = $data["category_rank"] ?? null;
$monthlyVisits = $data["monthly_visits"] ?? null;
$engagement = $data["engagement"] ?? null; // e.g., ["avg_visit_duration", "pages_per_visit", "bounce_rate"]
$trafficSources = $data["traffic_sources"] ?? null; // e.g., ["search", "direct", "social", "referrals"]
$topCountries = $data["top_countries"] ?? null; // e.g., [{"country_code": "US", "share": 0.45}, ...]
if ($globalRank === null) {
// Handle unknown/new domains: queue for review or fallback to categorization-only logic
echo "No global rank available for this domain\n";
exit(0);
}
// Simple gating example
if ($globalRank > 1000000) {
echo "Block: low-traffic/risky domain (global_rank = $globalRank)\n";
} else {
echo "Allow: global_rank = $globalRank\n";
}
// Optional: log additional signals
if (is_array($topCountries)) {
foreach ($topCountries as $tc) {
// Example: route by country share thresholds
}
}
// Cache the full response per domain with a TTL you choose
?>
Recommendations:
- Cache by domain (e.g., example.com) for a sensible TTL to reduce latency and cost.
- Normalize input URLs (lowercase, remove fragments, resolve redirects where possible).
- If global_rank is absent for a new or low-visibility site, rely on categorization-based rules and queue a recrawl later.
Python example: Enrich a signup with rank and top countries
This sample shows how to call the same endpoint and read key fields for analytics or CRM enrichment.
import os
import json
import requests
API_KEY = os.getenv("KLAZIFY_API_KEY", "YOUR_API_KEY")
URL = "https://www.klazify.com/api/domain_traffic_intelligence"
payload = {"url": "https://example.com"}
headers = {
"Authorization": f"Bearer {API_KEY}",
"Content-Type": "application/json",
}
resp = requests.post(URL, headers=headers, json=payload, timeout=20)
resp.raise_for_status()
data = resp.json()
global_rank = data.get("global_rank")
country_rank = data.get("country_rank")
category_rank = data.get("category_rank")
monthly_visits = data.get("monthly_visits")
engagement = data.get("engagement", {})
sources = data.get("traffic_sources", {})
top_countries = data.get("top_countries", [])
print("global_rank:", global_rank)
print("country_rank:", country_rank)
print("category_rank:", category_rank)
print("monthly_visits:", monthly_visits)
print("engagement:", engagement)
print("traffic_sources:", sources)
print("top_countries:", top_countries)
# Example action: tag high-priority leads if their domain ranks in top 250k
if global_rank is not None and global_rank <= 250000:
priority = "high"
else:
priority = "standard"
print("lead_priority:", priority)
Understand and use the domain categorization response
Ranking is more powerful when paired with categories. Below is the official categorization response example. Use it to map domains to IAB categories, extract a logo for UI, and retrieve company attributes to enrich accounts.
{
"domain": {
"categories": [
{
"confidence": 0.92,
"name": "/Computers & Electronics/Consumer Electronics",
"IAB-632-596": "Consumer Electronics/Technology & Computing/Consumer Electronics"
},
{
"confidence": 0.89,
"name": "/Internet & Telecom/Mobile & Wireless/Mobile Phones"
}
],
"social_media": null,
"logo_url": "https://klazify.s3.amazonaws.com/2110787991611585019600ed5fb1d1300.04730104.png"
},
"success": true,
"objects": {
"company": {
"url": "https://www.apple.com/",
"name": "Apple",
"city": "Cupertino",
"stateCode": "CA",
"countryCode": "US",
"employeesRange": "100K+",
"revenue": 274515000000,
"raised": null,
"tags": [
"E-commerce",
"Consumer Electronics",
"Mobile",
"B2C"
],
"tech": [
"omniture_adobe_analytics",
"atlassian_confluence",
"successfactors",
"apache_apex",
"talend",
"oracle_peoplesoft",
"salesforce",
"stripe",
"dell_boomi_atomsphere",
"gigya",
"sage_50cloud",
"quickbooks",
"webmethods",
"apache_tomcat",
"alteryx",
"tibco_rendezvous",
"atlassian_jira",
"..."
]
}
},
"domain_registration_data": {
"domain_age_date": "1987-02-19",
"domain_age_days_ago": "13026",
"domain_expiration_date": "2030-02-20",
"domain_expiration_days_left": "123"
},
"similar_domains": [
"bestbuy.com",
"icloud.com",
"microsoft.com",
"macrumors.com",
"google.com",
"samsung.com",
"twitter.com",
"hp.com",
"bhphotovideo.com",
"dell.com"
]
}
How to use these fields:
- domain.categories: Use name for human-readable category paths and the IAB-632-596 field for standard IAB mapping. Combine with category_rank from traffic intelligence to decide allow/block for ad placements or feeds.
- domain.logo_url: Display a recognizable brand mark in admin tools or CRM profiles.
- objects.company.*: Enrich your CRM with company name, location, size, and tags for segmentation and scoring.
- domain_registration_data: Add trust heuristics around domain age or time-to-expiry in fraud and compliance checks.
- similar_domains: Build discovery workflows, competitor groups, or replacement suggestions when blocking a category.
To retrieve this categorization, POST to https://www.klazify.com/api/categorize with the same Bearer scheme and a JSON body containing the url. See the MCP page for category mapping usage patterns.
Field-by-field: put traffic intelligence to work
- global_rank: Set thresholds to block low-visibility sites or prioritize high-traffic domains for ad inventory and partnerships.
- country_rank: Localize decisions; e.g., allow a domain in regions where it’s ranked highly, even if its global rank is more modest.
- category_rank: Execute brand safety and targeting rules by ranking within an IAB category. Pair category_rank with domain.categories for precise control.
- monthly_visits: Route leads and domains to different review queues (e.g., manual review for very low estimated visits).
- engagement: If bounce_rate is high or avg_visit_duration is short, add friction or fraud checks to signups from that domain.
- traffic_sources: Tune acquisition strategies; e.g., if a site’s share is mainly search, it may be content-heavy; heavy direct traffic can indicate brand affinity.
- top_countries: Localize campaigns and compliance checks. If a site’s traffic skews to a specific region, match it with geo-specific policies.
Batching, caching, and error handling
- Batching: If you process many domains, queue them and fan out requests in parallel with backoff. Respect rate limits as documented; if you approach limits, add jittered retries.
- Caching: Cache responses per domain for a practical TTL (hours to days depending on your use case). Cache both traffic intelligence and categorization to reduce latency and cost.
- Unknown/new domains: Sometimes fields like global_rank may be unavailable. In that case, fall back to domain.categories or company data to make a conservative decision, and recheck later.
- Normalization: Always canonicalize domains (lowercase, strip protocol/path where needed) and deduplicate before calling the API.
- Timeouts and retries: Use a 10–20s timeout and retry idempotently when you see transient network errors. Failed or unreachable calls are not billed.
Map IAB categories to your internal taxonomy
If your system uses custom labels, maintain a mapping table from IAB categories (from domain.categories and IAB-632-596) to your internal categories. Example mappings:
| IAB path or code | Internal label | Action |
|---|---|---|
| Consumer Electronics/Technology & Computing/Consumer Electronics | Tech-Retail | Allow ads, standard CPM |
| /Internet & Telecom/Mobile & Wireless/Mobile Phones | Mobile-Tech | Allow, prioritize mobile campaigns |
| (Category with high category_rank value) | Low-Visibility | Review or block |
Keep this mapping versioned and test it against a labeled set of domains. You can use similar_domains to expand coverage during QA.
Shipping to production: pipeline tips
- Data stores: Cache raw JSON per domain to preserve all fields for future scoring changes without re-calling the API immediately.
- Schema: Persist core fields (global_rank, country_rank, category_rank, monthly_visits, engagement.*, traffic_sources.*, top_countries[]) alongside categorization and company fields.
- Observability: Log HTTP status, latency, and response completeness (e.g., presence of global_rank) to monitor data quality and adjust TTLs.
- Access control: Store the Bearer token securely and rotate it periodically.
Common workflows this unlocks
- Ad placement auditing: Pull global and category ranks, pair with IAB category, and block placements on long-tail or mismatched content.
- Signup enrichment: Add rank and top_countries to leads, prioritize accounts from top-ranked domains.
- Content filtering: Use categories and ranks to set thresholds for public WiFi, schools, or enterprise networks.
- Analytics: Build dashboards with monthly_visits, engagement, and traffic_sources to compare partner sites.
Next steps and where to learn more
Sign up for a free trial and start testing with your domains. You can explore more features on the homepage and in the API Documentation. Use the categorization endpoint to enrich contexts and the traffic intelligence endpoint for ranking and engagement signals.
FAQ
- What’s the difference between global_rank and country_rank? Global_rank positions the domain among all websites worldwide, while country_rank indicates its best position within a specific country. Use both for global vs. local decisions.
- How should I handle domains with no rank? Treat them as unknown: apply conservative rules based on categories and company data, cache the result, and retry classification/traffic later.
- Can I query many domains at once? Send requests in parallel with a queue/worker system. Batch your workload and add retry/backoff to respect rate limits noted in the docs.
- What should I cache and for how long? Cache the full JSON per domain. Choose TTLs that fit your use case—traffic ranks can change, so refresh periodically while keeping latency and cost low.
- How do I combine ranks with IAB categories? Fetch category data via the categorize endpoint, map to your internal taxonomy, then layer category_rank and global_rank to enforce allow/block/priority rules.
Ready to implement this in your pipeline? Create a free account and get your API key now: Register. For reference material and integration patterns, see the Documentation and explore mappings in the MCP.
Ready to use Klazify?
Start classifying websites, enriching company data, and exploring web intelligence.
Get Started Free