Skip to content
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

Merged
merged 4 commits into from
Jan 31, 2024

Conversation

deborahchua
Copy link
Contributor

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:

  • Views & Navigation
  • Internal Search
  • User Feedback

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):

Screenshot 2024-01-15 at 14 50 07

Page views for gov.uk/sign-in-universal-credit (After):

Screenshot 2024-01-15 at 14 50 39

Unique page views for gov.uk/sign-in-universal-credit (Before):

Screenshot 2024-01-15 at 14 48 51

Unique page views for gov.uk/sign-in-universal-credit (After):

Screenshot 2024-01-15 at 14 49 36

Trello card: https://trello.com/c/c4jN6yxT/3330-migrate-ua-metrics-for-views-navigation-to-bigquery-in-content-data-api-5

⚠️ This repo is Continuously Deployed: make sure you follow the guidance ⚠️

@deborahchua deborahchua marked this pull request as ready for review January 17, 2024 11:27
Copy link
Contributor

@AgaDufrat AgaDufrat left a 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.

app/domain/etl/ga/views_and_navigation_service.rb Outdated Show resolved Hide resolved
app/domain/etl/ga/views_and_navigation_service.rb Outdated Show resolved Hide resolved
spec/domain/etl/ga/concerns/transform_path_spec.rb Outdated Show resolved Hide resolved
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.
@deborahchua deborahchua force-pushed the migrate-views-navigation-metrics-to-ga4-bq branch from 8ebd99f to 60e8072 Compare January 29, 2024 10:28
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.
@deborahchua deborahchua force-pushed the migrate-views-navigation-metrics-to-ga4-bq branch from 60e8072 to 54bfe80 Compare January 29, 2024 10:48
@deborahchua
Copy link
Contributor Author

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.

Thanks @AgaDufrat ! I've made those changes and given my branch one final test on Integration and is good to go 👍

@deborahchua deborahchua merged commit 5cfe0a8 into main Jan 31, 2024
9 checks passed
@deborahchua deborahchua deleted the migrate-views-navigation-metrics-to-ga4-bq branch January 31, 2024 12:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants