Posts tagged with google-ads-api

I'd like to get the number of click for each campaign on my account. For display campaign, I use the AdsApp.campaigns collection, and then call the targeting function for each campaign. It works fine.

But pour Performance Max Campaign, I see in the documentation that there is no targeting function for item in AdsApp.performanceMaxCampaign. I can just call the getStatsFor function for the campaign, not for each zone. Is there a way to do something similar to the classic campaign ?

Thanks for your help

Vincent

(1) In the area I am now, Google website is not visitable because of the Great Firewall. But I am using Clash for Windows and I could access and visit Google website. It works well on my browser.

(2)I am testing Google Ads API with simple function in Python like the following through Jupyter Notebook which is installed on my Windows 10 laptop:

import logging logging.basicConfig(level=logging.INFO) from google.ads.googleads.client import GoogleAdsClient from google.ads.googleads.errors import GoogleAdsException    # Define the main function def main(client, customer_id):     ga_service = client.get_service("GoogleAdsService")     query = """         SELECT             campaign.id,             campaign.name         FROM campaign         ORDER BY campaign.id     """     # Issues a search request using streaming.     stream = ga_service.search_stream(customer_id=customer_id, query=query)     # Iterate through the results and print them     for batch in stream:         for row in batch.results:             print(                 f"Campaign with ID {row.campaign.id} and name "                 f"{row.campaign.name}"             ) # Load Google Ads client from storage # Replace "PATH/TO/YOUR/google-ads.yaml" with the actual path to your file googleads_client = GoogleAdsClient.load_from_storage(path=r"C:\Users\tomxi\google-ads.yaml", version="v15") # Get customer ID from user input (optional) # Replace with your desired method of obtaining the customer ID customer_id = "xxxxxxxxxx" # Call the main function try:     main(googleads_client, customer_id) except GoogleAdsException as ex:     print(         f'Request with ID "{ex.request_id}" failed with status '         f'"{ex.error.code().name}" and includes the following errors:'     )     for error in ex.failure.errors:         print(f'\tError with message "{error.message}".')         if error.location:             for field_path_element in error.location.field_path_elements:                 print(f"\t\tOn field: {field_path_element.field_name}")     sys.exit(1) 

(3)I got the error:

[TransportError: HTTPSConnectionPool(host='accounts.google.com', port=443): Max retries exceeded with url: /o/oauth2/token (Caused by SSLError(SSLEOFError(8, '\[SSL: UNEXPECTED_EOF_WHILE_READING\] EOF occurred in violation of protocol (_ssl.c:1006)')))][1] 

(4)I guess the Google Ads API employs some route or something else which is not used or controlled by the Clash for Window on my laptop. I am not sure how to check and change it. Please help me.

How can I optimize the following script? It is timing out due to probably multiple loops. The loops are in order:

1-Loop through all Google Ads accounts.

2-Loop through all Ad Groups.

3-Within each Ad Group, check if any ads have a "DISAPPROVED" status. If yes, append the data to Google Sheets.

  function main() {   var sheetId = 'XXX';   var sheetName = 'XXX';   var spreadsheet = SpreadsheetApp.openById(sheetId);   var sheet = spreadsheet.getSheetByName(sheetName);   if (!sheet) {     sheet = spreadsheet.insertSheet(sheetName);   } else {     // Clear the existing contents     sheet.clearContents();   }   // Adding headers (column names)   var headers = ['Account Name', 'Campaign', 'Ad Group'];   sheet.appendRow(headers);    // Iterating through each client account   var accountIterator = AdsManagerApp.accounts().get();   while (accountIterator.hasNext()) {     var account = accountIterator.next();     AdsManagerApp.select(account);     var adGroupIterator = AdsApp.adGroups()         .withCondition('CampaignStatus = ENABLED')         .withCondition('AdGroupStatus = ENABLED')         .get();     while (adGroupIterator.hasNext()) {       var adGroup = adGroupIterator.next();       // Check if the ad group has any disapproved ads       var disapprovedAdFound = false;       var adIterator = adGroup.ads().get();       while (adIterator.hasNext()) {         var ad = adIterator.next();         if (ad.getPolicyApprovalStatus() === 'DISAPPROVED') {           disapprovedAdFound = true;           break;         }       }       if (disapprovedAdFound) { // Disapproved ads found         // Record the details of the ad group with disapproved ads         sheet.appendRow([           account.getName(),           adGroup.getCampaign().getName(),           adGroup.getName()         ]);       }     }   } } 

Using a third party tool (Appointy.com) to manage appointment sign ups. Goal is to take this conversion data and use it for Google Ads and Google Analytics (GA4). Per Appointy support, the only way to track appointments is through Google Tag manager integration. They have provided us directions on how to connect Tag manager to appointy, but we cannot figure out how to connect the newly created Google Tag to Google Analytics or Google Ads.

The confusing part is the Appointy to Google Tag manager tag uses a custom HTML tag, so there is not an inherently straight forward way (at least to me) on the next steps to integrate the tag in tag manager over to Google Analytics or Google Ads.

Knowing I can't access any code from the third party tool appointy, how do I take this custom HTML tag below and integrate that into Google Ads and Google Analytics?

Here are the only directions I Received from appointy:

How to set up Redirection after booking. ​ The redirection is only possible through Google tag manager. ​ Below are the Steps.

Login to your Google tag manager account. Click on Tag and create New Tag. Choose Tag type as "CUSTOM HTML" Input the below code in CUSTOM HTML and click SAVE. ​

<script>setInterval(function(){ var string = window.location.href; var substring1 = "bookings/confirmation"; if (string.indexOf(substring1) !== -1) { setTimeout(function(){ window.location.assign("Destination URL"); }, 3000); } }, 3000);</script> 

​ After saving you need to setup the trigger. Click on Trigger -> Create new triggers -> Select "All element" -> Select "All Click" and SAVE.