Snippets
Mit Sammlungen den Überblick behalten
Sie können Inhalte basierend auf Ihren Einstellungen speichern und kategorisieren.
Snippet-Erweiterung erstellen
function createSnippet() {
// For full details on creating a new snippet extension, see:
// https://developers.google.com/google-ads/scripts/docs/reference/adsapp/adsapp_snippetbuilder
const newSnippet = AdsApp.extensions().newSnippetBuilder()
// Replace the values below with your header, values, and mobile preferred
// For a list of supported headers, see: https://developers.google.com/adwords/api/docs/appendix/structured-snippet-headers
.withHeader('Brands') // required
.withValues(['Nest', 'Waymo','Google']) // required
.withMobilePreferred(true) // optional
.build()
.getResult();
// Add snippet to a campaign
const campaignIterator = AdsApp.campaigns()
.withCondition('campaign.name = "INSERT_CAMPAIGN_NAME_HERE"')
.get();
if (campaignIterator.hasNext()) {
const campaign = campaignIterator.next();
campaign.addSnippet(newSnippet);
}
// Add snippet to an ad group
const adGroupIterator = AdsApp.adGroups()
.withCondition('campaign.name = "INSERT_CAMPAIGN_NAME_HERE"')
.withCondition('ad_group.name = "INSERT_AD_GROUP_NAME_HERE"')
.get();
if (adGroupIterator.hasNext()) {
const adGroup = adGroupIterator.next();
adGroup.addSnippet(newSnippet);
}
// Add snippet to an account
const account = AdsApp.currentAccount();
account.addSnippet(newSnippet);
}
Details zu Protokoll-Snippets für eine Kampagne
function logSnippetDetails() {
// Get a campaign.
const campaignIterator = AdsApp.campaigns()
.withCondition('campaign.name = "INSERT_CAMPAIGN_NAME_HERE"')
.get();
if (!campaignIterator.hasNext()) {
throw new Error('Campaign not found.');
}
const campaign = campaignIterator.next();
// Retrieve the campaign's snippets. Retrieving an ad group's and
// account's sniuppets is similar.
const snippetIterator = campaign.extensions().snippets().get();
for (const snippet of snippetIterator) {
// You can also request reports for pre-defined date ranges. See
// https://developers.google.com/adwords/api/docs/guides/awql,
// DateRangeLiteral section for possible values.
const stats = snippet.getStatsFor('LAST_MONTH');
console.log(`Snippet header : ${ snippet.getHeader() }`);
console.log(`Snippet values : ${ snippet.getValues() }`);
console.log(`mobile preferred : ${ snippet.isMobilePreferred() }`);
console.log(`clicks : ${ stats.getClicks() }`);
console.log(`impressions : ${ stats.getImpressions() }`);
console.log('=======');
}
console.log(`${snippetIterator.totalNumEntities()} snippets in the campaign`);
}
Zeitplan für Snippets in einer Kampagne festlegen
function setSnippetSchedule() {
// Get a campaign.
const campaignIterator = AdsApp.campaigns()
.withCondition('campaign.name = "INSERT_CAMPAIGN_NAME_HERE"')
.get();
if (!campaignIterator.hasNext()) {
throw new Error('Campaign not found.');
}
const campaign = campaignIterator.next();
// Retrieve the campaign's snippets. Retrieving an ad group's and
// account's saitelinks is similar.
const snippetIterator = campaign.extensions().snippets().get();
for (const snippet of snippetIterator) {
if (snippet.getHeader() === 'Brands') {
// Set snippet schedule to run only on Mondays and Tuesdays, 9 AM to
// 6 PM.
const monday = {
dayOfWeek: 'MONDAY',
startHour: 9,
startMinute: 0,
endHour: 18,
endMinute: 0
};
const tuesday = {
dayOfWeek: 'TUESDAY',
startHour: 9,
startMinute: 0,
endHour: 18,
endMinute: 0
};
snippet.setSchedules([monday, tuesday]);
break;
}
}
}
Sofern nicht anders angegeben, sind die Inhalte dieser Seite unter der Creative Commons Attribution 4.0 License und Codebeispiele unter der Apache 2.0 License lizenziert. Weitere Informationen finden Sie in den Websiterichtlinien von Google Developers. Java ist eine eingetragene Marke von Oracle und/oder seinen Partnern.
Zuletzt aktualisiert: 2024-08-21 (UTC).
[[["Leicht verständlich","easyToUnderstand","thumb-up"],["Mein Problem wurde gelöst","solvedMyProblem","thumb-up"],["Sonstiges","otherUp","thumb-up"]],[["Benötigte Informationen nicht gefunden","missingTheInformationINeed","thumb-down"],["Zu umständlich/zu viele Schritte","tooComplicatedTooManySteps","thumb-down"],["Nicht mehr aktuell","outOfDate","thumb-down"],["Problem mit der Übersetzung","translationIssue","thumb-down"],["Problem mit Beispielen/Code","samplesCodeIssue","thumb-down"],["Sonstiges","otherDown","thumb-down"]],["Zuletzt aktualisiert: 2024-08-21 (UTC)."],[[["This script provides functionality to create new structured snippets with custom headers and values, and optionally mark them as mobile-preferred."],["It demonstrates how to add these snippets to campaigns, ad groups, or accounts for broader targeting."],["The script allows for retrieving and logging key performance metrics of existing snippets, such as clicks and impressions, over specified durations."],["It includes a feature to set custom schedules for snippets, enabling them to run only during defined days and times."]]],[]]