Skip to content

Commit 8b37071

Browse files
authored
Merge pull request #77 from AzureCosmosDB/ai_first
Add Google Analytics tracking for card clicks and deep link access in…
2 parents 9ebc23a + c4cc7f4 commit 8b37071

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

src/components/gallery/ShowcaseCard/index.tsx

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,19 @@ function ShowcaseCard({
6363
pathname: location.pathname,
6464
search: searchParams.toString(),
6565
});
66+
67+
// Track card click in Google Analytics
68+
if (typeof window !== 'undefined' && (window as any).gtag) {
69+
(window as any).gtag('event', 'card_click', {
70+
card_title: title,
71+
card_slug: cardSlug,
72+
card_author: user.author,
73+
card_tags: tags.join(','),
74+
event_category: 'engagement',
75+
event_label: title,
76+
});
77+
}
78+
6679
openPanel();
6780
};
6881

@@ -82,9 +95,20 @@ function ShowcaseCard({
8295
const searchParams = new URLSearchParams(location.search);
8396
const cardParam = searchParams.get('card');
8497
if (cardParam === cardSlug && !isOpen) {
98+
// Track deep link access in Google Analytics
99+
if (typeof window !== 'undefined' && (window as any).gtag) {
100+
(window as any).gtag('event', 'deep_link_open', {
101+
card_title: title,
102+
card_slug: cardSlug,
103+
card_author: user.author,
104+
event_category: 'engagement',
105+
event_label: `Deep Link: ${title}`,
106+
referrer: document.referrer || 'direct',
107+
});
108+
}
85109
openPanel();
86110
}
87-
}, [location.search, cardSlug, isOpen, openPanel]);
111+
}, [location.search, cardSlug, isOpen, openPanel, title, user.author]);
88112

89113
const fetchGitHubData = async (owner: string, repo: string) => {
90114
const token = siteConfig.customFields.REACT_APP_GITHUB_TOKEN;

0 commit comments

Comments
 (0)