Google Analytics 4¶
Google Analytics is an analytics service that measures traffic and engagement across your websites and apps. It is a new kind of property with different reports than what you are used to seeing in Universal Analytics properties:
Collects both website and app data to better understand the customer journey.
Uses event-based data instead of session-based.
Includes privacy controls such as cookie-less measurement, and behavioral and conversion modeling.
Predictive capabilities offer guidance without complex models.
Direct integrations to media platforms help drive actions on your website or app.
You can configure Denodo to retrieve data from Google Analytics by creating JSON data sources and base views in Denodo using the Google Analytics Data API.
As Google Analytics manages a very large amount of data and views, it may be hard work to add all the required data sources and base views in Denodo. In order to make this process easier and faster, we offer Google Analytics wizard. You just have to configure a few parameters in the form and Execute import into your Denodo server to get access to Google Analytics.
These Wizards for Google Analytics are adapted to Google Analytics 4.
Getting OAuth 2.0 Credentials¶
First, you need to register an application in the Google Cloud Console. This is to obtain the credentials that you will enter later, to connect to the API of this service.
Create a project in the Google Cloud Console.
Enabling Google Analytics Data API v1.
Filling the OAuth consent.
Create OAuth 2.0 credentials.
Note
Fill in with the values corresponding to your environment or see the Google Analytics documentation for more information.
Now, go back to the Design Studio and click the menu Tools > OAuth credential wizards > OAuth 2.0 wizard. Use this wizard to obtain the OAuth access token, and refresh token.
To get the OAuth tokens, enter the following parameters:
Client identifier. The client ID generated in the Google Cloud Console.
Client secret. The client secret generated in the Google Cloud Console.
Token endpoint URL. https://oauth2.googleapis.com/token.
Authorization server URL. https://accounts.google.com/o/oauth2/auth.
Redirect URI. http://localhost:9090/oauth/2.0/redirectURL.jsp.
Scopes. Enter this:
https://www.googleapis.com/auth/analytics.edit
https://www.googleapis.com/auth/analytics
https://www.googleapis.com/auth/analytics.readonly
These scopes are necessary to have the necessary privileges to query your data.
Note
If the callback URL is not externally accessible, the browser will display an error page when you try to get the authorization response URL. Just discard the error and copy the URL at your browser address bar in step 3.
Importing Artifacts¶
Now, you have all the data needed to create the predefined Google Analytics reports.
Click the menu File > New > Data source and select Google Analytics 4.
Provide these values:
Database. Database in which the predefined Google Analytics reports will be created.
Client ID. The client ID generated in the Google Cloud Console.
Client Secret. The client secret generated in the Google Cloud Console.
Access token. The access token generated in the wizard of the previous section.
Refresh token. The refresh token generated in the wizard of the previous section.
Property id. A Google Analytics GA4 property identifier whose events are tracked. You can use the Google Analytics wizard as many times as properties you have defined in your Google Analytics tool to get data of all of them.
View name prefix. You can configure the name prefix of every view and folder created in the Virtual DataPort, to relate the views created by this wizard, to reports of Google Analytics. The maximum length of this parameter is 10 characters.
Redirect URI. The OAuth 2.0 redirect URI configured.
Some of the predefined reports have configurable dimensions. For this, it is necessary to complete these properties:
Traffic dimension. A valid GA4 dimension related to Lifecycle Traffic Acquisition report. Default value is
sessionSource
. Other possible values are:sessionMedium
,sessionSourceMedium
,sourcePlatform
,sessionSourcePlatform
,sessionCampaignName
,sessionCampaignId
,sessionDefaultChannelGroup
.User acquisition dimension. A valid GA4 dimension related to Lifecycle User acquisition report. Default value is
firstUserMedium
. Other possible values are:firstUserMedium
,firstUserSource
,firstUserSourceMedium
,firstUserSourcePlatform
,firstUserCampaignId
,firstUserCampaignName
,firstUserDefaultChannelGroup
,firstUserGoogleAdsAdGroupName
,firstUserGoogleAdsAdNetworkType
.Event dimension. A valid GA4 dimension related to Lifecycle Engagement Events report. Default value is
eventName
.Conversion dimension. A valid GA4 dimension related to Lifecycle Engagement Conversions report. Default value is
eventName
.Pages screens dimensions. A valid GA4 dimension related to Lifecycle Engagement Pages and screens report. Default value is
unifiedScreenClass
. Other possible values are:unifiedPagePathScreen
,unifiedScreenName
,contentGroup
.Page dimension. A valid GA4 dimension related to Lifecycle Engagement Landing page report. Default value is
landingPage
.User dimension. A valid GA4 dimension related to User Demographics details report. Default value is
country
. Other possible values are:city
,region
,language
,interests
,userAgeBracket
,userGender
.Tech dimension. A valid GA4 dimension related to User Tech details report. Default value is
deviceCategory
. Other possible values are:browser
,operatingSystem
,deviceModel
,operatingSystemVersion
,operatingSystemWithVersion
,platform
,platformDeviceCategory
,screenResolution
.
The following properties will allow you to configure the name prefix of every view created in order to be able to relate the views with the GA4 dimension:
Traffic view prefix. The name prefix of the Lifecycle Traffic acquisition report view. The max length of this parameter is 10 characters.
User acquisition view prefix. The name prefix of the Lifecycle User acquisition report view. The max length of this parameter is 10 characters.
Event view prefix. The name prefix of the Lifecycle Engagement Events report view. The max length of this parameter is 10 characters.
Conversion view prefix. The name prefix of the Lifecycle Engagement Conversions report view. The max length of this parameter is 10 characters.
Pages screens view prefix. The name prefix of the Lifecycle Engagement Pages and screens report view. The max length of this parameter is 10 characters
Page view prefix. The name prefix of the Lifecycle Engagement Landing page report view. The max length of this parameter is 10 characters.
User view prefix. The name prefix of the User Demographics details report view. The max length of this parameter is 10 characters.
Tech view prefix. The name prefix of the User Tech details report view. The max length of this parameter is 10 characters.
Now, click Execute import to create the data sources and the views for querying your predefined Google Analytics reports.
Note
In the examples below, we used view1 as the value of the parameter View name prefix.
Real Time Reports¶
${view_name_prefix}_ga4_real_time. Returns a customized report of realtime event data for your property. Events appear in realtime reports seconds after they have been sent to Google Analytics. Realtime reports show events and usage data for the periods of time ranging from the present moment to 30 minutes ago (up to 60 minutes for Google Analytics 360 properties). Required parameters are:
dimensions. The dimension requested for your report.
metrics. The metric requested for your report.
Query With Real Time View¶
Now, you can execute queries over the Google Analytics views that have been created. In this example, we are going to create a
real time report to see the activeUsers
by city
.
Custom Reports¶
${view_name_prefix}_ga4_custom_report. Returns a customized report of your Google Analytics event data. Reports contain statistics derived from data collected by the Google Analytics tracking code. The data returned from the API is as a table with columns for the requested dimensions and metrics. Required parameters are:
dimensions
. A valid Google Analytics dimension.metrics
. A valid Google Analytics metrics.startdate
. Start date for fetching Google Analytics data.enddate
. End date for fetching Google Analytics data.
Query With Custom Report View¶
Now, you can execute queries on the Google Analytics views that have been created. In this example, we are going to create a
custom report to see the sessions
by browser
between 2022-12-01 and 2022-12-31:
Custom Pivot Reports¶
${view_name_prefix}_ga4_custom_pivot_report. Returns a customized pivot report of your Google Analytics event data. In a pivot report, dimensions are only visible if they are included in a pivot. Required parameters are:
dimensions
. A valid Google Analytics dimension.metrics
. A valid Google Analytics metrics.startdate
. Start date for fetching Google Analytics data.enddate
. End date for fetching Google Analytics data.limit_0
. The number of unique combinations of dimension values to return in this pivot.dimension_pivot1
. Dimension name for visible columns in the report response.dimension_pivot2
. Dimension name for visible columns in the report response.
Query With Custom Pivot Report View¶
Now, you can execute queries on the Google Analytics views that have been created. In this example, we are going to create
a custom pivot report to see the sessions
by deviceCategory
and date
between 2022-12-01 and 2022-12-31:
GA4 New Features Predefined Reports¶
These views have fixed metrics while the dimension can be configurable in the Google Analytics wizard.
All of them have two required parameters: startdate
and enddate
:
${traffic_view_prefix}_ga4_traffic. Returns the predefined Lifecycle Traffic Acquisition report with the following parameters:
metrics
. newUsers, engagedSessions, engagementRate, sessionsPerUser, averageSessionDuration, eventCount, conversions, totalRevenue.dimension
. Configurable with the Traffic dimension parameter. Default value is sessionSource.
${user_acquisition_view_prefix}_ga4_user_ac. Returns the predefined Lifecycle User Acquisition report with the following parameters:
metrics
. newUsers, engagedSessions, engagementRate, sessionsPerUser, averageSessionDuration, eventCount, conversions, totalRevenue.dimension
. Configurable with the User acquisition dimension parameter. Default value is firstUserMedium.
${user_view_prefix}_ga4_users. Returns the predefined User Demographics details report with the following parameters:
metrics
. activeUsers, newUsers, engagedSessions, sessionsPerUser, userEngagementDuration, eventCount, conversions, totalRevenue.dimension
. Configurable with the User dimension parameter. Default value is country.
${conversion_view_prefix}_ga4_conversion. Returns the predefined Lifecycle Engagement Conversions report with the following parameters:
metrics
. conversions, totalUsers, totalRevenue.dimension
. Configurable with the Event dimension parameter. Default value is eventName.
${event_view_prefix}_ga4_events. Returns the predefined Lifecycle Engagement Event report with the following parameters:
metrics
. eventCount, totalUsers, eventCountPerUser, totalRevenue.dimension
. Configurable with the Event dimension parameter. Default value is eventName.
${page_view_prefix}_ga4_pages. Returns the predefined Lifecycle Engagement Landing page report with the following parameters:
metrics
. sessions, activeUsers, newUsers, averageSessionDuration, conversions, totalRevenue.dimensions
. Configurable with the Page dimension parameter. Default value is landingPage.
${pages_screens_view_prefix}_ga4_screens. Returns the predefined Lifecycle Engagement Pages and screens report with the following parameters:
metrics
. screenPageViewsPerSession, activeUsers, screenPageViewsPerUser, averageSessionDuration, eventCount,conversions, totalRevenue.dimension
. Configurable with the Pages screens dimension parameter. Default value is unifiedScreenClass.
${tech_view_prefix}_ga4_tech. Returns the predefined User Tech details report with the following parameters:
metrics
. activeUsers, newUsers, engagedSessions, engagementRate, sessionsPerUser, userEngagementDuration, eventCount, conversions, totalRevenue.dimension
. Configurable with the Tech dimension parameter. Default value is deviceCategory.
Query With GA4 Dimension Configurable Reporting Views¶
Newly imported predefined reports can now be executed. In the example below the ${traffic_view_prefix}_ga4_traffic view has been executed with the following configured parameters value:
traffic_view_prefix
= sstraffic_dimension
= sessionSource
Appendix I. How To Use Google Analytics Data API v1¶
The Google Analytics Data API v1 gives you access to report data in Google Analytics platform.
To use the Analytics Data API v1 to request data, you can construct a RunReportRequest
object which has these minimum requirements:
A valid entry in the
dateRangesfield
.At least one valid entry in the
dimensions
field.At least one valid entry in the
metrics
field.
Here you can see the complete RunReportRequest
object.
{
"dimensions": [
{
object (Dimension)
}
],
"metrics": [
{
object (Metric)
}
],
"dateRanges": [
{
object (DateRange)
}
],
"dimensionFilter": {
object (FilterExpression)
},
"metricFilter": {
object (FilterExpression)
},
"offset": string,
"limit": string,
"metricAggregations": [
enum (MetricAggregation)
],
"orderBys": [
{
object (OrderBy)
}
],
"currencyCode": string,
"cohortSpec": {
object (CohortSpec)
},
"keepEmptyRows": boolean,
"returnPropertyQuota": boolean
}
Example¶
Create a report showing eventCount
and sessions
in a Safari browser in VDP.
First, create a new JSON data source by clicking New > Data source > Others > JSON and set HTTP Client as data route:
Finally, you have to configure the data source authentication. You must use the OAuth 2.0 credentials created in your Google Cloud Console.
Requires one of the following OAuth scopes:
https://www.googleapis.com/auth/analytics.readonly
https://www.googleapis.com/auth/analytics scopes.
Click Save.
Once the JSON data source is created, it is time to create the base view to get the Google Analytics report data. Use the CREATE BASE VIEW button for this.
Use properties/YOUR_PROPERTY_ID:runReport
as Relative URL in the base view configuration wizard and use the following json object
as the Post body (you can customize it as you want):
{
"dateRanges": [
{"endDate": "2022-12-31", "startDate": "2022-12-01"}
],
"metrics": [
{"name": "sessions"},
{"name": "eventCount"}
],
"dimensions": [
{"name": "browser" }
],
"dimensionFilter": {
"filter": {
"fieldName": "browser",
"stringFilter": {
"value": "Safari"
}
}
}
}
Now, you can execute the created base view.
The response body of the API request is an instance of a RunReportResponse
object. The structure is defined in the dimensionHeaders
and metricHeaders
objects which describe the dimensions and metrics and their data types in the report. The values of the dimensions and metrics
are specified in the rows
field.
This is the JSON response for the sample report created above:
{
"dimensionHeaders": [
{
"name": "browser"
}
],
"metricHeaders": [
{
"name": "sessions",
"type": "TYPE_INTEGER"
},
{
"name": "eventCount",
"type": "TYPE_INTEGER"
}
],
"rows": [
{
"dimensionValues": [
{
"value": "Safari"
}
],
"metricValues": [
{
"value": "3231"
},
{
"value": "22961"
}
]
}
],
"rowCount": 1,
"metadata": {
"currencyCode": "USD",
"timeZone": "America/Los_Angeles"
},
"kind": "analyticsData#runReport"
}