How to detect sampling in Google Analytics API v4? - google-analytics-api

Google Analytics Core Reporting API v3 has the containsSampledData field we can use to see if results have been sampled. How is this done in v4? Can't find anything about it in the documentation.

There are two fields you will need to read from the API response:
reportData.samplesReadCounts: If the results are sampled, this returns the total number of samples read, one entry per date range. If the results are not sampled this field will not be defined.
resportData.samplingSpaceSizes: If the results are sampled, this returns the total number of samples present, one entry per date range. If the results are not sampled this field will not be defined.
GAV4 - Analytics Reporting API V4 Compatibility Library Analytics
The API release was accompanied by the release of a compatibility library which converts Core Reporting API V3 requests into Analytics Reporting API V4 requests and V4 responses into V3 responses. To determine if the response was sampled you simply need to check if these fields are set in the response:
# Calculated sampling.
report_data = report.get('data', {})
sample_sizes = report_data.get('samplesReadCounts', [])
sample_spaces = report_data.get('samplingSpaceSizes', [])
if sample_sizes and sample_spaces:
data['sampleSize'] = sample_sizes[0]
data['sampleSpace'] = sample_spaces[0]
data['containsSampledData'] = True
else:
data['containsSampledData'] = False
Migrating from V3 to V4
There is a detailed Migration guide and Developer guide which describe how to determine if a V4 response contains sampled data.

Related

Where are the methods specified that are needed to analyse an Analytics Data API V1 Beta report?

I have added GTM and GA4 to some website apps to produce tables of detailed stats on click-throughs of ads per advertiser for a date range. I now have suitable reports working successfully using Data Studio, but my attempts to do the same using the PHP implementation of Analytics Data API V1 Beta (in order to do batch runs covering many date ranges) repeatedly hit a brick wall: the methods needed to analyse the response from instantiating BetaAnalyticsDataClient and then invoking runPivotReport or batchRunReports or batchRunPivotReports (and so on) appear not be specified.
The only example that I could work from is the ‘quickstart’ one that does a basic dimension and metric retrieval, and even this employs:
getRows()
getDimensionValues()
getValue()
getMetricValues
that do not appear in the API documentation, at least that I can find.
The JSON response format for each report is of course documented: for example the output from running runPivotReport is documented as an instantiation of runPivotReportResponse.
But nowhere can I find a specification of the methods to be used to traverse the JSON tree (vide getDimensionValues() above) and extract some output data.
Guesswork has taken me part way, but purely for example, when retrieving pivot data, should a
getPivotDimensionHeaders()[0]
be followed by a
getDimensionValues()
or a
getPivotDimensionValues()
I am obviously approaching this all wrong, but what should I do, please?

Querying multiple timeseries using Stackdriver/Cloud Monitoring Rest API

I am trying to use the Google Cloud monitoring REST APIs to get timeseries data of my project. I have been looking at the documentation here: https://cloud.google.com/monitoring/api/ref_v3/rest/v3/projects.timeSeries/list
I do not see any API where I can query for multiple timeseries (with different filters each) using one single REST call. Is that possible with the available APIs ?
For example, for a given timerange, I might want to get the kubernetes/cpu/usage metric with certain filters and the kubernetes/memory/usage metric with a different set of filters in one single REST API call.

Why do returned data rows from Google Analytics Reporting API include zero values for metrics?

I use the Google Analytics (GA) Reporting API to retrieve custom data from my GA views. Often my queries include a mixture of standard and custom dimensions regarding different URLs and their respective page views, e.g. something like ga:pagePath, ga:pageTitle, ga:dimensionX, where dimensionX is set on a hit level and send with every page view (like publishing date or some CMS identifier).
The returned data regularly includes rows that represent some kind of dimension combination with 0 page views. How can that be? Why would GA report a data point with 0 hits?
PS: I don't use 360, so sampling applies.
Looks like you have set includeEmptyRows: true in the request.
includeEmptyRows boolean
If set to false, the response does not include rows if all the
retrieved metrics are equal to zero. The default is false which will
exclude these rows.
from: https://developers.google.com/analytics/devguides/reporting/core/v4/rest/v4/reports/batchGet#ReportRequest

Bing Maps REST API Basic key returns different results than Enterprise key

This unstructured format
http://dev.virtualearth.net/REST/v1/Locations?addressLine=3712%20Adelaide&adminDistrict=TX&locality=The%20Colony&countryRegion=US&postalCode=75056&maxRes=1&key=YourKey
does not seem to return the same result as this structured format
http://dev.virtualearth.net/REST/v1/Locations/US/TX/75056/The%20Colony/3712%20Adelaide?o=json&key=YourKey
The structured format is returning high confidence and the unstructured format is returning medium. What am I missing?
Edit: I never would have expected this. I have discovered the unstructured format returns medium confidence with my current API key and returns high confidence with a new trial key. What does this mean?
Trying the URL's you provided I see the exact same results with the same high confidence value.
Here is the response from the Microsoft Bing Team:
Issue Definition: Question regarding Bing Maps REST Location API service. Scope Agreement: As per our communication, you provided a query for 3712 Adelaide, The Colony, TX 75056 with the Bing Maps REST Location API with a Basic and Enterprise key and received different results and you would like to know the reason. The reason you are receiving different results is because we are in the middle of deploying new information to the Bing Maps REST geocoder. This information is first flighted on Basic (free) accounts before it is released to Enterprise customers.
Our Product Group let us know that it should be deployed to all Enterprise customers by the end of this month.

Google Analytics API TotalEvents query

I'm trying to get a total count for a give event,however I get a number much bigger(10-20 times bigger), than I see on the GA website, what am I doing wrong? (api v3)
here is the segment
metric:
ga:totalEvents
segment:
dynamic::ga:eventCategory==mycategory;ga:eventAction==myaction;ga:eventLabel==mylabel
note that I get wrong results with the query explorer as well.
You are using a segment instead of a filter.
Segments are session based so it will include all events in a session if it matches you specification. So essentially if I triggered the event you want plus other events they will all be included in the total events field.
What you need to do Is remove the segment and add a filter, the filter will include only the data you request.
Hope that helps