diff --git a/src/app/footer/footer.component.html b/src/app/footer/footer.component.html index 40e44a83e3b..b5ba6d5af1e 100644 --- a/src/app/footer/footer.component.html +++ b/src/app/footer/footer.component.html @@ -88,29 +88,7 @@

Services

ga('create', 'UA-27008245-2', 'cuni.cz'); ga('send', 'pageview'); //]]> - - - - - - + diff --git a/src/app/footer/footer.component.spec.ts b/src/app/footer/footer.component.spec.ts index 593a9f9e51d..e193db48612 100644 --- a/src/app/footer/footer.component.spec.ts +++ b/src/app/footer/footer.component.spec.ts @@ -5,8 +5,6 @@ import { CUSTOM_ELEMENTS_SCHEMA, DebugElement } from '@angular/core'; import { CommonModule } from '@angular/common'; -import { By } from '@angular/platform-browser'; - import { TranslateLoader, TranslateModule } from '@ngx-translate/core'; import { StoreModule } from '@ngrx/store'; @@ -62,10 +60,6 @@ describe('Footer component', () => { fixture = TestBed.createComponent(FooterComponent); comp = fixture.componentInstance; // component test instance - - // query for the title

by CSS element selector - de = fixture.debugElement.query(By.css('p')); - el = de.nativeElement; }); it('should create footer', inject([FooterComponent], (app: FooterComponent) => { diff --git a/src/app/statistics/angulartics/dspace/view-tracker.component.ts b/src/app/statistics/angulartics/dspace/view-tracker.component.ts index 805d311cfd9..edb8165967a 100644 --- a/src/app/statistics/angulartics/dspace/view-tracker.component.ts +++ b/src/app/statistics/angulartics/dspace/view-tracker.component.ts @@ -40,7 +40,8 @@ export class ViewTrackerComponent implements OnInit, OnDestroy { action: 'page_view', properties: { object: this.object, - referrer + referrer, + category: 'page_view', }, }); }); diff --git a/src/main.browser.ts b/src/main.browser.ts index 43b2ffbaf40..03e39a7c739 100644 --- a/src/main.browser.ts +++ b/src/main.browser.ts @@ -10,6 +10,7 @@ import { environment } from './environments/environment'; import { AppConfig } from './config/app-config.interface'; import { extendEnvironmentWithAppConfig } from './config/config.util'; import { enableProdMode } from '@angular/core'; +import { matomoSettings } from './matomo/matomo-settings'; const bootstrap = () => platformBrowserDynamic() .bootstrapModule(BrowserAppModule, {}); @@ -26,6 +27,7 @@ const main = () => { if (environment.production) { enableProdMode(); } + addMatomoStatistics(); if (hasTransferState) { // Configuration will be taken from transfer state during initialization @@ -42,6 +44,22 @@ const main = () => { } }; +function addMatomoStatistics() { + (window as any)._paq = (window as any)._paq || []; + + // Push all configuration commands first + (window as any)._paq.push(['setTrackerUrl', matomoSettings.hostUrl + 'matomo.php']); + (window as any)._paq.push(['setSiteId', matomoSettings.siteId]); + (window as any)._paq.push(['enableLinkTracking']); + + const g = document.createElement('script'); + g.type = 'text/javascript'; + g.async = true; + g.defer = true; + g.src = matomoSettings.hostUrl + 'matomo.js'; + document.getElementsByTagName('head')[0].appendChild(g); +} + // support async tag or hmr if (document.readyState === 'complete' && !hasTransferState) { main(); diff --git a/src/matomo/matomo-settings.ts b/src/matomo/matomo-settings.ts new file mode 100644 index 00000000000..e0217cfb66b --- /dev/null +++ b/src/matomo/matomo-settings.ts @@ -0,0 +1,7 @@ +/** + * Matomo settings for tracking statistics. This file could be mounted in the docker container. + */ +export const matomoSettings = { + hostUrl: 'http://localhost:8135/', + siteId: '1' +}; diff --git a/src/modules/app/browser-app.module.ts b/src/modules/app/browser-app.module.ts index d6295cf791d..48f0f823aa0 100644 --- a/src/modules/app/browser-app.module.ts +++ b/src/modules/app/browser-app.module.ts @@ -15,7 +15,9 @@ import { AppModule } from '../../app/app.module'; import { ClientCookieService } from '../../app/core/services/client-cookie.service'; import { CookieService } from '../../app/core/services/cookie.service'; import { AuthService } from '../../app/core/auth/auth.service'; -import { Angulartics2GoogleTagManager, Angulartics2RouterlessModule } from 'angulartics2'; +import { + Angulartics2GoogleTagManager, Angulartics2Module, +} from 'angulartics2'; import { SubmissionService } from '../../app/submission/submission.service'; import { StatisticsModule } from '../../app/statistics/statistics.module'; import { BrowserKlaroService } from '../../app/shared/cookies/browser-klaro.service'; @@ -54,7 +56,7 @@ export function getRequest(transferState: TransferState): any { // forRoot ensures the providers are only created once IdlePreloadModule.forRoot(), StatisticsModule.forRoot(), - Angulartics2RouterlessModule.forRoot(), + Angulartics2Module.forRoot(), BrowserAnimationsModule, BrowserTransferStateModule, TranslateModule.forRoot({ diff --git a/src/modules/app/browser-init.service.ts b/src/modules/app/browser-init.service.ts index bf40f0c68b6..2a0dc6662fb 100644 --- a/src/modules/app/browser-init.service.ts +++ b/src/modules/app/browser-init.service.ts @@ -33,6 +33,7 @@ import { MenuService } from '../../app/shared/menu/menu.service'; import { RootDataService } from '../../app/core/data/root-data.service'; import { firstValueFrom, Subscription } from 'rxjs'; import { ServerCheckGuard } from '../../app/core/server-check/server-check.guard'; +import { Angulartics2Matomo } from 'angulartics2'; /** * Performs client-side initialization. @@ -59,6 +60,7 @@ export class BrowserInitService extends InitService { protected menuService: MenuService, private rootDataService: RootDataService, protected serverCheckGuard: ServerCheckGuard, + private angulartics2Matomo: Angulartics2Matomo ) { super( store, @@ -100,6 +102,7 @@ export class BrowserInitService extends InitService { this.initRouteListeners(); this.themeService.listenForThemeChanges(true); this.trackAuthTokenExpiration(); + this.angulartics2Matomo.startTracking(); this.initKlaro();