Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

Daily budget Increase Based on Conv. Value

167 views
Skip to first unread message

Riken Patel

unread,
Jan 31, 2025, 5:31:13 AMJan 31
to Google Ads Scripts Forum
Hi Guys, 

So the objective of the script is to check all campaign at 5pm Sydney Time to see if conv. value is greater than 4.5, If yes then increase budget daily budget by 15%.

But for some reason it's not working. Can anyone help ?

function main() {
  const TIMEZONE = AdsApp.currentAccount().getTimeZone(); // Ensure correct timezone
  const now = new Date();
  const currentHour = Utilities.formatDate(now, TIMEZONE, "HH");
  const currentMinute = Utilities.formatDate(now, TIMEZONE, "mm");

  if (currentHour === "17" && currentMinute === "00") {
    Logger.log("Running script at 5 PM Sydney time.");
    checkAndUpdateCampaignBudgets();
  } else {
    Logger.log("Script is not running because it is not 5 PM Sydney time.");
  }
}

function checkAndUpdateCampaignBudgets() {
  const THRESHOLD = 4.5; // Conversion value / cost threshold
  const BUDGET_INCREASE_PERCENTAGE = 15; // Increase daily budget by 15%

  const campaignIterator = AdsApp.campaigns()
    .withCondition("Status = ENABLED")
    .get();

  while (campaignIterator.hasNext()) {
    const campaign = campaignIterator.next();
    const stats = campaign.getStatsFor("TODAY");

    const cost = stats.getCost();
    const conversionValue = stats.getConversionValue();

    if (cost > 0) { // Prevent division by zero
      const ratio = conversionValue / cost; // Calculate conversion value / cost

      if (ratio > THRESHOLD) {
        increaseBudget(campaign, BUDGET_INCREASE_PERCENTAGE);
        sendEmailNotification(campaign, ratio);
      }
    }
  }
}

function increaseBudget(campaign, percentage) {
  const currentBudget = campaign.getBudget().getAmount();
  const newBudget = currentBudget * (1 + percentage / 100);

  campaign.getBudget().setAmount(newBudget);
  Logger.log(`Increased budget for campaign '${campaign.getName()}' from $${currentBudget.toFixed(2)} to $${newBudget.toFixed(2)} (15% increase).`);
}

function sendEmailNotification(campaign, ratio) {
  const emailRecipients = [
    "" ];

  const subject = `Google Ads Budget Increase Alert - ${campaign.getName()}`;
  const body = `The daily budget for campaign '${campaign.getName()}' was increased by 15% of its current budget because the conversion value / cost exceeded the threshold of 4.5.\n\n` +
               `Current Conversion Value / Cost: ${ratio.toFixed(2)}`;

  MailApp.sendEmail(emailRecipients.join(","), subject, body);
  Logger.log(`Sent email notification for campaign '${campaign.getName()}'.`);
}


Google Ads Scripts Forum

unread,
Jan 31, 2025, 7:24:16 AMJan 31
to Google Ads Scripts Forum
Hi,

Thank you for reaching out to the Google Ads Scripts Support team.

I would like to inform you that you can set the frequency of the script based on your requirement, scripts will follow the timezone associated with your Google Ads UI. I have also observed one issue related to "stats.getConversionValue()" which is not a valid function, you can replace this with "stats.getConversions()".

If you still face any issue, you can share the below details to check further:
  • Google Ads account ID/CID
  • Name of the script.
  • Error Screenshot (if any)
You can share the requested details via Reply privately to the author option or a direct private reply to this email.

Thanks,
Google Ads Scripts team

Riken Patel

unread,
Feb 2, 2025, 7:36:25 PMFeb 2
to Google Ads Scripts Forum
Hi Team, 

Thanks for looking into this, details mentioned below,

  • Google Ads account ID/CID - 226-178-9962 (CPAP Clinic, The)
  • Name of the script - ROAS 450% >> 15% budget Inc
  • Error Screenshot (if any) - There is no error but the script is not making any changes in the campaign. (Screenshot below) 

image.png

Regards,
Riken


--
-- You received this message because you are subscribed to the Google Groups AdWords Scripts Forum group. Please do not reply to this email. To post to this group or unsubscribe please visit https://developers.google.com/adwords/scripts/community.
---
You received this message because you are subscribed to a topic in the Google Groups "Google Ads Scripts Forum" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/adwords-scripts/hHwYY1Hpsbo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to adwords-scrip...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/adwords-scripts/a406eba1-6dbe-4e13-8244-f6411c0565edn%40googlegroups.com.


--

Riken Patel

Sr. Manager - Digital Marketing

+91 8080 771 667

ser...@searchrescue.com.au

www.searchrescue.com.au

 

Google Ads Scripts Forum

unread,
Feb 2, 2025, 9:16:39 PMFeb 2
to Google Ads Scripts Forum
Hi,

I recommend you to remove the "currentMinute" conditions from the script as the frequency that was set to the script will run at any point of time in between 5pm to 6pm as we don't have any specific time scheduled during this period. This will make the script execute with currentHour 17 and do the necessary updates based on the logic. Other approach is you can completely remove the if condition related to the time validation as you have already set the frequency of the script. You can refer to the "ROAS 450% >> 15% budget Inc (copy)" script which I previewed from my end for the current time which is of 1 PM.

Hope this helps! Feel free to get back in case of any further queries.

Thanks,
Google Ads Scripts team

Riken Patel

unread,
Feb 3, 2025, 8:51:42 AMFeb 3
to Google Ads Scripts Forum
I have made the changes related to time. 

Also replaced "stats.getConversionValue()" with "stats.getConversions()". However, will this change the script to look into the conversion value / cost being more than 4.5 or the conversions? 

As originally we want the script to look into the conversion value / cost and increase the budget based on that. 

Let me know what you think. 

Thanks,
Riken



Google Ads Scripts Forum

unread,
Feb 3, 2025, 2:24:52 PMFeb 3
to Google Ads Scripts Forum

Hi Riken,

Yes, the value conversions per cost is not the same conversion value per cost. I would like to inform you that there is no method available in the Google Ads Scripts to get conversion value from the stats as you are getting for conversions. In order to get conversion value via scripts, you may use Google Ads Query Language and retrieve the data from the query by using the AdsApp.report method. You may use the sample query to retrieve conversion value via the GAQL.

Query: `SELECT campaign.id, campaign.name, metrics.conversions_value, metrics.cost_micros FROM campaign WHERE segments.date DURING TODAY`

You can edit or add more metrics and validate the query by referring to Google Ads Query Builder.

I hope this helps! Kindly get back to us if you still have any concerns.

Thanks,
Google Ads Scripts support team

Riken Patel

unread,
Feb 13, 2025, 1:09:51 AMFeb 13
to Google Ads Scripts Forum
Thanks for the details, 

but where should I add the query in the script that you have provided?. 

Request you to please make changes in your script and include the query to fetch conversion value so I can replicate it. 

Regards,
Riken

Google Ads Scripts Forum

unread,
Feb 13, 2025, 2:21:34 AMFeb 13
to Google Ads Scripts Forum
Hi,

I would like to inform you that we can't create any scripts on users'behalf. You need to include the query instead of the current "conversionValue" constant defined in your script and the query needs to retrieve the conversion value based on the individual campaign. You can retrieve the campaign name by the campaign variable as given below. You can refer to the script "ROAS 450% >> 15% budget Inc (copy)" for more information on the change. Below is the sample query you can use to get the conversion value.

const campaignName= campaign.getName();
let report = AdsApp.report(`SELECT metrics.conversions_value FROM campaign WHERE campaign.name = '${campaignName}' AND segments.date DURING TODAY`);
    let rows = report.rows();
    while (rows.hasNext()) {
        let row = rows.next();
        const conversionValue = row["metrics.conversions_value"];
//next lines of script
}

Feel free to get back in case of any further queries.

Thanks,
Google Ads Scripts team

Riken Patel

unread,
Feb 28, 2025, 12:15:35 AMFeb 28
to Google Ads Scripts Forum
Hi,

As per your instructions, I have created below mentioned script removing the currentmunite condition, adding GAQL, please check and let me know if any further changes required. 

function main() {
  const TIMEZONE = AdsApp.currentAccount().getTimeZone(); // Ensure correct timezone
  const now = new Date();
  const currentHour = Utilities.formatDate(now, TIMEZONE, "HH");
  const currentMinute = Utilities.formatDate(now, TIMEZONE, "mm");
    Logger.log(TIMEZONE);
    Logger.log(currentHour);
    Logger.log(currentMinute);
  if (currentHour === "17") {

    Logger.log("Running script at 5 PM Sydney time.");
    checkAndUpdateCampaignBudgets();
  } else {
    Logger.log("Script is not running because it is not 5 PM Sydney time.");
  }
}

function checkAndUpdateCampaignBudgets() {
  const THRESHOLD = 4.5; // Conversion value / cost threshold
  const BUDGET_INCREASE_PERCENTAGE = 15; // Increase daily budget by 15%

  const campaignIterator = AdsApp.campaigns()
    .withCondition("Status = ENABLED")
    .get();

  while (campaignIterator.hasNext()) {
    const campaign = campaignIterator.next();  
    const campaignName= campaign.getName();
    console.log(campaignName);

    const stats = campaign.getStatsFor("TODAY");

    const cost = stats.getCost();
    //const conversionValue = stats.getConversions();

    let report = AdsApp.report(`SELECT metrics.conversions_value FROM campaign WHERE campaign.name = '${campaignName}' AND segments.date DURING TODAY`);
    let rows = report.rows();
    while (rows.hasNext()) {
        let row = rows.next();
        const conversionValue = row["metrics.conversions_value"];    
    Logger.log("cost  " + cost);
    Logger.log("conversionValue  " + conversionValue);


    if (cost > 0) { // Prevent division by zero
      const ratio = conversionValue / cost; // Calculate conversion value / cost
      Logger.log("ratio  " + ratio);

      if (ratio > THRESHOLD) {
        increaseBudget(campaign, BUDGET_INCREASE_PERCENTAGE);
        sendEmailNotification(campaign, ratio);
      }
    }
   }
  }
}

function increaseBudget(campaign, percentage) {
  const currentBudget = campaign.getBudget().getAmount();
  const newBudget = currentBudget * (1 + percentage / 100);

  campaign.getBudget().setAmount(newBudget);
  Logger.log(`Increased budget for campaign '${campaign.getName()}' from $${currentBudget.toFixed(2)} to $${newBudget.toFixed(2)} (15% increase).`);
}

function sendEmailNotification(campaign, ratio) {
  const emailRecipients = [

  ];

  const subject = `Google Ads Budget Increase Alert - ${campaign.getName()}`;
  const body = `The daily budget for campaign '${campaign.getName()}' was increased by 15% of its current budget because the conversion value / cost exceeded the threshold of 4.5.\n\n` +
               `Current Conversion Value / Cost: ${ratio.toFixed(2)}`;

  MailApp.sendEmail(emailRecipients.join(","), subject, body);
  Logger.log(`Sent email notification for campaign '${campaign.getName()}'.`);
}


#########################################

Also, I am not sure about where you want me to add the below code, could you please place it in the above script and send it back in the email, I'll copy paste it in the script from my end.

const campaignName= campaign.getName();
let report = AdsApp.report(`SELECT metrics.conversions_value FROM campaign WHERE campaign.name = '${campaignName}' AND segments.date DURING TODAY`);
    let rows = report.rows();
    while (rows.hasNext()) {
        let row = rows.next();
        const conversionValue = row["metrics.conversions_value"];
//next lines of script
}


Regards,
Riken

Riken Patel

unread,
Feb 28, 2025, 1:47:55 AMFeb 28
to Google Ads Scripts Forum
Also, I have set the frequency to be daily between 5pm to 6pm. Which timezone is this setting considered? Is it an account level timezone? i.e (GMT+11:00) Eastern Australia Time for this account. 

Reason for asking this is because, when I did a preview today it showed 10:44 am IST time, which is correct as I am situated in India. But I have set the frequency between 5pm to 6pm, So will this be considered as 5pm IST. If that is the case then the script will trigger at midnight in Sydney time. which is not correct. we want it to be run between 5pm to 6pm sydney time.  
 
image.png
 
Please let me know your thoughts.

Regards,
Riken

Google Ads Scripts Forum Advisor

unread,
Feb 28, 2025, 4:03:15 AMFeb 28
to adwords...@googlegroups.com
Hi,

I would like to inform you that the script you shared here is the updated script with the changes that includes GAQL query to retrieve the conversion value. Request you to look over the "emailRecipients" and "currentHour" that are required to be adjusted and execute the script. Regarding the timing, the scripts are dependent on the Google Ads account timezone that is present. Based on the timezone adjust the frequency of the script to run between 5PM-6PM Sydney time. If you are facing any challenges in the script execution due to the time zone, I would suggest you to set the frequency approximately between 11:30 AM to 12:30 PM IST as we don't have this option available under frequency which will refer to 5PM-6PM Sydney time

Feel free to get back in case of any further issue.
 

Thanks,
 
Google Logo Google Ads Scripts Team

Feedback
How was our support today?

rating1    rating2    rating3    rating4    rating5
[2025-02-28 09:02:42Z GMT] This message is in relation to case "ref:!00D1U01174p.!5004Q02vH4hI:ref" (ADR-00290414)



Riken Patel

unread,
Mar 13, 2025, 1:08:30 AM (7 days ago) Mar 13
to Google Ads Scripts Forum on behalf of adsscripts
Thanks for the update. Will try this today and let you know. 

--
-- You received this message because you are subscribed to the Google Groups AdWords Scripts Forum group. Please do not reply to this email. To post to this group or unsubscribe please visit https://developers.google.com/adwords/scripts/community.
---
You received this message because you are subscribed to a topic in the Google Groups "Google Ads Scripts Forum" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/adwords-scripts/hHwYY1Hpsbo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to adwords-scrip...@googlegroups.com.

Riken Patel

unread,
Mar 13, 2025, 2:40:26 AM (7 days ago) Mar 13
to Google Ads Scripts Forum on behalf of adsscripts
Hi Team, 

I have made the frequency between 11 AM to 12 PM IST but it did not work automatically, 

- This script is not working automatically, I have to run it manually. 

- Script only made changes in the search campaigns and irrespective of the conv. value / cost bench march of 4.5.

- Script did not work on the PMax campaigns. 

What could be the problem? 
image.png


Regards,
Riken


Google Ads Scripts Forum Advisor

unread,
Mar 13, 2025, 5:11:01 AM (7 days ago) Mar 13
to adwords...@googlegroups.com
Hi,

I would like to inform you that the script will run at any point of time between 11AM to 12PM. So kindly change the timing accordingly based on your requirements and wait for the frequency scheduled time to be completed to validate the script execution.

Currently the script is using AdsApp.campaigns() which will work for search and display campaigns. In order to include performance max campaigns, I would recommend you to use AdsApp.performanceMaxCampaigns(). You can refer to the documentation for more information.

Feel free to get back in case of any further queries.
 

Thanks,
 
Google Logo Google Ads Scripts Team

Feedback
How was our support today?

rating1    rating2    rating3    rating4    rating5

[2025-03-13 09:10:27Z GMT] This message is in relation to case "ref:!00D1U01174p.!5004Q02vH4hI:ref" (ADR-00290414)



Reply all
Reply to author
Forward
0 new messages