How to check my script whether active or not

27 views
Skip to first unread message

Mạnh Hùng Phùng

unread,
Jul 9, 2021, 4:17:25 AM7/9/21
to AdWords API and Google Ads API Forum
Hi ads
I created a script to control my budget based on location, 
But I do not know whether it is active or not ? And my money and location is in Viet Nam, should I change "$" to "VNĐ".
Please check my script below: 

//Google Ads script for modifying targeted location bid adjustments.
//Feel free to change the values before the main function.
//Bid modifiers are returned as follows:

// 0 = - 100%
// 1 = 0%
// 2 = + 100%


//Editable values;
var cpaTreshold = 60;
var costTreshold = 80;
var increaseBid = 0.10;
var decreaseBid = 0.05;

function main() {


  //Selects campaigns based on the given conditions;
  var campaigns = AdsApp.campaigns()
  .withCondition('Status = ENABLED')
  .withCondition('Name CONTAINS_IGNORE_CASE "Global"')
  .withCondition('Name DOES_NOT_CONTAIN_IGNORE_CASE "display"')
  .get();


  //Loops through the selected campaigns campaigns;
  while (campaigns.hasNext()) {
    var campaign = campaigns.next();

    Logger.log('Currently running campaign: ' + campaign.getName());


    //Selects the targeted location of a campaign;
    var locations = campaign.targeting().targetedLocations().get();


    //Loops through the selected targeted locations;
    while (locations.hasNext()) {

      var location = locations.next();


      //Gets the current bid adjustment of a selected location;
      var bidAdjustment = location.getBidModifier();


      //Gets the statistics for the selected location
      var cost = location.getStatsFor('LAST_30_DAYS').getCost();
      var conversions = location.getStatsFor('LAST_30_DAYS').getConversions();


      //Calculates the CPA of a selected location. Returns 0 if there were 0 conversions;
      if (conversions == 0) {
        var cpa = 0;
      } else {
        var cpa = (cost / conversions).toFixed(2);
      }

      //Returns a nice log message :)
      Logger.log(location.getName() + ': Cost = Đ' + cost + ', Conversions = ' + conversions + ', with a CPA of Đ' + cpa);


      //Adjusts the bid modifiers according to the set values;
      if (cost > costTreshold && conversions == 0) {
        location.setBidModifier(bidAdjustment - decreaseBid);
      }

      if (cpa > cpaTreshold) {
        location.setBidModifier(bidAdjustment - decreaseBid);
      }

      if (cpa < cpaTreshold && conversions != 0) {
        location.setBidModifier(bidAdjustment + increaseBid);
      }
      
    }
  }
}

Google Ads API Forum Advisor

unread,
Jul 9, 2021, 12:40:34 PM7/9/21
to manh...@maxbuy.vn, adwor...@googlegroups.com
Hi,

Please post in Scripts forum for Google Ads script related concern. Feel free to contact us for Ads API related questions.

https://groups.google.com/g/adwords-scripts

Thanks,
Google Logo
Lakshmi Prathipati
Google Ads API Team
 

 

ref:_00D1U1174p._5004Q2JZvwN:ref
Reply all
Reply to author
Forward
0 new messages