Share links example

Track as sharing links

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

How it looks (preview)

How to call this example

<%= render "govuk_publishing_components/components/share_links", {
  track_as_sharing: true,
  ga4_extra_data: {
    optional_extra_values: "go here"
  },
  links: [
    {
      href: "share",
      text: "Share on Facebook",
      icon: "facebook"
    },
    {
      href: "share",
      text: "Share on Twitter",
      icon: "twitter"
    }
  ]
} %>