Skip to content

Commit

Permalink
Add GA4 tracking to webchat available link
Browse files Browse the repository at this point in the history
  • Loading branch information
AshGDS committed Feb 20, 2024
1 parent dd69bf5 commit 9dcb822
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
11 changes: 10 additions & 1 deletion app/views/shared/_webchat.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,16 @@
</span>
<span class="js-webchat-advisers-available govuk-!-display-none">
<%= t("shared.webchat.available") %>
<a href="#" data-redirect="<%= @content_item.webchat.open_url_redirect.present? ? 'true' : 'false' %>" rel="external" class="js-webchat-open-button"><%= t("shared.webchat.speak_to_adviser") %></a>.
<a
href="#"
data-redirect="<%= @content_item.webchat.open_url_redirect.present? ? 'true' : 'false' %>"
rel="external"
class="js-webchat-open-button"
data-module="ga4-link-tracker"
data-ga4-track-links-only
data-ga4-link="<%= { event_name: "navigation", type: "webchat", text: t("shared.webchat.speak_to_adviser", lang: :en) }.to_json %>">
<%= t("shared.webchat.speak_to_adviser") %>
</a>.
</span>
<% end %>
</span>
Expand Down
8 changes: 8 additions & 0 deletions test/integration/contact_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,12 @@ class ContactTest < ActionDispatch::IntegrationTest
# reset back to default driver
Capybara.use_default_driver
end

test "has GA4 tracking on the webchat available link" do
setup_and_visit_content_item("contact", { base_path: "/government/organisations/hm-passport-office/contact/hm-passport-office-webchat", details: { "more_info_webchat": "<p>Some HTML</p>\n" } })

assert_selector ".js-webchat-advisers-available a[data-module=ga4-link-tracker]"
assert_selector ".js-webchat-advisers-available a[data-ga4-track-links-only]"
assert_selector ".js-webchat-advisers-available a[data-ga4-link='{\"event_name\":\"navigation\",\"type\":\"webchat\",\"text\":\"Speak to an adviser now\"}']"
end
end

0 comments on commit 9dcb822

Please sign in to comment.