1. Component Guide
  2. Share links
  3. Track as sharing links
Share links example

Track as sharing links

Where the component is used to allow users to share content on social media, tracking can be added that uses 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_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"
    }
  ]
} %>