diff --git a/src/analytics/google.js b/src/analytics/google.js new file mode 100644 index 0000000..0cdbfb0 --- /dev/null +++ b/src/analytics/google.js @@ -0,0 +1,7 @@ +export function trackEvent(action, category, label, value) { + window.gtag('event', action, { + event_category: category, + event_label: label, + value: value, + }); +} diff --git a/src/components/Button/Button.js b/src/components/Button/Button.js index 441aa94..315dbe3 100644 --- a/src/components/Button/Button.js +++ b/src/components/Button/Button.js @@ -1,9 +1,17 @@ import React, { memo } from 'react'; import { string } from 'prop-types'; +import { trackEvent } from '../../analytics/google'; +import { runtimeConfig } from '../../config'; function Button(props) { const { name, href, displayName, logo } = props; + const handleClick = () => { + if (runtimeConfig?.GA_TRACKING_ID) { + trackEvent('click', 'social', name, 1); + } + }; + return ( <> {logo && ( {`${displayName} @@ -29,4 +38,5 @@ Button.propType = { srcSet: string, alt: string.isRequired, href: string, + name: string, };