1
0
mirror of https://github.com/kamranahmedse/developer-roadmap.git synced 2025-09-01 05:21:43 +02:00

Add event tracking for topic load

This commit is contained in:
Kamran Ahmed
2023-03-16 00:52:39 +00:00
parent 5fe506324a
commit d3578756d4
2 changed files with 25 additions and 2 deletions

View File

@@ -2,6 +2,8 @@ export {};
declare global {
interface Window {
// To selectively enable/disable debug logs
__DEBUG__: boolean;
gtag: any;
fireEvent: (props: GAEventType) => void;
}
@@ -27,6 +29,10 @@ window.fireEvent = (props: GAEventType) => {
return;
}
if (window.__DEBUG__) {
console.log('Analytics event fired', props);
}
window.gtag('event', action, {
event_category: category,
event_label: label,

View File

@@ -177,7 +177,16 @@ export class Topic {
this.activeTopicId = topicId;
this.resetDOM();
this.renderTopicFromUrl(`/best-practices/${bestPracticeId}/${topicId.replaceAll(':', '/')}`);
const topicUrl = `/best-practices/${bestPracticeId}/${topicId.replaceAll(':', '/')}`;
window.fireEvent({
category: `BestPracticesClick`,
action: `Load Topic`,
label: topicUrl,
});
this.renderTopicFromUrl(topicUrl).then(() => null);
}
handleRoadmapTopicClick(e) {
@@ -192,7 +201,15 @@ export class Topic {
this.activeTopicId = topicId;
this.resetDOM();
this.renderTopicFromUrl(`/${roadmapId}/${topicId.replaceAll(':', '/')}`);
const topicUrl = `/${roadmapId}/${topicId.replaceAll(':', '/')}`;
window.fireEvent({
category: `RoadmapClick`,
action: `Load Topic`,
label: topicUrl,
});
this.renderTopicFromUrl(topicUrl).then(() => null);
}
querySvgElementsByTopicId(topicId) {