เครื่องมือปรับแต่งโฆษณา
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
สร้างแหล่งที่มาของข้อมูลเครื่องมือปรับแต่งโฆษณา
function createMixersAdCustomizerSource() {
// This example snippet creates an ad customizer source named "Mixers", modeled after
// the example data shown at https://support.google.com/google-ads/answer/6072565.
const sourceName = 'Mixers';
// Ad Customizer attributes can be added one at a time with `addAttribute` or all at
// once with `addAttributes`.
const mixersSourceOperation = AdsApp.newAdCustomizerSourceBuilder()
.withName(sourceName)
.addAttribute('Model', 'text')
.addAttributes({
'Capacity': 'number',
'Type': 'text',
'Start_price': 'price',
'Sale_ends': 'date',
})
.build();
return mixersSourceOperation;
}
ค้นหาแหล่งที่มาของข้อมูลเครื่องมือปรับแต่งโฆษณาด้วยชื่อ
function getAdCustomizerSourceByName(sourceName) {
let sourceCount = 0;
let foundSource = null;
for (const source of AdsApp.adCustomizerSources()) {
if (source.getName() === sourceName) {
foundSource = source;
sourceCount += 1;
}
}
if (foundSource === null) {
throw new Error(`No Ad Customizer Source found with name "${sourceName}"`);
}
if (sourceCount > 1) {
console.warn(`Found ${sourceCount} Ad Customizer Sources with name "${sourceName}", returning just one of them`);
}
console.log(`Source "${foundSource.getName()}" has attributes ${foundSource.getAttributes()}`);
return foundSource;
}
รับรายการเครื่องมือปรับแต่งของแหล่งที่มาของข้อมูล
function getAdCustomizerItems(sourceName) {
let sourceCount = 0;
let foundSource = null;
for (const source of AdsApp.adCustomizerSources()) {
if (source.getName() === sourceName) {
foundSource = source;
sourceCount += 1;
}
}
if (foundSource === null) {
throw new Error(`No Ad Customizer Source found with name "${sourceName}"`);
}
if (sourceCount > 1) {
console.warn(`Found ${sourceCount} Ad Customizer Sources with name "${sourceName}", using just one of them`);
}
const itemIterator = foundSource.items().get();
console.log(`Source "${foundSource.getName()}" has ${itemIterator.totalNumEntities()} items`);
return itemIterator;
}
สร้างรายการเครื่องมือปรับแต่งโฆษณา
function createMixersAdCustomizerItem() {
// This example snippet creates an ad customizer item in the source named "Mixers",
// modeled after the example data shown at
// https://support.google.com/google-ads/answer/6072565.
const sourceName = 'Mixers';
let sourceCount = 0;
let mixersSource = null;
for (const source of AdsApp.adCustomizerSources()) {
if (source.getName() === sourceName) {
mixersSource = source;
sourceCount += 1;
}
}
if (mixersSource === null) {
throw new Error(`No Ad Customizer Source found with name "${sourceName}"`);
}
if (sourceCount > 1) {
console.warn(`Found ${sourceCount} Ad Customizer Sources with name "${sourceName}", using just one of them`);
}
// Item values can be specified one at a time with `withAttributeValue` or all at once
// with `withAttributeValues`.
const mixersItemOperation = mixersSource.adCustomizerItemBuilder()
.withAttributeValue('Model', 'ProWhip 300')
.withAttributeValues({
'Capacity': 5,
'Type': 'tilt-head',
'Start_price': '$199',
'Sale_ends': '20150515 200000',
})
.withTargetKeyword('prowhip 300')
.build();
return mixersItemOperation;
}
สร้างโฆษณาแบบข้อความที่ขยายออกด้วยเครื่องมือปรับแต่งโฆษณา
function createCustomizedMixersExpandedTextAd() {
// This example snippet creates an ad in the ad group named "Kitchen Store" that
// shows details based on the data in the ad customizer named "Mixers". This
// example is modeled after https://support.google.com/google-ads/answer/6072565.
const adGroupName = 'Kitchen Store';
const adGroupIterator = AdsApp.adGroups()
.withCondition(`ad_group.name = "${adGroupName}"`)
.get();
if (!adGroupIterator.hasNext()) {
throw new Error(`No Ad Group found with name "${adGroupName}"`);
}
if (adGroupIterator.totalNumEntities() > 1) {
console.warn(`Found ${adGroupIterator.totalNumEntities()} Ad Groups with name "${adGroupName}", using just one of them`);
}
const adGroup = adGroupIterator.next();
const mixersAdOperation = adGroup.newAd().expandedTextAdBuilder()
.withHeadlinePart1('{=Mixers.model}')
.withHeadlinePart2('Stand Mixer')
.withDescription1('{=Mixers.Capacity} quart {=Mixers.Type} stand mixer.')
.withDescription2('{=Mixers.Start_price} - sale ends in {=COUNTDOWN(Mixers.Sale_ends)}.')
.withFinalUrl('http://www.example.com')
.build();
return mixersAdOperation;
}
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-08-21 UTC
[null,null,["อัปเดตล่าสุด 2025-08-21 UTC"],[[["\u003cp\u003eThe provided code snippets demonstrate how to manage Ad Customizer data sources and items within Google Ads scripts.\u003c/p\u003e\n"],["\u003cp\u003eYou can create, find, and retrieve items from an Ad Customizer data source using dedicated functions.\u003c/p\u003e\n"],["\u003cp\u003eAd Customizer items can be associated with specific keywords for targeted ad delivery.\u003c/p\u003e\n"],["\u003cp\u003eThe code showcases how to build Expanded Text Ads that dynamically insert data from Ad Customizer sources using placeholders like \u003ccode\u003e{=Mixers.Model}\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eThese snippets use a 'Mixers' example source with attributes like Model, Capacity, and Sale_ends to illustrate the functionality.\u003c/p\u003e\n"]]],[],null,["# Ad Customizers\n\nCreate an ad customizer data source\n-----------------------------------\n\n```mysql\nfunction createMixersAdCustomizerSource() {\n // This example snippet creates an ad customizer source named \"Mixers\", modeled after\n // the example data shown at https://support.google.com/google-ads/answer/6072565.\n const sourceName = 'Mixers';\n\n // Ad Customizer attributes can be added one at a time with `addAttribute` or all at\n // once with `addAttributes`.\n const mixersSourceOperation = AdsApp.newAdCustomizerSourceBuilder()\n .withName(sourceName)\n .addAttribute('Model', 'text')\n .addAttributes({\n 'Capacity': 'number',\n 'Type': 'text',\n 'Start_price': 'price',\n 'Sale_ends': 'date',\n })\n .build();\n\n return mixersSourceOperation;\n}\n```\n\nFind an ad customizer data source by name\n-----------------------------------------\n\n```perl6\nfunction getAdCustomizerSourceByName(sourceName) {\n let sourceCount = 0;\n let foundSource = null;\n\n for (const source of AdsApp.adCustomizerSources()) {\n if (source.getName() === sourceName) {\n foundSource = source;\n sourceCount += 1;\n }\n }\n\n if (foundSource === null) {\n throw new Error(`No Ad Customizer Source found with name \"${sourceName}\"`);\n }\n\n if (sourceCount \u003e 1) {\n console.warn(`Found ${sourceCount} Ad Customizer Sources with name \"${sourceName}\", returning just one of them`);\n }\n\n console.log(`Source \"${foundSource.getName()}\" has attributes ${foundSource.getAttributes()}`);\n return foundSource;\n}\n```\n\nGet a data source's customizer items\n------------------------------------\n\n```perl6\nfunction getAdCustomizerItems(sourceName) {\n let sourceCount = 0;\n let foundSource = null;\n\n for (const source of AdsApp.adCustomizerSources()) {\n if (source.getName() === sourceName) {\n foundSource = source;\n sourceCount += 1;\n }\n }\n\n if (foundSource === null) {\n throw new Error(`No Ad Customizer Source found with name \"${sourceName}\"`);\n }\n\n if (sourceCount \u003e 1) {\n console.warn(`Found ${sourceCount} Ad Customizer Sources with name \"${sourceName}\", using just one of them`);\n }\n\n const itemIterator = foundSource.items().get();\n console.log(`Source \"${foundSource.getName()}\" has ${itemIterator.totalNumEntities()} items`);\n return itemIterator;\n}\n```\n\nCreate an ad customizer item\n----------------------------\n\n```mysql\nfunction createMixersAdCustomizerItem() {\n // This example snippet creates an ad customizer item in the source named \"Mixers\",\n // modeled after the example data shown at\n // https://support.google.com/google-ads/answer/6072565.\n const sourceName = 'Mixers';\n\n let sourceCount = 0;\n let mixersSource = null;\n\n for (const source of AdsApp.adCustomizerSources()) {\n if (source.getName() === sourceName) {\n mixersSource = source;\n sourceCount += 1;\n }\n }\n\n if (mixersSource === null) {\n throw new Error(`No Ad Customizer Source found with name \"${sourceName}\"`);\n }\n\n if (sourceCount \u003e 1) {\n console.warn(`Found ${sourceCount} Ad Customizer Sources with name \"${sourceName}\", using just one of them`);\n }\n\n // Item values can be specified one at a time with `withAttributeValue` or all at once\n // with `withAttributeValues`.\n const mixersItemOperation = mixersSource.adCustomizerItemBuilder()\n .withAttributeValue('Model', 'ProWhip 300')\n .withAttributeValues({\n 'Capacity': 5,\n 'Type': 'tilt-head',\n 'Start_price': '$199',\n 'Sale_ends': '20150515 200000',\n })\n .withTargetKeyword('prowhip 300')\n .build();\n\n return mixersItemOperation;\n}\n```\n\nCreate expanded text ad with ad customizers\n-------------------------------------------\n\n```gdscript\nfunction createCustomizedMixersExpandedTextAd() {\n // This example snippet creates an ad in the ad group named \"Kitchen Store\" that\n // shows details based on the data in the ad customizer named \"Mixers\". This\n // example is modeled after https://support.google.com/google-ads/answer/6072565.\n const adGroupName = 'Kitchen Store';\n const adGroupIterator = AdsApp.adGroups()\n .withCondition(`ad_group.name = \"${adGroupName}\"`)\n .get();\n\n if (!adGroupIterator.hasNext()) {\n throw new Error(`No Ad Group found with name \"${adGroupName}\"`);\n }\n\n if (adGroupIterator.totalNumEntities() \u003e 1) {\n console.warn(`Found ${adGroupIterator.totalNumEntities()} Ad Groups with name \"${adGroupName}\", using just one of them`);\n }\n\n const adGroup = adGroupIterator.next();\n const mixersAdOperation = adGroup.newAd().expandedTextAdBuilder()\n .withHeadlinePart1('{=Mixers.model}')\n .withHeadlinePart2('Stand Mixer')\n .withDescription1('{=Mixers.Capacity} quart {=Mixers.Type} stand mixer.')\n .withDescription2('{=Mixers.Start_price} - sale ends in {=COUNTDOWN(Mixers.Sale_ends)}.')\n .withFinalUrl('http://www.example.com')\n .build();\n\n return mixersAdOperation;\n}\n```"]]