Google Ads Scripts – Cost Alert
RO: Cum funcționează?
Dacă costul pe conversie depășește o limită stabilită de tine, vei primi un mail atunci când rulează scriptul, arătând costul mediu pe conversie pentru ultimele 30 de zile și media pentru acea zi.
ENG: How it works?
If the cost per conversion exceeds a limit you set, you will receive an mail when the script runs, showing the average cost per conversion over the last 30 days and the average for that day.
var emailAddress = “contact@encorem.ro”; // Replace with your email address
var campaignThreshold = 10; // Set your desired threshold for campaigns in your currency
var keywordThreshold = 10; // Set your desired threshold for search terms in your currency
javascript
function main() {
var emailAddress = "contact@encorem.ro"; // Replace with your email address
var campaignThreshold = 10; // Set your desired threshold for campaigns in EURO
var keywordThreshold = 10; // Set your desired threshold for search terms in EURO
// Get the account
var account = AdsApp.currentAccount();
// Get all campaigns in the account
var campaignIterator = AdsApp.campaigns().get();
var tableRows = [];
while (campaignIterator.hasNext()) {
var campaign = campaignIterator.next();
// Calculate average conversion cost for the last 30 days for campaigns
var campaignStats = campaign.getStatsFor("LAST_30_DAYS");
var campaignConversions = campaignStats.getConversions();
var campaignCost = campaignStats.getCost();
var campaignAvgConvCost = campaignCost / campaignConversions;
// Check if the average conversion cost for the campaign exceeds the campaign threshold
if (campaignAvgConvCost > campaignThreshold) {
var highCostSearchTerms = getHighCostSearchTerms(campaign, keywordThreshold);
for (var i = 0; i < highCostSearchTerms.length; i++) {
var rowData = [
campaign.getName(),
campaignAvgConvCost.toFixed(2) + " EURO",
highCostSearchTerms[i].term,
highCostSearchTerms[i].avgConvCost
];
tableRows.push(rowData);
}
}
}
// Create an HTML table with dynamic introductory text
var introText = "List of campaigns + search terms containing high costs. Campaign threshold set at: " + campaignThreshold + " EURO, Search term threshold set at: " + keywordThreshold + " EURO";
var tableHtml = "" + introText + "
Campaign Name Average Cost Conv. - 30 Days Search Terms Average Cost Conv. - Today ";
for (var i = 0; i < tableRows.length; i++) {
tableHtml += "";
tableHtml += "" + tableRows[i][0] + " ";
tableHtml += "" + tableRows[i][1] + " ";
tableHtml += "" + tableRows[i][2] + " ";
tableHtml += "" + tableRows[i][3] + " ";
tableHtml += " ";
}
tableHtml += "
";
// Send email alert with the HTML table
var subject = "Google Ads Alert - High Conversion Cost";
sendEmail(emailAddress, subject, tableHtml);
}
function getHighCostSearchTerms(campaign, threshold) {
var highCostTerms = [];
var queryIterator = campaign.keywords()
.withCondition("Conversions > 0")
.forDateRange("TODAY")
.get();
while (queryIterator.hasNext()) {
var keyword = queryIterator.next();
var keywordStats = keyword.getStatsFor("TODAY");
var keywordConversions = keywordStats.getConversions();
var keywordCost = keywordStats.getCost();
var keywordAvgConvCost = keywordCost / keywordConversions;
// Check if the average conversion cost for the keyword exceeds the keyword threshold
if (keywordAvgConvCost > threshold) {
highCostTerms.push({
term: keyword.getText(),
avgConvCost: keywordAvgConvCost.toFixed(2) + " EURO"
});
}
}
return highCostTerms;
}
function sendEmail(recipient, subject, message) {
MailApp.sendEmail({
to: recipient,
subject: subject,
htmlBody: message
});
}
Cum să Implementezi Scriptul
- Navighează la interfața Google Ads.
- Mergi la “Instrumente și Setări” (pictograma cheii) în colțul din dreapta sus.
- Sub “Acțiuni în masă”, selectează “Scripturi”.
- Click pe butonul albastru plus pentru a crea un nou script.
- Copiază și lipeste scriptul furnizat în editor.
- Autorizează scriptul să acceseze contul tău Google Ads urmând instrucțiunile.
- Salvează și previzualizează scriptul pentru a te asigura că rulează corect.
Articole recente
- Google March 2025 Core Update: Ce Se Întâmplă cu Algoritmul și Cum Te Poate Afecta March 21, 2025
- GHID AVANSAT SEO: AI, SOCIAL MEDIA ȘI VIITORUL OPTIMIZĂRII February 15, 2025
- Actualizari Google Ads pentru Lead Generation in 2025 February 15, 2025
- Cum să revitalizezi un brand în 2025: Studiu de caz Duolingo February 13, 2025
- Studiu de Caz: Reclama Pepsi cu Kendall Jenner February 13, 2025