1
votes

I've been trying to use the Analytics API to get site search terms into a Google Ads script. I've used this basic setup before and it worked perfectly, but the data this time doesn't match what's in the interface by a long shot. I've also tried using the query explorer but that's also giving me very different numbers to what's in the interface (by almost a factor of 10).

I've checked and double checked that the metrics and dimensions I'm using are correct, but there really aren't that many options. Does anyone know what I'm doing wrong?

Here's the code I've been using:

  // Build the query for the Analytics API
  var query = {
    "optionalArgs": { "dimensions": "ga:searchKeyword", },
    "ids": "ga:" + analyticsView,
    "metrics": "ga:searchUniques",
    "start-date": startDate,
    "end-date": "yesterday" };
  var results = Analytics.Data.Ga.get(query.ids, query['start-date'], query['end-date'], query.metrics, query.optionalArgs);

  // Format the results for Javascript
  var formattedJson = JSON.stringify(results, null, 2);
  var jsonData = JSON.parse(formattedJson);

  // Iterate through the results 
  for (var i = 0; i < jsonData.rows.length; i++) {
    var row = jsonData.rows[i];
    var searchTerm = row[0];
    var sessions = row[1];

I've tried with ga:sessions instead of searchUniques and a few other combinations of metrics and dimensions but nothing works and based on the documentation the ones I have in the code really seem to me to be the right ones!

2
What exactly are you comparing? Can you put screen shots of the two versions you are comparing. - DaImTo
Well for example (using the same exact date ranges), Analytics interface tells me the top search term is A with 140 unique searches, while the query explorer/API tells me it's B, with 9 unique searches - Jul

2 Answers

0
votes

I've noticed this myself just now (May 2019) when comparing a regular monthly-run API query to the Query Explorer today. The Query Explorer numbers are, similar to your case, at least about nine times greater.

The API-sourced numbers seem to be pretty consistent, and in the past the Query Explorer numbers were in line with the API-sourced numbers, so...

The only conclusion I can make is that the Query Explorer is presently broken (or changed enough it would take significant alteration in its usage to make it not broken).

This is consistent with my expectations of Google code "quality" and "QA".

I would suggest you rely on Google less as much as possible. They do not make reliable products, and they are not interested in your business’ longevity.

0
votes

In case anyone else gets stuck here, my issue was simply that I was limited to a maximum of 10,000 entities returned, and since I wasn't sorting them I was getting 10,000 random ones back and not what I expected. As soon as I sorted them descending by what I needed I got exactly what I expected!