1
votes

I'm trying to write a script to calculate customer health scores for my company. Part of the equation entails whether or not they've taken specific actions in the last 90 days, which we track via Google Analytics events.

I'm noticing inconsistency with the results returned by the API causing the script output to be missing records for particular users. For reference, we track which user took each action via custom dimension 4. So at this point I started debugging using the Query Explorer provided by Google (https://ga-dev-tools.appspot.com/query-explorer/), which shows the same inconsistencies.

If I push the start-date back past 75 days, the query results return an empty array for some user IDs... but 75 days ago or less, and the results contain up to 86 events for this user. Shouldn't those events be included in 90daysAgo?

The tests I've run in the query explorer...

First batch of results

  • start-date: 30daysAgo (up to 75daysAgo)
  • end-date: yesterday
  • metrics: ga:totalEvents
  • dimensions: ga:dimension4,ga:date
  • filters: ga:eventAction=@Download;ga:dimension4==1564

This returns 28 events when start-date is set to 30daysAgo and 86 when start-date is set to 75daysAgo.

Second batch of results

  • start-date: 90daysAgo
  • end-date: yesterday
  • metrics: ga:totalEvents
  • dimensions: ga:dimension4,ga:date
  • filters: ga:eventAction=@Download;ga:dimension4==1564

Everything is the same but start-date is now 90daysAgo instead of 75. This query returns 0 results.

Third test

  • start-date: 90daysAgo
  • end-date: yesterday
  • metrics: ga:totalEvents
  • dimensions: ga:dimension4,ga:date
  • filters: ga:eventAction=@Download;ga:dimension4==311651

With my test account, if I push the date back to 90daysAgo, it returns the same 6 events that I get when I run with 75daysAgo or 30daysAgo.

I would expect running the query with the start-date set to 90daysAgo should return at least the same results that 75daysAgo returns for any user ID but instead I'm getting an empty array for a user that I know has events. I'm not sure what else I can do on my end but wasn't sure if I should take this to the Google Issue Tracker yet or if I was overlooking something.

1

1 Answers

1
votes

I somewhat found the answer. Might help if Google made this a little more clear in their documentation, but when doing a regular query on the Analytics, the results may be "sampled" meaning the query only searched a portion of the full events.

In this case, my query was searching ~60% of the events we had tracked and the ones matching my filter were apparently in the other 40%.

I'm looking to see how to use the API to pull unsampled data, but that's the short answer to this problem.