pip install kpireport-googleanalytics
- class kpireport_googleanalytics.datasource.GoogleAnalyticsDatasource(report, **kwargs)¶
A Datasource that provides data from the Google Analytics APIs.
This Datasource supports a whitelist of query types:
report: Get a Report from the V4 Reporting API.
query_report()for additional options/arguments.
To use in a View, the type of query is specified as the first argument. Any additional keyword arguments are interpreted as options specific to that query type.
# From within a View member function... df = self.datasources.query("ga", "report", account_like="MyAccount")
The Google service account key file (must be in JSON format.) Refer to the Google Cloud documentation for more information on how to set up this authentication credential. Default
- query(input: str, **kwargs) pandas.core.frame.DataFrame ¶
Query the Google Analytics API.
input (str) – The name of the query command to invoke. Currently supports only “report”.
A DataFrame with the query results.
- query_report(account_like=None, property_like=None, view_like=None, dimensions=None, metrics=None, filters_expression=None, order_bys=None) pandas.core.frame.DataFrame ¶
Request a report from the GA v4 Analytics API.
account_like (str) – the GA account name or ID to search for the view. If not defined, the first account found is used.
property_like (str) – the GA property name or ID to search for the view. If not defined, the first property found is used.
view_like (str) –
the GA view name or ID. If not defined, the first view found is used.
If you have multiple accounts or properties available from your credentials, ensure you set
property_likeif you are using this field, as the default functionality for both of those options is to naively take the first account/property found, which may not have the view you’re looking for.
dimensions (List[str]) – a list of dimensions. These can be just dimension names, or the full object syntax. If one of these dimensions is a “date-like” dimension (e.g., “ga:date.*”), the output DataFrame will have this dimension treated as a DateTimeIndex, making it effectively return something that looks like a time series.
metrics (List[str]) – a list of metrics. These can be just metric expressions, or the full object syntax.
filters_expression (str) – an optional filter expression.
order_bys (List[dict]) – a list of orderings.
pd.DataFramewith dimensions and metrics added.
The dimensions will be the first columns in the resulting table, and each metric returned will be in a subsequent column.
- Return type
Fixes support for Python 3.7