Native Google Analytics Data Connector
The Google Analytics Data Connector is used to read data from the Google Analytics Data API and make it available in the CData Virtuality Server in the relational form. In this way, you can query Google Analytics Data via SQL and write complex queries that are directed to multiple different data sources. For example, a single SQL query can join tables from MySQL and combine them with data coming from Google Analytics Data.
Connector Configuration
Metadata
Before issuing the SQL queries to the Google Analytics Data, we need to configure a connection using the SYSADMIN.createConnection()
procedure.
The connection can be created in several ways:
via client email and private key:
CODE
|
via OAuth2 providing a
refreshToken
:
CODE
|
via OAuth2 providing an
authCode
andredirectUri
:
CODE
|
Usage
The Google Analytics Data data is represented as a relational table account
and procedures listProperties
, getMetricsDimensions
and runReport
in the schema named as the alias name given in createDatasource()
.
SELECT Query
To query these tables, a normal SQL select query like the following can be used:
CODE
|
Examples
CODE
|
To get properties, use the listProperties()
stored procedure. Use parent:accounts/
with an account name from accounts
table in filter
parameter:
CODE
|
To get metrics and dimensions, use the getMetricsDimensions
stored procedure
To get the default metrics and dimensions, use 0
value for the propertyId
parameter:
CODE
|
To get the default and custom metrics and dimensions, use the appropriate propertyId
returned by the listProperties()
stored procedure:
CODE
|
runReport Procedure
To query actual data from an Analytics account, you can use the runReport
stored procedure
runReport
with default metrics and dimensions:
CODE
|
runReport
with default and custom metrics and dimensions:
CODE
|
Here is the full list and meaning of the procedure parameters:
Parameter | Description |
---|---|
| Property ID. Available propertyIds can be retrieved by |
| Start date to query data from |
| End date to query data to |
| Date range. You can specify either one date period using the Format: |
| Comma-separated list of requested metrics (specified without the 'ga:' prefix) |
| Comma-separated list of requested dimensions; may be null or skipped |
| Comma-separated list of dimensions or metrics that determine the sort order for Analytics data; may be null or skipped. Format: [{dimension/metric=<value>},{...},..]. The second parameter can be provided for dimension:
|
| Boolean descending order. Data is sorted in descending order if the parameter is set to |
| Comma-separated list of dimension filters; may be null or skipped. Formats:
Match types:
|
| Comma-separated list of exclude dimension filters; may be null or skipped. Format: |
| Comma-separated expressions with |
| Currency code; may be null or skipped |
| Boolean. Shows empty rows if set to |
| Offset of record to start returning data from; may be null or skipped |
| Maximum results to return for the request; may be null or skipped |
Formally the procedure returns all possible columns (for all possible default metrics and dimensions and 2 more columns - customMetrics
and customDimensions
. These 2 columns contain arrays of values for custom metrics and dimensions), but for all columns that are not passed with the metrics
and dimensions
parameters, it returns null. To cut off such redundant columns, use the appropriate projection in the SELECT
clause.
Google Analytics Data connector is available since v4.0.6
getMetricsDimensions
stored procedure is available since v4.0.8
customMetrics
and customDimensions
columns of the runReport
stored procedure are available since v4.0.8
authCode
and redirectUri
support is available since v4.0.8