I am trying to use Google Ads on Google Apps Script using this guide. I created client id and client secret on Google Console's API & Services.

Not too sure if this configuration is correct but the account is linked to Google Apps Script as I have pagespeed insights as well and there are some requests on the dashboard. I added https://www.googleapis.com/auth/drive as the scope. Again not too sure if I should add Google Ads to the scope. Lastly, got my refresh token from Google Auth playground. When I run the script above I got the following error:

Error: No access token received: {   "error": "invalid_client",   "error_description": "Unauthorized" } authenticate_   @ test.gs:120 withRefreshToken    @ test.gs:144 initializeOAuthClient   @ test.gs:28 

Honestly not too sure what I am doing wrong here so any help would be very much appreciated. Thank you.

Edit Codes:

//From Google Console API & Services var CLIENT_ID = '"MY_CLIENT_ID'; var CLIENT_SECRET = 'MY_CLIENT_SECRET'; //From Google Authplayground var REFRESH_TOKEN = 'REFRESH_TOKEN'; // Enter scopes which should match scopes in File > Project properties // For this project, e.g.: https://www.googleapis.com/auth/drive var SCOPES = "https://www.googleapis.com/auth/adwords"; // Script ID taken from 'File > Project Properties' var SCRIPT_ID = 'MY_SCRIPT_ID'; var authUrlFetch; // Call this function just once, to initialize the OAuth client. function initializeOAuthClient() {   if (typeof OAuth2 === 'undefined') {     var libUrl = 'https://developers.google.com/google-ads/scripts/docs/examples/oauth20-library';     throw Error('OAuth2 library not found. Please take a copy of the OAuth2 ' +         'library from ' + libUrl + ' and append to the bottom of this script.');   }   var tokenUrl = 'https://accounts.google.com/o/oauth2/token';   authUrlFetch = OAuth2.withRefreshToken(tokenUrl, CLIENT_ID, CLIENT_SECRET,     REFRESH_TOKEN, SCOPES); } /**  * Execute a remote function.  * @param {string} remoteFunctionName The name of the function to execute.  * @param {Object[]} functionParams An array of JSON objects to pass to the  *     remote function.  * @return {?Object} The return value from the function.  */ function executeRemoteFunction(remoteFunctionName, functionParams) {   var apiParams = {     'function': remoteFunctionName,     'parameters': functionParams   };   var httpOptions = {     method: 'POST',     headers: {       'Content-Type': 'application/json'     },     payload: JSON.stringify(apiParams)   };   var url = 'https://script.googleapis.com/v1/scripts/' + SCRIPT_ID + ':run';   var response = authUrlFetch.fetch(url, httpOptions);   var data = JSON.parse(response.getContentText());   // Retrieve the value that has been returned from the execution.   if (data.error) {     throw Error('There was an error: ' + response.getContentText());   }   return data.response.result; } // Paste in OAuth2 library here, from: // https://developers.google.com/google-ads/scripts/docs/examples/oauth20-library 

I have pasted the oauth2.0 library under the codes above.

Edit 2
I fixed the part of function initializeOAuthClient. It now shows execution complete, but when I try to run function executeRemoteFunction I am getting TypeError: Cannot read property 'fetch' of undefined. I am guessing I have to input remoteFunctionName and functionParams but where do I find them?

I'm using Google Tag Manager to set a Google Ads conversion tag in my website. When I was debugging using the Tag Assistant window from GTM, my conversion tag was fired successful. When I opened the Tag Assistant Legacy extension from Chrome, I found two error messages related to the "Google Ads Conversion Tracking" tag:

  • "An error occured while the tag was fired: net::ERR_ABORTED"
  • "Error while sending request: net::ERR_ABORTED"

How can I solve this error messages?

Other tags such as "Google Tag Manager", "Global Site Tag (gtag.js)" or "Remarketing Tag" had no errors.

My site is https://mardemor.com.br

Thanks

At the moment I am getting stats this way:

    $adWordsServices = new AdWordsServices();     $session = (new AdWordsSessionBuilder())->fromFile($this->account->token)->withOAuth2Credential($this->oAuth2Credential)         ->build();     $managedCustomerService = $adWordsServices->get(         $session,         ManagedCustomerService::class     );     // Create selector.     $selector = new Selector();     $selector->setFields(['CustomerId', 'Name']);     $selector->setOrdering([new OrderBy('CustomerId', SortOrder::ASCENDING)]);     $selector->setPaging(new Paging(0, 100)); 

but how to get statistics for all accounts active and inactive? This code returns only list of active accounts.

I am trying to implement App Tracking Transparency in my app. I tried to do this on first ViewControllor, but it crashes the app after uploading to the test flight.

After this, I found a lot of info that this should be done in appDelegate I did this way. Of course, I have set NSUserTrackingUsageDescription in Info.plist

I tried to figure it out with this post.

In the debugger, I always see "Not Determined". Could anyone please help with this?

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {         // Override point for customization after application launch.         requestTrackingPermission()         GADMobileAds.sharedInstance().start(completionHandler: nil)         return true     } 

The function

func requestTrackingPermission() {       if #available(iOS 14, *) {         // ATTrackingManager.requestTrackingAuthorization { status in         ATTrackingManager.requestTrackingAuthorization(completionHandler: { status in           switch status {           case .authorized:             // Tracking authorization dialog was shown             // and we are authorized             print("Authorized")                           // Now that we are authorized we can get the IDFA             print(ASIdentifierManager.shared().advertisingIdentifier)                          case .denied:             // Tracking authorization dialog was             // shown and permission is denied             print("Denied")           case .notDetermined:             // Tracking authorization dialog has not been shown             print("Not Determined")           case .restricted:             print("Restricted")           @unknown default:             print("Unknown")           }         }       )}     } 

I have configured a Google Ads DataTransfer stream from Google Ads to my GoogleBigQuery project. It runs, data flows, everything is fine. But when I decided to build a query that return an amount of money spend in the context of distinct combination of utm_marks (source, medium, campaign) I've faced a trouble with 'doublicated' data.

So, the query firstly goes to Adstat Table and takes the stats of every creativeId (I suppose creativeId means Ad) in every campaignId. Then it takes an every utm_marks from AdTrackingUrlTemplate of every creativeId from every campaign. Finally it merges two tables in one and in the output I have a full info about stats for every utm_mark.

Query looks like this:

 with   Adstat as (             select *              from `myproject.GoogleAds.AdStats_7394379271`         ),  Ad as (         select              CampaignId,              CreativeId,              REGEXP_EXTRACT(CreativeTrackingUrlTemplate, r"[?&]utm_source=([^&]+)") as source,             REGEXP_EXTRACT(CreativeTrackingUrlTemplate, r"[?&]utm_medium=([^&]+)") as medium,             REGEXP_EXTRACT(CreativeTrackingUrlTemplate, r"[?&]utm_campaign=([^&]+)") as campaign         from              `myproject.GoogleAds.p_Ad_7394379271`         where              CreativeTrackingUrlTemplate is not null          and              CreativeTrackingUrlTemplate!="{lpurl}"         group by              CampaignId, CreativeId, source, medium, campaign        ) select     date, CampaignId, CreativeId, impressions,      Clicks, Cost, Cost * 1.2/1000000 as adCost, source, medium, campaign from      Adstat  left join       Ad using (CampaignId, CreativeId) where      date = '2021-11-26' and      CampaignId = 1688777252 and      CreativeId = 328994634699 

output:

date CampaignId CreativeId impressions Clicks adCost source medium campaign
2021-11-26 1688777252 328994634699 1 1 10 google cpc _cntr_sale_15
2021-11-26 1688777252 328994634699 1 1 10 google cpc cntr_sale_16
2021-11-26 1688777252 328994634699 1 1 10 google cpc cntr_sale_17

And there is a trouble. If a creativeId during its lifetime has a several utm_marks in AdTrakingTemplate, all of them will go to result and all of them will receive a stats from AdStats Table (you can see at in output: same date, same CreativeAd, same stats, but different utms). So we have a double (triple,quadriple) impressions, clicks, amount spent etc. It's a pretty common case, because it's easier from manager to change a tracking template, than create a new Ad or Campaign in Google Ads.

And, unfortunatly, I don`t know, how to figure it out, cause there no way to determ which exactly utm_marks were in createiveIdTrakingTemplate when some stat actcions (impressions, click, etc) were performed.

Does anyone know, how to deal with it? Thanks for help!