Share links example

Track as follow links

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_extra_data object.

How it looks (preview)

How to call this example

<%= render "govuk_publishing_components/components/share_links", {
  track_as_follow: true,
  ga4_extra_data: {
    optional_extra_values: "go here"
  },
  links: [
    {
      href: "follow",
      text: "Follow us on Facebook",
      hidden_text: "",
      icon: "facebook"
    },
    {
      href: "follow",
      text: "Follow us on Twitter",
      hidden_text: "",
      icon: "twitter"
    }
  ]
} %>