-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Enhance 404 page and analytics integration
- Refactored 404.js to integrate analytics tracking with `trackEvent`. - Updated analytics.js to add a reusable `trackEvent` function for event tracking. - Improved event tracking on index.js for buttons, social links, and copy-link functionality. - Renamed and standardized CSS class names in 404.scss and 404.ejs for consistency. - Added lazy loading for images on the 404 page and optimized clipboard functionality.
- Loading branch information
Showing
5 changed files
with
55 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,10 @@ | ||
import '../scss/404.scss'; | ||
import "./analytics.js"; | ||
import { trackEvent } from "./analytics.js"; | ||
|
||
document.addEventListener('DOMContentLoaded', () => { | ||
document.querySelectorAll('.clazz-error-container a').forEach(a => { | ||
a.addEventListener('click', (e) => { | ||
trackEvent("click", a); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,36 @@ | ||
import '../scss/index.scss'; | ||
import { analytics } from './analytics.js'; | ||
import { logEvent } from "firebase/analytics"; | ||
import { trackEvent } from "./analytics.js"; | ||
|
||
function trackButtonClick(obj) { | ||
const event = obj.innerText || obj.textContent; | ||
logEvent(analytics, "click", { name: event }); | ||
} | ||
|
||
function trackSocialButtonClick(obj) { | ||
const event = obj.getAttribute('aria-label'); | ||
logEvent(analytics, "click-social", { name: event }); | ||
} | ||
|
||
function copyLink(url) { | ||
window.navigator.clipboard.writeText(url); | ||
confirm("Page URL copied to the clipboard."); | ||
function copyLinkToClipboard(url) { | ||
if (navigator.clipboard) { | ||
navigator.clipboard.writeText(url).then(() => { | ||
alert('Page URL copied to the clipboard.'); | ||
}).catch(() => { | ||
alert('Failed to copy the URL. Please copy manually.'); | ||
}); | ||
} else { | ||
alert('Clipboard API is not supported in this browser.'); | ||
} | ||
} | ||
|
||
// Attach Event Handlers | ||
document.addEventListener('DOMContentLoaded', () => { | ||
document.querySelectorAll('.clazz-button-container a').forEach(a => { | ||
a.addEventListener('click', (e) => { | ||
trackButtonClick(a); | ||
document.querySelectorAll('.clazz-button-container a').forEach(a => { | ||
a.addEventListener('click', (e) => { | ||
trackEvent("click", a); | ||
}); | ||
}); | ||
}); | ||
|
||
document.querySelectorAll('.clazz-social-links a').forEach(a => { | ||
a.addEventListener('click', (e) => { | ||
trackSocialButtonClick(a); | ||
document.querySelectorAll('.clazz-social-links a').forEach(a => { | ||
a.addEventListener('click', (e) => { | ||
trackEvent("social-click", a); | ||
}); | ||
}); | ||
}); | ||
|
||
document.querySelectorAll('.clazz-copy-link').forEach(a => { | ||
a.addEventListener('click', (e) => { | ||
e.preventDefault(); | ||
copyLink(window.location.href); | ||
document.querySelectorAll('.clazz-copy-link').forEach(a => { | ||
a.addEventListener('click', (e) => { | ||
e.preventDefault(); | ||
copyLinkToClipboard(window.location.href); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters