Skip to content

Commit

Permalink
Rename data-ga4 to data-ga4-event
Browse files Browse the repository at this point in the history
  • Loading branch information
AshGDS committed Nov 24, 2022
1 parent bf6fac1 commit 9916830
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
this.$module.showOrHideAllButton = this.$module.querySelectorAll('.js-step-controls-button')[0]

if (showAllGa4Data) {
this.$module.showOrHideAllButton.setAttribute('data-ga4', showAllGa4Data)
this.$module.showOrHideAllButton.setAttribute('data-ga4-event', showAllGa4Data)
this.$module.showOrHideAllButton.setAttribute('data-ga4-expandable', '') // Enables tracking of aria-expanded in ga4-event-tracker.
this.$module.removeAttribute('data-ga4-show-all-attributes') // Remove it to prevent repetition. The JSON lives there temporarily until the HTML it is needed on is rendered by this JS.
}
Expand Down Expand Up @@ -176,9 +176,9 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
var title = thisel.querySelectorAll('.js-step-title')[0]
var contentId = thisel.querySelectorAll('.js-panel')[0].getAttribute('id')
var titleText = title.textContent || title.innerText // IE8 fallback
var ga4Data = title.getAttribute('data-ga4')
var ga4Data = title.getAttribute('data-ga4-event')

ga4Data = ga4Data ? "data-ga4-expandable data-ga4='" + ga4Data + "'" : '' // Construct GA4 data-attributes for ga4-event-tracker.
ga4Data = ga4Data ? "data-ga4-expandable data-ga4-event='" + ga4Data + "'" : '' // Construct GA4 data-attributes for ga4-event-tracker.

title.outerHTML =
'<span class="js-step-title">' +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
index: step_index + 1,
index_total: steps.length
}.to_json %>
data-ga4="<%= ga4_data %>"
data-ga4-event="<%= ga4_data %>"
<% end %>
>
<%= step[:title] %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ examples:
with_google_analytics_4_tracking:
description: |
The ga4_tracking boolean allows you to add Google Analytics 4 (GA4) tracking to your component.
Setting this to true will add a data-ga4 attribute and data-ga4-expandable attribute to the "Show all steps" button, and each clickable Step heading.
Setting this to true will add a data-ga4-event attribute and data-ga4-expandable attribute to the "Show all steps" button, and each clickable Step heading.
GA4 will then track these elements when they are expanded or collapsed.
data-ga4 contains a JSON with event data relevant to our tracking. data-ga4-expandable enables the value of aria-expanded to be captured.
data-ga4-event contains a JSON with event data relevant to our tracking. data-ga4-expandable enables the value of aria-expanded to be captured.
See the ga4-event-tracker docs for more information.
data:
ga4_tracking: true
Expand Down

0 comments on commit 9916830

Please sign in to comment.