added analytics service (in progress)

This commit is contained in:
Sofia Papacharalampous 2024-05-21 18:04:57 +03:00
parent e4786ed5f5
commit d63e87c9d6
6 changed files with 121 additions and 2 deletions

View File

@ -40,6 +40,7 @@ import { OpenDMPCustomTranslationCompiler } from './utilities/translate/opendmp-
import { CoreAnnotationServiceModule } from 'annotation-service/services/core-service.module';
import { CoreNotificationServiceModule } from '@notification-service/services/core-service.module';
import { DepositOauth2DialogModule } from './ui/misc/deposit-oauth2-dialog/deposit-oauth2-dialog.module';
import { AnalyticsService } from './core/services/matomo/analytics-service';
// AoT requires an exported function for factories
export function HttpLoaderFactory(languageHttpService: LanguageHttpService) {
@ -182,7 +183,8 @@ export function InstallationConfigurationFactory(appConfig: ConfigurationService
},
Title,
CookieService,
MatomoService
MatomoService,
AnalyticsService
],
bootstrap: [AppComponent]
})

View File

@ -0,0 +1,67 @@
export class AnalyticsProviders {
private _providers: AnalyticsProvider[];
get providers(): AnalyticsProvider[] {
return this._providers;
}
set providers(providers: AnalyticsProvider[]) {
this._providers = providers;
}
public static parseValue(value: any): AnalyticsProviders {
const analyticsProvidersObj: AnalyticsProviders = new AnalyticsProviders();
analyticsProvidersObj.providers = [];
for (let providerValue of value.providers) {
const providerObj: AnalyticsProvider = AnalyticsProvider.parseValue(providerValue);
analyticsProvidersObj.providers.push(providerObj);
}
return analyticsProvidersObj;
}
}
export class AnalyticsProvider {
private _type: AnalyticsProviderType;
get type(): AnalyticsProviderType {
return this._type;
}
set type(type: AnalyticsProviderType) {
this._type = type;
}
private _enabled: boolean;
get enabled(): boolean {
return this._enabled;
}
set enabled(enabled: boolean) {
this._enabled = enabled;
}
private _options: any;
get options(): any {
return this._options;
}
set options(options: any) {
this._options = options;
}
public static parseValue(value: any): AnalyticsProvider {
const obj: AnalyticsProvider = new AnalyticsProvider();
obj.type = value.type;
obj.enabled = value.enabled;
obj.options = value.options;
return obj;
}
}
export enum AnalyticsProviderType {
Matomo = "matomo"
}

View File

@ -10,6 +10,7 @@ import { HttpClient } from '@angular/common/http';
import { KeycloakConfiguration } from '@app/core/model/configuration-models/keycloak-configuration.model';
import { Guid } from '@common/types/guid';
import { AuthProviders } from '@app/core/model/configuration-models/auth-providers.model';
import { AnalyticsProviders } from '@app/core/model/configuration-models/analytics-providers.model';
@Injectable({
providedIn: 'root',
@ -153,6 +154,11 @@ export class ConfigurationService extends BaseComponent {
get authProviders(): AuthProviders {
return this._authProviders;
}
private _analyticsProviders: AnalyticsProviders;
get analyticsProviders(): AnalyticsProviders {
return this._analyticsProviders;
}
private _researcherId: any;
get researcherId(): boolean {
@ -239,6 +245,7 @@ export class ConfigurationService extends BaseComponent {
this._newReleaseNotificationLink = config.newReleaseNotification?.link;
this._newReleaseNotificationVersionCode = config.newReleaseNotification?.versionCode;
this._authProviders = AuthProviders.parseValue(config.authProviders);
this._analyticsProviders = AnalyticsProviders.parseValue(config.analytics);
this._researcherId = config.referenceTypes.researcherId;
this._grantId = config.referenceTypes.grantId;
this._organizationId = config.referenceTypes.organizationId;

View File

@ -0,0 +1,31 @@
import { Injectable } from "@angular/core";
import { ConfigurationService } from "../configuration/configuration.service";
import { MatomoService } from "./matomo-service";
import { AnalyticsProviderType, AnalyticsProviders } from "@app/core/model/configuration-models/analytics-providers.model";
@Injectable()
export class AnalyticsService {
public static Dashboard: string = 'Home Dashboard';
constructor(
private configurationService: ConfigurationService,
private matomoService: MatomoService
) { }
trackPageView(customTitle?: string): void {
const analytics: AnalyticsProviders = this.configurationService.analyticsProviders;
for (let provider of analytics.providers) {
switch(provider.type) {
case(AnalyticsProviderType.Matomo):
this.matomoService.trackPageViewCopy(provider, customTitle);
}
}
}
trackSiteSearch(keyword: string, category?: string, resultsCount?: number): void {
}
trackDownload(category: "dmps" | "datasets" | "descriptions", type: string, id: string): void {
}
}

View File

@ -2,6 +2,7 @@ import { Injectable } from '@angular/core';
import { MatomoInitializerService, MatomoTracker } from 'ngx-matomo-client';
import { AuthService } from '../auth/auth.service';
import { ConfigurationService } from '../configuration/configuration.service';
import { AnalyticsProvider } from '@app/core/model/configuration-models/analytics-providers.model';
@Injectable()
export class MatomoService {
@ -28,6 +29,14 @@ export class MatomoService {
this.matomoTracker.trackPageView(customTitle);
}
}
trackPageViewCopy(provider: AnalyticsProvider, customTitle?: string): void {
if (provider.enabled) {
var principalid = this.authService.userId();
if (principalid != null) { this.matomoTracker.setUserId(principalid.toString()); }
this.matomoTracker.trackPageView(customTitle);
}
}
trackSiteSearch(keyword: string, category?: string, resultsCount?: number): void {
if (this.configurationService.matomoEnabled) {

View File

@ -18,6 +18,7 @@ import { CookieService } from 'ngx-cookie-service';
import { takeUntil } from 'rxjs/operators';
import { StartNewDescriptionDialogComponent } from '../description/start-new-description-dialog/start-new-description-dialog.component';
import { StartNewDmpDialogComponent } from '../dmp/new/start-new-dmp-dialogue/start-new-dmp-dialog.component';
import { AnalyticsService } from '@app/core/services/matomo/analytics-service';
@Component({
@ -43,6 +44,7 @@ export class DashboardComponent extends BaseComponent implements OnInit {
private language: TranslateService,
private guidedTourService: GuidedTourService,
private matomoService: MatomoService,
private analyticsService: AnalyticsService,
public referenceTypeService: ReferenceTypeService,
private fb: UntypedFormBuilder,
private cookieService: CookieService,
@ -62,7 +64,8 @@ export class DashboardComponent extends BaseComponent implements OnInit {
}
});
this.matomoService.trackPageView('Home Dashboard');
this.analyticsService.trackPageView(AnalyticsService.Dashboard);
// this.matomoService.trackPageView('Home Dashboard');
if (!this.isAuthenticated()) {
this.dashboardService.getPublicDashboardStatistics()