Website Traffic Checker Tool
........
async function checkTraffic() {
const websiteUrl = document.getElementById('websiteUrl').value.trim();
const resultDiv = document.getElementById('result');
const errorDiv = document.getElementById('error');
// Clear previous results
resultDiv.innerHTML = '';
errorDiv.innerHTML = '';
if (!websiteUrl) {
errorDiv.innerHTML = 'Please enter a valid website URL.';
return;
}
// Free API example (replace with your own API key)
const apiUrl = `https://website-traffic.p.rapidapi.com/rank/${websiteUrl}`;
const options = {
method: 'GET',
headers: {
'X-RapidAPI-Key': 'YOUR_RAPIDAPI_KEY', // Replace with your RapidAPI key
'X-RapidAPI-Host': 'website-traffic.p.rapidapi.com'
}
};
try {
const response = await fetch(apiUrl, options);
const data = await response.json();
if (data.rank) {
resultDiv.innerHTML = `
Website: ${websiteUrl}
Global Rank: ${data.rank}
Monthly Visits: ${data.monthlyVisits}
`;
} else {
errorDiv.innerHTML = 'No traffic data found for this website.';
}
} catch (error) {
errorDiv.innerHTML = 'Failed to fetch traffic data. Please try again.';
}
}
No comments:
Post a Comment