Add event tracking for topic load

pull/3649/head
Kamran Ahmed 2 years ago
parent 5fe506324a
commit d3578756d4
  1. 6
      src/components/Analytics/analytics.ts
  2. 21
      src/components/TopicOverlay/topic.js

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

@ -177,7 +177,16 @@ export class Topic {
this.activeTopicId = topicId; this.activeTopicId = topicId;
this.resetDOM(); 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) { handleRoadmapTopicClick(e) {
@ -192,7 +201,15 @@ export class Topic {
this.activeTopicId = topicId; this.activeTopicId = topicId;
this.resetDOM(); 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) { querySvgElementsByTopicId(topicId) {

Loading…
Cancel
Save