Tracking playing only 1 video

hello
i need to track video playing for one video (no need media plugin just for one)
i do this
My html

<div id="motion" class="et_pb_module et_pb_video et_pb_video_0 lwp-no-download">
				<div class="et_pb_video_box">
				<video controls="" controlslist="nodownload">
					<source type="video/mp4" src="mavideo.mp4">
					<source type="video/webm" src="mavideo.webm">
				</video></div>
				<div style="" class="et_pb_video_overlay"><div class="et_pb_video_overlay_hover"><a href="#" class="et_pb_video_play"></a></div></div>
			</div>

1 j create a tag
2 i add action on click

<script>_paq(['trackEvent','play video', 'properly sent', 'it works']);</script>

but nothing in event (no categorie, no return)
thanks for any help

Hello yannick berges,

you will track wich video-file is played? Use currentSrc with an onplay event.
onplay="_paq.push(['trackEvent','video', 'video-play', this.currentSrc]);"

<div id="motion" class="et_pb_module et_pb_video et_pb_video_0 lwp-no-download">
				<div class="et_pb_video_box">
				<video controls="" controlslist="nodownload" onplay="_paq.push(['trackEvent','video', 'video-play', this.currentSrc]);">
					<source type="video/mp4" src="mavideo.mp4">
					<source type="video/webm" src="mavideo.webm">
				</video></div>
				<div style="" class="et_pb_video_overlay"><div class="et_pb_video_overlay_hover"><a href="#" class="et_pb_video_play"></a></div></div>
			</div>

Consider, the matomo Event Tracking has 3 values with 2 hierachies.

_paq.push(['trackEvent','Categories', 'Actions', 'Names']);

  • Categories
    – Actions
  • Actions
    – Names

but not

  • Categories
    – Actions
    — Names

Edit: Track only the filename without extension:

this.currentSrc.replace(string.split('.').pop(), "")

@melbao @yannick_berges
You missed .push:

_paq.push(['trackEvent','Category', 'Action', 'Label']);

See:
https://developer.matomo.org/guides/tracking-javascript-guide#manually-trigger-events

hello
i add this in head

<script>
window.onload = function() {
    document.getElementById('motion').querySelector('video').addEventListener('play', function(e) {
        _paq.push(['trackEvent', 'Categories', 'play video', 'motion']);
		console.log('video jouée');
    });
}</script>

when i test clic on video console.log is ok but i didn’t find any return to matomo
no category in event, etc …
i do a mistake for sure but i doesn’t understand where
thanks for your help

Thanks Philippe,

@yannick_berges , i have no idea. Try this:

var documentreadystateinterval = setInterval(function() {
  if (document.readyState === "complete") {
    var videoelements = document.getElementsByTagName("video");      
    for (var i = 0; i < videoelements.length; i++) {
      videoelements[i].addEventListener('play', function(e) {
        _paq.push(['trackEvent', 'Categories', 'play video', 'motion']);
        console.log('video jouée');
      });
	}
    clearInterval(documentreadystateinterval);
  }
}, 100);

Otherwise maybe your tracking has a failure.

AHH my code works just need time to see return in matomo
thanks for all help !

Hi @yannick_berges
Yes indeed, you need to wait data are archived:

To be sure tracking works well (in case you don’t have the the QueueTracking plugin activated that could delay a few), use the Real-time report: