Learn business growth with Google Analytics 4 Forums Google Analytics 4 How can I retrieve adCost and adClicks information for a property using the GA4 Data API?

  • How can I retrieve adCost and adClicks information for a property using the GA4 Data API?

    Posted by Daniel on 28 June 2022 at 6:38 am

    So, I’ve been trying to adjust to this new GA4 Data API by Google, and hit a bit of a snag. Before on Universal Analytics API, I used to fetch daily total ad cost and ad clicks for a single view with an API request. Now when I try to do that using the advertiserAdCost and advertiserAdClicks metrics on the new system, I get this error message about “incompatible dimensions and metrics”. Any hints on how pulls these details for a single property?

    Also, I tried using the new GA4 Data API explorer folx are talking about. Made this request for fetching metrics: advertiserAdCost, advertiserAdClicks, and advertiserAdCostPerClick for a single day.

    {
      "metrics": [
        {
          "name": "advertiserAdCost"
        },
        {
          "name": "advertiserAdClicks"
        },
        {
          "name": "advertiserAdCostPerClick"
        }
      ],
      "dateRanges": [
        {
          "startDate": "2023-01-11",
          "endDate": "2023-01-12"
        }
      ]
    }
    

    That should have given me a tidy summary of the total ad cost, ad clicks, and ad cost per click data for that day across my website. But guess what? Scored another error message instead. Same as before!

    {
      "error": {
        "code": 400,
        "message": "The dimensions and metrics are incompatible.",
        "status": "INVALID_ARGUMENT"
      }
    }
    
    

    Ah, any help here would be much appreciated.

    Jacob replied 1 year, 4 months ago 3 Members · 2 Replies
  • 2 Replies
  • Pham

    Member
    11 September 2022 at 10:55 am

    Absolutely, I understand your struggle. What’s usually the case with these kind of error messages is that some dimensions and metrics just don’t play well together. It’s like trying to mix oil and water, they just don’t combine. This is usually because the data needed to generate the report across these dimensions and metrics simply doesn’t exist.

    The solution? You would typically need to remove one of the offending dimensions or metrics that is causing the conflict. It’s a bit of a hit-and-miss process to find what works best for your needs, but once you figure it out, you’ll be able to generate the reports you need.

  • Jacob

    Member
    14 November 2022 at 4:54 pm

    The error might be because you’re not adding a dimension to your request. For the new GA4 data API, certain metrics require a corresponding dimension to provide context for your data. In your case, you might need to include ‘sessionCampaignName’ as a dimension. You can test your request using Google’s GA4 Data API’s query explorer, and if the dimension is missing, it will recommend adding it. Including the mentioned dimension should return the result you’re looking for, given that there’s available data related to your metrics.

Log in to reply.