Repository navigation
Expand file tree
/
Copy pathanalytics.js
More file actions
74 lines (63 loc) · 1.66 KB
/
Copy pathanalytics.js
File metadata and controls
74 lines (63 loc) · 1.66 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// Simple analytics for adibaIcon usage
class AdibaAnalytics {
constructor() {
this.events = [];
this.sessionId = this.generateSessionId();
}
generateSessionId() {
return Date.now().toString(36) + Math.random().toString(36).substr(2);
}
track(event, data = {}) {
const eventData = {
event,
data,
timestamp: Date.now(),
sessionId: this.sessionId,
url: window.location.href,
};
this.events.push(eventData);
// Send to analytics endpoint (placeholder)
if (typeof fetch !== 'undefined') {
fetch('/api/analytics', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(eventData),
}).catch(() => {}); // Silent fail
}
}
trackIconUsage(iconName) {
this.track('icon_used', { icon: iconName });
}
trackPageView() {
this.track('page_view');
}
trackDownload(type) {
this.track('download', { type });
}
}
// Auto-track icon usage
if (typeof window !== 'undefined') {
const analytics = new AdibaAnalytics();
// Track page views
analytics.trackPageView();
// Track icon clicks
document.addEventListener('click', (e) => {
const icon = e.target.closest('[class*="adiba-"]');
if (icon) {
const classes = icon.className.split(' ');
const iconClass = classes.find(
(c) =>
c.startsWith('adiba-') &&
!c.includes('xs') &&
!c.includes('sm') &&
!c.includes('md') &&
!c.includes('lg') &&
!c.includes('xl')
);
if (iconClass) {
analytics.trackIconUsage(iconClass);
}
}
});
window.adibaAnalytics = analytics;
}