diff --git a/packages/gatsby-plugin-google-gtag/src/index.js b/packages/gatsby-plugin-google-gtag/src/index.js index 8be786d406d73..455ba289465c6 100644 --- a/packages/gatsby-plugin-google-gtag/src/index.js +++ b/packages/gatsby-plugin-google-gtag/src/index.js @@ -1,50 +1,51 @@ import React from "react" import PropTypes from "prop-types" -function OutboundLink(props) { - return ( - { - if (typeof props.onClick === `function`) { - props.onClick(e) - } - let redirect = true - if ( - e.button !== 0 || - e.altKey || - e.ctrlKey || - e.metaKey || - e.shiftKey || - e.defaultPrevented - ) { - redirect = false - } - if (props.target && props.target.toLowerCase() !== `_self`) { - redirect = false - } - if (window.gtag) { - window.gtag(`event`, `click`, { - event_category: `outbound`, - event_label: props.href, - transport_type: redirect ? `beacon` : ``, - event_callback: function() { - if (redirect) { - document.location = props.href - } - }, - }) - } else { - if (redirect) { - document.location = props.href - } +const OutboundLink = React.forwardRef(({ children, ...props }, ref) => ( + { + if (typeof props.onClick === `function`) { + props.onClick(e) + } + let redirect = true + if ( + e.button !== 0 || + e.altKey || + e.ctrlKey || + e.metaKey || + e.shiftKey || + e.defaultPrevented + ) { + redirect = false + } + if (props.target && props.target.toLowerCase() !== `_self`) { + redirect = false + } + if (window.gtag) { + window.gtag(`event`, `click`, { + event_category: `outbound`, + event_label: props.href, + transport_type: redirect ? `beacon` : ``, + event_callback: function() { + if (redirect) { + document.location = props.href + } + }, + }) + } else { + if (redirect) { + document.location = props.href } + } - return false - }} - /> - ) -} + return false + }} + > + {children} + +)) OutboundLink.propTypes = { href: PropTypes.string,