Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Instead of video title, send video ID to Matomo Media Analytics Plugin #8

Closed
snoesberger opened this issue Mar 19, 2024 · 10 comments · Fixed by #11
Closed

Instead of video title, send video ID to Matomo Media Analytics Plugin #8

snoesberger opened this issue Mar 19, 2024 · 10 comments · Fixed by #11

Comments

@snoesberger
Copy link
Contributor

@miesgre as discussed at the Opencast summit in Zaragoza, here my wish for the Matomo integration.

In the case of the Matomo Media Analytics plugin, the data sent to Matomo includes the title of the video. As the video title is not unique in Opencast, this can cause statistics to be aggregated if several videos have the same name. If we would send the video ID, we could make sure that we collect the statistics for each unique video separately. This would also make it easier to read the statistics for a single unique video from Matomo.

One could also imagine making it configurable whether the video title, ID or other data can be sent.

If you need any further information, please do not hesitate to contact me.

Thanks for having a look at it!

@snoesberger
Copy link
Contributor Author

To clarify, the title is currently only sent with Paella 6, and is completely missing with Paella 7. See this comment for more information: #5 (comment)

The missing title information was also once a problem in Paella 6 and was fixed with this commit: polimediaupv/paella@2a65b3e

@miesgre
Copy link
Collaborator

miesgre commented Apr 11, 2024

Thanks @snoesberger for the info.

Matomo documentation: Enriching and customising media data tracking

@luniki
Copy link
Contributor

luniki commented Jun 19, 2024

I'll take a look at this.

@luniki
Copy link
Contributor

luniki commented Jun 25, 2024

Originally I thought I could change this directly in this project. However, to send the video ID instead of the document title requires changes to the code using paella-core instead (as @miesgre linked above).

@miesgre
Copy link
Collaborator

miesgre commented Jun 26, 2024

I don't have the Media Analitycs plugin and I can not test it, but. Is the title currently being sent?

According to the documentation:

Media Analytics will detect the media title by searching for the following pieces of information:

  • firstly, the data-matomo-title HTML attribute.
  • next, the data-piwik-title HTML attribute.
  • Media title from YouTube / Vimeo player.
  • title HTML attribute.
  • finally, the alt HTML attribute.

If the title is currently being sent, you may only need to change the title of the document.
maybe a

document.title = `${videoId} - ${videoTitle}`;

or making it configurable in the config.

@snoesberger
Copy link
Contributor Author

I don't have the Media Analitycs plugin and I can not test it, but. Is the title currently being sent?

We have the Media Analytics plugin installed and at the moment the title information isn't send. The ma_ti parameter is always empty, other parameters like ma_id, ma_pn, etc. are set.

@luniki
Copy link
Contributor

luniki commented Jul 5, 2024

Thank you for your links @miesgre !

I have created a solution for the Opencast integration of the paella player by extending MatomoUserTrackingDataPlugin and this load method:

  load() {
    bindEvent(this.player, Events.STREAM_LOADED, () => {
      this.player.containerElement.querySelector('video').dataset.matomoTitle = <video-id>;
    });
    super.load();
  }

So essentially I am searching for the video element inside the player's containerElement to set the data-matomo-title attribute.

Is there a better way to access the video element in order to add the data attribute?

(I tried to understand the paella-core documentation for the correct way but failed :-( )

@miesgre
Copy link
Collaborator

miesgre commented Jul 5, 2024

I think right now it's the best we can do.

The only drawback I see is if at some point the <video> element is replaced. In that case the data-matomo-title attribute would be lost (I'm not sure if the STREAM_LOADED event would be thrown again in these cases).
But this should not happen in paella-core, so in theory it should work correctly

Please make a PR with the changes.
Thank you very much for your contributions.

@miesgre
Copy link
Collaborator

miesgre commented Jul 5, 2024

As I said, I don't have the plugin and I can't test it...
I have a question. Paella plays multiple videos... so is the plugin counting the views correctly or is it counting for each of the videos (presenter+presentation)?
Is Matomo counting twice? Maybe we should only activate monitoring of the "master" video?

@snoesberger
Copy link
Contributor Author

I have tested @luniki's suggested solution on my local Opencast installation with the Media Analytics plugin and it works fine with single videos. But with multiple videos, no statistics are collected for Media Analytics.
In the case of multiple videos in the Paella player, the Media Analytics stats for each video are sent as form data in a single post request to Matomo, whereas in the case of a single video, the data is sent as url parameters. It seems that Matomo doesn't take into account the data sent as form data (bug in Matomo?).

I played around a bit and found a solution that works for both single and multiple videos. I also found a way to put the code directly into the pealla-user-tracking plugin instead of the Opencast integration (MatomoUserTrackingDataPlugin). This will make it easier to integrate with other tools like Tobira or LMSs. I'll be submitting a PR with my suggestions later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants