We are introducing Builders as the standard way to create entities in AdWords scripts. You can use Builders in either synchronous or asynchronous mode. You can also check whether the operation was successful or not, and take appropriate actions depending on the operation’s outcome. The following code snippet shows how to create a keyword using builders.
We are also deprecating the following creation methods. These methods will work fine for now, but they will be sunset in the future.
The current release adds builder support for ads and keywords. The existing builders for ad groups and Ad Extensions - phone number, site links and mobile apps have also been standardized. The
// Retrieve your ad group.
var adGroup = AdWordsApp.adGroups().get().next();
// Create a keyword operation.
var keywordOperation = adGroup.newKeywordBuilder().
.withCpc(1.2)
.withText("shoes")
.withDestinationUrl("http://www.example.com/shoes")
.build();
// Optional: examine the outcome. The call to isSuccessful()
// will block until the operation completes.
if (keywordOperation.isSuccessful()) {
// Get the result.
var keyword = keywordOperation.getResult();
} else {
// Handle the errors.
var errors = keywordOperation.getErrors();
}
addSitelink
, addPhoneNumber
, and addMobileApp
methods of AdGroup and Campaign classes will now return the resulting operation.We are also deprecating the following creation methods. These methods will work fine for now, but they will be sunset in the future.
- AdGroup.createKeyword [variant 2, variant 3]
- AdGroup.createTextAd [variant 2]
- AdGroupBuilder.create()
- MobileAppBuilder.create()
- PhoneNumberBuilder.create()
- SitelinkBuilder.create()