mirror of
https://github.com/kamranahmedse/developer-roadmap.git
synced 2025-08-11 19:53:59 +02:00
feat: add all page views (#5154)
This commit is contained in:
@@ -101,22 +101,10 @@ export function CustomRoadmap(props: CustomRoadmapProps) {
|
||||
setIsLoading(false);
|
||||
}
|
||||
|
||||
async function trackVisit() {
|
||||
if (!isLoggedIn() || isEmbed) {
|
||||
return;
|
||||
}
|
||||
|
||||
await httpPost(`${import.meta.env.PUBLIC_API_URL}/v1-visit`, {
|
||||
resourceId: id,
|
||||
resourceType: 'roadmap',
|
||||
});
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
getRoadmap().finally(() => {
|
||||
hideRoadmapLoader();
|
||||
});
|
||||
trackVisit().then();
|
||||
}, []);
|
||||
|
||||
if (isLoading) {
|
||||
|
@@ -117,19 +117,6 @@ 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;
|
||||
@@ -138,8 +125,6 @@ export class Renderer {
|
||||
const urlParams = new URLSearchParams(window.location.search);
|
||||
const roadmapType = urlParams.get('r');
|
||||
|
||||
this.trackVisit();
|
||||
|
||||
if (roadmapType) {
|
||||
this.switchRoadmap(`/${roadmapType}.json`);
|
||||
} else {
|
||||
|
25
src/components/PageVisit/PageVisit.tsx
Normal file
25
src/components/PageVisit/PageVisit.tsx
Normal file
@@ -0,0 +1,25 @@
|
||||
import { useEffect } from 'react';
|
||||
import { isLoggedIn } from '../../lib/jwt';
|
||||
import { httpPost } from '../../lib/http';
|
||||
import type { ResourceType } from '../../lib/resource-progress';
|
||||
|
||||
type PageVisitProps = {
|
||||
resourceId?: string;
|
||||
resourceType?: ResourceType;
|
||||
};
|
||||
|
||||
export function PageVisit(props: PageVisitProps) {
|
||||
const { resourceId, resourceType } = props;
|
||||
|
||||
useEffect(() => {
|
||||
if (!isLoggedIn()) {
|
||||
return;
|
||||
}
|
||||
|
||||
httpPost(`${import.meta.env.PUBLIC_API_URL}/v1-visit`, {
|
||||
...(resourceType && { resourceType, resourceId }),
|
||||
}).finally(() => {});
|
||||
}, []);
|
||||
|
||||
return null;
|
||||
}
|
@@ -11,6 +11,8 @@ import { Toaster } from '../components/Toast';
|
||||
import { PageSponsor } from '../components/PageSponsor';
|
||||
import { siteConfig } from '../lib/config';
|
||||
import '../styles/global.css';
|
||||
import { PageVisit } from '../components/PageVisit/PageVisit';
|
||||
import type { ResourceType } from '../lib/resource-progress';
|
||||
|
||||
export interface Props {
|
||||
title: string;
|
||||
@@ -25,6 +27,8 @@ export interface Props {
|
||||
initialLoadingMessage?: string;
|
||||
permalink?: string;
|
||||
jsonLd?: Record<string, unknown>[];
|
||||
resourceId?: string;
|
||||
resourceType?: ResourceType;
|
||||
}
|
||||
|
||||
const {
|
||||
@@ -39,6 +43,8 @@ const {
|
||||
jsonLd = [],
|
||||
redirectUrl = '',
|
||||
initialLoadingMessage = '',
|
||||
resourceId,
|
||||
resourceType,
|
||||
} = Astro.props;
|
||||
|
||||
// Remove trailing slashes to consider the page as canonical
|
||||
@@ -55,7 +61,7 @@ const gaPageIdentifier = Astro.url.pathname
|
||||
.replace(/\//g, ':');
|
||||
---
|
||||
|
||||
<!DOCTYPE html>
|
||||
<!doctype html>
|
||||
<html lang='en'>
|
||||
<head>
|
||||
<meta charset='UTF-8' />
|
||||
@@ -171,5 +177,10 @@ const gaPageIdentifier = Astro.url.pathname
|
||||
<slot name='after-footer' />
|
||||
|
||||
<Analytics />
|
||||
<PageVisit
|
||||
resourceId={resourceId}
|
||||
resourceType={resourceType}
|
||||
client:load
|
||||
/>
|
||||
</body>
|
||||
</html>
|
||||
|
@@ -67,6 +67,8 @@ if (roadmapFAQs.length) {
|
||||
keywords={roadmapData.seo.keywords}
|
||||
noIndex={roadmapData.isUpcoming}
|
||||
jsonLd={jsonLdSchema}
|
||||
resourceId={roadmapId}
|
||||
resourceType='roadmap'
|
||||
>
|
||||
<!-- Preload the font being used in the renderer -->
|
||||
<link
|
||||
|
@@ -49,7 +49,7 @@ if (bestPracticeData.schema) {
|
||||
datePublished: bestPracticeSchema.datePublished,
|
||||
dateModified: bestPracticeSchema.dateModified,
|
||||
imageUrl: bestPracticeSchema.imageUrl,
|
||||
})
|
||||
}),
|
||||
);
|
||||
}
|
||||
---
|
||||
@@ -62,6 +62,8 @@ if (bestPracticeData.schema) {
|
||||
keywords={bestPracticeData.seo.keywords}
|
||||
noIndex={bestPracticeData.isUpcoming}
|
||||
jsonLd={jsonLdSchema}
|
||||
resourceId={bestPracticeId}
|
||||
resourceType='best-practice'
|
||||
>
|
||||
<!-- Preload the font being used in the renderer -->
|
||||
<link
|
||||
|
Reference in New Issue
Block a user