mirror of
https://github.com/techno-tim/littlelink-server.git
synced 2024-11-23 05:35:28 +01:00
feat(GoogleAnalytics): Added gtag events for button clicks
This commit is contained in:
parent
bece421882
commit
962742ced7
7
src/analytics/google.js
Normal file
7
src/analytics/google.js
Normal file
@ -0,0 +1,7 @@
|
||||
export function trackEvent(action, category, label, value) {
|
||||
window.gtag('event', action, {
|
||||
event_category: category,
|
||||
event_label: label,
|
||||
value: value,
|
||||
});
|
||||
}
|
@ -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,
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user