feat: analytics and ads

This commit is contained in:
2026-02-04 14:47:34 -08:00
parent cbd6499079
commit e5b15e02de
5 changed files with 204 additions and 4 deletions
@@ -0,0 +1,42 @@
/**
* @copyright 2026 NHCarrigan
* @license Naomi's Public License
* @author Naomi Carrigan
*/
import { Injectable, inject } from '@angular/core';
import { Router, NavigationEnd } from '@angular/router';
import { filter } from 'rxjs/operators';
declare global {
interface Window {
plausible?: (event: string, options?: { props?: Record<string, string> }) => void;
}
}
@Injectable({
providedIn: 'root'
})
export class AnalyticsService {
private router = inject(Router);
initialise(): void {
this.router.events.pipe(
filter((event): event is NavigationEnd => event instanceof NavigationEnd)
).subscribe((event) => {
this.trackPageView(event.urlAfterRedirects);
});
}
private trackPageView(path: string): void {
if (window.plausible) {
window.plausible('pageview', {
props: {
domain: 'library.nhcarrigan.com',
page: 'Naomi\'s Library',
path: path || '/'
}
});
}
}
}