# Events & Analytics plugin

The events plugin allows to track a bunch of player events and record the most important events through Google Analycis, Matomo (formerly Piwik), javascript or custom URL.

## Initialize player and plugins

This is essential to set unique title and unique id for each video that events you want to track. You can do it in several ways, e.g. as Nuevo plugin options.

    <link href="../skins/nuevo/videojs.min.css" rel="stylesheet" type="text/css" />
    <script src="../video.min.js"></script>
    <script src="../nuevo.min.js"></script>
    <script src="../plugins/videojs.events.js"></script>

    <script>
    	var player = videojs('player_1');
    	player.nuevo({ title:"Events Example Video", video_id:"v111" });
    	player.events();
    </script>

To enable one of available analytics methods just enable appropriate option. Events plugin automatically detects analytics method used on website.

    player.events({ analytics:true });

You can also track events through custom URL. This enables an option to record user details through user event if Abstract API Key defined.

    player.events({ trackingUrl: "https://tracking_url", abstractApiKey: "Your API Key" });

To track events through javscript you can listen to track event.

    <script>
    player.on('track', (e, data) => {
      var event_name = data.eventType;
      let session_id = data.sessionId;
      let category = data.category;
      let video_id = data.playerId;
      let video_title = data.playerTitle;
    });
    </script>

By default, events plugin attempts to obtain user details through ipapi.co service. Free plan allows up to 1000 requests daily. Other services that you may use instead of ipapi.co are ipdata.co and abstractapi.com. Both require apiKey that you may pass as specific plugin's option.
Full plugin's description, list of events available to track, usage tutorial you can find on Nuevodevel demo website page.