1
0
mirror of https://github.com/kamranahmedse/developer-roadmap.git synced 2025-08-24 01:42:55 +02:00

Add visit tracker to roadmap

This commit is contained in:
Kamran Ahmed
2023-05-08 23:06:09 +01:00
parent 41de9c47b0
commit 6591c36ef4

View File

@@ -3,6 +3,8 @@ import {
renderResourceProgress,
ResourceType,
} from '../../lib/resource-progress';
import { isLoggedIn } from '../../lib/jwt';
import { httpPost } from '../../lib/http';
export class Renderer {
resourceId: string;
@@ -104,6 +106,19 @@ export class Renderer {
});
}
trackVisit() {
if (!isLoggedIn()) {
return;
}
window.setTimeout(() => {
httpPost(`${import.meta.env.PUBLIC_API_URL}/v1-visit`, {
resourceId: this.resourceId,
resourceType: this.resourceType,
}).then(() => null);
}, 0);
}
onDOMLoaded() {
if (!this.prepareConfig()) {
return;
@@ -112,6 +127,8 @@ export class Renderer {
const urlParams = new URLSearchParams(window.location.search);
const roadmapType = urlParams.get('r');
this.trackVisit();
if (roadmapType) {
this.switchRoadmap(`/jsons/roadmaps/${roadmapType}.json`);
} else {