// Import the AdSense API Client Library and initialize it
const {google} = require('googleapis');
const adsense = google.adsense('v1.4');
// Define the AdSense account ID and ad client ID
const accountId = 'INSERT_ACCOUNT_ID_HERE';
const adClientId = 'INSERT_AD_CLIENT_ID_HERE';
// Set up the AdSense Management API request to retrieve invalid click information
adsense.accounts.reports.generate({
accountId: accountId,
startDate: '30daysAgo',
endDate: 'today',
metrics: 'CLICKS,INVALID_CLICKS',
dimensions: 'DATE',
filters: 'AD_CLIENT_ID==' + adClientId
}, (err, response) => {
if (err) {
console.log('The API returned an error: ' + err);
return;
}
const rows = response.data.rows;
if (rows) {
console.log('Date, Clicks, Invalid Clicks:');
rows.forEach((row) => {
console.log(`${row[0]}, ${row[1]}, ${row[2]}`);
});
} else {
console.log('No data found.');
}
});
// Set up the AdSense Management API request to retrieve invalid traffic information
adsense.accounts.adclients.get({
accountId: accountId,
adClientId: adClientId
}, (err, response) => {
if (err) {
console.log('The API returned an error: ' + err);
return;
}
const adClient = response.data;
console.log(`Invalid traffic percentage: ${adClient.invalidTrafficAdsPercentage}`);
});
0 تعليقات:
إرسال تعليق
الاشتراك في تعليقات الرسالة [Atom]
<< الصفحة الرئيسية