-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Migrate views navigation metrics to ga4 bq #2005
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent PR, well structured and with great commit messages making it easy to review 😍 – thank you!
I can see that the relevant env vars are set up alphagov/govuk-helm-charts@ad647c2 and present in AWS Secrets Manager.
I left a couple minor inline comments.
We may want to send some comms out before deploying it, I'll check on that.
This commit removes reference to, and the collecting of: - bounces - entrances - exits - page_time / average page_time These metrics were introduced during the development of Content Data but were not fully implemented as the team building it was disbanded whilst it was in it's Beta stage. There are no references to them in content-data-admin and are not available to the user through the UI. These metrics will no longer be collected going forward as we migrate away from UA to GA4/BigQuery. By default these metrics are set to 0 when entries are being made to the database. Further down the line after the migration work is done, we can look at removing these fields from the database once we are confident we don’t need them.
The GA4 API does not have direct mappings available for the metrics we currently collect from UA. Our workaround is to use BigQuery which provides more flexibility and futher processing of GA4's data that we can query. This commit tests the initial connection, and the class will be expanded in future commits as we migrate each service from UA to GA4: - Views & Navigation - Internal Search - User Feedback BigQuery requires the following credentials for authentication: - `project_id` - `private_key` (stored in the credentials JSON) - `client_email` (stored in the credentials JSON) The credentials will be accepted in the form of a file or as JSON. We can store them in environment variables which are then converted into the correct format. For more information see https://cloud.google.com/ruby/docs/reference/google-cloud-bigquery/latest/AUTHENTICATION This is configured locally in local_env.yml and stored in AWS Secrets Manager.
8ebd99f
to
60e8072
Compare
The metrics required will be pre-stored in a table in BigQuery. It will contain data from when GA4 was first made available (since 2022), and will be configured to pull in data from the past 24hrs daily at ~3am where there aren't many users on the site. This may need to be tweaked later to ensure the data is available before the scheduled cron tasks are run in each environment (https://github.com/alphagov/govuk-helm-charts/blob/main/charts/app-config/values-production.yaml#L499-L580) Instead of fetching data from UA we now use the BigQuery API which allows us to query the table for the specific metrics we need. It already returns the information we need in the correct format and reduces the amount of work required post query.
`ga_response_with_govuk_prefix` has not been used in any of the tests and looks like it has been missed previously. We should expect paths that contain the gov.uk prefix to be transformed into it's base path. If an an event already exists with the same path in the Events::GA table, it should update the entry with the aggregative total for the metrics which is then reflected in the Facts::Metrics table.
60e8072
to
54bfe80
Compare
Thanks @AgaDufrat ! I've made those changes and given my branch one final test on Integration and is good to go 👍 |
Google are sunsetting their Universal Analytics (UA) product in July 2024 and is being replaced by Google Analytics 4 (GA4).
Content Data uses three services to obtain various Google metrics on GOV.UK pages:
This PR migrates the Views & Navigation metrics from using UA to GA4/BigQuery. It also includes stopping the collection of some metrics as they are are not actively available to the user (and we will not be collecting in GA4).
We expect GA4 to collect more fine-tuned metrics and therefore the numbers will be higher than what is available in UA.
See individual commits for more detail.
This has been tested on Integration - see screenshots below.
Page views for gov.uk/sign-in-universal-credit (Before):
Page views for gov.uk/sign-in-universal-credit (After):
Unique page views for gov.uk/sign-in-universal-credit (Before):
Unique page views for gov.uk/sign-in-universal-credit (After):
Trello card: https://trello.com/c/c4jN6yxT/3330-migrate-ua-metrics-for-views-navigation-to-bigquery-in-content-data-api-5