Google Ad Data not showing in Google Analytics 4 API for only one Property

35 Views Asked by At

When calling the Google Analytics API for one of our properties, it's returning 0 every time even though there is data there, but for other properties, it's working fine. Plus, when I make the date range a whole previous month, it works fine.

Has anyone had this issue before? I'm presuming its to do with Google Sampling the data, but how is there a way to get around that or speed up the proccess.

Note:

  • Date range is 2023-11-01 to 2023-11-30 (Whole of last month)
  • I've made sure Google Ads is linked in GA4 Admin.
  • I can see Paid Ad data in my GA4 Dashboard.
const fetchDataFromAnalytics = async (request, propertyID, token, type) => {
      try {
        const response = await fetch(
   `https://analyticsdata.googleapis.com/v1beta/properties/${propertyID}:runReport`,
          {
            method: 'POST',
            headers: {
              'Content-Type': 'application/json',
              Authorization: `Bearer ${token}`,
            },
            body: request,
          }
        );
        const data = await response.json();
        return data;
      } catch (error) {
        console.error('Fetch error:', error.message); // Log the error message
        throw error;
      }
    };

const requestBody = JSON.stringify({
            metrics: [
              {
                name: 'advertiserAdClicks',
              },
              {
                name: 'advertiserAdCost',
              },
              {
                name: 'advertiserAdCostPerClick',
              },
              {
                name: 'advertiserAdCostPerConversion',
              },
            ],
            dimensions: [
              {
                name: 'campaignName',
              },
            ],
            dateRanges: [
              {
                startDate: newStartDate,
                endDate: newEndDate,
              },
            ],
            keepEmptyRows: true,
          });

Returned Row Data

[
    {
        "dimensionValues": [
            {
                "value": "(direct)"
            }
        ],
        "metricValues": [
            {
                "value": "0"
            },
            {
                "value": "0"
            },
            {
                "value": "0"
            },
            {
                "value": "0"
            }
        ]
    },
    {
        "dimensionValues": [
            {
                "value": "(organic)"
            }
        ],
        "metricValues": [
            {
                "value": "0"
            },
            {
                "value": "0"
            },
            {
                "value": "0"
            },
            {
                "value": "0"
            }
        ]
    },
    {
        "dimensionValues": [
            {
                "value": "(referral)"
            }
        ],
        "metricValues": [
            {
                "value": "0"
            },
            {
                "value": "0"
            },
            {
                "value": "0"
            },
            {
                "value": "0"
            }
        ]
    },
    {
        "dimensionValues": [
            {
                "value": "Abandoned Cart"
            }
        ],
        "metricValues": [
            {
                "value": "0"
            },
            {
                "value": "0"
            },
            {
                "value": "0"
            },
            {
                "value": "0"
            }
        ]
    }
]
0

There are 0 best solutions below