Posts tagged with google-ads-api

I've been tasked to extract the period comparison data from Google Ads. At the moment a user can select a comparison date period in the ads.google.com UI, to see percentage growth of their ads, from one period to another.

I'd like to extract these comparison percentages from their API.

Does anyone know if this is even possible, or do I have to calculate them myself?

I've read through the API docs, but I'm afraid I missed something.

image of google ads ui

With the script below, I find a number of keywords with AdWordsApp.keywords() based on some parameters. Once these words are found, they must be paused.

My question is the following: How can I use the same list of ExactKeywords, that I have already found, to activate the same keyword in another campaign with a different name than CampaignName?


   var Exact_CampaignName = "CampaignName_1";          function main() {       // Getting list of keywords with cliks       var kw_Conv_Exact = AdWordsApp.keywords()         .withCondition("Click >= 50")         .withCondition("Status = ENABLED")         .withCondition(Exact_CampaignName)         .get();                      // Get Keywords from Campaigns_1       var ExactKeywords = [];       while (kw_Conv_Exact.hasNext()) {         var kw_exact = kw_Conv_Exact.next();         ExactKeywords.push(kw_exact);                       // Pause exaxt keywords.         for(var i in ExactKeywords) {           ExactKeywords[i].pause();         }   //But how do I enable the same keywords from var ExactKeywords = [] but in another campaign_2???      } 


Thanks in advance

I have a Ghost newsletter that has a premium subscription set up with Stripe.

Basically, people go to the /subscribe page, choose a price, get redirected to Stripe, and then upon success, get redirected to the main page /, where the url will now have this appended:

?stripe_portal=success

I want to track Google Adwords conversions when the purchase is made.

I don't know how to do that, as conversion code on the main page would also count normal visits.

I am trying to fetch campaigns' reports from Google Ads API. But, getting an error when trying to fetch data with MCC:

Code:

  import sys,os   from google.ads.google_ads.client import GoogleAdsClient   from google.ads.google_ads.errors import GoogleAdsException   def get_data(client, customer_id):     ga_service = client.get_service("GoogleAdsService", version="v6")     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         """     # Issues a search request using streaming.     response = ga_service.search_stream(customer_id, query=query)     try:         for batch in response:             for row in batch.results:                 print(                     row                 )     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)     if __name__ == "__main__":         # get client object with oauth2         credentials = {'developer_token': "xxxxxxxxxxxxxxx",             'refresh_token': "xxxxxxxxxxxxxxxx",             'client_id': "xxxxxxxxxxxxxxx",             'client_secret': "xxxxxxxxxxxxxxxx"                        }         google_ads_client = GoogleAdsClient.load_from_dict(credentials)              get_data(google_ads_client, 'xxxxxxxxx') 

Wehn Running the code with MCC client ID:

get_data(google_ads_client, 'MANAGER(MCC)_CLIENT_ID') 

I'm Getting Error_1:

Request made: ClientCustomerId: xxxxxxxxx, Host: googleads.googleapis.com:443, Method: /google.ads.googleads.v6.services.GoogleAdsService/SearchStream, RequestId: xxxxxxxxxx, IsFault: True, FaultMessage: Metrics cannot be requested for a manager account. To retrieve metrics, issue separate requests against each client account under the manager account.

I assumed, the solution would be to set a different ClientCustomerId of the account itself, not MCC. So I did, and run the code again with the client id of the direct account, and, got another error:

Wehn Running the code with Account client ID:

get_data(google_ads_client, 'ACCOUNT_CLIENT_ID') 

I'm Getting Error_2:

Request made: ClientCustomerId: xxxxxxx, Host: googleads.googleapis.com:443, Method: /google.ads.googleads.v6.services.GoogleAdsService/SearchStream, RequestId: xxxxxxxxxx, IsFault: True, FaultMessage: User doesn't have permission to access customer. Note: If you're accessing a client customer, the manager's customer id must be set in the 'login-customer-id' header. See https://developers.google.com/google-ads/api/docs/concepts/call-structure#cid

That error essentially says to insert the manager's client id, which I already did and got error_1 (!).

What am I missing here?