-
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
Refactor GA4 code #3224
Refactor GA4 code #3224
Conversation
04667a7
to
1202ab3
Compare
1202ab3
to
521a9ea
Compare
a51c58a
to
aafc003
Compare
f83d197
to
8ccaa26
Compare
8ccaa26
to
7dd9b6f
Compare
7dd9b6f
to
1897f74
Compare
1897f74
to
8c3e780
Compare
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.
Looks good, though a small is change needed 👍
8c3e780
to
228b8aa
Compare
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.
LGTM 👍
Thanks @AshGDS. I'm currently looking at expanding this PR further, which is going to involve some changes in the gem first, so I'm going to pause on this for the moment (you might want to withdrawn your approval). |
@andysellick No worries 👍 |
@AshGDS have added some more changes to this PR. This should now fully remove the JS for event listening and setting indexes on the option select and expander component buttons. It's related to this change in the gem for the option select, so will need to be tested together and I'll figure out how to deploy these two changes simultaneously. Haven't updated the docs yet, that's another thing to look at, but should be enough to review for now. |
@AshGDS I've bumped the gem in this PR to include the needed changes to the option select component. If you have time can you give this a final once over to check I've not overlooked anything? I haven't looked at documentation yet, I've just realised... I might do that in a separate PR for the sake of simplicity. |
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.
Looks good 👍
} | ||
var buttonAttributes = this.$module.getAttribute('data-button-data-attributes') | ||
if (buttonAttributes) { | ||
buttonAttributes = JSON.parse(buttonAttributes) |
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.
Does this need to be in a try/catch
?
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.
Good shout, will match the same thing in the option select. Have added.
41ac9ec
to
e8adfdd
Compare
- allow it to accept data attributes to be applied to the expand/collapse button - will allow us to add GA4 tracking via a Rails/component approach and remove some JS - likely to be a breaking change as will depend on some other stuff in a subsequent commit - brings the component more in line with the option select component changes coming here: alphagov/govuk_publishing_components#3750
- removes the need for some of the JS around setting indexes on JS generated elements
- includes the change to the option select component, which allows us to pass data attributes for the JS generated button
e8adfdd
to
98ba043
Compare
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.
Thanks for adding the try/catch
. I may have noticed something regarding the regex
try { | ||
buttonAttributes = JSON.parse(buttonAttributes) | ||
for (var rawKey in buttonAttributes) { | ||
var key = rawKey.replace(/_/i, '-').toLowerCase() |
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.
I just noticed something with this regex which also applies to the one in govuk_publishing_components
Would /i
be irrelevant here as it's capturing a symbol rather than a character, so setting it to insensitive isn't necessary?
Also, should it have the /g
flag instead so that it replaces every instance of an underscore in the key? With the current regex, I think it only works if the key only has one underscore?
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.
That's really helpful, thanks @AshGDS. Yes I think you're right, although for readability I've gone with the replaceAll
function. I've also updated the tests to reflect this.
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.
Once I'm happy with this I'll make the same change on the option select component in the gem as well.
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.
Thanks @andysellick - just to confirm, are we dropping IE11 support? If I recall correctly replaceAll
doesn't work in IE11 (and it seems to not be working when I check in IE11 via BrowserStack). If we're not supporting IE11 anymore then happy to approve the change 👍
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.
Ah thanks for spotting that, hadn't realised. Have reverted it back to replace
.
71caa96
to
8bf9425
Compare
@AshGDS going to hold off on merging this until tomorrow now. Feel free to take your time if you want to look over it again - it's already proved useful! |
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.
Thanks @andysellick 👍 Looks like there's one small thing to fix in the test
@@ -131,7 +131,8 @@ describe('An expander module', function () { | |||
ga4_expandable: '', | |||
ga4_event: { | |||
event_name: 'select_content', | |||
type: 'finder' | |||
type: 'finder', | |||
test_attribute_with_many_underscores: 'oh yes' |
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.
I think this needs to be outside of ga4_event
otherwise it isn't being treated as a data-attribute, so the replace code doesn't get tested against this key.
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.
Thanks for spotting this, have corrected. Have also updated the related PR alphagov/govuk_publishing_components#3767 with the same change.
e140e90
to
5952026
Compare
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.
LGTM 👍
What
Refactor some of the GA4 code in
finder-frontend
, based on @floehopper's previous work in #3166. This moves the logic for generating indexes for GA4 tracking on search elements (the option select and expander components) from the JS into Ruby.Now depends upon this change in the components gem: alphagov/govuk_publishing_components#3750
Why
We want our code to be clean and readable.
Visual changes
None.
Trello card: https://trello.com/c/OdYXlYqQ/673-finder-frontend-code-optimisations