Skip to content

Commit 6d8242c

Browse files
authored
Merge pull request #1365 from fedspendingtransparency/FDG-hover-fix
FDG 9526 GA4 Hover Fix
2 parents 84be6e3 + f267b31 commit 6d8242c

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

src/components/home-main-content/home-main-content.jsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,19 @@ import HomeHighlightCards from '../home-highlight-cards/home-highlight-cards';
44
import { mainContent, sectionHeader, highlightCardsHeader } from './home-main-content.module.scss';
55
import { faChartColumn } from '@fortawesome/free-solid-svg-icons';
66
import CustomLink from '../links/custom-link/custom-link';
7+
import Analytics from '../../utils/analytics/analytics';
8+
import { ga4DataLayerPush } from '../../helpers/google-analytics/google-analytics-helper';
79

810
const HomeMainContent = () => {
11+
const analyticsHandler = label => {
12+
Analytics.event({
13+
category: 'Homepage Navigation',
14+
action: 'Citation Click',
15+
label: label,
16+
});
17+
};
918
const datasetSearchPage = (
10-
<CustomLink url="/datasets/" id="Dataset Search">
19+
<CustomLink url="/datasets/" id="Dataset Search" onClick={() => analyticsHandler('Dataset Search')}>
1120
Dataset Search page
1221
</CustomLink>
1322
);

src/components/topics-section/homepage-tile/homepage-tile.jsx

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import { Grid } from '@material-ui/core';
2222
import Analytics from '../../../utils/analytics/analytics';
2323
import { ga4DataLayerPush } from '../../../helpers/google-analytics/google-analytics-helper';
2424

25+
let homepageTile;
2526
const ExplainerTile = ({ content, images, width, layout, hasMobileImage, explainerTile }) => {
2627
let desktopImage, mobileImage;
2728
if (images) {
@@ -87,10 +88,28 @@ const ExplainerTile = ({ content, images, width, layout, hasMobileImage, explain
8788
});
8889
};
8990

91+
const handleMouseEnter = label => {
92+
homepageTile = setTimeout(() => {
93+
Analytics.event({
94+
category: 'Homepage Cards',
95+
action: 'Card Hover',
96+
label: label,
97+
});
98+
}, 3000);
99+
};
100+
const handleMouseLeave = () => {
101+
clearTimeout(homepageTile);
102+
};
90103
return (
91104
<>
92105
{content.path ? (
93-
<Link to={content.path} data-testid={'tile-link'} onClick={() => analyticsHandler('Citation Click', content.analyticsName)}>
106+
<Link
107+
to={content.path}
108+
data-testid={'tile-link'}
109+
onClick={() => analyticsHandler('Citation Click', content.analyticsName)}
110+
onMouseEnter={() => handleMouseEnter(content.analyticsName)}
111+
onMouseLeave={handleMouseLeave}
112+
>
94113
{card}
95114
</Link>
96115
) : (

0 commit comments

Comments
 (0)