Google Ima Ads plugin

Code Source

<!--Inset Viddeojs and Ima CSS into website Head tag-->
<link href="../videojs/skins/nuevo/videojs.min.css" rel="stylesheet" type="text/css" />
<link href="../videojs/skins/nuevo/ima.min.css" rel="stylesheet" type="text/css" />

<!--Load videojs plugins and Ima SDK-->
<script src="//"></script>
<script src="../videojs/video.min.js"></script>
<script src="../videojs/plugins/videojs.ima.min.js"></script>
<script src="../videojs/plugins/videojs-contrib-ads.min.js"></script>
<script src="../videojs/nuevo.min.js"></script>

<!--Video tag setup-->
<video id="player_1" class="video-js vjs-fluid" controls preload playsinline poster="images/poster.jpg">
	<source src="//" type="video/mp4">
	<source src="//" type="video/webm">

<!--Initialize player and Nuevo pluging-->
	var player = videojs('player_1');
		//option1: 'value',
		//option2: 'value'

	<!--Initialize Ima Ads-->
	var options = {
		id: 'player_1',
		adTagUrl: 'YOUR_IMA_AD_TAG'

	<!--Enable iOS playback-->

	<!--Part required for proper Ima playback on mobile device-->
	var contentPlayer =  document.getElementById('player_1_html5_api');
	if ((navigator.userAgent.match(/iPad/i) ||
		  navigator.userAgent.match(/Android/i)) &&
		contentPlayer.hasAttribute('controls')) {
	var startEvent = 'click';
	if (navigator.userAgent.match(/iPhone/i) ||
		navigator.userAgent.match(/iPad/i) ||
		navigator.userAgent.match(/Android/i)) {
	  startEvent = 'touchend';
	}, function() {
This is optimal code to load and play Adsense video Ima ads, including mobile devices.
Pay attention to player unique id. It appears 4 times: as video id, to initialize videojs, as Ima options id and as a part if IMA contentPlayer id. Of course it must be same across entire player code setup. In our code example unique id is easy to find, marked in blue color.

It is required to setup proper CORS (Cross-Origin Resource Sharing) configuration on server to enable cross-site HTTP requests.
Implementing the request headers to set up CORS correctly depends on the language and framework of the backend.
More information about enabling CORS you can find on