Google Analytics Data Connector
The Google Analytics Data API gives you programmatic access to Google Analytics 4 (GA4) report data.
Pre-requisites
You need the
privateKeyId
,privateKey
,authType
,timeout
,clientEmail
,clientId
parameters.
How to Connect
To connect the Google Analytics Data connector, you need to deploy the connector (if not already deployed) and configure the connection.
To check if the connector is already deployed, run this command:
SELECT "deployed" FROM "SYSADMIN.ModularConnectors" WHERE "name" = 'google-analytics-data';;
Deploy the connector using the
SYSADMIN.deployModularConnector
procedure:
CALL "SYSADMIN.deployModularConnector"(
"name" => 'google-analytics-data',
"deploy" => true
);;
Configure the connection using the
SYSADMIN.createConnection()
procedure.
The connection can be created in several ways:
via client email and private key:
CALL SYSADMIN.createConnection ( name => 'analytics_data_ds' ,jbossCLITemplateName => 'ga4' ,connectionOrResourceAdapterProperties => 'timeout=<timeout>,authType=<authType>,privateKeyId=<privateKeyId>,privateKey=<privateKey>,clientEmail=<clientEmail>,clientId=<clientId>');;
CALL SYSADMIN.createDataSource ( name => 'analytics_data_ds' ,translator => 'analytics_data' ,modelProperties => '' ,translatorProperties => '');;
via OAuth2 providing a
refreshToken
:
CALL SYSADMIN.createConnection("name" => 'analytics_data_ds', "jbossCLITemplateName" => 'ga4', "connectionOrResourceAdapterProperties" => 'authType="authorized_user",clientSecret=<client secret>,refreshToken=<refresh token>,clientId=<client Id>,timeout=100') ;;
CALL SYSADMIN.createDataSource("name" => 'analytics_data_ds', "translator" => 'ga4', "modelProperties" => '', "translatorProperties" => '', "encryptedModelProperties" => '', "encryptedTranslatorProperties" => '') ;;
via OAuth2 providing an
authCode
andredirectUri
:
CALL SYSADMIN.createConnection("name" => 'analytics_data_ds', "jbossCLITemplateName" => 'ga4', "connectionOrResourceAdapterProperties" => 'authType="authorized_user",clientSecret=<client secret>,clientId=<client Id>,authCode=<auth code>,redirectUri=<redirect URI>,timeout=100') ;;
CALL SYSADMIN.createDataSource("name" => 'analytics_data_ds', "translator" => 'ga4', "modelProperties" => '', "translatorProperties" => '', "encryptedModelProperties" => '', "encryptedTranslatorProperties" => '') ;;
'No translator found with the specified name' Error
If the modular connector has not been deployed before running the SYSADMIN.createDataSource connection, you will see the following error message:
Message from SYSADMIN.createDataSource: No translator found with the specified name: ...
In this case, deploy the connector as described in Step 1 above.
Usage
Select the metrics and dimensions you need. Use the CreateProcedure_ReplicateData
procedure to create your own data retrieval procedure.
Available Dimensions
API Name | UI Name |
---|---|
| Achievement ID |
| Ad format |
| Ad source |
| Ad unit |
| App version |
| Audience ID |
| Audience name |
| Interests |
| Browser |
| Campaign ID |
| Campaign |
| Character |
| City |
| City ID |
| Cohort |
| Daily cohort |
| Monthly cohort |
| Weekly cohort |
| Content group |
| Content ID |
| Content type |
| Continent |
| Continent ID |
| Country |
| Country ID |
| Date |
| Date + hour (YYYYMMDDHH) |
| Date hour and minute |
| Day |
| Day of week |
| Day of week name |
| Default channel group |
| Device category |
| Device model |
| Event name |
| File extension |
| File name |
| First session date |
| First user campaign ID |
| First user campaign |
| First user default channel group |
| First user Google Ads account name |
| First user Google Ads ad group ID |
| First user Google Ads ad group name |
| First user Google Ads ad network type |
| First user Google Ads campaign ID |
| First user Google Ads campaign |
| First user Google Ads campaign type |
| First user Google Ads creative ID |
| First user Google Ads customer ID |
| First user Google Ads keyword text |
| First user Google Ads query |
| First user manual ad content |
| First user manual term |
| First user medium |
| First user source |
| First user source / medium |
| First user source platform |
| Full page URL |
| Google Ads account name |
| Google Ads ad group ID |
| Google Ads ad group name |
| Google Ads ad network type |
| Google Ads campaign ID |
| Google Ads campaign |
| Google Ads campaign type |
| Google Ads creative ID |
| Google Ads customer ID |
| Google Ads keyword text |
| Google Ads query |
| Group ID |
| Hostname |
| Hour |
| Is conversion event |
| ISO week of the year |
| ISO year |
| ISO week of ISO year |
| Item affiliation |
| Item brand |
| Item category |
| Item category 2 |
| Item category 3 |
| Item category 4 |
| Item category 5 |
| Item ID |
| Item list ID |
| Item list name |
| Item list position |
| Item location ID |
| Item name |
| Item promotion creative name |
| Item promotion creative slot |
| Item promotion ID |
| Item promotion name |
| Item variant |
| Landing page + query string |
| Language |
| Language code |
| Level |
| Link classes |
| Link domain |
| Link ID |
| Link text |
| Link URL |
| Manual ad content |
| Manual term |
| Medium |
| Method |
| Minute |
| Device brand |
| Device |
| Mobile model |
| Month |
| New / returning |
| Nth day |
| Nth hour |
| Nth minute |
| Nth month |
| Nth week |
| Nth year |
| Operating system |
| OS version |
| Operating system with version |
| Order coupon |
| Outbound |
| Page location |
| Page path |
| Page path + query string |
| Page referrer |
| Page title |
| Percent scrolled |
| Platform |
| Platform / device category |
| Region |
| Screen resolution |
| Search term |
| Session campaign ID |
| Session campaign |
| Session default channel group |
| Session Google Ads account name |
| Session Google Ads ad group ID |
| Session Google Ads ad group name |
| Session Google Ads ad network type |
| Session Google Ads campaign ID |
| Session Google Ads campaign |
| Session Google Ads campaign type |
| Session Google Ads creative ID |
| Session Google Ads customer ID |
| Session Google Ads keyword text |
| Session Google Ads query |
| Session manual ad content |
| Session manual term |
| Session medium |
| Session SA360 ad group name |
| Session SA360 campaign ID |
| Session SA360 campaign |
| Session SA360 creative format |
| Session SA360 engine account ID |
| Session SA360 engine account name |
| Session SA360 engine account type |
| Session SA360 keyword text |
| Session SA360 medium |
| Session SA360 query |
| Session SA360 source |
| Session source |
| Session source / medium |
| Session source platform |
| Shipping tier |
| Signed in with user ID |
| Source |
| Source / medium |
| Source platform |
| Stream ID |
| Stream name |
| Test data filter ID |
| Test data filter name |
| Transaction ID |
| Page path and screen class |
| Page path + query string and screen class |
| Page title and screen class |
| Page title and screen name |
| Age |
| Gender |
| Video provider |
| Video title |
| Video URL |
| Virtual currency name |
| Visible |
| Week |
| Year |
| Year month |
| Year week |
Available Metrics
API Name | UI Name |
---|---|
| 1-day active users |
| 28-day active users |
| 7-day active users |
| Active users |
| Add to carts |
| Ad unit exposure |
| Ads clicks |
| Ads cost |
| Ads cost per click |
| Cost per conversion |
| Ads impressions |
| Average purchase revenue |
| ARPPU |
| Average purchase revenue per user |
| ARPU |
| Average session duration |
| Bounce rate |
| Cart-to-view rate |
| Checkouts |
| Cohort active users |
| Cohort total users |
| Conversions |
| Crash-affected users |
| Crash-free users rate |
| DAU / MAU |
| DAU / WAU |
| Ecommerce purchases |
| Engaged sessions |
| Engagement rate |
| Event count |
| Event count per user |
| Events per session |
| Event value |
| First-time purchaser conversion |
| First time purchasers |
| First-time purchasers per new user |
| Item-list click events |
| Item list click through rate |
| Item-list view events |
| Item view events |
| Items added to cart |
| Item promotion click through rate |
| Item revenue |
| Items checked out |
| Items clicked in list |
| Items clicked in promotion |
| Items purchased |
| Items viewed |
| Items viewed in list |
| Items viewed in promotion |
| New users |
| Organic google search average position |
| Organic google search clicks |
| Organic google search click through rate |
| Organic google search impressions |
| Promotion clicks |
| Promotion views |
| Publisher ad clicks |
| Publisher ad impressions |
| Purchaser conversion |
| Purchase-to-view rate |
| Return on ad spend |
| Views |
| Views per session |
| Views per user |
| Scrolled users |
| Session conversion rate |
| Sessions |
| Sessions per user |
| Shipping amount |
| Tax amount |
| Total ad revenue |
| Total purchasers |
| Total revenue |
| Total users |
| Transactions |
| Transactions per purchaser |
| User conversion rate |
| User engagement |
| WAU / MAU |
Examples
1. Creating an ActiveUsersInCountry
procedure that returns a dataset with three fields: country, userGender, activeUsers
:
CALL analytics_data_ds.CreateProcedure_ReplicateData( dimensions => 'country,userGender', metrics => 'activeUsers', procName => 'ActiveUsersInCountry');;
The procedure makes use of the following parameters:
dimensions
: comma-separated list of dimensionsmetrics
: comma-separated list of metricsprocName
: name of the procedure to be created
2. Calling the ActiveUsersInCountry
procedure to get data:
CALL analytics_data_ds.ActiveUsersInCountry( propertyId => <propertyId>, startDate => '2023-06-01', endDate => '2023-06-21', preview => true);;
For instructions on how to get the property identifier, please refer to the Google Analytics Data API documentation.
A useful tool is Google Query Explorer. You can construct a query there and see if it will return any data or if the result should be empty for the given combination of dimensions/metrics.