Это аналитика. service.ts :
Код: Выделить всё
import { Injectable } from '@angular/core';
@Injectable({
providedIn: 'root'
})
export class AnalyticsService {
private isLoaded = false;
constructor() {}
loadGoogleAnalytics(measurementId: string): void {
console.log('hi loadGoogleAnalytics', measurementId);
if (!measurementId || this.isLoaded) {
return;
}
this.isLoaded = true;
// Create script tag
const script = document.createElement('script');
script.async = true;
script.src = `https://www.googletagmanager.com/gtag/js?id=${measurementId}`;
document.head.appendChild(script);
// Initialize GA
script.onload = () => {
(window as any).dataLayer = (window as any).dataLayer || [];
function gtag(...args: any[]) {
(window as any).dataLayer.push(args);
}
(window as any).gtag = gtag;
gtag('js', new Date());
gtag('config', measurementId);
this.trackPageView();
};
}
trackPageView(): void {
console.log('Tracking page view:', window.location.hash);
if ((window as any).gtag) {
(window as any).gtag('event', 'page_view', {page_title: document.title, page_path: window.location.hash });
}
}
}
Итак, каково предложенное решение для решения этой проблемы?
Подробнее здесь: https://stackoverflow.com/questions/794 ... in-angular
Мобильная версия