Kyon147
Kyon147

Reputation: 798

Google Analytics Reporting API - Getting around sampling?

I am using the Reporting API to get transaction data - such as transactionID but we have quite a lot of sessions and the reports can be sampled when using the browser.

Through the API what is the best practice to detect that sampling has occurred and how would I break down the data set to not sample the data but still get the full result?

I thought about using a date range, then if it returns sampled to reduce the range by half and try again. Then loop through half and half to get the full range.

Upvotes: 0

Views: 1934

Answers (1)

Max
Max

Reputation: 13334

These are the ways you can get around sampling:

  • Sampling Level: set it to LARGE to reduce sampling inaccuracy

  • Smaller date ranges: that's the process you described and what I personally use. I implemented something similar. Don't forget to add to your algorithm the logic of increasing the range. The reason is that if you have irregular traffic, your algorithm will scale the range down to fit the busiest traffic period and will continue processing the rest of the data with that unnecessarily small range, making overall processing unoptimized and time-consuming. What I also do is that I set pageSize to 1 on my initial probing request (because if it's sampled I'm not interested in the data anyways, and processing a response with only 1 entry is faster/takes less network/CPU/memory resources)

  • Filters: sampling basically kicks-in when you ask GA for something that's not available as part of the default reporting. If you can manage to somehow use filters and their search/replace logic to overwrite default dimensions with your custom data, you could pull it out unsampled. Filters working on per-view basis, you could create a view to prepare that data for API reporting purposes.

  • GA 360: if you have the money, you can upgrade to GA 360 which has unsampled exports and higher sampling limits (100M vs 500K sessions if my memory serves)

  • Unsampled Analytics solution: you can use solutions such as Matomo (formerly Piwik) or Mixpanel which provide unsampled reports out of the box.

Upvotes: 1

Related Questions