Posts tagged with google-ads-api

As per my question, I want to filter the campaign's metrics based on the date range filter read the below code:

 /**  * Runs the example.  *  * @param GoogleAdsClient $googleAdsClient the Google Ads API client  * @param int $customerId the customer ID  */ public static function getGoogleAdCampaigns(GoogleAdsClient $googleAdsClient, int $customerId){     $googleAdsServiceClient = $googleAdsClient->getGoogleAdsServiceClient();     // Creates a query that retrieves all campaigns.     $query = "SELECT campaign.id, campaign.name,campaign.status, metrics.impressions, metrics.clicks, metrics.conversions, metrics.ctr, metrics.average_cpc, metrics.cost_micros, campaign.start_date, campaign.end_date FROM campaign WHERE campaign.status = 'ENABLED'";     // Issues a search stream request.     /** @var GoogleAdsServerStreamDecorator $stream */     $stream = $googleAdsServiceClient->searchStream(         SearchGoogleAdsStreamRequest::build($customerId, $query)     );     // Iterates over all rows in all messages and prints the requested field values for     // the campaign in each row.     // Initialize an array to hold campaign data    $campaigns = [];    // Iterates over all rows in all messages and collects the requested field values for    // the campaign in each row.    foreach ($stream->iterateAllElements() as $googleAdsRow) {        /** @var GoogleAdsRow $googleAdsRow */        $campaigns[] = [            'id' => $googleAdsRow->getCampaign()->getId(),            'name' => $googleAdsRow->getCampaign()->getName(),            'start_date' => $googleAdsRow->getCampaign()->getStartDate(),            'end_date' => $googleAdsRow->getCampaign()->getEndDate(),            'status' => $googleAdsRow->getCampaign()->getStatus(),            'impressions' => $googleAdsRow->getMetrics()->getImpressions(),            'clicks' => $googleAdsRow->getMetrics()->getClicks(),            'conversions' => $googleAdsRow->getMetrics()->getConversions(),            'ctr' => $googleAdsRow->getMetrics()->getCtr(),            'average_cpc' => $googleAdsRow->getMetrics()->getAverageCpc(),            'cost_micros' => $googleAdsRow->getMetrics()->getCostMicros(),        ];    }    // print_r($stream->iterateAllElements());    // Return the collected campaign data array     echo json_encode($campaigns);     exit(); } 

Suppose I want to get last week's clicks, impressions last week's cost, etc.

Reference : https://groups.google.com/g/adwords-api/c/H-6qp8v-k-o?pli=1

I need to create a report on asset performance from google ads transfer data in bigquery. The report should be similar to the one in Google Ads UI (under Assets with assets names, campaigns, clicks etc). I have enabled PMAX within the bigquery data transfer and now have views about Assets (e.g. ads_Assets, ads_CampaignAssetStats etc) When I query ads_CampaignAssetStats I see an asset field campaign_asset_asset of format customers/1111111111/assets/111111111111, I would like to somehow get the name of this particular asset, but I cannot find this in any asset related tables.

So either that data is not available in BQ data transfer and I need to get it from the api or I am not searching or understanding the data. Where can I find this data within BQ data transfer tables (if at all?

I have looked through google ads data transfer documentation expecting some more insights into the asset views but it didn't clarify how I can get the names of the assets.

I have browsed through other tables within BQ google ads data transfer but haven't found a way to connect the data.

I am getting duplicate data in my Big Query tables from Google Ads.

I can look at the tables and see rows with the exact same data. Furthermore when I aggregate the data to see total cost of campaigns, it is double what is shown in the Google Ads platform.

I followed the guide for the data transfer and didn't do anything outside the standard set up. I did do a backfill to get data for the entire month because it originally only imported data for the previous week. I also set the date range on the backfill to not include the week of data already imported. And there are duplicates for everyday of the month.

Has anyone experiences this and know why it is making duplicate entries and if so how do I get rid of the duplicates?

My Google OAuth refresh token expires after one hour, even though both my OAuth and Google Ads API applications are verified and approved.

  • Both OAuth and Google Ads API apps are verified and approved.
  • Created a new client_credentials.json file after approval.
  • Using the provided Laravel example for the PHP Google Ads API.
  • Added the developer token with basic access and populated clientId and clientSecret in the google_ads_php.ini file.

For the refresh token i used command ~/go/bin/oauth2l fetch --credentials CLIENT_SECRET.json --scope adwords to obtain a refresh token. And added this token to google_ads_php.ini too.

Despite these steps, I consistently encounter a "token has been expired or revoked" error after 60 minutes.