Google Analytics Data API only returns Google Ads campaigns with clicks

55 Views Asked by At

I´m trying to use the Google Analytics Data API to download Google Ads data (impressions, clicks, cost) per campaign for a given week. When I compare the data that I get from the API with the data that I (CSV) export from Google Ads in CSV format, it seems that the API does not return any campaigns that had no clicks (but some impressions). I`d like to see all campaigns, even if they had only impressions, but no clicks. How can I achieve this? Please see below the request json of my API call from GA4 Query Explorer, my PHP code and a comparison of the data that I get from the API and the CSV export. Thanks a lot!

GA4 Query Explorer json query:

{"dimensions":[{"name":"campaignName"}],"metrics":[{"name":"advertiserAdClicks"},{"name":"advertiserAdCost"},{"name":"advertiserAdImpressions"}],"dateRanges":[{"startDate":"2023-09-25","endDate":"2023-10-1"}],"keepEmptyRows":true}

PHP code for similar query:

$client = $this->getClient();

// Make an API call.
$response = $client->runReport([
    'property' => 'properties/' . $this->getGa_propertyID(),
    'dateRanges' => [
        new DateRange([
            'start_date' => $startDate,
            'end_date' => $endDate,
        ]),
    ],
    'dimensions' => [
        new Dimension(['name' => 'sessionCampaignName']),
        //new Dimension(['name' => 'year']),
        //new Dimension(['name' => 'isoWeek']),
    ],
    'metrics' => [
        new Metric(['name' => 'advertiserAdImpressions']), 
        new Metric(['name' => 'advertiserAdClicks']), 
        new Metric(['name' => 'advertiserAdCost']), 
        
    ],
    'orderBys' => [
        new OrderBy([
            'dimension' => new OrderBy\DimensionOrderBy([
                'dimension_name' => 'sessionCampaignName', 
                'order_type' => OrderBy\DimensionOrderBy\OrderType::ALPHANUMERIC
            ]),
            'desc' => false,
        ]),
    ],
    'keepEmptyRows' => true,  
    
]);

return $response;

Comparison of data from API and Google Ads CSV export (please note that the first element in the API list (left) is the first campaign that also has clicks) enter image description here

0

There are 0 best solutions below