added matomo integration

This commit is contained in:
Diamantis Tziotzios 2020-12-10 15:29:24 +02:00
parent ca38f0b0a4
commit 6ea5dfff42
9 changed files with 109 additions and 33 deletions

View File

@ -35,6 +35,7 @@
"ngx-cookieconsent": "^2.2.3",
"ngx-dropzone": "^2.2.2",
"ngx-guided-tour": "^1.1.10",
"ngx-matomo": "^0.1.4",
"rxjs": "^6.3.2",
"tinymce": "^5.4.2",
"tslib": "^1.10.0",

View File

@ -16,6 +16,8 @@ import { LanguageService } from './core/services/language/language.service';
import { ConfigurationService } from './core/services/configuration/configuration.service';
import { Location } from '@angular/common';
import { MatomoInjector } from 'ngx-matomo';
import { MatomoService } from './core/services/matomo/matomo-service';
declare const gapi: any;
@ -46,9 +48,11 @@ export class AppComponent implements OnInit {
private ccService: NgcCookieConsentService,
private language: LanguageService,
private configurationService: ConfigurationService,
private location: Location
private location: Location,
private matomoService: MatomoService
) {
this.initializeServices();
this.matomoService.init();
this.helpContentEnabled = configurationService.helpService.enabled;
}

View File

@ -1,7 +1,8 @@
import { OverlayModule } from '@angular/cdk/overlay';
import { HttpClient, HttpClientModule } from '@angular/common/http';
import { LOCALE_ID, NgModule, APP_INITIALIZER } from '@angular/core';
import { LOCALE_ID, NgModule } from '@angular/core';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { MatFormFieldDefaultOptions, MAT_FORM_FIELD_DEFAULT_OPTIONS } from '@angular/material';
import { MatMomentDateModule, MAT_MOMENT_DATE_FORMATS } from '@angular/material-moment-adapter';
import { DateAdapter, MAT_DATE_FORMATS, MAT_DATE_LOCALE } from '@angular/material/core';
import { BrowserModule, Title } from '@angular/platform-browser';
@ -23,16 +24,14 @@ import { MomentUtcDateAdapter } from '@common/date/moment-utc-date-adapter';
import { CommonHttpModule } from '@common/http/common-http.module';
import { CommonUiModule } from '@common/ui/common-ui.module';
import { TranslateLoader, TranslateModule } from '@ngx-translate/core';
import { TranslateHttpLoader } from '@ngx-translate/http-loader';
import { environment } from 'environments/environment';
import { CookieService } from 'ngx-cookie-service';
import { NgcCookieConsentConfig, NgcCookieConsentModule } from 'ngx-cookieconsent';
import { TranslateServerLoader } from './core/services/language/server.loader';
import { BaseHttpService } from './core/services/http/base-http.service';
import { MatomoModule } from 'ngx-matomo';
import { ConfigurationService } from './core/services/configuration/configuration.service';
import { Oauth2DialogModule } from './ui/misc/oauth2-dialog/oauth2-dialog.module';
import { MAT_FORM_FIELD_DEFAULT_OPTIONS, MatFormFieldDefaultOptions } from '@angular/material';
import { TranslateServerLoader } from './core/services/language/server.loader';
import { MatomoService } from './core/services/matomo/matomo-service';
import { GuidedTourModule } from './library/guided-tour/guided-tour.module';
import { Oauth2DialogModule } from './ui/misc/oauth2-dialog/oauth2-dialog.module';
// AoT requires an exported function for factories
export function HttpLoaderFactory(http: HttpClient, appConfig: ConfigurationService) {
@ -95,6 +94,7 @@ const appearance: MatFormFieldDefaultOptions = {
CommonHttpModule,
MatMomentDateModule,
LoginModule,
MatomoModule,
//Ui
NotificationModule,
NavigationModule,
@ -131,7 +131,8 @@ const appearance: MatFormFieldDefaultOptions = {
useValue: appearance
},
Title,
CookieService
CookieService,
MatomoService
],
bootstrap: [AppComponent]
})

View File

@ -1,8 +1,14 @@
import { ModuleWithProviders, NgModule, Optional, SkipSelf, APP_INITIALIZER } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { APP_INITIALIZER, ModuleWithProviders, NgModule, Optional, SkipSelf } from '@angular/core';
import { CookieService } from 'ngx-cookie-service';
import { AdminAuthGuard } from './admin-auth-guard.service';
import { AuthGuard } from './auth-guard.service';
import { AuthService } from './services/auth/auth.service';
import { ConfigurationService } from './services/configuration/configuration.service';
import { ContactSupportService } from './services/contact-support/contact-support.service';
import { CultureService } from './services/culture/culture-service';
import { LanguageInfoService } from './services/culture/language-info-service';
import { CurrencyService } from './services/currency/currency.service';
import { DashboardService } from './services/dashboard/dashboard.service';
import { DatasetProfileService } from './services/dataset-profile/dataset-profile.service';
import { DatasetWizardService } from './services/dataset-wizard/dataset-wizard.service';
@ -11,6 +17,7 @@ import { DatasetService } from './services/dataset/dataset.service';
import { DmpInvitationService } from './services/dmp/dmp-invitation.service';
import { DmpProfileService } from './services/dmp/dmp-profile.service';
import { DmpService } from './services/dmp/dmp.service';
import { EmailConfirmationService } from './services/email-confirmation/email-confirmation.service';
import { ExternalDataRepositoryService } from './services/external-sources/data-repository/extternal-data-repository.service';
import { ExternalDatasetService } from './services/external-sources/dataset/external-dataset.service';
import { ExternalSourcesConfigurationService } from './services/external-sources/external-sources-configuration.service';
@ -18,32 +25,25 @@ import { ExternalSourcesService } from './services/external-sources/external-sou
import { ExternalRegistryService } from './services/external-sources/registry/external-registry.service';
import { ExternalResearcherService } from './services/external-sources/researcher/external-researcher.service';
import { ExternalServiceService } from './services/external-sources/service/external-service.service';
import { BaseHttpService } from './services/http/base-http.service';
import { LoggingService } from './services/logging/logging-service';
import { UiNotificationService } from './services/notification/ui-notification-service';
import { ProgressIndicationService } from './services/progress-indication/progress-indication-service';
import { FunderService } from './services/funder/funder.service';
import { GrantFileUploadService } from './services/grant/grant-file-upload.service';
import { GrantService } from './services/grant/grant.service';
import { BaseHttpService } from './services/http/base-http.service';
import { LanguageService } from './services/language/language.service';
import { LockService } from './services/lock/lock.service';
import { LoggingService } from './services/logging/logging-service';
import { MergeEmailConfirmationService } from './services/merge-email-confirmation/merge-email-confirmation.service';
import { UiNotificationService } from './services/notification/ui-notification-service';
import { OrganisationService } from './services/organisation/organisation.service';
import { ProgressIndicationService } from './services/progress-indication/progress-indication-service';
import { ProjectService } from './services/project/project.service';
import { QuickWizardService } from './services/quick-wizard/quick-wizard.service';
import { SearchBarService } from './services/search-bar/search-bar.service';
import { TimezoneService } from './services/timezone/timezone-service';
import { UserGuideService } from './services/user-guide/user-guide.service';
import { UserService } from './services/user/user.service';
import { CollectionUtils } from './services/utilities/collection-utils.service';
import { TypeUtils } from './services/utilities/type-utils.service';
import { QuickWizardService } from './services/quick-wizard/quick-wizard.service';
import { OrganisationService } from './services/organisation/organisation.service';
import { EmailConfirmationService } from './services/email-confirmation/email-confirmation.service';
import { FunderService } from './services/funder/funder.service';
import { ContactSupportService } from './services/contact-support/contact-support.service';
import { LanguageService } from './services/language/language.service';
import { AdminAuthGuard } from './admin-auth-guard.service';
import { LockService } from './services/lock/lock.service';
import { UserGuideService } from './services/user-guide/user-guide.service';
import { ConfigurationService } from './services/configuration/configuration.service';
import { HttpClient } from '@angular/common/http';
import { LanguageInfoService } from './services/culture/language-info-service';
import { CurrencyService } from './services/currency/currency.service';
import { MergeEmailConfirmationService } from './services/merge-email-confirmation/merge-email-confirmation.service';
//
//
// This is shared module that provides all the services. Its imported only once on the AppModule.

View File

@ -76,6 +76,21 @@ export class ConfigurationService extends BaseComponent {
return this._orcidPath;
}
private _matomoEnabled: boolean;
get matomoEnabled(): boolean {
return this._matomoEnabled;
}
private _matomoSiteUrl: string;
get matomoSiteUrl(): string {
return this._matomoSiteUrl;
}
private _matomoSiteId: number;
get matomoSiteId(): number {
return this._matomoSiteId;
}
public loadConfiguration(): Promise<any> {
return new Promise((r, e) => {
@ -114,6 +129,11 @@ export class ConfigurationService extends BaseComponent {
this._doiLink = config.doiLink;
this._useSplash = config.useSplash;
this._orcidPath = config.orcidPath;
if (config.matomo) {
this._matomoEnabled = config.matomo.enabled;
this._matomoSiteUrl = config.matomo.url;
this._matomoSiteId = config.matomo.siteId;
}
}
}

View File

@ -0,0 +1,39 @@
import { Injectable } from '@angular/core';
import { MatomoInjector, MatomoTracker } from 'ngx-matomo';
import { AuthService } from '../auth/auth.service';
import { ConfigurationService } from '../configuration/configuration.service';
@Injectable()
export class MatomoService {
constructor(
private configurationService: ConfigurationService,
private matomoInjector: MatomoInjector,
private matomoTracker: MatomoTracker,
private authService: AuthService
) {
}
init() {
if (this.configurationService.matomoEnabled) {
this.matomoInjector.init(this.configurationService.matomoSiteUrl, this.configurationService.matomoSiteId);
}
}
trackPageView(customTitle?: string): void {
if (this.configurationService.matomoEnabled) {
var principal = this.authService.current();
this.matomoTracker.setUserId(principal ? principal.id : null);
this.matomoTracker.trackPageView(customTitle);
}
}
trackSiteSearch(keyword: string, category?: string, resultsCount?: number): void {
if (this.configurationService.matomoEnabled) {
var principal = this.authService.current();
this.matomoTracker.setUserId(principal ? principal.id : null);
this.matomoTracker.trackSiteSearch(keyword, category, resultsCount);
}
}
}

View File

@ -17,6 +17,7 @@ import { FormControl } from '@angular/forms';
import { OrcidUser } from '@app/core/model/orcid/orcidUser';
import { ZenodoToken } from '@app/core/model/zenodo/zenodo-token.model';
import { LoginInfo } from '@app/core/model/auth/login-info';
import { MatomoService } from '@app/core/services/matomo/matomo-service';
/// <reference types="gapi" />
/// <reference types="facebook-js-sdk" />
@ -52,10 +53,12 @@ export class LoginComponent extends BaseComponent implements OnInit, AfterViewIn
private configurationService: ConfigurationService,
private mergeLoginService: MergeLoginService,
private oauth2DialogService: Oauth2DialogService,
private httpClient: HttpClient
private httpClient: HttpClient,
private matomoService: MatomoService
) { super(); }
ngOnInit(): void {
this.matomoService.trackPageView('loginPage');
this.route.queryParams
.pipe(takeUntil(this._destroyed))
.subscribe((params: Params) => {

View File

@ -34,6 +34,7 @@ import { TranslateService } from '@ngx-translate/core';
import { UiNotificationService, SnackBarNotificationLevel } from '@app/core/services/notification/ui-notification-service';
import { GuidedTourService } from '@app/library/guided-tour/guided-tour.service';
import { GuidedTour, Orientation } from '@app/library/guided-tour/guided-tour.constants';
import { MatomoService } from '@app/core/services/matomo/matomo-service';
@Component({
@ -86,7 +87,8 @@ export class DashboardComponent extends BaseComponent implements OnInit, IBreadC
private dialog: MatDialog,
private language: TranslateService,
private uiNotificationService: UiNotificationService,
private guidedTourService: GuidedTourService
private guidedTourService: GuidedTourService,
private matomoService: MatomoService
) {
super();
// this.dashboardStatisticsData.totalDataManagementPlanCount = 0;
@ -96,6 +98,7 @@ export class DashboardComponent extends BaseComponent implements OnInit, IBreadC
ngOnInit() {
this.matomoService.trackPageView('Home Dashboard');
// if (this.isAuthenticated()) {
// this.userService.getRecentActivity()
// .pipe(takeUntil(this._destroyed))

View File

@ -48,6 +48,11 @@
"enabled": true,
"logLevels": ["debug", "info", "warning", "error"]
},
"matomo": {
"enabled": true,
"url": "https://beta.analytics.openaire.eu/",
"siteId": 361
},
"lockInterval": 60000,
"guideAssets": "assets/images/guide",
"allowOrganizationCreator": true,