Skip to content

Commit ef8235d

Browse files
authored
Merge pull request #79 from AzureCosmosDB/ai_first
Enhance Google Analytics tracking in ShowcaseCard; add console loggin…
2 parents 234a77e + 021362d commit ef8235d

File tree

1 file changed

+32
-18
lines changed

1 file changed

+32
-18
lines changed

src/components/gallery/ShowcaseCard/index.tsx

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,22 @@ function ShowcaseCard({
6565
});
6666

6767
// 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-
});
68+
if (typeof window !== 'undefined') {
69+
const gtag = (window as any).gtag;
70+
if (typeof gtag === 'function') {
71+
gtag('event', 'card_click', {
72+
card_title: title,
73+
card_slug: cardSlug,
74+
card_author: user.author,
75+
card_tags: tags.join(','),
76+
event_category: 'engagement',
77+
event_label: title,
78+
send_to: 'G-CNSKHL41CT',
79+
});
80+
console.log('GA Event: card_click', { title, cardSlug });
81+
} else {
82+
console.log('gtag not available');
83+
}
7784
}
7885

7986
openPanel();
@@ -103,15 +110,22 @@ function ShowcaseCard({
103110
// Only open if URL matches this card and panel is not already open
104111
if (cardParam === cardSlug && !isOpen) {
105112
// Track deep link access in Google Analytics
106-
if (typeof window !== 'undefined' && (window as any).gtag) {
107-
(window as any).gtag('event', 'deep_link_open', {
108-
card_title: title,
109-
card_slug: cardSlug,
110-
card_author: user.author,
111-
event_category: 'engagement',
112-
event_label: `Deep Link: ${title}`,
113-
referrer: document.referrer || 'direct',
114-
});
113+
if (typeof window !== 'undefined') {
114+
const gtag = (window as any).gtag;
115+
if (typeof gtag === 'function') {
116+
gtag('event', 'deep_link_open', {
117+
card_title: title,
118+
card_slug: cardSlug,
119+
card_author: user.author,
120+
event_category: 'engagement',
121+
event_label: `Deep Link: ${title}`,
122+
referrer: document.referrer || 'direct',
123+
send_to: 'G-CNSKHL41CT',
124+
});
125+
console.log('GA Event: deep_link_open', { title, cardSlug });
126+
} else {
127+
console.log('gtag not available for deep link');
128+
}
115129
}
116130
openPanel();
117131
} else if (!cardParam && isOpen) {

0 commit comments

Comments
 (0)