Google Analytics is a fantastic tool, however there is a certain type of Google Analytics account situation that can make things a bit awkward.
An account collects enough Google Analytics data to cause sampling to occur, however they don’t have the funds to afford premium. What do they do?
Simple! You use the Google Analytics core reporting API. You can also do this to graph certain data points at hourly level granularity which is pretty neat.
Important Things To Consider
- Google Analytics Core Reporting API has some limits, both quota and request. 50,000 requests per project per day and 10 queries per second per IP address.
- We will be extracting data out of Google Analytics, so you will need some place to store it.
- The data you extract out of Google Analytics will use the default last non-direct click attribution model (as long as it’s not from a multi channel report).
Next you’ll want to ask some questions to decide what data you want to extract, how often you want to extract it, etc.
Questions To Ask
- What metrics and dimensions do I want to store to my DB for reference?
- What granularity do I want to store at?
- What kind of delay do I want to store at to allow for Google Analytics data latency period?
- What will I do if the data I pull through the API doesn’t exactly match the user interface data on a 1:1 ratio? What variance should I consider acceptable?
Step 1) Setup Your Credentials & Authentication
Now that we’ve identified the questions we want to answer, the first step is to enable authentication with Google APIs. I like to use service accounts, although they definitely have their downside with other Google APIs.
Configure your service account authentication by following these instructions (PHP).
Step 2) Make Your First Calls To Google Analytics API
After you enable your configurations, you’ll be able to make your first calls to your Google Analytics account through the API.
Step 3) Configure Your Segment, Your Dimensions & Metrics, And Your Date Interval
Tweak the default script above to do more custom things, such as introducing optional parameters, filtering, and segmenting like below. I recommend keeping the date interval as granular as you can, because this keeps your session counts low (and reduces risk of sampling).
You can see below that I built a segment to only return sessions from a specific country on a specific date set, per api call.
Hopefully this gives you the foundation to work around the sampling issues you’re dealing with. If not, feel free to post in the comments!
Latest posts by austin (see all)
- How To Minimize Google Analytics Sampling For Free Accounts - May 30, 2018
- How Google Analytics Sequence & Conditional Segments Actually Work… - May 30, 2018
- Google Tag Manager: Image Click Tracking - August 19, 2017