Create an ad customizer data source
function createAdCustomizerSource() {
AdsApp.newAdCustomizerSourceBuilder()
.withName('Flowers')
.addAttribute('flower', 'text')
.addAttribute('price', 'price')
.build();
}
Find an ad customizer data source by name
function getAdCustomizerSource() {
var sources = AdsApp.adCustomizerSources().get();
while (sources.hasNext()) {
var source = sources.next();
if (source.getName() == 'Flowers') {
Logger.log(source.getName() + ' ' + source.getAttributes());
}
}
}
Get a data source's customizer items
function getAdCustomizerItems() {
var source = AdsApp.adCustomizerSources().get().next();
var items = source.items().get();
while (items.hasNext()) {
var item = items.next();
Logger.log(item.getAttributeValues());
}
}
Create ad customizers
function createAdCustomizers() {
var source = AdsApp.newAdCustomizerSourceBuilder()
.withName('Flowers')
.addAttribute('flower', 'text')
.addAttribute('price', 'price')
.build()
.getResult();
source.adCustomizerItemBuilder()
.withAttributeValue('flower', 'roses')
.withAttributeValue('price', '$29.99')
.withTargetKeyword('roses')
.build();
}
Create text ad with ad customizers
function setupCustomizedAd() {
// If you have multiple ad groups with the same name, this snippet will
// pick an arbitrary matching ad group each time. In such cases, just
// filter on the campaign name as well:
//
// AdsApp.adGroups()
// .withCondition('Name = "INSERT_ADGROUP_NAME_HERE"')
// .withCondition('CampaignName = "INSERT_CAMPAIGN_NAME_HERE"')
var adGroupIterator = AdsApp.adGroups()
.withCondition('Name = "INSERT_ADGROUP_NAME_HERE"')
.get();
if (adGroupIterator.hasNext()) {
var adGroup = adGroupIterator.next();
// This ad will try to fill in the blanks using the 'flower' and 'price'
// attributes from the 'Flower' data source.
adGroup.newAd().expandedTextAdBuilder()
.withHeadlinePart1('Flowers for sale')
.withHeadlinePart2('Fresh cut {=Flowers.flower}')
.withDescription('starting at {=Flowers.price}')
.withFinalUrl('http://example.com/flowers')
.build();
}
}