var playersubsec = window.playersubsec || false; var platform = "videoshow"; var loadUrl = window.location.href || ''; var player = player || undefined; var globalAgency = globalAgency || ''; var fallbackMute = false; var defaultVolume = 100; var unmuteOnTap = true; var defaultVideoViewTime = 3; var isVideoViewSent = false; var is10SecViewSent = false; var defaultPageSection = "videoshow"; var playerContainerId,playerDOMObj; var videoRequestTime, timeTakenToVideoReady; window.SPLSkipGALibLoad = true; var TimesApps = window.TimesApps || {}; TimesApps.loadJs = function (url, cb, nodeid) { var head = document.getElementsByTagName('head')[0], s = document.createElement('script'); s.type = 'text/javascript'; s.src = url; s.async = true; nodeid && (s.id = nodeid); var ieCallback = function (el, callback) { if (el.readyState === 'loaded' || el.readyState === 'complete') { callback(); } else { setTimeout(function () { ieCallback(el, callback); }, 20); } }; if (typeof cb === 'function') { if (typeof s.addEventListener !== 'undefined') { s.addEventListener('load', cb, false); s.addEventListener('error', cb, false); } else { s.onreadystatechange = function () { s.onreadystatechange = null; ieCallback(s, cb); }; } } head.appendChild(s); } function _parseCookieValue ( s ) { if( s.indexOf( '"' ) === 0 ) { // This is a quoted cookie as according to RFC2068, unescape... s = s.slice( 1, -1 ).replace( /\\"/g, '"' ).replace( /\\\\/g, '\\' ); } try { // If we can't decode the cookie, ignore it, it's unusable. // Replace server-side written pluses with spaces. return decodeURIComponent( s.replace( /\+/g, ' ' ) ); } catch( e ) {} } function get_cookie( name ) { var result = name ? undefined : {}; var cookies = document.cookie ? document.cookie.split( '; ' ) : []; for( var i = 0, l = cookies.length; i < l; i++ ) { var parts = cookies[ i ].split( '=' ); var nameK = decodeURIComponent( parts.shift() ); var cookie = parts.join( '=' ); cookie = _parseCookieValue( cookie ); if( name && name === nameK ) { result = cookie; break; } if( !name && cookie !== undefined ) { result[ nameK ] = cookie; } } return result; } var checkGdprAndCall = function(callback, callbackForEu, checkForUserConsent){ try{ window.TimesGDPR = window.parent.TimesGDPR; }catch(e){} if ( window.TimesGDPR && TimesGDPR.common.consentModule.gdprCallback ){ TimesGDPR.common.consentModule.gdprCallback(function(data){ if(data && data.isEUuser && typeof callbackForEu == "function" ){ callbackForEu(); }else if( !data.isEUuser && typeof callback == "function" ){ callback(); } }); }else if(typeof callbackForEu == "function"){ callbackForEu(); } } TimesApps.prepareComscoreDataAndFireReq = function(event, eventData, eventType){ var parentWindow = window; if(typeof parentWindow == "undefined"){ return; } var parentHostname = parentWindow.location.hostname; if( parentHostname.indexOf(".jeetwin-gaming.com") == -1 ){ return; } if( typeof parentWindow.TimesApps == "undefined"){ return; } var config = parentWindow.TimesApps.comscoreTrackingConfig; if( typeof config == "undefined" ){ return; } var contentType = eventData.stream || ""; contentType = contentType.toUpperCase(); var trackingDetails = {}; trackingDetails.contentGenre = config.contentGenre; trackingDetails.seoLocation = playerDOMObj.getAttribute("data-seolocation"); var dateObj = playerDOMObj.getAttribute("data-artdate"); dateObj = dateObj.split("#")[1]; dateObj = new Date(Date.parse(dateObj)); dateObj = dateObj.getFullYear() + "-" + (dateObj.getMonth()+1) + "-" +dateObj.getDate(); var date = dateObj; trackingDetails.airDate = date; var videoObj = eventData || {}; videoObj.pdata = {}; videoObj.id = playerDOMObj.getAttribute("data-msid"); //converting to mins //remove once all videos are migrated to Slike videoObj.duration = ( videoObj.duration || 00 ) / 60; videoObj.title = playerDOMObj.getAttribute("data-title"); videoObj.pdata.adposition = eventData.adtype; trackingDetails.c3 = config.c3; if(typeof eventType === 'string' && eventType != "") eventType = eventType.toUpperCase(); fireComscoreTrackingRequest(config.comscoreCustomerId, eventType, contentType, config.stationTitle, config.publisherName, trackingDetails, videoObj); if( eventType == "ADSKIP" ){ TimesApps.setAdStatus(contentType,eventType); } } var TimesApps = window.TimesApps || {}; TimesApps.ComscoreConfig = TimesApps.ComscoreConfig || {}; checkGdprAndCall && checkGdprAndCall(null, function(){ TimesApps.ComscoreConfig['cs_ucfr'] = 0; }, false); //flag to check if next video has been played by the player //used in case of videoshow and videolist TimesApps.playingSubsequentVideo = false; TimesApps.videoEventsMap = { "START" : "START", "STOP" : "STOP", "PAUSED" : "PAUSED", "ADCOMPLETE" : "ADCOMPLETE" } /* *remvoe fn post Slike migration * check point, CMS INSERTED LIVE TV */ var convertMinutesToMs = function(timeInMinutes){ var timeInMs = 0; if( typeof timeInMinutes != "undefined" ){ var timeSplit = timeInMinutes.toString().split(":"); var SECONDS_IN_A_MINUTE = 60; var MS_IN_A_SECOND = 1000; if(timeSplit.length ==2){ timeInMs = timeSplit[0] * SECONDS_IN_A_MINUTE * MS_IN_A_SECOND; timeInMs += timeSplit[1] * MS_IN_A_SECOND; }else if(timeSplit.length ==1){ timeInMs = timeSplit[0] * SECONDS_IN_A_MINUTE * MS_IN_A_SECOND; } } return timeInMs; } /* currently moved to vod_player_js remove after moving to Utils for vod, live, minitv */ TimesApps.convertMinutesToMs = TimesApps.convertMinutesToMs || convertMinutesToMs; TimesApps.setAdStatus = function(contentType,eventType, adDuration){ if( contentType == "AD" ){ if( eventType == "PAUSED" ){ TimesApps.adStatus = "PAUSED"; }else if( eventType == "START" ){ TimesApps.adStatus = "PLAYING"; }else if( eventType == "ADCOMPLETE" ){ TimesApps.adStatus = "ADCOMPLETE"; TimesApps.isServingAdInFlashPlayer = false; } else if( eventType == "ADSKIP" ){ TimesApps.adStatus = "ADSKIP"; TimesApps.isServingAdInFlashPlayer = false; } else if( eventType == "ADDURATION" ){ //hack for flash players ( livetv, mini ) //as insufficient data //is available with events in such cases TimesApps.isServingAdInFlashPlayer = true; TimesApps.adDuration = adDuration; } }else{ //request was for content video //implies that ad has been skipped TimesApps.adStatus = "ADCOMPLETE"; TimesApps.isServingAdInFlashPlayer = false; } } var fireComscoreTrackingRequest = function(comscoreCustomerId, eventType, contentType, stationTitle, publisherName, trackingDetails, videoObj){ if( typeof window.myStreamingTag == 'undefined' || eventType == "REPLAY" ){ window.myStreamingTag = new ns_.StreamingTag({ customerC2: comscoreCustomerId }); } if( typeof TimesApps.videoEventsMap[eventType] == "undefined" ){ //event is not in list of events to track return; } if( typeof comscoreCustomerId == 'undefined' || comscoreCustomerId == '' ){ return; } if( TimesApps.isServingAdInFlashPlayer ){ contentType = "AD"; } try{ if( eventType == "START" || eventType == 'PLAYING' || eventType == 'ADVIEW' ){ if(contentType == "AD"){ if( TimesApps.adStatus == "PAUSED" ){ //ad was paused and has just switched to playing status //tracking not required return; } var adStr = ""; if( typeof videoObj.pdata == "undefined" ){ return; } var adposition = videoObj.pdata.adposition || ""; if( adposition.toUpperCase() == "PRE"){ adStr = ns_.StreamingTag.AdType.LinearOnDemandPreRoll; }else{ adStr = ns_.StreamingTag.AdType.LinearOnDemandPostRoll; } adDurationInMinutesFormat = "00:" + (videoObj.duration || videoObj.pdata.tottime || 00 ); var adDuration = TimesApps.convertMinutesToMs(adDurationInMinutesFormat); myStreamingTag.playVideoAdvertisement({ ns_st_cl: adDuration }, adStr); }else{ var seoLocation = trackingDetails.seoLocation.split("/"); if( seoLocation.length >= 2 ){ var seoLocationWithoutTitle = seoLocation.length -1; seoLocation = seoLocation.slice(0, seoLocationWithoutTitle).join("/"); }else{ seoLocation = trackingDetails.seoLocation; } var videoDuration = TimesApps.convertMinutesToMs(videoObj.duration); var metd = { "ns_st_ci": videoObj.id || videoObj.videoid || 0, "ns_st_cl": videoDuration || 0, "ns_st_st": stationTitle, "ns_st_pu": publisherName, "ns_st_pr": seoLocation, "ns_st_ep": videoObj.title, "ns_st_sn": "*null", "ns_st_en": "*null", "ns_st_ge": trackingDetails.contentGenre, "ns_st_ti": "*null", "ns_st_ia": "0", "ns_st_ce": "0", "ns_st_ddt": trackingDetails.airDate, "ns_st_tdt": trackingDetails.airDate, "c3": trackingDetails.c3 || "*null", "c4": "*null", "c6": "*null" } if( TimesApps.ComscoreConfig.hasOwnProperty('cs_ucfr') && TimesApps.ComscoreConfig['cs_ucfr'] === 0 ){ metd['cs_ucfr'] = TimesApps.ComscoreConfig['cs_ucfr']; } myStreamingTag.playVideoContentPart(metd, ns_.StreamingTag.ContentType.ShortFormOnDemand); } }else if(!(contentType == "AD" && eventType != "ADCOMPLETE" )){ //STOP, VIDEOCOMPLETE, PAUSED myStreamingTag.stop(); } TimesApps.setAdStatus(contentType,eventType); }catch(e){} } var etimes_video_ga = (function () { function saveVideoRequestTime() { videoRequestTime = Date.now(); } function fetchTimeTakeToVideoReady() { return timeTakenToVideoReady = Date.now() - videoRequestTime + 'ms_'; } function fetchIsUserInitiated() { return (isUserInitiated == true) ? "user-initiated" : "autoplay"; } function fetchCurrentSeolocation() { return playerDOMObj.getAttribute("data-seolocation"); } function fetchCurrentMsid() { return playerDOMObj.getAttribute("data-msid"); } function fetchCurrentAgency() { return (playerDOMObj.getAttribute("data-agency") != "" && playerDOMObj.getAttribute("data-agency") != "undefined") ? playerDOMObj.getAttribute("data-agency") : "TNN"; } function fetchCampaign() { return (playerDOMObj.getAttribute("data-campaign") != "" && playerDOMObj.getAttribute("data-campaign") != "undefined") ? "_"+playerDOMObj.getAttribute("data-campaign") : ""; } function sendGAEvent(category, action, label) { if (typeof (ga) == "function") ga('send', 'event', category, action, label); } function sendGA4(eventData) { if(typeof window !== 'undefined' && Array.isArray(window.dataLayer)) { window.dataLayer.push(eventData); window.dataLayer.push({ label: '', category: '' }); } } function getEventAction() { return fetchIsUserInitiated() + "_" + fetchCurrentSeolocation() + "/" + fetchCurrentMsid() + "_" + fetchCurrentAgency() + fetchCampaign(); } function getEventLabel() { var _sourceval = (playerDOMObj.getAttribute("data-source") !="")?playerDOMObj.getAttribute("data-source") : defaultPageSection; return platform + "_" + _sourceval; } function sendSlikeJsLoadRequest() { sendGAEvent("SLIKEREQUESTED", getEventAction(), getEventLabel()) } function sendSlikeLoaded() { sendGAEvent("SLIKELOADED", getEventAction(), getEventLabel()) } function sendSlikeError() { sendGAEvent("SLIKELOADFAIL", getEventAction(), getEventLabel()) } function getEmbedSource(){ return (playerDOMObj.getAttribute("data-source") == "audioembed" ) ? "AUDIO" : "VIDEO"; } function sendVideoRequest() { saveVideoRequestTime(); sendGAEvent(getEmbedSource() + "REQUEST", getEventAction(), getEventLabel()) } function sendVideoError(errmessage) { sendGAEvent(getEmbedSource() +"ERROR", getEventAction(), getEventLabel() + "/" + errmessage) } function sendVideoReady() { sendGAEvent(getEmbedSource() +"READY", fetchTimeTakeToVideoReady() + getEventAction(), getEventLabel()) } function sendVideoView() { sendGAEvent(getEmbedSource() +"VIEW", getEventAction(), getEventLabel()) // TimesApps.iBeat.loadiBeat(); } function sendVideoStarted(){ sendGAEvent(getEmbedSource() +"STARTED", getEventAction(), getEventLabel()) } function sendVideoComplete(duration) { sendGAEvent(getEmbedSource() +"COMPLETE", getEventAction() + "_" + parseInt(duration) + "s", getEventLabel()) } function sendAdRequest(identifier) { //sendGAEvent("ADREQUEST", identifier + "/" + getEventAction(), getEventLabel()) } function sendAdError(identifier) { //sendGAEvent("ADERROR", identifier + "/" + getEventAction(), getEventLabel()) } function sendAdLoaded(identifier) { //sendGAEvent("ADLOADED", identifier + "/" + getEventAction(), getEventLabel()) } function sendAdView(identifier) { //sendGAEvent("ADVIEW", identifier + "/" + getEventAction(), getEventLabel()) } function sendAdComplete(identifier) { //sendGAEvent("ADCOMPLETE", identifier + "/" + getEventAction(), getEventLabel()) } function sendAdSkip(identifier) { sendGAEvent("ADSKIP", identifier + "/" + getEventAction(), getEventLabel()) } function sendAdStart(identifier) { sendGAEvent("ADSTART", identifier + "/" + getEventAction(), getEventLabel()) } function sendVideoLoadRequest(identifier) { sendGAEvent("VIDEOLOADREQUEST", identifier + "/" + getEventAction(), getEventLabel()) } function sendVideoInit(identifier) { sendGAEvent("VIDEOINIT", identifier + "/" + getEventAction(), getEventLabel()) } return { _sendSlikeJsLoadRequest: function () { sendSlikeJsLoadRequest(); }, _sendSlikeLoaded: function () { sendSlikeLoaded(); }, _sendSlikeError: function () { sendSlikeError(); }, _sendVideoRequest: function () { sendVideoRequest(); }, _sendVideoError: function (errmessage) { sendVideoError(errmessage); }, _sendVideoReady: function () { sendVideoReady(); }, _sendVideoInit: function () { sendVideoInit(); }, _sendVideoStarted: function(){ sendVideoStarted(); }, _sendVideoView: function () { sendVideoView(); }, _sendVideoComplete: function (duration) { sendVideoComplete(duration); }, _sendAdRequest: function (identifier) { sendAdRequest(identifier); }, _sendAdError: function (identifier) { sendAdError(identifier); }, _sendAdLoaded: function (identifier) { sendAdLoaded(identifier); }, _sendAdView: function (identifier) { sendAdView(identifier); }, _sendAdStart: function (identifier) { sendAdStart(identifier); }, _sendAdComplete: function (identifier) { sendAdComplete(identifier); }, _sendAdSkip: function (identifier) { sendAdSkip(identifier); }, _sendVideoLoadRequest: function (identifier){ sendVideoLoadRequest(identifier); }, _sendGA4: function(eventData){ sendGA4(eventData); } } }()); function onJSLoadError(type) { switch (type) { case 'slike': etimes_video_ga._sendSlikeError(); break; } } function onJSLoaded(type) { switch (type) { case 'slike': etimes_video_ga._sendSlikeLoaded(); break; } } function getPlayerVolume() { return defaultVolume } function getBgImg() { if (playerDOMObj.getAttribute("data-refreshed") == "0" && playerDOMObj.getAttribute("data-bgImg") != null && playerDOMObj.getAttribute("data-bgImg") != "") { return playerDOMObj.getAttribute("data-bgImg") } else { var msidVal = playerDOMObj.getAttribute("data-msid"); var imgPath = "http://static.toiimg.com/thumb/msid-" + msidVal + ",width-800,resizemode-4/" + msidVal + ".jpg"; return imgPath; } } function getUserCountry() { var geoinfo = window.geoinfo; var countryCode; if (geoinfo != "" && geoinfo && geoinfo.CountryCode && geoinfo.CountryCode != '') { countryCode = geoinfo.CountryCode;; } else { var script = document.createElement("script"); script.type = "text/javascript"; script.src = "//geoapi.jeetwin-gaming.com/?cb=1"; script.async = "async"; script.onload = function () { var geoinfo = window.geoinfo; countryCode = geoinfo.CountryCode; } document.head.appendChild(script); } return countryCode; } function playVideoFromPlayList(index, player) { if (window.playListObj != undefined && window.playListObj != null && typeof window.playListObj != "undefined") { if (window.playListObj.playlist != undefined && window.playListObj.playlist.length > 1) { player = player || window.player; var nextvideodata; var playerObj = playerDOMObj; if (typeof index === 'number' && !isNaN(index) && index > -1) { // Notify: Changed condition here nextvideodata = window.playListObj.playlist[index]; playerObj.setAttribute("data-userinitiated", "1"); window.playListObj.callbacks.onTerminate(index); window.playListObj.currentIndex = index; } else { nextvideodata = window.playListObj.playlist[window.playListObj.nextIndex]; playerObj.setAttribute("data-userinitiated", "0"); window.playListObj.callbacks.onEnded(); window.playListObj.currentIndex = window.playListObj.nextIndex; } var slikeId = nextvideodata.media.slikeid; var videoMsid = nextvideodata.msid; var seoLocation = nextvideodata.media.seolocation; var playerType = nextvideodata.media.rmid; var videoTitle = nextvideodata.media.videoheading; var videoAgency = nextvideodata.media.agency; var skipAds = (nextvideodata.media.skipads == "1") ? true : false; var bgImg = getBgImg(); playerObj.setAttribute("data-msid", videoMsid); playerObj.setAttribute("data-slikeid", slikeId); playerObj.setAttribute("data-seolocation", seoLocation); playerObj.setAttribute("data-rmid", playerType); playerObj.setAttribute("data-title", videoTitle); playerObj.setAttribute("data-agency", videoAgency); playerObj.setAttribute("data-skipads", nextvideodata.media.skipads); playerObj.setAttribute("data-refreshed", "1"); isUserInitiated = (playerDOMObj.getAttribute("data-userinitiated") == "1") ? true : false; player.setPlayerConfig({ player: { skipAd: skipAds } }); // TODO: do we need to skip ad on playlist next item etimes_video_ga._sendVideoRequest(); player.endScreen.hide(); player.load({ id: slikeId, playerType: playerType, image: bgImg, title: videoTitle, shareUrl: loadUrl, startTime: 0, pid: videoAgency, sp: "embed", msid: videoMsid }); window.playListObj.nextIndex = window.playListObj.currentIndex + 1; if (window.playListObj.nextIndex == window.playListObj.playlist.length) { window.playListObj.nextIndex = 0; } } } } function setPlayerMuteVal(muteVal) { muteVal = (muteVal == true) ? 1 : 0; } function getTargetkeyWords(keywords) { try { var pickKeysFromPage = ['SCN', 'SubSCN', 'Hyp1']; if (window && window.Times && window.Times.adsKeys) { pickKeysFromPage.forEach(function (key) { var value = window.Times.adsKeys[key]; if (value) { keywords += keywords ? ',' : ''; keywords += value; } }); } } catch (error) { // } return keywords; }; function getPlayerConfig() { var slikeId = playerDOMObj.getAttribute("data-slikeid"); var playerType = playerDOMObj.getAttribute("data-rmid"); var bgImg = getBgImg(); var videoTitle = playerDOMObj.getAttribute("data-title"); var autoPlay = (playerDOMObj.getAttribute("data-autoplay") == "1") ? true : false; var skipAds = (playerDOMObj.getAttribute("data-skipads") == "1") ? true : false; //var adSection = playerDOMObj.getAttribute("data-adsection") || "default"; var adSection = new URLSearchParams(window.location.search).get('utm_medium') === 'campaign' ? 'taboola' : playerDOMObj.getAttribute("data-adsection") || "default"; var description_url = playerDOMObj.getAttribute("data-description_url"); var volume = getPlayerVolume(); var pagetpl = 'videoshow' var pageSection = getPageSectionName();//playerDOMObj.getAttribute("data-secname") ? playerDOMObj.getAttribute("data-secname") : getPageSection(description_url); var videoMsid = playerDOMObj.getAttribute("data-msid"); var videoAgency = playerDOMObj.getAttribute("data-agency"); var devmode = playerDOMObj.getAttribute('data-dev'); var isetimes = (playerDOMObj.getAttribute('data-isetimes') == "1") ? true : false; var iswapview = (playerDOMObj.getAttribute('data-iswapview') == "0") ? false : true; var nextVideoMsidArray = playerDOMObj.getAttribute('data-nextVideoMsidArray'); globalAgency = videoAgency; var transmitValue = (typeof geoinfo != "undefined" && geoinfo.CountryCode == "US") ? true : false; var apiKey = getApiKey(iswapview, !isetimes); var contenttype = playerDOMObj.getAttribute("data-contenttype"); var specialid = playerDOMObj.getAttribute('data-specialid'); var metaKeywords = getMetaKeywords(contenttype, specialid); var sgParams = window._dfpObj && window._dfpObj.getCcaudData && window._dfpObj.getCcaudData() || ''; var playerConfig = { apiKey: apiKey, //isetimes ? "toi371mweb5awm99g9o6" : "toimweb5t9tCpb7nb5q6jUb", //devmode ? "test403web5a8sg6o9ug" : "toimweb5t9tCpb7nb5q6jUb", contEl: playerContainerId, // env: 'stg', // version: '3.6.6', // debug:true, GDPR_MODE: window.TimesGDPR?.common?.consentModule?.isEUuser(), // TODO: Get GDPR value colombiaCookieId: (get_cookie("_col_uuid") != "" && typeof get_cookie("_col_uuid") != 'undefined') ? get_cookie("_col_uuid") : '', // TODO: Colombia cookie id controls: {dock: false}, // callbacks: { // canPlayNextVideo(videoData, callback) { // if (videoData.msid) { // window.top.location = videoData.msid.replace( // '/videoshow/', // '/amp_videoshow/', // ).replace('jeetwin-gaming.com', 'm.timesofindia.com'); // } else { // callback(); // } // }, // }, video: { id: slikeId, playerType: playerType, image: bgImg, title: videoTitle, shareUrl: (pagetpl == "audioembed") ? "" : loadUrl, startTime: 0, pid: videoAgency, sp: "embed", msid: videoMsid, description_url: description_url || false, Meta_Keywords: getTargetkeyWords(metaKeywords), sg: sgParams }, player: { lbandonIsv: true, adSection: adSection, autoPlay: autoPlay, contWidth: document.getElementById(playerContainerId).parentElement.offsetWidth || 0, contHeight: document.getElementById(playerContainerId).parentElement.offsetHeight || 300, description_url: description_url, //fallbackMute: fallbackMute, id: slikeId, image: bgImg, msid: videoMsid, mute: false, pageSection: pageSection, pagetpl: pagetpl, pid: "TOI.in", playerType: 0, playlist: false, playlistUrl : 'undefined', section: 'videos', showTitle: false, skipAd: skipAds, //skipYT scrollBehaviour: { inViewPercent: 50, dock: false, autoPlay: false, autoPause: false }, volume: volume, unmuteOnTap: false, preRollAdFiller:{ "enable": true, "time": 7 } }, compAd: { container: document.getElementById('compAd'), width: 300, height: 200 } }; playerConfig.callbacks = { onAdsCallback: function() { return { headerbiding: true }; } } return playerConfig; } function playerEventsFn() { var videoAgency = playerDOMObj.getAttribute("data-agency"); return { onPlayerError: function(player, eventName, eventData) { var eventType = "VIDEOERROR"; etimes_video_ga._sendVideoError("Error : " + eventName + " - " + eventData.code); etimes_video_ga._sendGA4({ event: 'player_load', video_template: 'videoshow', status: 'Failure', experiment_id: window.TimesApps && window.TimesApps.videoshowPageExperimentID ? window.TimesApps.videoshowPageExperimentID : 'Null', }); }, onInit: function(player, eventName, eventData) { var eventType = "VIDEOINIT"; etimes_video_ga._sendVideoInit(); // Notify: This was earlier video ready event TimesApps.prepareComscoreDataAndFireReq({}, eventData, eventType); etimes_video_ga._sendGA4({ event: 'player_load', video_template: 'videoshow', status: 'success', experiment_id: window.TimesApps && window.TimesApps.videoshowPageExperimentID ? window.TimesApps.videoshowPageExperimentID : 'Null', }); if ( window && window.player && window.player.updateConfig && typeof window.player.updateConfig === 'function' ) { window.player.updateConfig({ player: { exp: window.TimesApps.videoshowPageExperimentID ? window.TimesApps.videoshowPageExperimentID : 'Null', custom_params: { exp: window.TimesApps.videoshowPageExperimentID ? window.TimesApps.videoshowPageExperimentID : 'Null', } }, }); } }, onVideoRequested: function (player, eventName, eventData) { var eventType = "VIDEOLOADREQUEST"; etimes_video_ga._sendVideoReady(); // Notify: This was earlier video ready event TimesApps.prepareComscoreDataAndFireReq({}, eventData, eventType); // console.log("VIDEOLOADREQUEST") // etimes_video_ga._sendGA4({ // event: 'video_request', // status: 'success', // }); }, onVideoStarted: function(player, eventName, eventData) { var eventType = "VIDEOSTART"; window.isVideoViewSent = false; window.is10SecViewSent = false; //etimes_video_ga._sendVideoStarted(); TimesApps.prepareComscoreDataAndFireReq({}, eventData, eventType); etimes_video_ga._sendGA4({ event: 'video_show', video_template: 'videoshow', status: 'success', experiment_id: window.TimesApps && window.TimesApps.videoshowPageExperimentID ? window.TimesApps.videoshowPageExperimentID : 'Null', }); }, onVideoTimeUpdate: function(player, eventName, eventData) { if(Math.round(window.player.store.video.currentTime) > 10 && window.is10SecViewSent === false){ const event = new Event('10_SEC_COMPLETED'); window.dispatchEvent(event); window.is10SecViewSent = true; } if(Math.round(window.player.store.video.currentTime) == Math.round(window.defaultVideoViewTime) && window.isVideoViewSent == false){ var eventType = "VIDEOVIEW"; etimes_video_ga._sendVideoView(); window.isVideoViewSent = true; TimesApps.prepareComscoreDataAndFireReq({}, eventData, eventType); } }, onVideoResumed: function(player, eventName, eventData) { var eventType = "PLAYING"; // TODO: event changed for start if(typeof window != "undefined") window.isPlaying= true; TimesApps.prepareComscoreDataAndFireReq({}, eventData, eventType); }, onVideoPaused: function(player, eventName, eventData) { var eventType = "PAUSED"; if(typeof window != "undefined") window.isPlaying= false; TimesApps.prepareComscoreDataAndFireReq({}, eventData, eventType); }, onVolumeChange: function(player, eventName, eventData) { var volume = player.getVideoState().volume; //setPlayerVolume(volume); if(volume > 0) { setPlayerMuteVal(false); } }, onVideoMuted: function(player, eventName, eventData) { setPlayerMuteVal(true); }, onVideoCompleted: function(player, eventName, eventData) { if (videoAgency != "YouTube") { etimes_video_ga._sendVideoComplete(player.getVideoState().duration); } etimes_video_ga._sendGA4({ event: 'video_complete', video_template: 'videoshow', status: 'success', experiment_id: window.TimesApps && window.TimesApps.videoshowPageExperimentID ? window.TimesApps.videoshowPageExperimentID : 'Null', }); }, onVideoEnded: function(player, eventName, eventData) { const event = new Event('PLAYERVIDEOEND'); window.dispatchEvent(event); var eventType = "VIDEOCOMPLETE"; if (videoAgency == "YouTube") { etimes_video_ga._sendVideoComplete(player.getVideoState().duration); } TimesApps.prepareComscoreDataAndFireReq({}, eventData, eventType); var newUrl = playerDOMObj.getAttribute("data-nextVideoUrl") || ''; if (newUrl && newUrl !== 'undefined' && newUrl !== '') { newUrl = newUrl.replace("jeetwin-gaming.com","m.timesofindia.com"); document.getElementById(playerContainerId).innerHTML = ''; window.location.href = `${window.location.origin}/${newUrl}`; } }, onVideoNext : function(player, eventName, eventData) { console.log('onVideoNext>>'); const event = new CustomEvent('PLAYERVIDEONEXT', {'detail': eventData}); window.dispatchEvent(event); var newUrl = playerDOMObj.getAttribute("data-nextVideoUrl") || ''; if (newUrl && newUrl !== 'undefined' && newUrl !== '') { newUrl = newUrl.replace("jeetwin-gaming.com","m.timesofindia.com"); document.getElementById(playerContainerId).innerHTML = ''; window.location.href = `${window.location.origin}/${newUrl}`; } } } }; function adEventsFn() { var eventNameMap = { "onAdResume": "PLAYING", "onAdStart": "ADSTART", "onAdView": "ADVIEW", "onAdPause": "PAUSED", "onAdComplete": "ADCOMPLETE", "onAdSkip": "ADSKIP", "onAdRequest": "ADREQUEST", "onAdLoaded": "AdLoaded", "onAdError": "ERROR" }; return { onAdComplete: function(player, eventName, eventData) { etimes_video_ga._sendAdComplete(eventData.type); TimesApps.prepareComscoreDataAndFireReq({}, eventData, eventNameMap[eventName]); if(typeof v1 != "undefined" && typeof v1.subscribeEvents_ != "undefined" ) callChartBeatBackData(eventData, eventNameMap[eventName]); }, onAdSkip: function(player, eventName, eventData) { etimes_video_ga._sendAdSkip(eventData.type); TimesApps.prepareComscoreDataAndFireReq({}, eventData, eventNameMap[eventName]); if(typeof v1 != "undefined" && typeof v1.subscribeEvents_ != "undefined" ) callChartBeatBackData(eventData, eventNameMap[eventName]); }, onAdLoaded: function(player, eventName, eventData) { etimes_video_ga._sendAdLoaded(eventData.type); TimesApps.prepareComscoreDataAndFireReq({}, eventData, eventNameMap[eventName]); if(typeof v1 != "undefined" && typeof v1.subscribeEvents_ != "undefined" ) callChartBeatBackData(eventData, eventNameMap[eventName]); etimes_video_ga._sendGA4({ event: 'ad_request', status: 'success', video_template: 'videoshow', AdType: eventData.type+'roll', experiment_id: window.TimesApps && window.TimesApps.videoshowPageExperimentID ? window.TimesApps.videoshowPageExperimentID : 'Null', }); }, onAdRequest: function(player, eventName, eventData) { etimes_video_ga._sendAdRequest(eventData.type); TimesApps.prepareComscoreDataAndFireReq({}, eventData, eventNameMap[eventName]); if(typeof v1 != "undefined" && typeof v1.subscribeEvents_ != "undefined" ) callChartBeatBackData(eventData, eventNameMap[eventName]); }, onAdError: function(player, eventName, eventData) { etimes_video_ga._sendAdError(eventData.type); TimesApps.prepareComscoreDataAndFireReq({}, eventData, eventNameMap[eventName]); if(typeof v1 != "undefined" && typeof v1.subscribeEvents_ != "undefined" ) callChartBeatBackData(eventData, eventNameMap[eventName]); etimes_video_ga._sendGA4({ event: 'ad_request', video_template: 'videoshow', status: 'failure', AdType:eventData.type+'roll', experiment_id: window.TimesApps && window.TimesApps.videoshowPageExperimentID ? window.TimesApps.videoshowPageExperimentID : 'Null', }); }, onAdResume: function(player, eventName, eventData) { TimesApps.prepareComscoreDataAndFireReq({}, eventData, eventNameMap[eventName]); if(typeof v1 != "undefined" && typeof v1.subscribeEvents_ != "undefined" ) callChartBeatBackData(eventData, eventNameMap[eventName]); }, onAdStart: function(player, eventName, eventData) { //etimes_video_ga._sendAdStart(eventData.type); TimesApps.prepareComscoreDataAndFireReq({}, eventData, eventNameMap[eventName]); if(typeof v1 != "undefined" && typeof v1.subscribeEvents_ != "undefined" ) callChartBeatBackData(eventData, eventNameMap[eventName]); }, onAdView: function(player, eventName, eventData) { etimes_video_ga._sendAdView(eventData.type); TimesApps.prepareComscoreDataAndFireReq({}, eventData, eventNameMap[eventName]); if(typeof v1 != "undefined" && typeof v1.subscribeEvents_ != "undefined" ) callChartBeatBackData(eventData, eventNameMap[eventName]); etimes_video_ga._sendGA4({ event: 'ad_show', video_template: 'videoshow', status: 'success', AdType:eventData.type+'roll', experiment_id: window.TimesApps && window.TimesApps.videoshowPageExperimentID ? window.TimesApps.videoshowPageExperimentID : 'Null', }); }, onAdPause: function(player, eventName, eventData) { TimesApps.prepareComscoreDataAndFireReq({}, eventData, eventNameMap[eventName]); if(typeof v1 != "undefined" && typeof v1.subscribeEvents_ != "undefined" ) callChartBeatBackData(eventData, eventNameMap[eventName]); } } }; function handlePlayerEvents(player) { var eventToFunction = function(player, eventName, data) { var funcName = eventName.replace('spl', 'on'); var eventData = data || {}; eventData.userInitiated = (isUserInitiated == true) ? "user-initiated" : "autoplay"; // TODO: what is is user initiated eventData.source = "videoshow"; if (typeof playerEvents[funcName] === 'function') { playerEvents[funcName](player, eventName, eventData); } }; Object.keys(SlikePlayer.Events).forEach(function(eventKey) { var eventName = SlikePlayer.Events[eventKey]; player.on(eventName, eventToFunction.bind(null, player)); }); } function handleAdEvents(player) { var eventToFunction = function(player, eventName, data) { var funcName = eventName.replace('spl', 'on'); var eventData = data || {}; if (typeof adEvents[funcName] === 'function') { adEvents[funcName](player, funcName, eventData); } }; Object.keys(SlikePlayer.AdEvents).forEach(function(eventKey) { var eventName = SlikePlayer.AdEvents[eventKey]; player.on(eventName, eventToFunction.bind(null, player)); }); } function createPlayer(playerConfig , _msid) { var player = new SlikePlayer(playerConfig); handlePlayerEvents(player); handleAdEvents(player); window.player = player; } function loadPlayer(_msid) { var playerConfig = getPlayerConfig(); if(typeof SlikePlayer === "function"){ etimes_video_ga._sendVideoRequest(); createPlayer(playerConfig,_msid); } else{ spl.load(playerConfig, function (sdkLoadStatus) { if (sdkLoadStatus) { etimes_video_ga._sendVideoRequest(); etimes_video_ga._sendVideoLoadRequest(); createPlayer(playerConfig,_msid); } else { etimes_video_ga._sendSlikeError(); } }); } } function setGlobalParamsForLoadVideo(){ window.loadUrl = window.location.href || ''; if(typeof window.player != "undefined"){ window.player.pause(); } else{ window.player = undefined; } window.defaultVideoViewTime = 3; window.isVideoViewSent = false; window.is10SecViewSent = false; window.playerContainerId = "toiPlayerContainer"; window.playerDOMObj = document.getElementById(playerContainerId); if(window.playerDOMObj && window.playerDOMObj !==''){ window.playerEvents = playerEventsFn(); window.adEvents = adEventsFn(); window.isUserInitiated = ( playerDOMObj.getAttribute("data-userinitiated") == "1" ) ? true : false; window.videoRequestTime = undefined; window.timeTakenToVideoReady = undefined; window.SPLSkipGALibLoad = true; let msid = playerDOMObj.getAttribute("data-msid"); loadPlayer(msid); } } // if(typeof window !== 'undefined'){ // window.setGlobalParamsForLoadVideo = setGlobalParamsForLoadVideo(); // } function getApiKey(isMobile, isTOI){ if (isMobile && isTOI){ return 'toimweb5t9tCpb7nb5q6jUb'; } else if (isMobile && !isTOI){ return 'toi371mweb5awm99g9o6'; } else if (!isMobile && isTOI){ return 'toiweba5ec9705eb7ac2c984033e061'; } else if (!isMobile && !isTOI){ return 'toi371web5awj999ou6'; } else { return 'test403web5a8sg6o9ug'; } } function getPageSectionName() { const l1 = window.Times?.adsKeys?.SCN; if (l1 && l1 !== '') { const l2 = window.Times?.adsKeys?.SubSCN; if (l2 && l2 !== '') { let lLast = window.Times?.adsKeys?.LastSubSCN; if (lLast && lLast !== '') { for (let i = 1; i < 10; i += 1) { const v = `LastSubSCN_Child_${i}`; if (window.Times?.adsKeys[v] && window.Times?.adsKeys[v] !== '') { lLast = `${lLast}/${window.Times?.adsKeys[v]}`; } else { break; } } return `${l1}/${l2}/${lLast}`; } return `${l1}/${l2}`; } return l1; } return window.Times?.adsKeys?.Tmpl_SCN === 'home' ? 'Home Page' : ''; }; function getPageSection(description_url){ let requrl = description_url || ''; if(!requrl || requrl === '') return 'videoshow'; let urlPathArray = typeof requrl !== 'undefined' ? requrl.split('.com')[1] : []; let pageSectionName = ''; if (typeof urlPathArray !== 'undefined') { urlPathArray = urlPathArray.split('/'); if ( urlPathArray.length >= 4 && urlPathArray[1] && urlPathArray[2] && urlPathArray[3].length <= 15 ) { pageSectionName = `${urlPathArray[1]}/${urlPathArray[2]}/${ urlPathArray[3] }`; } else if ( urlPathArray.length >= 3 && urlPathArray[1] && urlPathArray[2] ) { pageSectionName = `${urlPathArray[1]}/${urlPathArray[2]}`; } else if (urlPathArray.length === 2 && urlPathArray[1]) { pageSectionName = `${urlPathArray[1]}`; } else if ( requrl.split('.com')[1] === '/' || requrl.split('.com')[1] === '' ) { pageSectionName = 'Home'; } } return pageSectionName; } function getMetaKeywords(contenttype, specialid){ let result = ''; if (contenttype && specialid) { result = `${contenttype},${specialid}`; } else if (contenttype) { result = contenttype; } else if (specialid) { result = specialid; } return result; }