From 1619c3ec05f435a63a379c644f17247feadfc21d Mon Sep 17 00:00:00 2001
From: piotrpekala7 <31202938+piotrpekala7@users.noreply.github.com>
Date: Tue, 24 Aug 2021 17:07:47 +0200
Subject: [PATCH] Fix for https://github.com/GNS3/gns3-web-ui/issues/1184
---
.../settings/settings.component.html | 1 +
src/app/services/google-analytics.service.ts | 7 +++++--
src/app/services/settings.service.ts | 21 +++++++++++++++++++
3 files changed, 27 insertions(+), 2 deletions(-)
diff --git a/src/app/components/settings/settings.component.html b/src/app/components/settings/settings.component.html
index 53e8d179..3a844574 100644
--- a/src/app/components/settings/settings.component.html
+++ b/src/app/components/settings/settings.component.html
@@ -11,6 +11,7 @@
Send anonymous crash reports
+ Send anonymous usage statistics
Integrate link labels to links
Open consoles in the widget instead of in new tabs after clicking start consoles for all nodes
diff --git a/src/app/services/google-analytics.service.ts b/src/app/services/google-analytics.service.ts
index ca4afb28..72c2c3a2 100644
--- a/src/app/services/google-analytics.service.ts
+++ b/src/app/services/google-analytics.service.ts
@@ -1,14 +1,17 @@
import { Injectable } from '@angular/core';
import { NavigationEnd, Router } from '@angular/router';
import { environment } from '../../environments/environment';
+import { SettingsService } from './settings.service';
declare var gtag: Function;
@Injectable()
export class GoogleAnalyticsService {
- constructor(router: Router) {
+ private settingsService: SettingsService;
+
+ constructor(router: Router, settingsService: SettingsService) {
if (!environment.production) return;
router.events.subscribe((event) => {
- if (event instanceof NavigationEnd) {
+ if (settingsService.getStatisticsSettings() && event instanceof NavigationEnd) {
gtag('set', 'page', event.url);
gtag('send', 'pageview');
}
diff --git a/src/app/services/settings.service.ts b/src/app/services/settings.service.ts
index 9017ec71..c3153eb3 100644
--- a/src/app/services/settings.service.ts
+++ b/src/app/services/settings.service.ts
@@ -4,6 +4,7 @@ import { BehaviorSubject } from 'rxjs';
export interface Settings {
crash_reports: boolean;
console_command: string;
+ anonymous_statistics: boolean;
}
@Injectable({
@@ -13,10 +14,12 @@ export class SettingsService {
private settings: Settings = {
crash_reports: true,
console_command: undefined,
+ anonymous_statistics: true
};
private readonly reportsSettings: string = 'crash_reports';
private readonly consoleSettings: string = 'console_command';
+ private readonly statisticsSettings: string = 'statistics_command';
constructor() {
if (this.getItem(this.reportsSettings))
@@ -24,6 +27,9 @@ export class SettingsService {
if (this.getItem(this.consoleSettings))
this.settings.console_command = this.getItem(this.consoleSettings);
+
+ if (this.getItem(this.statisticsSettings))
+ this.settings.anonymous_statistics = this.getItem(this.statisticsSettings) === 'true' ? true : false;
}
setReportsSettings(value: boolean) {
@@ -36,10 +42,24 @@ export class SettingsService {
}
}
+ setStatisticsSettings(value: boolean) {
+ this.settings.anonymous_statistics = value;
+ this.removeItem(this.statisticsSettings);
+ if (value) {
+ this.setItem(this.statisticsSettings, 'true');
+ } else {
+ this.setItem(this.statisticsSettings, 'false');
+ }
+ }
+
getReportsSettings() {
return this.getItem(this.reportsSettings) === 'true' ? true : false;
}
+ getStatisticsSettings() {
+ return this.getItem(this.statisticsSettings) === 'true' ? true : false;
+ }
+
setConsoleSettings(value: string) {
this.settings.console_command = value;
this.removeItem(this.consoleSettings);
@@ -70,5 +90,6 @@ export class SettingsService {
this.settings = settings;
this.setConsoleSettings(settings.console_command);
this.setReportsSettings(settings.crash_reports);
+ this.setStatisticsSettings(settings.anonymous_statistics);
}
}