Dspace 7.5 Matomo setup

416 views
Skip to first unread message

Sarfaraz Mohamed

unread,
Sep 28, 2023, 6:16:02 AM9/28/23
to DSpace Technical Support
Good Day

I would like to know whats the process to setup Matomo on Dspace 7.5
in Dspace 6 was included in :

page-structure.xsl

Which does not exist in Dspace 7.

Any assistance would be appreciated.

Thank you

DSpace Technical Support

unread,
Oct 4, 2023, 11:23:10 AM10/4/23
to DSpace Technical Support
Hi,

At this time, DSpace 7 doesn't have Matomo support.  That said, I do know several other institutions/developers are interested in finding a way to support Matomo in DSpace 7.  See this ticket for more details: https://github.com/DSpace/DSpace/issues/8414   That ticket has also been highlighted to the OpenAIRE team that has built a prior Matomo plugin for DSpace in the past: https://github.com/openaire/OpenAIRE-Piwik-DSpace/issues/3

Currently, this work is waiting on a volunteer to move it forward.  I agree that Matomo support should be added to DSpace, but the next step is to find a volunteer interested in making it happen.

Tim

Sarfaraz Mohamed

unread,
Oct 19, 2023, 3:41:17 AM10/19/23
to DSpace Technical Support
Thank you
much appreciated

Sergio Fredes Mena

unread,
Jan 14, 2024, 7:40:05 PM1/14/24
to DSpace Technical Support
Hola, para integrar Matomo en DSpace 7.x, me sirvio modificar el archivo footer.component.ts, dentro del archivo debes colocar lo siguiente:

import { Component, AfterViewInit, Renderer2, ElementRef } from '@angular/core';
import { Router, NavigationEnd } from '@angular/router';
import { FooterComponent as BaseComponent } from '../../../../app/footer/footer.component';

declare global {
  interface Window {
    _paq: any[];
  }
}

@Component({
  selector: 'ds-footer',
  styleUrls: ['footer.component.scss'],
  templateUrl: 'footer.component.html'
})

export class FooterComponent implements AfterViewInit {
  currentYear = new Date().getFullYear();
  private previousPageUrl: string;
  constructor(
    private renderer: Renderer2,
    private el: ElementRef,
    private router: Router
  ) {}

  ngAfterViewInit() {
    this.initializeMatomo();
    this.trackPageViews();
  }
  private initializeMatomo() {
    window._paq = window._paq || [];
    window._paq.push(['trackPageView']);
    window._paq.push(['enableLinkTracking']);
    window._paq.push(['setTrackerUrl', '//URL_MATOMO/matomo.php']);
    window._paq.push(['setSiteId', '1']);
    const script = this.renderer.createElement('script');
    script.type = 'text/javascript';
    script.async = true;
    script.src = '// URL_MATOMO/matomo.js';
    this.renderer.appendChild(this.el.nativeElement, script);
  }

  private trackPageViews() {
    this.router.events.subscribe(event => {
      if (event instanceof NavigationEnd) {
        if (this.previousPageUrl) {
          window._paq.push(['setReferrerUrl', this.previousPageUrl]);
        }
        window._paq.push(['setCustomUrl', window.location.pathname + window.location.search]);
        window._paq.push(['setDocumentTitle', document.title]);
        window._paq.push(['trackPageView']);
        this.previousPageUrl = window.location.href;
      }
    });
  }
}

De esta forma Matomo comenzará a rastrear toda la actividad dentro de DSpace. Luego solo debes incorporar el atributo download="download" dentro del archivo file-download-link.html

<a [routerLink]="(bitstreamPath$| async)?.routerLink" download="download" class="dont-break-out" [queryParams]="(bitstreamPath$| async)?.queryParams" [target]="isBlank ? '_blank': '_self'" [ngClass]="cssClasses">

Agregando el atributo download, matomo comprende que cuando el usuario hace clic en el enlace de descarga, es efectivamente una descarga.

Aplicando estos cambios, Matomo debería capturar datos sin problema, al menos a mi me funciona sin problema.

Reply all
Reply to author
Forward
0 new messages