Project

General

Profile

1
import { Component, OnInit } from '@angular/core';
2
import { NavigationEnd, Router, RoutesRecognized } from '@angular/router';
3
import { AuthenticationService } from './services/authentication.service';
4
import { environment } from '../environments/environment';
5
import { MatomoInjector, MatomoTracker } from 'ngx-matomo';
6

    
7
@Component({
8
  selector: 'oa-repo-manager',
9
  templateUrl: './app.component.html',
10
  styleUrls: ['./app.component.css']
11
})
12
export class AppComponent implements OnInit {
13
  constructor(private router: Router,
14
              private authService: AuthenticationService,
15
              private matomoInjector: MatomoInjector,
16
              private matomoTracker: MatomoTracker) {
17

    
18
    console.log('21-06-2019. Fixed matomo to log userIds?');
19

    
20
    let piwikUrl;
21
    if (window.location.origin.includes('beta')) {
22
      // piwikUrl = 'https://analytics.openaire.eu/piwik.php?idsite=92&rec=1';
23
      piwikUrl = '92';
24
    } else if (window.location.origin.includes('localhost:4200') ||
25
               window.location.origin.includes('athenarc')) {
26
      // piwikUrl = 'https://analytics.openaire.eu/piwik.php?idsite=92&rec=1';
27
      piwikUrl = '9222222';
28
    } else {
29
      // piwikUrl = 'https://analytics.openaire.eu/piwik.php?idsite=111&rec=1';
30
      piwikUrl = '111';
31
    }
32
    this.matomoInjector.init('https://analytics.openaire.eu/', piwikUrl);
33

    
34
    /*disabling console.log in production*/
35
    if ( environment.production === true ) {
36
      console.log = function () {};
37
    }
38

    
39
    // URL of the SPA to redirect the user to after login
40
    // this.authService.redirectUrl = "/dashboard";
41

    
42
    if (window.location.pathname.includes('/compatibility/browseHistory/')) {
43
      this.authService.redirectUrl = window.location.pathname;
44
      console.log('redirectUrl', this.authService.redirectUrl);
45
    }
46

    
47
    this.authService.tryLogin();
48
  }
49

    
50
  ngOnInit() {
51
    this.router.events.subscribe((evt) => {
52
      if (!(evt instanceof NavigationEnd)) {
53
        return;
54
      }
55
      if (this.authService.isLoggedIn) {
56
        this.matomoTracker.setUserId(this.authService.getUserEmail());
57
      }
58
      window.scrollTo(0, 0);
59
    });
60
  }
61

    
62
}
(5-5/6)