Google Analytics 4 (GA4) Integration
⭐️ Overview
Google Analytics 4 was added to Hyku in v6.0. Google Analytics is enabled at the global application level. Currently, this requires the application/repository administrator and a developer to work in tandem to configure the application. Once the application is configured, tenants can create their own analytics accounts.
Setting up Google Analytics requires configurations in Google Cloud Console, Google Analytics, and the Hyku application. Each tenant will create a Google Analytics account and configure the Hyku application.
What is Google Analytics?
Google Analytics (GA4) is a free tool that tracks users' interactions with the Hyku application.
Hyku can be configured to use Google Analytics to track the following:
Visits to the application
Work views
Collection views
File set views
File set downloads
There is an optional configuration to issue batch emails to depositors with the analytics relating to their works.
Quick Reference
Service Account email address - ends with
gserviceaccount.comMeasurement ID -
G-XXXXXXXXXXJSON key file is sent to the developers, encoded, and added to the application ENV secrets in GitHub
Admin and tenant Service Account email address need to be added to Google Analytics
Account access management
🌎 System Admin
If you are the admin of an individually hosted Hyku application, this is your to-do list.
Task Checklist Overview
Set up Google Cloud Console
Create a Service Account project
Create a Service Account email address
Generate JSON key file
Send JSON key file to the developer
Enable Google Analytics Data API
Create a Google Analytics account
Create a new Account
Create a new Property
Get Measurement ID -
G-XXXXXXXXXXGet Google Analytics Property ID
Add the Service Account email address to the Account access management
Add Google Analytics to Hyku
Enable analytics in Hyku
Enable Google Analytics for a tenant
Provide Service Account email
1. Set up Google Cloud Console
2. Create a Google Analytics account
3. Add Google Analytics to Hyku
4. Enable Google Analytics for a tenant
📚 Tenant
If you are the tenant of the application, this is your to do list.
NOTE: If you are on a manage instance of Hyku, this is your do to list.
Task Checklist Overview
Create a Service Account email address in Google Cloud Console
Create Service Account email address
Create a Google Analytics account
Create a new Property
Get Measurement ID -
G-XXXXXXXXXXGet Google Analytics Property ID
Add the Service Account email address to the Account access management
Add the global admin (or hosted service provider) Service Account email address to the Account access management
Configure Hyku settings
1. Create a Service Account email address in Google Cloud Console
2. Creating a New Google Analytics Account
3. Configure Hyku settings
💻 Developer
If you are the developer with access to GitHub, this is your to do list.
Task Checklist
Encode the JSON key
Add JSON key to ENV variables in GitHub
Encoding the JSON Key
Download the JSON key file.
The admin of the Hyku account should create this file in Google Cloud Console and provide it to the developer.
In terminal, run the following:
base64 -b 0 -i ~/Downloads/<file-name>.json | pbcopyThis will copy the encoded key to your clipboard.
Adding JSON Key to Enable Google Analytics in Hyku
Update
ENV['GOOGLE_ACCOUNT_JSON']with the encoded JSON keyGitHub > Settings > Environments > Add or edit Environment secrets
🔎 Retrieving Existing Account Information
Google Cloud Console
Service account email address - ends with
gserviceaccount.comGo to Google Cloud Console
In the sidebar > IAM & Admin > Service Accounts
JSON private key file
The JSON cannot be retrieved or recreated. If you don't have access to the JSON, create a new key and sent the new JSON file to the development team.
Go to Google Cloud Console
In the sidebar > IAM & Admin > Service Accounts
Click on the newly created Email link > Keys > Add Key > Create new key > JSON > file will be downloaded
Google Analytics
Google Analytics Measurement ID
G-XXXXXXXXXXIn the sidebar > Admin (gear icon) > Property settings > Data collection and modification > Data streams
Click on the side arrow > the Web stream details page will have the Measurement ID
G-XXXXXXXXXX
Google Analytics Property ID
In the sidebar > Admin (gear icon) > Property > Property Details > Property ID is in the upper right corner
Data Visualization (Optional)
In the left navigation, choose “Explore.”
Choose “Blank (Create a new exploration).”
Under “Variables,” click the plus sign ( + ) to the right of “Dimensions.”
Open “Event” and check “Event name.”
Open “Page/Screen” and check “Content ID” and “Content type.”Click “Confirm” in upper right corner.
Under “Variables,” click the plus sign ( + ) to the right of “Metrics.
Open “Event” and check “Event count.”
Click “Confirm” in the upper right corner.
Settings
Drag and drop the Event name, Content type, and Content ID under Rows.
Drag and drop the Event count under Values.
Find “Show rows” and update it to 500.
In the left Navigation choose “Explore” again.
Click the vertical ellipsis / three dots on the right side of the exploration you created and select “Share” from the dropdown. This will read-only share with all users on this GA4 property.