Google Analytics¶
Google Analytics is a great way to track what happens on your website.
The datastore specification have the following attributes :
Parameters |
Details |
---|---|
name |
how you want this datastore be refered as |
type |
should be googleAnalytics |
viewId |
the identification number of the Google Analytics view (see ViewId) |
serviceAccountEmail |
Service account to use (see Google Service Account) |
keyFileLocation |
The location of the p12 key (see Google Service Account) |
Then, you can define any number of tables with the following attributes :
Parameters |
Details |
---|---|
name |
Table name |
viewId |
the identification number of the Google Analytics view (see ViewId) |
startDate |
Starting date of the timeframe |
endDate |
End date of the timeframe |
As you can see in the example below, each table can be provided a startDate and endDate field. You can give it in absolute with a YYYY-MM-DD pattern or using some special keys like today, yesterday, XdaysAgo (where X is a number).
Then, you can define two types of rows, dimensions and measures (more details at Dimensions & Metrics Explorer from Google ). Columns gaName field correspond to the Google Analytics API name and gaType is either dimension or measure. In case of a measure, type is always bigint. For a dimension it’s text.
<datastore name="ga" type="googleAnalytics" viewId="123456789">
<!-- It will import all data from 30 days ago to yesterday -->
<table name="sessions" startDate="30daysAgo" endDate="yesterday">
<!-- We start by defining the dimensions (type = text) -->
<column name="date" type="text" gaName="ga:date" gaType="dimension"/>
<column name="medium" type="text" gaName="ga:medium" gaType="dimension"/>
<column name="source" type="text" gaName="ga:source" gaType="dimension"/>
<column name="campaign" type="text" gaName="ga:campaign" gaType="dimension"/>
<column name="country" type="text" gaName="ga:country" gaType="dimension"/>
<column name="city" type="text" gaName="ga:city" gaType="dimension"/>
<!-- Then measures (type = bigint) -->
<column name="sessions" type="bigint" gaName="ga:sessions" gaType="measure"/>
<column name="bounces" type="bigint" gaName="ga:bounces" gaType="measure"/>
<column name="pageviews" type="bigint" gaName="ga:pageviews" gaType="measure"/>
</table>
</datastore>
View ID¶
The viewId is the view identifier in Google Analytics, it can be defined at the datastore level and/or at the table level. If both are specified, the table one will be choosen.
The viewId can be found on the View Settings on the Admin panel of Google Analytics.
You need also to allow Data Brewery to access the data. For that, you need to create a service account and add the service account email to the User Management settings (just below the View Settings) with Read & Analyse permissions like below: