Skip to content

Commit 390d66f

Browse files
committed
Add comprehensive Google Analytics tracking to sandbox and benchmark sites
1 parent 5035529 commit 390d66f

1 file changed

Lines changed: 43 additions & 0 deletions

File tree

sandbox/main.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,15 @@ class SandboxUI {
475475
});
476476
}
477477

478+
// Track example run in Google Analytics
479+
if (typeof gtag === 'function') {
480+
gtag('event', 'button_click', {
481+
button_type: 'example_run',
482+
button_id: example.id,
483+
example_title: example.title
484+
});
485+
}
486+
478487
// Run example
479488
const result = await this.examplesController.runExample(testId, updateOutput, onStatusChange);
480489

@@ -642,6 +651,37 @@ class FooterScrollTracker {
642651

643652
}
644653

654+
// Footer Scroll Tracker
655+
class FooterScrollTracker {
656+
657+
constructor() {
658+
this.init();
659+
}
660+
661+
init() {
662+
const footer = document.querySelector('.footer');
663+
if (footer && typeof IntersectionObserver !== 'undefined') {
664+
let hasTrackedFooter = false;
665+
const footerObserver = new IntersectionObserver((entries) => {
666+
entries.forEach(entry => {
667+
if (entry.isIntersecting && !hasTrackedFooter && typeof gtag === 'function') {
668+
gtag('event', 'view_item', {
669+
content_type: 'section',
670+
item_id: 'footer'
671+
});
672+
hasTrackedFooter = true;
673+
footerObserver.disconnect(); // Only track once
674+
}
675+
});
676+
}, {
677+
threshold: 0.5 // Trigger when 50% of footer is visible
678+
});
679+
footerObserver.observe(footer);
680+
}
681+
}
682+
683+
}
684+
645685
// Scroll to Bottom Button Manager
646686
class ScrollToBottom {
647687

@@ -689,3 +729,6 @@ new ScrollToBottom();
689729

690730
// Initialize footer scroll tracker
691731
new FooterScrollTracker();
732+
733+
// Initialize footer scroll tracker
734+
new FooterScrollTracker();

0 commit comments

Comments
 (0)