### Install Google Authentication Library Source: https://developers.google.com/search-ads/reporting/sample-code/generate-user-credentials Use pip to install the necessary Google authentication library for Python. ```bash $ pip install google-auth-oauthlib ``` -------------------------------- ### Install Python Client Library Source: https://developers.google.com/search-ads/reporting/client-libraries/python-config Use this command to install the Python client library after extracting the tarball. Avoid using `python setup.py` to prevent potential dependency issues. ```bash python -m pip install . ``` -------------------------------- ### SearchAds360Service.Search Query Example Source: https://developers.google.com/search-ads/reporting/concepts/search-reports This example demonstrates a simple SELECT query for campaign data, specifying the fields to retrieve: campaign ID, name, and status. Only these fields will be populated in the response objects. ```sql SELECT campaign.id, campaign.name, campaign.status FROM campaign ``` -------------------------------- ### SearchAds360Service.searchStream Request Example Source: https://developers.google.com/search-ads/reporting/concepts/search-reports This example shows the structure of an HTTP POST request for the searchStream endpoint, including the Host, User-Agent, Content-Type, Accept, and Authorization headers, along with the query parameters. ```http POST /VERSION_NUMBER/customers/CUSTOMER_ID/searchads360:searchStream HTTP/1.1 Host: searchads360.googleapis.com User-Agent: curl Content-Type: application/json Accept: application/json Authorization: Bearer [OAUTH_2.0_ACCESS_TOKEN] Parameters: { "query" : "SELECT campaign.name, campaign.status, segments.device, metrics.impressions, metrics.clicks, metrics.ctr, metrics.average_cpc, metrics.cost_micros FROM campaign WHERE segments.date DURING LAST_30_DAYS" } ``` -------------------------------- ### Operator Examples Source: https://developers.google.com/search-ads/reporting/query/query-grammar Lists the available operators for building conditions in the WHERE clause. ```sql = | != | > | >= | < | <= | IN | NOT IN | LIKE | NOT LIKE | CONTAINS ANY | CONTAINS ALL | CONTAINS NONE | IS NULL | IS NOT NULL | DURING | BETWEEN | REGEXP_MATCH | NOT REGEXP_MATCH ``` -------------------------------- ### Function Examples Source: https://developers.google.com/search-ads/reporting/query/query-grammar Provides a list of predefined functions for date ranges and relative time periods. ```sql LAST_14_DAYS | LAST_30_DAYS | LAST_7_DAYS | LAST_BUSINESS_WEEK | LAST_MONTH | LAST_WEEK_MON_SUN | LAST_WEEK_SUN_SAT | THIS_MONTH | THIS_WEEK_MON_TODAY | THIS_WEEK_SUN_TODAY | TODAY | YESTERDAY ``` -------------------------------- ### Example Campaign Resource Name Source: https://developers.google.com/search-ads/reporting/concepts/api-structure An example of a campaign resource name, showing a specific customer ID and campaign ID. ```text customers/1234567/campaigns/987654 ``` -------------------------------- ### Example JSON Response for Implicit Segmentation Source: https://developers.google.com/search-ads/reporting/concepts/search-reports This is an example of the JSON output when using implicit segmentation, showing how metrics are associated with specific resource names. ```json { "results":[ { "adGroup":{ "resourceName":"customers/1234567890/adGroups/2222222222" }, "metrics":{ "impressions":"237" } }, { "adGroup":{ "resourceName":"customers/1234567890/adGroups/33333333333" }, "metrics":{ "impressions":"15" } }, { "adGroup":{ "resourceName":"customers/1234567890/adGroups/44444444444" }, "metrics":{ "impressions":"0" } } ] } ``` -------------------------------- ### Segmentation Example Source: https://developers.google.com/search-ads/reporting/concepts/search-reports Demonstrates how to segment search results by adding a `segments.FIELD_NAME` to the `SELECT` clause. ```APIDOC ## Segmentation ### Description Segment your search results by adding a `segments.FIELD_NAME` field to the `SELECT` clause of your query. ### Example ```sql SELECT campaign.name, campaign.status, segments.device, metrics.impressions FROM campaign ``` ### Response Example ```json { "results":[ { "campaign":{ "resourceName":"customers/1234567890/campaigns/111111111", "name":"Test campaign", "status":"ENABLED" }, "metrics":{ "impressions":"10922" }, "segments":{ "device":"MOBILE" } }, { "campaign":{ "resourceName":"customers/1234567890/campaigns/111111111", "name":"Test campaign", "status":"ENABLED" }, "metrics":{ "impressions":"28297" }, "segments":{ "device":"DESKTOP" } }, ... ] } ``` See `segments` for a list of available segment fields. ``` -------------------------------- ### Example SearchAds360Service.SearchStream Response Source: https://developers.google.com/search-ads/reporting/concepts/search-reports This JSON string represents a sample response from the `SearchAds360Service.SearchStream` method, showing segmented campaign data. ```json { "results":[ { "campaign":{ "resourceName":"customers/1234567890/campaigns/111111111", "name":"Test campaign", "status":"ENABLED" }, "metrics":{ "impressions":"10922" }, "segments":{ "device":"MOBILE" } }, { "campaign":{ "resourceName":"customers/1234567890/campaigns/111111111", "name":"Test campaign", "status":"ENABLED" }, "metrics":{ "impressions":"28297" }, "segments":{ "device":"DESKTOP" } }, ... ] } ``` -------------------------------- ### LIKE Operator Escaping Example Source: https://developers.google.com/search-ads/reporting/query/query-grammar Demonstrates how to match literal characters like '[', ']', '%', or '_' using the LIKE operator by enclosing them in square brackets. ```sql WHERE campaign.name LIKE '[[]Earth[_]to[_]Mars[]]%' ``` -------------------------------- ### Campaign Start Date Source: https://developers.google.com/search-ads/reporting/api/reference/fields/v0/campaign The date when the campaign began serving ads. ```APIDOC ## campaign.start_date ### Description The date when campaign started in serving customer's timezone in YYYY-MM-DD format. ### Data Type DATE ### Filterable True ### Selectable True ### Sortable True ``` -------------------------------- ### Select Metrics Fields Source: https://developers.google.com/search-ads/reporting/query/query-structure Select metrics fields for a given resource without including other resource fields. This example selects impressions and clicks metrics for the campaign resource. ```sql SELECT metrics.impressions, metrics.clicks FROM campaign ``` -------------------------------- ### Callout Asset Start Date Source: https://developers.google.com/search-ads/reporting/api/reference/fields/v0/asset Information about the start date for callout assets. ```APIDOC ## asset.callout_asset.start_date ### Description Start date of when this asset is effective and can begin serving, in yyyy-MM-dd format. ### Category `ATTRIBUTE` ### Data Type `DATE` ### Filterable True ### Selectable True ### Sortable True ### Repeated False ``` -------------------------------- ### Initialize SearchAds360Client in Python Source: https://developers.google.com/search-ads/reporting/sample-code/run-mcc-query-page Initializes the SearchAds360Client, loading configuration from the default file path if none is specified. It also sets up argument parsing for the login customer ID. ```python search_ads_360_client = SearchAds360Client.load_from_file() parser = argparse.ArgumentParser( description=( 'Retrieves all customer_client for a mcc manager customer and runs a' ' query on each customer_client.' ) ) # Arguments to provide to run the example. parser.add_argument( '-l', '--login_customer_id', type=str, required=True, help=( 'The Search Ads 360 MCC manager login customer ID (10 digits, no' ' dashes). This can be obtained from the UI or from calling' ' ListAccessibleCustomers - ' 'https://developers.google.com/search-ads/reporting/concepts/login-customer-id.' ), ) args = parser.parse_args() search_ads_360_client.set_ids(args.login_customer_id, args.login_customer_id) try: main(search_ads_360_client, args.login_customer_id) except Exception: # pylint: disable=broad-except traceback.print_exc() ``` -------------------------------- ### Initialize Client with YAML File Path Source: https://developers.google.com/search-ads/reporting/client-libraries/python-config Initialize the Search Ads 360 client by providing the path to your YAML configuration file. This file contains authentication details. ```python from util_searchads360 import SearchAds360Client client = SearchAds360Client.load_from_file("path/to/search-ads-360.yaml") ``` -------------------------------- ### Initialize SearchAds360Client in Java Source: https://developers.google.com/search-ads/reporting/sample-code/run-mcc-query-page Initializes the SearchAds360Client with a specified login customer ID and builds the SearchAds360ServiceClient. Handles potential exceptions during client creation and execution. ```java final SearchAds360Client searchAds360Client = SearchAds360Client.newBuilder() .setLoginCustomerId(loginCustomerId) .fromPropertiesFile() .build(); // Creates the Search Ads 360 Service client. SearchAds360ServiceClient client = searchAds360Client.create(); new RunMccQuery().runExample(client, loginCustomerId); ``` -------------------------------- ### GET /searchAds360Fields/{resourceName} Source: https://developers.google.com/search-ads/reporting/api/reference/rest/v0/searchAds360Fields/get Retrieves a specific SearchAds360Field resource by its resource name. This endpoint requires authentication and uses a GET request. ```APIDOC ## GET /searchAds360Fields/{resourceName} ### Description Retrieve a specific SearchAds360Field resource using its resource name. ### Method GET ### Endpoint `https://searchads360.googleapis.com/v0/{resourceName=searchAds360Fields/*}` ### Parameters #### Path Parameters - **resourceName** (string) - Required - The resource name of the field to get. #### Request Body The request body must be empty. ### Response #### Success Response (200) - **SearchAds360Field** (object) - An instance of SearchAds360Field containing details about the requested field. ### Authorization scopes Requires the following OAuth scope: - `https://www.googleapis.com/auth/doubleclicksearch` ``` -------------------------------- ### YAML Configuration for Desktop and Web Application Flows Source: https://developers.google.com/search-ads/reporting/client-libraries/python-config Example YAML configuration for desktop and web application flows. Ensure you replace placeholder values with your actual credentials obtained from Google Cloud Console. ```yaml # Credential for accessing Google's OAuth servers. # Provided by console.cloud.google.com. client_id: INSERT_CLIENT_ID_HERE # Credential for accessing Google's OAuth servers. # Provided by console.cloud.google.com. client_secret: INSERT_CLIENT_SECRET_HERE # Renewable OAuth credential associated with 1 or more Search Ads accounts. refresh_token: INSERT_REFRESH_TOKEN_HERE # Required for manager accounts only: Specify the login customer ID used to # authenticate API calls. This will be the customer ID of the authenticated # manager account. You can also specify this later in code if your application # uses multiple manager account + OAuth pairs. ``` -------------------------------- ### Configure SearchAds360Client from Properties File Source: https://developers.google.com/search-ads/reporting/client-libraries/java-config Use this snippet to initialize the SearchAds360Client by loading credentials and other attributes from a properties file. Ensure the properties file is correctly configured. ```java SearchAds360Client searchAds360Client = SearchAds360Client.newBuilder() .fromPropertiesFile() .build(); ``` -------------------------------- ### GET /customers/{customerId}/customColumns Source: https://developers.google.com/search-ads/reporting/api/reference/rest/v0/customers.customColumns/list Retrieves all custom columns associated with a specific customer. This endpoint uses an HTTP GET request and requires the customer ID as a path parameter. The request body should be empty, and the response will contain a JSON object with an array of custom columns. ```APIDOC ## GET /customers/{customerId}/customColumns ### Description Retrieves detailed information about all custom columns associated with a specific customer. ### Method GET ### Endpoint `https://searchads360.googleapis.com/v0/customers/{customerId}/customColumns` ### Parameters #### Path Parameters - **customerId** (string) - Required - The ID of the customer to apply the CustomColumn list operation to. #### Request Body The request body must be empty. ### Response #### Success Response (200) - **customColumns** (array) - The CustomColumns owned by the provided customer. ### Response Example ```json { "customColumns": [ { "customColumn": "object (CustomColumn)" } ] } ``` ### Authorization scopes Requires the following OAuth scope: - `https://www.googleapis.com/auth/doubleclicksearch` ``` -------------------------------- ### Initialize Client with Default YAML Location Source: https://developers.google.com/search-ads/reporting/client-libraries/python-config Initialize the Search Ads 360 client without specifying a path. The library will automatically look for the YAML configuration file in your `$HOME` directory. ```python from util_searchads360 import SearchAds360Client client = SearchAds360Client.load_from_file() ``` -------------------------------- ### List Accessible Customers using Java Source: https://developers.google.com/search-ads/reporting/sample-code/ListAccessibleCustomers.java This Java code snippet shows how to initialize the SearchAds360Client and use the CustomerServiceClient to list all accessible customer accounts. Ensure your local properties file is configured for authentication. ```java // Copyright 2022 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // https://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package sample; import com.google.ads.searchads360.v0.lib.SearchAds360Client; import com.google.ads.searchads360.v0.services.CustomerServiceClient; import com.google.ads.searchads360.v0.services.ListAccessibleCustomersRequest; import com.google.ads.searchads360.v0.services.ListAccessibleCustomersResponse; /** List all customers that can be accessed by the authenticated Google account. */ public class ListAccessibleCustomers { public static void main(String[] args) { try { // Creates a SearchAds360Client with local properties file final SearchAds360Client searchAds360Client = SearchAds360Client.newBuilder().fromPropertiesFile().build(); // Creates the Customer Service Client. CustomerServiceClient client = searchAds360Client.createCustomerServiceClient(); new ListAccessibleCustomers().runExample(client); } catch (Exception exception) { System.err.printf("Failed with exception: %s%n", exception); exception.printStackTrace(); System.exit(1); } } private void runExample(CustomerServiceClient customerServiceClient) { ListAccessibleCustomersResponse response = customerServiceClient.listAccessibleCustomers( ListAccessibleCustomersRequest.getDefaultInstance()); System.out.printf("Total results: %d%n", response.getResourceNamesCount()); for (String customerResourceName : response.getResourceNamesList()) { System.out.printf("Customer resource name: %s%n", customerResourceName); } } } ``` -------------------------------- ### Customer Resource Name Example Source: https://developers.google.com/search-ads/reporting/api/reference/rest/resource-names Represents a Search Ads 360 customer account. ```text customers/1234567890 ``` -------------------------------- ### GET /v0/{resourceName=searchAds360Fields/*} Source: https://developers.google.com/search-ads/reporting/api/reference/rest Retrieves a specific field from the Search Ads 360 resource. ```APIDOC ## GET /v0/{resourceName=searchAds360Fields/*} ### Description Returns just the requested field. ### Method GET ### Endpoint `/v0/{resourceName=searchAds360Fields/*}` ### Parameters #### Path Parameters - **resourceName** (string) - Required - The resource name of the field to retrieve. Example: `searchAds360Fields/customer.id` ``` -------------------------------- ### Retrieve Customer Details with Java Source: https://developers.google.com/search-ads/reporting/sample-code/get-customers-page Initializes the Search Ads 360 client and retrieves customer information using a stream. Ensure you have the necessary credentials and customer ID configured. ```java SearchAds360ServiceClient client = searchAds360Client.create(); new GetCustomersStream().runExample(client, customerId); ``` ```java String query = """ SELECT customer.id, customer.descriptive_name, customer.account_type, customer.manager, customer.manager_id, customer.manager_descriptive_name, customer.sub_manager_id, customer.sub_manager_descriptive_name, customer.associate_manager_id, customer.associate_manager_descriptive_name, customer.account_level FROM customer """; ``` ```java SearchSearchAds360StreamRequest request = SearchSearchAds360StreamRequest.newBuilder() .setCustomerId(customerId) .setQuery(query) .build(); ``` ```java ServerStream stream = searchAds360ServiceClient.searchStreamCallable().call(request); ``` ```java for (SearchSearchAds360StreamResponse response : stream) { for (SearchAds360Row element : response.getResultsList()) { System.out.printf( "Customer found with ID %d%n" + "\tdescriptive_name: %s%n" + "\taccount_type: %s%n" + "\tis_manager: %s%n" + "\tmanager_id: %d%n" + "\tmanager_descriptive_name: %s%n" + "\tsub_manager_id: %d%n" + "\tsub_manager_descriptive_name: %s%n" + "\tassociate_manager_id: %d%n" + "\tassociate_manager_descriptive_name: %s%n" + "\taccount_level: %s%n", element.getCustomer().getId(), element.getCustomer().getDescriptiveName(), element.getCustomer().getAccountType(), element.getCustomer().getManager(), element.getCustomer().getManagerId(), element.getCustomer().getManagerDescriptiveName(), element.getCustomer().getSubManagerId(), element.getCustomer().getSubManagerDescriptiveName(), element.getCustomer().getAssociateManagerId(), element.getCustomer().getAssociateManagerDescriptiveName(), element.getCustomer().getAccountLevel()); } } ``` -------------------------------- ### Retrieve Campaigns Using Stream Request in Java Source: https://developers.google.com/search-ads/reporting/sample-code/get-campaigns-stream-page Retrieves campaign details using the SearchStream method. This example requires a SearchAds360ServiceClient and a customer ID. It demonstrates how to set up the client and construct the stream request. ```java // Copyright 2022 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // https://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package sample; import com.beust.jcommander.Parameter; import com.google.ads.searchads360.v0.lib.SearchAds360Client; import com.google.ads.searchads360.v0.services.SearchAds360Row; import com.google.ads.searchads360.v0.services.SearchAds360ServiceClient; import com.google.ads.searchads360.v0.services.SearchSearchAds360StreamRequest; import com.google.ads.searchads360.v0.services.SearchSearchAds360StreamResponse; import com.google.api.gax.rpc.ServerStream; /** Get campaign details using SearchStream. */ public class GetCampaignsStream { private static class GetCampaignsStreamParams extends CodeSampleParams { @Parameter(names = "--customerId", required = true) private String customerId; @Parameter(names = "--loginCustomerId") private String loginCustomerId; } public static void main(String[] args) { GetCampaignsStreamParams params = new GetCampaignsStreamParams(); if (!params.parseArguments(args)) { // Optional: You may pass the loginCustomerId on the command line or specify a loginCustomerId // here (10 digits, no dashes). If neither are set, customerId will be used as // loginCustomerId. // params.loginCustomerId = Long.parseLong("INSERT_LOGIN_CUSTOMER_ID_HERE"); } final String loginCustomerId = params.loginCustomerId; final String customerId = params.customerId; try { // Creates a SearchAds360Client with the specified loginCustomerId. If there's // no loginCustomerId, customerId will be used instead. final SearchAds360Client searchAds360Client = SearchAds360Client.newBuilder() .setLoginCustomerId(loginCustomerId == null ? customerId : loginCustomerId) .fromPropertiesFile() .build(); // Creates the Search Ads 360 Service client. SearchAds360ServiceClient client = searchAds360Client.create(); new GetCampaignsStream().runExample(client, customerId); } catch (Exception exception) { System.err.printf("Failed with exception: %s%n", exception); exception.printStackTrace(); System.exit(1); } } private void runExample(SearchAds360ServiceClient searchAds360ServiceClient, String customerId) { // Creates a query that retrieves all campaigns under the customerId. String query = """ SELECT campaign.name, campaign.id, campaign.status FROM campaign """ SearchSearchAds360StreamRequest request = ``` -------------------------------- ### Campaign Resource Name Example Source: https://developers.google.com/search-ads/reporting/api/reference/rest/resource-names Represents a campaign within a Search Ads 360 customer. ```text customers/1234567890/campaigns/8765432109 ``` -------------------------------- ### Retrieve Customer Client Details in Python Source: https://developers.google.com/search-ads/reporting/sample-code/get-customer-client-page Use this Python snippet to fetch customer client information. Ensure you have authenticated and set up the necessary client libraries. ```python from google.ads.googleads.client import GoogleAdsClient def main(client): # Use the GoogleAdsService to get customer clients. google_ads_service = client.get_service("GoogleAdsService") # Create a query that retrieves customer clients. query = "" """ SELECT customer_client.descriptive_name, customer_client.client_customer_id, customer_client.status FROM customer_client """ # Issues a search request. search_params = client.search_params search_params.query = query search_params.customer_id = "CUSTOMER_ID" stream = google_ads_service.search_stream(search_params) for batch in stream: for row in batch.results: customer_client = row.customer_client print( f"Customer client found with name \"{customer_client.descriptive_name}\", " f"customer ID \"{customer_client.client_customer_id}\", " f"and status \"{customer_client.status}\"." ) ``` -------------------------------- ### AdGroup Resource Name Example Source: https://developers.google.com/search-ads/reporting/api/reference/rest/resource-names Represents an ad group within a Search Ads 360 campaign. ```text customers/1234567890/adGroups/54321098765 ``` -------------------------------- ### Retrieve Campaigns Details (Java) Source: https://developers.google.com/search-ads/reporting/sample-code/get-campaigns-page?hl=tr Fetches campaign details including name, ID, and status using the Search Ads 360 client library. This example requires customer ID and optionally a login customer ID for authentication. ```java // Copyright 2022 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // https://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package sample; import com.beust.jcommander.Parameter; import com.google.ads.searchads360.v0.lib.SearchAds360Client; import com.google.ads.searchads360.v0.services.SearchAds360Row; import com.google.ads.searchads360.v0.services.SearchAds360ServiceClient; import com.google.ads.searchads360.v0.services.SearchAds360ServiceClient.SearchPagedResponse; import com.google.ads.searchads360.v0.services.SearchSearchAds360Request; /** Get campaign details. */ public class GetCampaigns { private static final int PAGE_SIZE = 200; private static class GetCampaignsParams extends CodeSampleParams { @Parameter(names = "--customerId", required = true) private String customerId; @Parameter(names = "--loginCustomerId") private String loginCustomerId; } public static void main(String[] args) { GetCampaignsParams params = new GetCampaignsParams(); if (!params.parseArguments(args)) { // Optional: You may pass the loginCustomerId on the command line or specify a loginCustomerId // here (10 digits, no dashes). If neither are set, customerId will be used as // loginCustomerId. // params.loginCustomerId = Long.parseLong("INSERT_LOGIN_CUSTOMER_ID_HERE"); } final String loginCustomerId = params.loginCustomerId; final String customerId = params.customerId; try { // Creates a SearchAds360Client with the specified loginCustomerId. If there's // no loginCustomerId, customerId will be used instead. final SearchAds360Client searchAds360Client = SearchAds360Client.newBuilder() .setLoginCustomerId(loginCustomerId == null ? customerId : loginCustomerId) .fromPropertiesFile() .build(); // Creates the Search Ads 360 Service client. SearchAds360ServiceClient client = searchAds360Client.create(); new GetCampaigns().runExample(client, customerId); } catch (Exception exception) { System.err.printf("Failed with exception: %s%n", exception); exception.printStackTrace(); System.exit(1); } } private void runExample(SearchAds360ServiceClient searchAds360ServiceClient, String customerId) { // Creates a query that retrieves all campaigns under the customerId. String query = """ SELECT campaign.name, campaign.id, campaign.status FROM campaign """ SearchSearchAds360Request request = SearchSearchAds360Request.newBuilder() ``` -------------------------------- ### MaximizeConversionValue Bidding Strategy Source: https://developers.google.com/search-ads/reporting/api/reference/rest/v0/SearchAds360Row An automated bidding strategy to help get the most conversion value for your campaigns while spending your budget. ```APIDOC ## MaximizeConversionValue ### Description An automated bidding strategy to help get the most conversion value for your campaigns while spending your budget. ### JSON Representation ```json { "targetRoas": number } ``` ### Fields - `targetRoas` (number) - The target return on ad spend (ROAS) option. If set, the bid strategy will maximize revenue while averaging the target return on ad spend. If the target ROAS is high, the bid strategy may not be able to spend the full budget. If the target ROAS is not set, the bid strategy will aim to achieve the highest possible ROAS for the budget. ``` -------------------------------- ### Example Search Query for Campaign Performance Source: https://developers.google.com/search-ads/reporting/concepts/search-reports This query retrieves performance data for campaigns over the last 30 days, segmented by device. It selects campaign name, status, device, impressions, clicks, CTR, average CPC, and cost in micros. ```sql SELECT campaign.name, campaign.status, segments.device, metrics.impressions, metrics.clicks, metrics.ctr, metrics.average_cpc, metrics.cost_micros FROM campaign WHERE segments.date DURING LAST_30_DAYS ``` -------------------------------- ### SearchAds360FieldService - Get SearchAds360 Field Source: https://developers.google.com/search-ads/reporting/api/reference/rpc/google.ads.searchads360.v0.services Retrieves a specific Search Ads 360 API field by its resource name. ```APIDOC ## GET /api/searchAds360Fields/{resource_name} ### Description Returns just the requested field. ### Method GET ### Endpoint /api/searchAds360Fields/{resource_name} ### Parameters #### Path Parameters - **resource_name** (string) - Required - The resource name of the field to get. ### Response #### Success Response (200) - **SearchAds360Field** (object) - The requested Search Ads 360 field. ### Errors - AuthenticationError - AuthorizationError - HeaderError - InternalError - QuotaError - RequestError ### Authorization Requires the following OAuth scope: * `https://www.googleapis.com/auth/doubleclicksearch` ``` -------------------------------- ### Query Raw Event Conversion Dimensions and Metrics Source: https://developers.google.com/search-ads/reporting/concepts/custom-floodlight-variables This example demonstrates how to query for specific raw event conversion dimensions and metrics using their IDs. Ensure you have the correct conversion_custom_variable IDs and variable types before running this query. ```sql SELECT raw_event_conversion_dimensions.id[1234], raw_event_conversion_metrics.id[5678] FROM conversion WHERE segments.date=20240118 ``` -------------------------------- ### Resource Name Format Source: https://developers.google.com/search-ads/reporting/query/query-grammar Defines the valid format for resource names. Starts with a letter, followed by alphanumeric characters or underscores. ```regex [a-z] ([a-zA-Z_])* ``` -------------------------------- ### Retrieve Campaigns Details (Java) Source: https://developers.google.com/search-ads/reporting/sample-code/get-campaigns-page?hl=es-419 Fetches campaign details like name, ID, and status for a given customer ID using the Search Ads 360 API. This example requires the `google-ads-searchads360` library and a properties file for client configuration. ```java // Copyright 2022 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // https://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package sample; import com.beust.jcommander.Parameter; import com.google.ads.searchads360.v0.lib.SearchAds360Client; import com.google.ads.searchads360.v0.services.SearchAds360Row; import com.google.ads.searchads360.v0.services.SearchAds360ServiceClient; import com.google.ads.searchads360.v0.services.SearchAds360ServiceClient.SearchPagedResponse; import com.google.ads.searchads360.v0.services.SearchSearchAds360Request; /** Get campaign details. */ public class GetCampaigns { private static final int PAGE_SIZE = 200; private static class GetCampaignsParams extends CodeSampleParams { @Parameter(names = "--customerId", required = true) private String customerId; @Parameter(names = "--loginCustomerId") private String loginCustomerId; } public static void main(String[] args) { GetCampaignsParams params = new GetCampaignsParams(); if (!params.parseArguments(args)) { // Optional: You may pass the loginCustomerId on the command line or specify a loginCustomerId // here (10 digits, no dashes). If neither are set, customerId will be used as // loginCustomerId. // params.loginCustomerId = Long.parseLong("INSERT_LOGIN_CUSTOMER_ID_HERE"); } final String loginCustomerId = params.loginCustomerId; final String customerId = params.customerId; try { // Creates a SearchAds360Client with the specified loginCustomerId. If there's // no loginCustomerId, customerId will be used instead. final SearchAds360Client searchAds360Client = SearchAds360Client.newBuilder() .setLoginCustomerId(loginCustomerId == null ? customerId : loginCustomerId) .fromPropertiesFile() .build(); // Creates the Search Ads 360 Service client. SearchAds360ServiceClient client = searchAds360Client.create(); new GetCampaigns().runExample(client, customerId); } catch (Exception exception) { System.err.printf("Failed with exception: %s%n", exception); exception.printStackTrace(); System.exit(1); } } private void runExample(SearchAds360ServiceClient searchAds360ServiceClient, String customerId) { // Creates a query that retrieves all campaigns under the customerId. String query = """ SELECT campaign.name, campaign.id, campaign.status FROM campaign """ SearchSearchAds360Request request = SearchSearchAds360Request.newBuilder() ``` -------------------------------- ### Field Name Format Source: https://developers.google.com/search-ads/reporting/query/query-grammar Defines the valid format for field names in queries. Starts with a letter, followed by alphanumeric characters, dots, or underscores. ```regex [a-z] ([a-zA-Z0-9._])* ``` -------------------------------- ### ISO 8601 Date Filtering Source: https://developers.google.com/search-ads/reporting/concepts/search-reports Provides examples of using ISO 8601 format (`YYYY-MM-DD`) for specifying dates and date ranges in the `WHERE` clause. ```APIDOC ## ISO 8601 Date Filtering Examples ### Description These examples demonstrate how to use the `YYYY-MM-DD` format for date filtering in the `WHERE` clause. ### Method SELECT ### Endpoint [Resource Name] ### Parameters #### Query Parameters None #### Request Body None ### Request Example 1 (BETWEEN) ```sql WHERE segments.date BETWEEN '2022-06-01' AND '2022-06-30' ``` ### Request Example 2 (Greater/Less Than) ```sql WHERE segments.date >= '2022-06-01' AND segments.date <= '2022-06-30' ``` ### Request Example 3 (Month/Quarter/Year with Equals) ```sql WHERE segments.month = '2022-06-01' ``` ### Response #### Success Response (200) - Varies based on the `SELECT` clause. #### Response Example (See previous examples for response structure) ``` -------------------------------- ### Retrieve Campaigns with Pagination in Python Source: https://developers.google.com/search-ads/reporting/concepts/pagination?hl=th Use this Python script to retrieve campaigns for a specified customer ID. It configures the Search Ads 360 client, sets up the query, and handles pagination to fetch all campaign data. Ensure you have the `google-ads-searchads360` library installed and a `search-ads-360.yaml` configuration file. ```python import argparse import traceback from google.ads.searchads360.v0.services.types.search_ads360_service import SearchSearchAds360Request from util_searchads360 import SearchAds360Client _DEFAULT_PAGE_SIZE = 10000 def main(client, customer_id, page_size) -> None: search_ads_360_service = client.get_service() query = """ SELECT campaign.name, campaign.id, campaign.status FROM campaign""" request = SearchSearchAds360Request() request.customer_id = customer_id request.query = query request.page_size = page_size # Issues a search request. results = search_ads_360_service.search(request=request) for row in results: campaign = row.campaign print( f'campaign "{campaign.name}" has id {campaign.id} and status {campaign.status.name}' ) if __name__ == "__main__": # SearchAds360Client will read the search-ads-360.yaml configuration file in # the home directory if none is specified. search_ads_360_client = SearchAds360Client.load_from_file() parser = argparse.ArgumentParser( description=("Retrieves campaigns for a customer.")) # Arguments to provide to run the example. parser.add_argument( "-c", "--customer_id", type=str, required=True, help="The Search Ads 360 customer ID (10 digits, no dashes).", ) parser.add_argument( "-l", "--login_customer_id", type=str, required=False, help="The Search Ads 360 login customer ID (10 digits, no dashes).", ) args = parser.parse_args() search_ads_360_client.set_ids(args.customer_id, args.login_customer_id) try: main(search_ads_360_client, args.customer_id, _DEFAULT_PAGE_SIZE) except Exception: # pylint: disable=broad-except traceback.print_exc() ``` -------------------------------- ### Select Segments Field Source: https://developers.google.com/search-ads/reporting/query/query-structure Select segments fields without specifying accompanying resource fields or metrics. This example segments results by device. ```sql SELECT segments.device FROM campaign ``` -------------------------------- ### Java Properties for Desktop/Web Flows Source: https://developers.google.com/search-ads/reporting/client-libraries/java-config Use these keys in the `searchads360.properties` file for desktop and web application authentication flows. Ensure you replace placeholder values with your actual credentials. ```properties # Credential for accessing Google's OAuth servers. # Provided by console.cloud.google.com. api.searchads360.clientId=INSERT_CLIENT_ID_HERE # Credential for accessing Google's OAuth servers. # Provided by console.cloud.google.com. api.searchads360.clientSecret=INSERT_CLIENT_SECRET_HERE # Renewable OAuth credential associated with 1 or more Search Ads accounts. api.searchads360.refreshToken=INSERT_REFRESH_TOKEN_HERE # Required for manager accounts only: Specify the login customer ID used to # authenticate API calls. This will be the customer ID of the authenticated # manager account. You can also specify this later in code if your application # uses multiple manager account + OAuth pairs. # # api.searchads360.loginCustomerId=INSERT_LOGIN_CUSTOMER_ID_HERE ```