Forums Forums White Hat SEO PPC Need Help with Google Ads Script

  • PPC

    Need Help with Google Ads Script

    Posted by seohelper on March 5, 2020 at 2:09 pm

    Hey all,

    I have a campaign with several ad groups, one of which tends to use most of the budget on a daily basis. I’m trying to set up a script so that will pause the ad group when it exceeds a certain spend threshold, and then enables it the next day.

    Sadly, I’m not great with JavaScript. The script successfully paused the ad group, but never turned it back on. Could someone kindly point out what’s wrong with my script?

    function main() {
    //update the value of dailyBudget based on your requirement

    var dailyBudget = 30;
    var campaignNameContains = [“Smaller”];
    var ignorePausedCampaigns = ‘ENABLED’;
    var ignorePausedCampaigns = ‘ENABLED’;

    var adGroupIterator = AdWordsApp.adGroups()
    .withCondition(‘CampaignName CONTAINS ‘+campaignNameContains)
    .withCondition(‘CampaignStatus = ‘+ignorePausedCampaigns)

    .withCondition(‘CampaignStatus = ‘+ignorePausedCampaigns)

    .get();

    while (adGroupIterator.hasNext()) {
    var adGroup = adGroupIterator.next();

    Logger.log(“AdGroup Name : %s”, adGroup.getName());

    //use TODAY to get data for today
    var adGroupCost = adGroup.getStatsFor(‘TODAY’).getCost();
    Logger.log(“AdGroup Cost: %s”, adGroupCost);

    //if adGroupCost reached the defined dailyBudget, pause the current adgroup

    if (adGroupCost >= dailyBudget){
    adGroup.pause();
    }
    //if adGroupCost is less than the defined budget
    else if(adGroupCost < dailyBudget){
    adGroup.enable();
    }
    }
    }

    germandutchman1 replied 4 years ago 1 Member · 1 Reply
  • 1 Reply
  • germandutchman1

    Guest
    March 5, 2020 at 3:17 pm

    The scripts works fine for me, enabling and pausing adgroups according to the rules set – even though you’re repeating the variable “ignorePausedCampaigns” and condition twice, which is not necessary.

    Budget Control sits on the Campaign level for a reason – why not just split out this particular high budget adgroup into it’s own campaign?