* Manage your campaigns based on current weather. The contents of
* management logic.
// Example 1: Use weather summary provided by OpenWeathermap.
// Add your logic here.
/**
* Retrieves an ad group given a campaign and ad group name.
*
* @param {string} campaignName The campaign name.
* @param {string} adGroupName The ad group name.
* @return {!AdGroup} The ad group.
* @throws if the specified campaign and ad group does not exist.
*/
function getAdGroup(campaignName, adGroupName) {
return AdWordsApp.adGroups()
.withCondition('Name = "' + adGroupName + '"')
.withCondition('CampaignName = "' + campaignName + '"')
.get()
.next();
}
/**
* Creates customized ads if they haven't already been created.
*
* @param {!AdGroup} adGroup The ad group within which to create the ads.
*/
function maybeCreateAds(adGroup) {
var ads = adGroup.ads().get();
while (ads.hasNext()) {
var ad = ads.next();
if (ad.isType().expandedTextAd()) {
var expandedTextAd = ad.asType().expandedTextAd();
if (expandedTextAd.getHeadlinePart1() == 'Flowers For Sale') {
// The ads have already been created; no need to do more
return;
}
}
}
// Reference the 'Weather' data source here; text will be inserted when the
// ad is served.
adGroup.newAd().expandedTextAdBuilder()
.withHeadlinePart1('{=Weather.name} For Sale')
.withHeadlinePart2('Fresh cut {=Weather.name_lowercase}')
.withDescription('starting at {=Weather.price}')
.build();
// All ad groups also need to have an ad without ad customizers to fall back
// on, in case no ad customizers are able to serve.
adGroup.newAd().expandedTextAdBuilder()
.withHeadlinePart1('Flowers For Sale')
.withHeadlinePart2('Fresh cut flowers')
.withDescription('delivered for cheap')
.build();
}