analytics.js Youtube Plugin

With the analytics.js Youtube Plugin you can easily collect Youtube player events into the Segment ecosystem.

Prerequisites

The Segment Youtube Plugin requires the Youtube player JavaScript object as an input, so your Youtube player embed must use the Youtube IFrame player API.

To begin, you’ll need to generate an API Key for the Segment Youtube plugin, which it uses to access metadata about the video content being played. To do this, create a new project in the Google Developer Console, then create a new API Key in that project for the Segment Youtube plugin. You can read more about this process in the Youtube documentation on registering an application.

Getting Started

1. Enable

Enable a new plugin by navigating to the settings for your Source, and clicking Plugins. You can enable the YouTube plugin from this menu.

Note: At this time, only Javascript sources support plugins.

2. Initialize

Initialize the plugin by giving it access to the YouTube video player instance(s) running on your page. Use the initialize method in the Youtube onYouTubeIframeAPIReady() function: