-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgtag.js
More file actions
49 lines (44 loc) · 1.18 KB
/
Copy pathgtag.js
File metadata and controls
49 lines (44 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Google Analytics tracking
export const GA_TRACKING_ID = process.env.NEXT_PUBLIC_GA_ID || 'G-XXXXXXXXXX';
// https://developers.google.com/analytics/devguides/collection/gtagjs/pages
export const pageview = (url) => {
if (typeof window !== 'undefined' && window.gtag) {
window.gtag('config', GA_TRACKING_ID, {
page_location: url,
});
}
};
// https://developers.google.com/analytics/devguides/collection/gtagjs/events
export const event = ({ action, category, label, value }) => {
if (typeof window !== 'undefined' && window.gtag) {
window.gtag('event', action, {
event_category: category,
event_label: label,
value: value,
});
}
};
// Track component usage
export const trackComponentView = (componentName) => {
event({
action: 'view_component',
category: 'Components',
label: componentName,
});
};
// Track documentation views
export const trackDocView = (docPage) => {
event({
action: 'view_documentation',
category: 'Documentation',
label: docPage,
});
};
// Track search queries
export const trackSearch = (searchTerm) => {
event({
action: 'search',
category: 'Site Search',
label: searchTerm,
});
};