Skip to content
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

Add GA4 tracking to webchat available link #3103

Merged
merged 1 commit into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion app/views/shared/_webchat.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,15 @@
</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-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
7 changes: 7 additions & 0 deletions test/integration/contact_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,11 @@ 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-link='{\"event_name\":\"navigation\",\"type\":\"webchat\",\"text\":\"Speak to an adviser now\"}']"
end
end
Loading