From 839990defe69d428bca52cd2e1f50e7a529808f5 Mon Sep 17 00:00:00 2001 From: "mathias.chouet" <mathias.chouet@irstea.fr> Date: Tue, 30 Jun 2020 14:18:02 +0200 Subject: [PATCH] Fix #412 disable tracking when in dev mode --- src/app/app.component.ts | 64 ++++++++++--------- .../app-setup/app-setup.component.ts | 6 +- .../calculator.component.ts | 6 +- .../modules-diagram.component.ts | 7 +- .../session-properties.component.ts | 6 +- .../services/internationalisation.service.ts | 3 +- 6 files changed, 54 insertions(+), 38 deletions(-) diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 19b869681..2169ad712 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -1,4 +1,4 @@ -import { Component, OnInit, OnDestroy, HostListener, ViewChild, ElementRef } from "@angular/core"; +import { Component, OnInit, OnDestroy, HostListener, ViewChild, ElementRef, isDevMode } from "@angular/core"; import { Router, Event, NavigationEnd, ActivationEnd } from "@angular/router"; import { MatDialog } from "@angular/material/dialog"; import { MatSidenav } from "@angular/material/sidenav"; @@ -101,35 +101,37 @@ export class AppComponent implements OnInit, OnDestroy, Observer { ServiceFactory.instance.formulaireService = formulaireService; ServiceFactory.instance.notificationsService = notificationsService; - // évite de mettre en place un bandeau RGPD - this.matomoTracker.disableCookies(); - // Set custom dimension for Electron / Cordova / pure Web browser - this.matomoTracker.setCustomDimension(1, this.getRunningPlatform()); - // Matomo open-source Web analytics - this.matomoInjector.init("https://stasi.g-eau.fr/", 1); - - this.router.events.subscribe((event: Event) => { - // close side navigation when clicking a calculator tab - if (event instanceof NavigationEnd) { - this.sidenav.close(); - window.scrollTo(0, 0); - } - // [de]activate calc tabs depending on loaded route - if (event instanceof ActivationEnd) { - const path = event.snapshot.url[0].path; - if (path === "calculator") { - const calcUid = event.snapshot.params.uid; - if (this.calculatorExists(calcUid)) { - this.setActiveCalc(calcUid); + if (! isDevMode()) { + // évite de mettre en place un bandeau RGPD + this.matomoTracker.disableCookies(); + // Set custom dimension for Electron / Cordova / pure Web browser + this.matomoTracker.setCustomDimension(1, this.getRunningPlatform()); + // Matomo open-source Web analytics + this.matomoInjector.init("https://stasi.g-eau.fr/", 1); + + this.router.events.subscribe((event: Event) => { + // close side navigation when clicking a calculator tab + if (event instanceof NavigationEnd) { + this.sidenav.close(); + window.scrollTo(0, 0); + } + // [de]activate calc tabs depending on loaded route + if (event instanceof ActivationEnd) { + const path = event.snapshot.url[0].path; + if (path === "calculator") { + const calcUid = event.snapshot.params.uid; + if (this.calculatorExists(calcUid)) { + this.setActiveCalc(calcUid); + } else { + // if required calculator does not exist, redirect to list page + this.toList(); + } } else { - // if required calculator does not exist, redirect to list page - this.toList(); + this.setActiveCalc(null); } - } else { - this.setActiveCalc(null); } - } - }); + }); + } // hotkeys listeners this.hotkeysService.add(new Hotkey("alt+s", AppComponent.onHotkey(this.saveForm, this))); @@ -520,7 +522,9 @@ export class AppComponent implements OnInit, OnDestroy, Observer { */ private saveSession(calcList: any[], filename: string) { const session: string = this.buildSessionFile(calcList); - this.matomoTracker.trackEvent("userAction", "saveSession"); + if (! isDevMode()) { + this.matomoTracker.trackEvent("userAction", "saveSession"); + } this.formulaireService.downloadTextFile(session, filename); } @@ -664,7 +668,9 @@ export class AppComponent implements OnInit, OnDestroy, Observer { this.notificationsService.notify(this.intlService.localizeText("ERROR_PROBLEM_LOADING_SESSION"), 3500); } else { if (data.loaded && data.loaded.length > 0) { - this.matomoTracker.trackEvent("userAction", "loadSession"); + if (! isDevMode()) { + this.matomoTracker.trackEvent("userAction", "loadSession"); + } // notes merge detection: was there already some notes ? const currentNotes = Session.getInstance().documentation; if (existingNotes !== "" && currentNotes !== existingNotes) { diff --git a/src/app/components/app-setup/app-setup.component.ts b/src/app/components/app-setup/app-setup.component.ts index 85b0d4512..66b9df462 100644 --- a/src/app/components/app-setup/app-setup.component.ts +++ b/src/app/components/app-setup/app-setup.component.ts @@ -1,4 +1,4 @@ -import { Component, OnInit } from "@angular/core"; +import { Component, OnInit, isDevMode } from "@angular/core"; import { ParamDomainValue, Observer, ParamDomain } from "jalhyd"; @@ -36,7 +36,9 @@ export class ApplicationSetupComponent implements Observer, OnInit { private matomoTracker: MatomoTracker ) { this.appSetupService.addObserver(this); - this.matomoTracker.trackPageView("setup"); + if (! isDevMode()) { + this.matomoTracker.trackPageView("setup"); + } } public get availableLanguages() { diff --git a/src/app/components/generic-calculator/calculator.component.ts b/src/app/components/generic-calculator/calculator.component.ts index a72bd526e..b31a21eb5 100644 --- a/src/app/components/generic-calculator/calculator.component.ts +++ b/src/app/components/generic-calculator/calculator.component.ts @@ -1,5 +1,5 @@ import { Component, OnInit, DoCheck, OnDestroy, ViewChild, ViewChildren, - QueryList, AfterViewChecked, ElementRef, Inject, forwardRef } from "@angular/core"; + QueryList, AfterViewChecked, ElementRef, Inject, forwardRef, isDevMode } from "@angular/core"; import { ActivatedRoute, Router } from "@angular/router"; import { @@ -334,7 +334,9 @@ export class GenericCalculatorComponent implements OnInit, DoCheck, AfterViewChe } public doCompute() { - this.matomoTracker.trackEvent("userAction", "triggerCalculation", CalculatorType[this._formulaire.currentNub.calcType]); + if (! isDevMode()) { + this.matomoTracker.trackEvent("userAction", "triggerCalculation", CalculatorType[this._formulaire.currentNub.calcType]); + } this._formulaire.resetResults([]); this.appComponent.showProgressBar = true; this._computeClicked = true; diff --git a/src/app/components/modules-diagram/modules-diagram.component.ts b/src/app/components/modules-diagram/modules-diagram.component.ts index b701aeac9..150764b20 100644 --- a/src/app/components/modules-diagram/modules-diagram.component.ts +++ b/src/app/components/modules-diagram/modules-diagram.component.ts @@ -4,7 +4,8 @@ import { AfterContentInit, OnInit, AfterViewChecked, - AfterViewInit + AfterViewInit, + isDevMode } from "@angular/core"; import { Router } from "@angular/router"; @@ -59,7 +60,9 @@ export class ModulesDiagramComponent implements AfterContentInit, AfterViewCheck private matomoTracker: MatomoTracker ) { this.error = false; - this.matomoTracker.trackPageView("diagram"); + if (! isDevMode()) { + this.matomoTracker.trackPageView("diagram"); + } } public get uitextTitle(): string { diff --git a/src/app/components/session-properties/session-properties.component.ts b/src/app/components/session-properties/session-properties.component.ts index eb025789e..d9cbf6111 100644 --- a/src/app/components/session-properties/session-properties.component.ts +++ b/src/app/components/session-properties/session-properties.component.ts @@ -1,4 +1,4 @@ -import { Component, OnInit } from "@angular/core"; +import { Component, OnInit, isDevMode } from "@angular/core"; import { Router } from "@angular/router"; import { I18nService } from "../../services/internationalisation.service"; @@ -30,7 +30,9 @@ export class SessionPropertiesComponent implements OnInit { throwOnError: false, errorColor: "#cc0000" }; - this.matomoTracker.trackPageView("notes"); + if (! isDevMode()) { + this.matomoTracker.trackPageView("notes"); + } } public get content(): string { diff --git a/src/app/services/internationalisation.service.ts b/src/app/services/internationalisation.service.ts index b4424f3e4..bc3f5b5a6 100644 --- a/src/app/services/internationalisation.service.ts +++ b/src/app/services/internationalisation.service.ts @@ -176,7 +176,8 @@ export class I18nService extends Observable implements Observer { // replace "FORM_ID_X" by form name in current session, if any m = m.replace(/FORM_ID_(\w{6})/g, (match, p1) => { - const form = ServiceFactory.instance.formulaireService.getFormulaireFromNubId(p1); // cannot inject FormulaireService => cyclic dependency :/ + // cannot inject FormulaireService => cyclic dependency :/ + const form = ServiceFactory.instance.formulaireService.getFormulaireFromNubId(p1); let formName = "**UNKNOWN_FORM**"; if (form !== undefined) { formName = form.calculatorName; -- GitLab