feat(GoogleAnalytics): Added gtag events for button clicks

This commit is contained in:
Timothy Stewart 2021-10-09 00:11:39 -05:00
parent bece421882
commit 962742ced7
2 changed files with 17 additions and 0 deletions

7
src/analytics/google.js Normal file
View File

@ -0,0 +1,7 @@
export function trackEvent(action, category, label, value) {
window.gtag('event', action, {
event_category: category,
event_label: label,
value: value,
});
}

View File

@ -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 (
<>
<a
@ -11,6 +19,7 @@ function Button(props) {
href={href}
target="_blank"
rel="noopener noreferrer"
onClick={handleClick}
>
{logo && (
<img className="icon" src={logo} alt={`${displayName} logo`} />
@ -29,4 +38,5 @@ Button.propType = {
srcSet: string,
alt: string.isRequired,
href: string,
name: string,
};