feat: add all page views

feat/visit
Arik Chakma 10 months ago
parent 63c3850f0e
commit ab2327d539
  1. 12
      src/components/CustomRoadmap/CustomRoadmap.tsx
  2. 15
      src/components/FrameRenderer/renderer.ts
  3. 25
      src/components/PageVisit/PageVisit.tsx
  4. 13
      src/layouts/BaseLayout.astro
  5. 2
      src/pages/[roadmapId]/index.astro
  6. 4
      src/pages/best-practices/[bestPracticeId]/index.astro

@ -101,22 +101,10 @@ export function CustomRoadmap(props: CustomRoadmapProps) {
setIsLoading(false); setIsLoading(false);
} }
async function trackVisit() {
if (!isLoggedIn() || isEmbed) {
return;
}
await httpPost(`${import.meta.env.PUBLIC_API_URL}/v1-visit`, {
resourceId: id,
resourceType: 'roadmap',
});
}
useEffect(() => { useEffect(() => {
getRoadmap().finally(() => { getRoadmap().finally(() => {
hideRoadmapLoader(); hideRoadmapLoader();
}); });
trackVisit().then();
}, []); }, []);
if (isLoading) { 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() { onDOMLoaded() {
if (!this.prepareConfig()) { if (!this.prepareConfig()) {
return; return;
@ -138,8 +125,6 @@ export class Renderer {
const urlParams = new URLSearchParams(window.location.search); const urlParams = new URLSearchParams(window.location.search);
const roadmapType = urlParams.get('r'); const roadmapType = urlParams.get('r');
this.trackVisit();
if (roadmapType) { if (roadmapType) {
this.switchRoadmap(`/${roadmapType}.json`); this.switchRoadmap(`/${roadmapType}.json`);
} else { } else {

@ -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 { PageSponsor } from '../components/PageSponsor';
import { siteConfig } from '../lib/config'; import { siteConfig } from '../lib/config';
import '../styles/global.css'; import '../styles/global.css';
import { PageVisit } from '../components/PageVisit/PageVisit';
import type { ResourceType } from '../lib/resource-progress';
export interface Props { export interface Props {
title: string; title: string;
@ -25,6 +27,8 @@ export interface Props {
initialLoadingMessage?: string; initialLoadingMessage?: string;
permalink?: string; permalink?: string;
jsonLd?: Record<string, unknown>[]; jsonLd?: Record<string, unknown>[];
resourceId?: string;
resourceType?: ResourceType;
} }
const { const {
@ -39,6 +43,8 @@ const {
jsonLd = [], jsonLd = [],
redirectUrl = '', redirectUrl = '',
initialLoadingMessage = '', initialLoadingMessage = '',
resourceId,
resourceType,
} = Astro.props; } = Astro.props;
// Remove trailing slashes to consider the page as canonical // Remove trailing slashes to consider the page as canonical
@ -55,7 +61,7 @@ const gaPageIdentifier = Astro.url.pathname
.replace(/\//g, ':'); .replace(/\//g, ':');
--- ---
<!DOCTYPE html> <!doctype html>
<html lang='en'> <html lang='en'>
<head> <head>
<meta charset='UTF-8' /> <meta charset='UTF-8' />
@ -171,5 +177,10 @@ const gaPageIdentifier = Astro.url.pathname
<slot name='after-footer' /> <slot name='after-footer' />
<Analytics /> <Analytics />
<PageVisit
resourceId={resourceId}
resourceType={resourceType}
client:load
/>
</body> </body>
</html> </html>

@ -67,6 +67,8 @@ if (roadmapFAQs.length) {
keywords={roadmapData.seo.keywords} keywords={roadmapData.seo.keywords}
noIndex={roadmapData.isUpcoming} noIndex={roadmapData.isUpcoming}
jsonLd={jsonLdSchema} jsonLd={jsonLdSchema}
resourceId={roadmapId}
resourceType='roadmap'
> >
<!-- Preload the font being used in the renderer --> <!-- Preload the font being used in the renderer -->
<link <link

@ -49,7 +49,7 @@ if (bestPracticeData.schema) {
datePublished: bestPracticeSchema.datePublished, datePublished: bestPracticeSchema.datePublished,
dateModified: bestPracticeSchema.dateModified, dateModified: bestPracticeSchema.dateModified,
imageUrl: bestPracticeSchema.imageUrl, imageUrl: bestPracticeSchema.imageUrl,
}) }),
); );
} }
--- ---
@ -62,6 +62,8 @@ if (bestPracticeData.schema) {
keywords={bestPracticeData.seo.keywords} keywords={bestPracticeData.seo.keywords}
noIndex={bestPracticeData.isUpcoming} noIndex={bestPracticeData.isUpcoming}
jsonLd={jsonLdSchema} jsonLd={jsonLdSchema}
resourceId={bestPracticeId}
resourceType='best-practice'
> >
<!-- Preload the font being used in the renderer --> <!-- Preload the font being used in the renderer -->
<link <link

Loading…
Cancel
Save