-
Notifications
You must be signed in to change notification settings - Fork 20
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
Fix various bugs with the GA4 pageview tracker #3626
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This fixes a bug where the PIIRemove replaces the _ga/_gl values with [date], and then the regex to strip the values to become _ga=[id]/_gl=[id] does not work properly
If the #content element existed, but had no language on it, it would return this.nullValue instead of jumping out to check the html language value instead. This has been fixed, so that it wont return null when content doesnt have a language on it. It will now only return null if both #content and html do not have a language on them
AshGDS
changed the title
Ga4 pageview fixes
Fix various bugs with the GA4 pageview tracker
Sep 21, 2023
AshGDS
force-pushed
the
ga4-pageview-fixes
branch
from
September 21, 2023 10:44
4c56d5d
to
48ab079
Compare
andysellick
reviewed
Sep 21, 2023
@@ -148,7 +148,9 @@ window.GOVUK.analyticsGa4.analyticsModules = window.GOVUK.analyticsGa4.analytics | |||
var content = document.getElementById('content') | |||
var html = document.querySelector('html') | |||
if (content) { | |||
return content.getAttribute('lang') || this.nullValue | |||
if (content.getAttribute('lang')) { | |||
return content.getAttribute('lang') |
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.
Since you're calling this twice, you should probably store it in a variable.
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.
Whoops, good spot 👍
Thanks @andysellick - should be ready for a re-review 👍 |
andysellick
approved these changes
Sep 22, 2023
AshGDS
added a commit
that referenced
this pull request
Sep 22, 2023
Fix various bugs with the GA4 pageview tracker
Merged
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What
Fixes various bugs with the GA4 pageview tracker. These are:
query_string
parameter, I was redacting PII before stripping_ga
and_gl
. This breaks the _ga/_gl stripping code, as the PIIRemover detects the random characters in these values as[date]
. And therefore the regex for stripping the values would break, as correctly it doesn't count[
and]
as part of the _ga/_gl values.html lang='en'
never being grabbed in certain scenarios. Previously, if the#content
element existed, it would either grab the language value from it, or returnthis.nullValue
straight away. This isn't correct, as we want to check the HTML language value as well before returningthis.nullValue
. Ironically, we couldn't figure out how to test the<html>
element, and if we could we would've spotted this sooner!getLocation
in Redact GA params from pageview data #3568 andgetTitle
in Add personally identifiable information (PII) remover to GTM #2842. The defaultstripPII
function only does extra redaction if certain meta tags exist. We usually usestripPIIWithOverride
so that we can enable date and postcode redaction ourselves.This is a consequence of porting the PIIRemover directly from UA, and not really knowing what we wanted to redact at the time. Eventually we ended up needing to always use the highest level of redaction, so we created
stripPIIWithOverride
to allow this, whereas UA would usestripPII
which would only redact emails, state, password tokens and unlock tokens.stripPII
would only be stricter and redact dates/postcodes if certain meta tags existed on the page. Fortunately onfinder-frontend
, one of the meta tags existed<meta name="govuk:static-analytics:strip-postcodes" content="true">
so postcodes weren't being tracked in searches. Dates however are coming through so this will fix that. This change will also ensure the data/postcode redaction is site-wide.Why
Visual Changes
None.