Skip to content

Commit

Permalink
Use ga4_extra_data for share links
Browse files Browse the repository at this point in the history
Standardising the naming
  • Loading branch information
AshGDS committed Feb 19, 2024
1 parent 1870fcd commit 5f67a98
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
title ||= false
track_as_sharing ||= false
track_as_follow ||= false
ga4_data ||= {}
ga4_extra_data ||= {}
stacked ||= false
columns ||= false

Expand Down Expand Up @@ -58,15 +58,15 @@
'index_link': index + 1,
'index_total': links.length,
'text': link[:icon],
}.merge(ga4_data)
}.merge(ga4_extra_data)
end
if track_as_follow
ga4_link_data = {
'event_name': 'navigation',
'type': 'follow us',
'index_link': index + 1,
'index_total': links.length,
}.merge(ga4_data)
}.merge(ga4_extra_data)
end
%>
<%
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,10 @@ examples:
Where the component is used to allow users to share content on social media, tracking can be added that uses [Social Interactions](https://developers.google.com/analytics/devguides/collection/analyticsjs/social-interactions) in UA.
If this option is not included, it is assumed the component is simply linking to social media pages and the extra options are omitted from the tracking call in UA.
In GA4, when this is set to true, a JSON is added to a data-attribute called data-ga4-link, which is detected by ga4-link-tracker.js and pushed to the dataLayer.
Most of the tracking values are added by default, but if you need to add more GA4 values or override defaults, you can pass a ga4_data object.
Most of the tracking values are added by default, but if you need to add more GA4 values or override defaults, you can pass a ga4_extra_data object.
data:
track_as_sharing: true
ga4_data: {
ga4_extra_data: {
optional_extra_values: "go here"
}
links: [
Expand All @@ -133,10 +133,10 @@ examples:
description: |
Where the component is used to allow users to follow us on social media, tracking can be added.
When this is set to true, a JSON is added to a data-attribute called data-ga4-link, which is detected by ga4-link-tracker.js and pushed to the dataLayer.
Most of the tracking values are added by default, but if you need to add more GA4 values or override defaults, you can pass a ga4_data object.
Most of the tracking values are added by default, but if you need to add more GA4 values or override defaults, you can pass a ga4_extra_data object.
data:
track_as_follow: true
ga4_data: {
ga4_extra_data: {
optional_extra_values: "go here"
}
links: [
Expand Down
4 changes: 2 additions & 2 deletions spec/components/share_links_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,13 @@ def links
end

it "allows adding extra GA4 attributes for share links" do
render_component(links: [links[0]], track_as_sharing: true, ga4_data: { section: "This is a section", type: "overwritten type" })
render_component(links: [links[0]], track_as_sharing: true, ga4_extra_data: { section: "This is a section", type: "overwritten type" })
assert_select '.gem-c-share-links[data-module="gem-track-click ga4-link-tracker"]'
assert_select '.gem-c-share-links__link[data-ga4-link="{\"event_name\":\"navigation\",\"type\":\"overwritten type\",\"index_link\":1,\"index_total\":1,\"text\":\"facebook\",\"section\":\"This is a section\"}"]'
end

it "allows adding extra GA4 attributes for follow links" do
render_component(links: [links[0]], track_as_follow: true, ga4_data: { section: "This is another section", type: "overwritten type 2" })
render_component(links: [links[0]], track_as_follow: true, ga4_extra_data: { section: "This is another section", type: "overwritten type 2" })
assert_select '.gem-c-share-links[data-module="gem-track-click ga4-link-tracker"]'
assert_select '.gem-c-share-links__link[data-ga4-link="{\"event_name\":\"navigation\",\"type\":\"overwritten type 2\",\"index_link\":1,\"index_total\":1,\"section\":\"This is another section\"}"]'
end
Expand Down

0 comments on commit 5f67a98

Please sign in to comment.