Posts under category Google

I am looking for collect data from Google ADS API into GCP by using Python scripts and it requires to fill these items for authentication in the google-ads.yaml file:

developer_token: client_id: client_secret: refresh_token: login_customer_id: 

I was able to fill these items by asking people in my company or generating it with google python scripts in GitHub but I need to understand the role of each, the docs seems to be disperse with a long learning path.

8/3/2022 13:40:32   NotImplementedError: This is not implemented yet. For currently supported API, see: https://developers.google.com/google-ads/scripts-beta/docs/reference/adsapp/adsapp at Ha (adsapp_compiled:298:11) at new $y (adsapp_compiled:13027:5) at qC.newVideoAd (adsapp_compiled:15250:12) at Object.<anonymous> (adsapp_compiled:18396:54) 
     var youtubeVideoId = "youtubeVideoId";     var adGroupName = "adGroupName" // name of my target video ad group     var displayUrl = "display-url.com";     var finalUrl = "https://final-url.com";     var assetOperation = AdsApp.adAssets().newYouTubeVideoAssetBuilder()         .withName(adName)         .withYouTubeVideoId(youtubeVideoId)         .build();     var videoAsset = assetOperation.getResult();          var videoAdGroup = AdsApp.videoAdGroups()         .withCondition(`Name = '${adGroupName}'`)         .withLimit(1)         .get()         .next();          var videoAdOperation = videoAdGroup.newVideoAd().inStreamAdBuilder()         .withVideo(videoAsset)         .withAdName(adName)         .withDisplayUrl(displayUrl)         .withFinalUrl(finalUrl)         .build()         .getResult();          // Code crash before next statement     if(videoAdOperation.isSuccessful()) {         var videoAd = videoAdOperation.getResult();         Logger.log("VideoAd " + videoAd.getName() + " created.");     } else {         Logger.log(videoAdOperation.getErrors());     } 

Code breaks after videoAdGroup.newVideoAd().inStreamAdBuilder().

Following the google ads script docs everything should works nice.

But when I compile the script, I always get the next error:

I have just found in a Google ads scripts forum somebody who has the same problem here but no solution.

I'm trying to get a list of all campaigns using the Google Ads API. To do this, I use an example from the google-ads-php library, but this code does not work for me. What's weird is that the foreach loop doesn't even run and I don't see the output of var_dump. Can anyone suggest me what I'm doing wrong? Or give a link to an example with working code?

My PHP Symfony class code:

    class CheckController extends AbstractController{     /**      * @Route("/check", name="check")      */     public function index(): Response{         $config = $this->getParameter('kernel.project_dir') . '/google_ads_php.ini';         if (!is_file($config)) return $this->json([$config]);         $oAuth2Credential = (new OAuth2TokenBuilder())             ->fromFile($config)             ->build();         $googleAdsClient = (new GoogleAdsClientBuilder())             ->fromFile($config)             ->withOAuth2Credential($oAuth2Credential)             ->build();         try {             self::runExample(                 $googleAdsClient,                 'xxxxxxxxxx'             );         } catch (GoogleAdsException $googleAdsException) {             printf(                 "Request with ID '%s' has failed.%sGoogle Ads failure details:%s",                 $googleAdsException->getRequestId(),                 PHP_EOL,                 PHP_EOL             );             foreach ($googleAdsException->getGoogleAdsFailure()->getErrors() as $error) {                 /** @var GoogleAdsError $error */                 printf(                     "\t%s: %s%s",                     $error->getErrorCode()->getErrorCode(),                     $error->getMessage(),                     PHP_EOL                 );             }             exit(1);         } catch (ApiException $apiException) {             printf(                 "ApiException was thrown with message '%s'.%s",                 $apiException->getMessage(),                 PHP_EOL             );             exit(1);         }         $test = self::runExample($googleAdsClient, '1138211281');         foreach ($test->iterateAllElements() as $googleAdsRow) {             echo '<pre>';                 var_dump($googleAdsRow->getCampaign()->getId());             echo '</pre>';         }         /*echo '<pre>';                 var_dump($test);         echo '</pre>';*/         foreach ($test->iterateAllElements() as $googleAdsRow) {             /** @var GoogleAdsRow $googleAdsRow */             var_dump($googleAdsRow->getCampaign()->getId());         }         /*return $this->render('base.html.twig', [             'test' => $test         ]);*/          return $this->json([              'message' => 'Welcome to your new controller!',              'path' => 'src/Controller/CheckController.php',          ]);     }     /**      * @param GoogleAdsClient $googleAdsClient      * @param int $customerId      * @return void      * @throws ApiException      */     public static function runExample(GoogleAdsClient $googleAdsClient, int $customerId){         $googleAdsServiceClient = $googleAdsClient->getGoogleAdsServiceClient();         // Creates a query that retrieves all campaigns.         $query = 'SELECT campaign.id, campaign.name FROM campaign ORDER BY campaign.id';         // Issues a search stream request.         /** @var GoogleAdsServerStreamDecorator $stream */         $stream = $googleAdsServiceClient->searchStream($customerId, $query);         // Iterates over all rows in all messages and prints the requested field values for         // the campaign in each row.         foreach ($stream->iterateAllElements() as $googleAdsRow) {             /** @var GoogleAdsRow $googleAdsRow */             printf(                 "Campaign with ID %d and name '%s' was found.%s",                 $googleAdsRow->getCampaign()->getId(),                 $googleAdsRow->getCampaign()->getName(),                 PHP_EOL             );         }         return $stream;     } } 

I've run into an issue with the Google Ads Query Validator and need some help debugging.

  * API Version: v10

  * Query: "SELECT customer.id, metrics.impressions FROM group_placement_view WHERE group_placement_view.placement_type IN ("YOUTUBE_CHANNEL") AND (metrics.impressions + metrics.average_cpm) > 1000000"

  * Result: Invalid Query (errors below)

    * The filtering condition '(metrics.impressions + metrics.average_cpm) > 1000000' in the WHERE clause is not valid. Filtering conditions must take the form of 'field operator operand'. The operators IS NULL and IS NOT NULL take no operand.

  * Link to query result: https://gaql-query-builder.uc.r.appspot.com/v10/share?q=SELECT%20customer.id%2C%20metrics.impressions%20FROM%20group_placement_view%20WHERE%20group_placement_view.placement_type%20IN%20(%22YOUTUBE_CHANNEL%22)%20AND%20(metrics.impressions%20%2B%20metrics.average_cpm)%20%3E%201000000

  * Expected result: Using SQL, I can do arithmetic operation in the "WHERE" clause. This syntax is not valid for GAQL?

How can I filter group_placements WHERE the spend is above X ? There is no metric "spend" or "cost"

I thought to use: (all_conversions * cost_per_all_conversions)

I have been having trouble trying to figure out how to set a range of dates for a given lineItem using the google ads php client library. Basically, what I want to do is make a line item to be available for a specified start date and an end date but no success. In their example they have this snippet:

$lineItem->setStartDateTimeType(StartDateTimeType::IMMEDIATELY); $lineItem->setEndDateTime(             AdManagerDateTimes::fromDateTime(                 new DateTime('+1 month', new DateTimeZone('America/New_York'))             )         ); 

They're setting a start date for the line item to IMMEDIATELY, and and end date to 1 month from the time of creation. I tried passing to AdManagerDateTimes::fromDateTimeString a valid ISO 8601 string and no luck (GAM spits an error). Tried creating a DateTime() instance and passing it to the code above, nothing. I'm not too experienced in php and maybe this is way easier than i think it is but I'm stuck.

Any tips please? Thank you