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
Add the track click code from static into the gem. This has involved some changes:
the code is now a module which means that it has to be explicitly called usingEDIT: this was based on a misunderstanding of the code, it always needed to be initialised as a moduledata-module
on the element to be tracked, whereas previously this was done by the presence of other data attributes alone (data-track-category
anddata-track-action
)static
) the above change would be a massive breaking change across all of GOV.UK, which we don't have time to deal with right now. Instead, this code will exist as a small semi-duplication, which is less than ideal, but allows us to use itA side effect of this change was that until the module had been renamed it broke the tests because the
details
component explicitly uses the track click code fromstatic
for tracking, but because it can't access it the test created a dummy object which deleted the real one from the gem. For reference there are some notes below about how to fix this, which I did before realising renaming the track click code was a better solution.Background
The track click code is a simple wrapper to allow easy custom analytics tracking on elements. It should be part of the analytics code but for historical reasons isn't (yet). To make use of it, add
data-module="gem-track-click"
to any element, along with some additional data attributes, and clicking on that element will fire a GA event. You can also put the module on a parent element, then put the tracking attributes on any number of child elements to track them. Note that the elements don't have to be links.See examples in the tests for further clarity.
Why
We need to be able to do track click stuff in Accounts, which only has access to code from the gem, not static.
Visual Changes
None.
Details component
For reference, here's how to update the details component to use the track click code in the gem, not static.
in
details.js
...lines 15 and 16:
change to:
details-spec.js
remove lines 11 to 16:
update this test as follows:
Trello card: https://trello.com/c/2gMj38xR/330-build-analytics