Vimeo Analytics.js Plugin
Automatically track Vimeo video player events as Segment events.
To use a built version of the plugin from the CDN, simply add the following script tag to the
head of your site.
VimeoAnalytics will be available as part of a globally accessible object called
The above url will download the minified version of the plugin which you should use in production. To access the unminified version for use in development, simply replace
// `npm install @segment/vimeo-analytics --save` OR // `yarn add @segment/vimeo-analytics const VimeoAnalytics = require('@segment/vimeo-analytics');
To beging using the plugin you will need to generate an Access Token in Vimeo. The plugin will use this token to access metadata about the video content being played.
Vimeo provides documentation outlining this process here. Please ensure you are carefully selecting your access scopes! The plugin only needs to read information about your video(s).
To initialize the plugin you will need to create a new instance of the
VimeoAnalytics class and pass in the Vimeo.Player instance running on your page as the first argument and your Vimeo Access Token as the second.
Please read more about the constructor function in the API documentation.
Next, you will need to start the plugin by calling it's
.initialize method. The example below assumes you are using the CDN distribution option.
<iframe src="https://player.vimeo.com/video/76979871" width="640" height="360" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe> <script src="https://player.vimeo.com/api/player.js"></script> <script> var iframe = document.querySelector('iframe'); var player = new Vimeo.Player(iframe); var VimeoAnalytics = window.analyticsPlugins.VimeoAnalytics var vimeoAnalytics = new VimeoAnalytics(player, 'XXXXXXXXXXXXXXXXXXXXXXXXXXXX0365'); vimeoAnalytics.initialize(); </script>
The plugin will now begin listening for the Vimeo Player lifecycle events and responding to them with Segment video events.
new VimeoAnalytics(player, accessToken);
VimeoAnalyics constructor takes as it's arguments the instance of the Vimeo Player you would like to track events for and an Array of metadata about the video(s) that are accessible in the player.
Please ensure that the
assetId you pass in with each ContentEventObject is the Vimeo Id for that video.
.initialize method will bootstrap all the supported event listeners outlined below.
Play events from the Vimeo Player will trigger Video Content Started and Video Playback Started Segment events. If the video player was previously paused, the play event will instead trigger a Video Playback Resumed event.