المقتطفات
تنظيم صفحاتك في مجموعات يمكنك حفظ المحتوى وتصنيفه حسب إعداداتك المفضّلة.
إنشاء إضافة مقتطفات
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); }
تفاصيل مقتطف السجلّ لإحدى الحملات
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`); }
ضبط جدول عرض الإعلانات للمقتطفات في إحدى الحملات
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; } } }
إنّ محتوى هذه الصفحة مرخّص بموجب ترخيص Creative Commons Attribution 4.0 ما لم يُنصّ على خلاف ذلك، ونماذج الرموز مرخّصة بموجب ترخيص Apache 2.0. للاطّلاع على التفاصيل، يُرجى مراجعة سياسات موقع Google Developers. إنّ Java هي علامة تجارية مسجَّلة لشركة Oracle و/أو شركائها التابعين.
تاريخ التعديل الأخير: 2025-08-21 (حسب التوقيت العالمي المتفَّق عليه)
[[["يسهُل فهم المحتوى.","easyToUnderstand","thumb-up"],["ساعَدني المحتوى في حلّ مشكلتي.","solvedMyProblem","thumb-up"],["غير ذلك","otherUp","thumb-up"]],[["لا يحتوي على المعلومات التي أحتاج إليها.","missingTheInformationINeed","thumb-down"],["الخطوات معقدة للغاية / كثيرة جدًا.","tooComplicatedTooManySteps","thumb-down"],["المحتوى قديم.","outOfDate","thumb-down"],["ثمة مشكلة في الترجمة.","translationIssue","thumb-down"],["مشكلة في العيّنات / التعليمات البرمجية","samplesCodeIssue","thumb-down"],["غير ذلك","otherDown","thumb-down"]],["تاريخ التعديل الأخير: 2025-08-21 (حسب التوقيت العالمي المتفَّق عليه)"],[[["\u003cp\u003eThis script provides functionality to create new structured snippets with custom headers and values, and optionally mark them as mobile-preferred.\u003c/p\u003e\n"],["\u003cp\u003eIt demonstrates how to add these snippets to campaigns, ad groups, or accounts for broader targeting.\u003c/p\u003e\n"],["\u003cp\u003eThe script allows for retrieving and logging key performance metrics of existing snippets, such as clicks and impressions, over specified durations.\u003c/p\u003e\n"],["\u003cp\u003eIt includes a feature to set custom schedules for snippets, enabling them to run only during defined days and times.\u003c/p\u003e\n"]]],[],null,["Create a snippet extension \n\n```gdscript\nfunction createSnippet() {\n // For full details on creating a new snippet extension, see:\n // https://developers.google.com/google-ads/scripts/docs/reference/adsapp/adsapp_snippetbuilder\n const newSnippet = AdsApp.extensions().newSnippetBuilder()\n // Replace the values below with your header, values, and mobile preferred\n // For a list of supported headers, see: https://developers.google.com/adwords/api/docs/appendix/structured-snippet-headers\n .withHeader('Brands') // required\n .withValues(['Nest', 'Waymo','Google']) // required\n .withMobilePreferred(true) // optional\n .build()\n .getResult();\n\n // Add snippet to a campaign\n const campaignIterator = AdsApp.campaigns()\n .withCondition('campaign.name = \"INSERT_CAMPAIGN_NAME_HERE\"')\n .get();\n if (campaignIterator.hasNext()) {\n const campaign = campaignIterator.next();\n campaign.addSnippet(newSnippet);\n }\n\n // Add snippet to an ad group\n const adGroupIterator = AdsApp.adGroups()\n .withCondition('campaign.name = \"INSERT_CAMPAIGN_NAME_HERE\"')\n .withCondition('ad_group.name = \"INSERT_AD_GROUP_NAME_HERE\"')\n .get();\n if (adGroupIterator.hasNext()) {\n const adGroup = adGroupIterator.next();\n adGroup.addSnippet(newSnippet);\n }\n\n // Add snippet to an account\n const account = AdsApp.currentAccount();\n account.addSnippet(newSnippet);\n}\n```\n\nLog snippet details for a campaign \n\n```gdscript\nfunction logSnippetDetails() {\n // Get a campaign.\n const campaignIterator = AdsApp.campaigns()\n .withCondition('campaign.name = \"INSERT_CAMPAIGN_NAME_HERE\"')\n .get();\n if (!campaignIterator.hasNext()) {\n throw new Error('Campaign not found.');\n }\n const campaign = campaignIterator.next();\n\n // Retrieve the campaign's snippets. Retrieving an ad group's and\n // account's sniuppets is similar.\n const snippetIterator = campaign.extensions().snippets().get();\n for (const snippet of snippetIterator) {\n // You can also request reports for pre-defined date ranges. See\n // https://developers.google.com/adwords/api/docs/guides/awql,\n // DateRangeLiteral section for possible values.\n const stats = snippet.getStatsFor('LAST_MONTH');\n\n console.log(`Snippet header : ${ snippet.getHeader() }`);\n console.log(`Snippet values : ${ snippet.getValues() }`);\n console.log(`mobile preferred : ${ snippet.isMobilePreferred() }`);\n console.log(`clicks : ${ stats.getClicks() }`);\n console.log(`impressions : ${ stats.getImpressions() }`);\n console.log('=======');\n }\n\n console.log(`${snippetIterator.totalNumEntities()} snippets in the campaign`);\n}\n```\n\nSet schedule for snippets in a campaign \n\n```gdscript\nfunction setSnippetSchedule() {\n // Get a campaign.\n const campaignIterator = AdsApp.campaigns()\n .withCondition('campaign.name = \"INSERT_CAMPAIGN_NAME_HERE\"')\n .get();\n if (!campaignIterator.hasNext()) {\n throw new Error('Campaign not found.');\n }\n const campaign = campaignIterator.next();\n\n // Retrieve the campaign's snippets. Retrieving an ad group's and\n // account's saitelinks is similar.\n const snippetIterator = campaign.extensions().snippets().get();\n\n for (const snippet of snippetIterator) {\n if (snippet.getHeader() === 'Brands') {\n // Set snippet schedule to run only on Mondays and Tuesdays, 9 AM to\n // 6 PM.\n const monday = {\n dayOfWeek: 'MONDAY',\n startHour: 9,\n startMinute: 0,\n endHour: 18,\n endMinute: 0\n };\n\n const tuesday = {\n dayOfWeek: 'TUESDAY',\n startHour: 9,\n startMinute: 0,\n endHour: 18,\n endMinute: 0\n };\n\n snippet.setSchedules([monday, tuesday]);\n\n break;\n }\n }\n}\n```"]]