We are glad to announce that AdWords Scripts now support
Budgets as top-level objects. You can now fetch the budget’s
stats, determine whether it is
shared, and inspect its
delivery method. You can also fetch all campaigns associated with a budget.
To support budgets, we have had to tweak existing APIs a bit. We believe the impact on existing scripts will be minimal; please let us know if you experience any issues, and we'll help you work through them. Here’s what changed:
The good news - existing scripts should be largely unaffected by this change. Details below.
Campaign.getBudget()
Thanks to JavaScript flexibility, the same entity can act as both a Number and an Object. Consider this snippet:
var smartNumber = new Number(48.0);
smartNumber.getIQ = function() { return 150; } // indeed, a smart number!
// smartNumber acts like a regular number:
Logger.log(smartNumber); // prints '48.0'
Logger.log(smartNumber + 5); // prints '53.0'
Logger.log(smartNumber > 47); // prints 'true'
// and you can also call its methods
Logger.log(smartNumber.getIQ()); // prints '150'
We have used a similar approach for the return value of
Campaign.getBudget() method. The value returned from that method acts like a number (and thus existing scripts shouldn’t be affected), but also exposes methods from
Budget object (
getStats(),
getDeliveryMethod(), etc.)
The behavior observed by your script may change in the following (unlikely) scenarios:
- typeof operator - 'object' vs. 'number'
Type of the object returned by
getBudget() call has changed from 'number' to 'object':
Logger.log(typeof(21)); // prints 'number'
Logger.log(typeof(smartNumber)); // prints 'object'
If used for comparison of budget values, the triple-equals operator will now return
false instead of
true:
Logger.log(smartNumber == 48); // prints 'true'
Logger.log(smartNumber === 48); // prints 'false'
Campaign.setBudget(Number)
We are deprecating this method. The preferred way to change a campaign’s budget, going forward, is via the
Campaign.getBudget().setAmount() call.
Campaign.setBudget(Number) will continue working for non-shared budgets in the short term. For explicitly shared budgets, however, the call to this method will throw an exception (while in the past, it would log an error and proceed with the execution).
Happy scripting!
Posted by Ilya Netchitailo, AdWords Scripts Team