Phone Numbers
Stay organized with collections Save and categorize content based on your preferences.
Create a call extension
function createPhoneNumber() { // For full details on creating a new call extension, see: // https://developers.google.com/google-ads/scripts/docs/reference/adsapp/adsapp_phonenumberbuilder const newPhoneNumber = AdsApp.extensions().newPhoneNumberBuilder() // Replace the values below with your link country and phone number .withCountry('US') .withPhoneNumber('INSERT_PHONE_NUMBER_HERE') .build() .getResult(); // Add phone number to a campaign const campaignIterator = AdsApp.campaigns() .withCondition('campaign.name = "INSERT_CAMPAIGN_NAME_HERE"') .get(); if (campaignIterator.hasNext()) { const campaign = campaignIterator.next(); campaign.addPhoneNumber(newPhoneNumber); } // Add phone number 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.addPhoneNumber(newPhoneNumber); } }
Log phone number details for a campaign
function logPhoneNumberDetails() { // 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 phone numbers. Retrieving an ad group's and // account's phone number extensions is similar. const phoneNumberIterator = campaign.extensions().phoneNumbers().get(); for (const phoneNumber of phoneNumberIterator) { // 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 = phoneNumber.getStatsFor('LAST_MONTH'); console.log(`Phone number : ${ phoneNumber.getPhoneNumber() }`); console.log(`clicks : ${ stats.getClicks() }`); console.log(`impressions : ${ stats.getImpressions() }`); console.log('======='); } console.log(`${phoneNumberIterator.totalNumEntities()} phone number extensions in the campaign`); }
Set schedule for a call extension in a campaign
function setPhoneNumberSchedule() { // 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 phone numbers. Retrieving an ad group's and // account's phone number extensions is similar. const phoneNumberIterator = campaign.extensions().phoneNumbers().get(); for (const phoneNumber of phoneNumberIterator) { if (phoneNumber.getPhoneNumber() === 'INSERT_PHONE_NUMBER_HERE') { // Set phone number 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 }; phoneNumber.setSchedules([monday, tuesday]); break; } } }
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-08-20 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-20 UTC."],[[["\u003cp\u003eThis script demonstrates how to create and manage call extensions in Google Ads, including adding them to campaigns and ad groups.\u003c/p\u003e\n"],["\u003cp\u003eIt provides functionality to retrieve and log key performance metrics like clicks and impressions for call extensions within a specific campaign for the last month.\u003c/p\u003e\n"],["\u003cp\u003eThe script also illustrates how to set custom schedules for call extensions, controlling the days and times they are active.\u003c/p\u003e\n"],["\u003cp\u003eExample code shows how to configure a call extension to run only on Mondays and Tuesdays between 9 AM and 6 PM.\u003c/p\u003e\n"]]],[],null,["Create a call extension \n\n```gdscript\nfunction createPhoneNumber() {\n // For full details on creating a new call extension, see:\n // https://developers.google.com/google-ads/scripts/docs/reference/adsapp/adsapp_phonenumberbuilder\n const newPhoneNumber = AdsApp.extensions().newPhoneNumberBuilder()\n // Replace the values below with your link country and phone number\n .withCountry('US')\n .withPhoneNumber('INSERT_PHONE_NUMBER_HERE')\n .build()\n .getResult();\n\n // Add phone number 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.addPhoneNumber(newPhoneNumber);\n }\n\n // Add phone number 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.addPhoneNumber(newPhoneNumber);\n }\n}\n```\n\nLog phone number details for a campaign \n\n```gdscript\nfunction logPhoneNumberDetails() {\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 phone numbers. Retrieving an ad group's and\n // account's phone number extensions is similar.\n const phoneNumberIterator = campaign.extensions().phoneNumbers().get();\n\n for (const phoneNumber of phoneNumberIterator) {\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 = phoneNumber.getStatsFor('LAST_MONTH');\n\n console.log(`Phone number : ${ phoneNumber.getPhoneNumber() }`);\n console.log(`clicks : ${ stats.getClicks() }`);\n console.log(`impressions : ${ stats.getImpressions() }`);\n console.log('=======');\n }\n\n console.log(`${phoneNumberIterator.totalNumEntities()} phone number extensions in the campaign`);\n}\n```\n\nSet schedule for a call extension in a campaign \n\n```gdscript\nfunction setPhoneNumberSchedule() {\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 phone numbers. Retrieving an ad group's and\n // account's phone number extensions is similar.\n const phoneNumberIterator = campaign.extensions().phoneNumbers().get();\n\n for (const phoneNumber of phoneNumberIterator) {\n if (phoneNumber.getPhoneNumber() === 'INSERT_PHONE_NUMBER_HERE') {\n // Set phone number 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 phoneNumber.setSchedules([monday, tuesday]);\n\n break;\n }\n }\n}\n```"]]