var vsl_percentage_tags = { 0 : { 'is_set' : false }, 1 : { 'is_set' : false }, 20 : { 'is_set' : false }, 40 : { 'is_set' : false }, 60 : { 'is_set' : false }, 80 : { 'is_set' : false }, 95 : { 'is_set' : false }, } var vsl_cta_tags = { } var popins = [ { divId: "order-frame", showAt: time_delay_of, hideAt: 99999, tagId: tag_id_of, ctaGoal: "Saw CTA - Order Form" }, { divId: "arrow-scroll-down", showAt: time_delay_of, hideAt: 99999 }, ]; //----------------------------------------------------------------------- if (typeof is_ha_webinar === 'undefined') { var is_ha_webinar = false; var webinar = { 'JIT' : false }; } //----------------------------------------------------------------------- function createCookie(name,value,days) { if (days) { var date = new Date(); date.setTime(date.getTime()+(days*24*60*60*1000)); var expires = "; expires="+date.toGMTString(); } else var expires = ""; document.cookie = name+"="+value+expires+"; path=/"; } function readCookie(name) { var nameEQ = name + "="; var ca = document.cookie.split(';'); for(var i=0;i < ca.length;i++) { var c = ca[i]; while (c.charAt(0)==' ') c = c.substring(1,c.length); if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length); } return null; } //----------------------------------------------------------------------- var popinController = {}; popinController.tagsSet = {}; popinController.goalsFired = {}; popinController.playerdivName = "playerdiv"; popinController.resume_cookie_name = 'vsl_resume_' + 'ha1'; popinController.lastShowHide = -1; popinController.popins = popins; popinController.lastGoodPlaySecond = 0; popinController.position_from_cookies = 0; //----------------------------------------------------------------------- if (typeof VDL_EMBED_CODE_ID != 'string') { VDL_EMBED_CODE_ID = 'vidalytics_embed_xVoRpaSS7N5aTs76'; } var PLAYER_VENDOR = 'vidalytics'; popinController.vidalyticsCountFindPlayerAttempts = 0; //----------------------------------------------------------------------- //----------------------------------------------------------------------- popinController.activate_resume = function(position) { createCookie(this.resume_cookie_name,position,7); //one week } //----------------------------------------------------------------------- popinController.timeMonitor = function(position, pctWatched) { if ( Math.abs( position - this.lastShowHide ) >= 1 ) { this.showHidePopins(position); this.setPlaybackTags(position, pctWatched); jQuery("video").attr("title", "HousingAlerts Webinar"); //if (! is_ha_webinar ) { this.activate_resume(position); //} this.lastShowHide = position; // if (this.video.inSilentPlaybackMode()) { // jQuery("#silentModeMessage").show(); // } else { // jQuery("#silentModeMessage").hide(); // } } } //----------------------------------------------------------------------- popinController.showHidePopin = function(divId,show) { if (show) { jQuery("#" + divId).show(); } else { jQuery("#" + divId).hide(); } } //----------------------------------------------------------------------- popinController.setPercentageTag = function(pct) { console.log("setting_percentage_tag" + pct); email = ''; if (typeof(currentUserEmail) == 'string') email = currentUserEmail; jQuery.ajax({ url: "/ifsapi/?action=addvslpcttag&pct=" + pct + "&email=" + email + "&page_style=webinar&webinar_class=ha1&jit=" + webinar.JIT + "&replay=" + webinar.is_replay}); } //----------------------------------------------------------------------- popinController.setCTATag = function(time) { console.log("setting_cta_tag" + time); email = ''; if (typeof(currentUserEmail) == 'string') email = currentUserEmail; jQuery.ajax({ url: "/ifsapi/?action=addvslctatag&time=" + time + "&email=" + email + "&page_style=webinar&webinar_class=ha1&jit=" + webinar.JIT + "&replay=" + webinar.is_replay}); } //----------------------------------------------------------------------- popinController.addTag = function(tag) { console.log("setting_tag" + tag); email = ''; if (typeof(currentUserEmail) == 'string') email = currentUserEmail; jQuery.ajax({ url: "/ifsapi/?action=addtag&tag=" + tag + "&email=" + email}); } //----------------------------------------------------------------------- popinController.setPlaybackTags = function(position, pctWatched) { var pct_watched = -1; if (isNaN(pctWatched)) { pct_watched = this.video.percentWatched() * 100; } else { pct_watched = pctWatched; } //console.log("pctw: " + pct_watched); for (pct_key in vsl_percentage_tags) { pct = parseInt(pct_key); if ( pct_watched >= pct ) { if (!vsl_percentage_tags[pct].is_set) { vsl_percentage_tags[pct].is_set = true; this.setPercentageTag(pct); } } } for (pct_key in vsl_cta_tags) { time = parseInt(pct_key); if ( position >= time ) { if (!vsl_cta_tags[time].is_set) { vsl_cta_tags[time].is_set = true; this.setCTATag(time); } } } if (is_ha_webinar) { if ( pct_watched > 1 ) { // Set attendance tag and goal if (typeof(this.tagsSet[39082]) == 'undefined') { //Set 'attendance' tags this.tagsSet[39082] = true; this.addTag(39082); if (typeof(webinar_viewed_tag) != 'undefined') { this.tagsSet[webinar_viewed_tag] = true; this.addTag(webinar_viewed_tag); } if (webinar.is_public_replay) { this.addTag(39376); } //----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- this.setAttendanceFields(); //----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- } var schedule_type = webinar.Type; if ( webinar.is_replay ) schedule_type = 'Replay'; if ( webinar.is_public_replay ) schedule_type = 'Replay'; if ( webinar.is_yesterday_replay ) schedule_type = 'Replay'; var goal_name_attended = 'Show-' + schedule_type; // if ( video_enable_controls ) goal_name_attended = goal_name_attended + '-Controls'; // Controls should now be just "replay" this.fireImprovelyGoal(goal_name_attended); //----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- if ( pct_watched > 40 ) { this.fireImprovelyGoal('40-' + schedule_type); } if ( pct_watched > 80 ) { this.fireImprovelyGoal('80-' + schedule_type); } } } } //----------------------------------------------------------------------- popinController.fireImprovelyGoal = function(goalName) { return false; // Do Not use Improvely! if (typeof this.goalsFired[goalName] != 'undefined') return 0; this.goalsFired[goalName] = true; var event_code = 'HAL-'; var goalNameFull = 'HA1-' + event_code + goalName; console.log("Setting Improvely Goal:[" + goalNameFull + "]"); improvely.init('housingalerts', 12); // REMEMBER: Update this # per client Project and in the below. improvely.goal({ type: goalNameFull, // Types: sale or optin and Add -[Product] or -[Detail] as needed to string values. revenue: 0, reference: currentUserEmail }); } //----------------------------------------------------------------------- popinController.setAttendanceFields = function() { if (!webinar.is_replay) { jQuery.ajax({ url: "/ifsapi/?action=set_attendace_time&webinar_class=ha1&email=" + currentUserEmail }); } } //----------------------------------------------------------------------- popinController.showHidePopins = function(position) { jQuery("#debug_div").html("Position:" + position); for (key in this.popins) { var popin = this.popins[key]; var show = false; if ( ( position >= popin.showAt ) && ( position <= popin.hideAt ) ) show = true; if ( show != popin.shown ) { if ((typeof(popin.tagId) != 'undefined') && popin.tagId > 0) { this.addTag(popin.tagId); } if ((typeof(popin.ctaGoal) != 'undefined') && popin.ctaGoal.length > 0) { //this.fireImprovelyGoal(popin.ctaGoal); // Commented out... ( https://realtyalerts.slack.com/archives/D6QE58WD9/p1563982054012500 ) } this.showHidePopin( popin.divId, show ); popin.shown = show; } } } //----------------------------------------------------------------------- popinController.initPlayerJW = function() { jwplayer.key="CdB25rr1XmmsCIVCJ/PgbXxG7cvoCmC1vcan3g=="; jwplayer(this.playerdivName).setup({ "file": "//d3cboxrrizd66h.cloudfront.net/training/160929_FINAL_Markets_Page_video-HB720RF30.mp4", //"file": "//localhost:8888/160929_FINAL_Markets_Page_video-HB720RF30.mp4", //"image": "http://example.com/myImage.png", // "height": 360, // "width": 640, width: "50%", aspectratio: "16:9", }); jwplayer(this.playerdivName).on('time', function(e) { popinController.timeMonitor(e.position); }); } //----------------------------------------------------------------------- popinController.injectWebinarVideo = function() { jQuery(".wistia_responsive_wrapper").html("
 
"); } //----------------------------------------------------------------------- popinController.injectPreWebinarCounter = function(delay) { jQuery("#countdown_timer_webinar").html(""); jQuery("#countdown_timer_webinar").show(); show_counter_extra('pre_webinar_counter', delay, 300, 70, "000000"); } //----------------------------------------------------------------------- popinController.injectPreReplayCounter = function(delay) { jQuery("#countdown_timer_replay").html(""); jQuery("#countdown_timer_replay").show(); show_counter_extra('pre_replay_counter', delay, 300, 70, "000000"); } //----------------------------------------------------------------------- popinController.disablePauseWistia = function(video) { video.bind('pause', function() { popinController.video.play() }); } //----------------------------------------------------------------------- popinController.lastSecondWatched = function() { var secondsWatchedVector = popinController.video.secondsWatchedVector(); playbackstarted = false; lastSecondWatched = 0; for (var i=0; i <= secondsWatchedVector.length; i++) { if ( secondsWatchedVector[i] == 1 ) { playbackstarted = true; lastSecondWatched = i; } else { if (playbackstarted) return lastSecondWatched; //1st zero after some ones } } return lastSecondWatched; } //----------------------------------------------------------------------- popinController.getPlayerVDL = function() { var embeds = (window._vidalytics || {}).embeds || {}; if (embeds[VDL_EMBED_CODE_ID]) { return embeds[VDL_EMBED_CODE_ID].player || {}; } return {}; } //----------------------------------------------------------------------- popinController.initPlayerVidalytics = function() { popinController.vidalyticsCountFindPlayerAttempts++; console.log("Looking for Vidalytics Player. Attempt [" + popinController.vidalyticsCountFindPlayerAttempts + "]"); var player = popinController.getPlayerVDL(); if (!player._player) { if (popinController.vidalyticsCountFindPlayerAttempts > 10) { console.error('Player Not Found'); } else { var that = this; setTimeout(popinController.initPlayerVidalytics, 1000); } return 0; } console.log('Player Found'); vidalyticsPlayerAPI = player; vidalyticsPlayerAPI._player.addEventHandler('onPaused', function () { console.log('Vidalytics onPaused event'); }); setInterval(function() { var s = vidalyticsPlayerAPI.getCurrentVideoTime(); var videoDuration = vidalyticsPlayerAPI.player.getDuration(); pctWatched = Math.round((s / videoDuration)*100); popinController.timeMonitor(s, pctWatched); },1000); vidalyticsPlayerAPI._player.addEventHandler('onTimeChanged'), function () { if (vidalyticsPlayerAPI.getCurrentVideoTime() > 5) { console.log(vidalyticsPlayerAPI.getCurrentVideoTime()) } } } //----------------------------------------------------------------------- popinController.initPlayerWistia = function() { window._wq = window._wq || []; playerOptions = { autoPlay: video_autoplay, silentAutoPlay: 'allow', playerColor: "#5e5e5e", playbar: video_enable_controls, fakeFullscreen: true, playbackRateControl: false } if ( is_ha_webinar ) { console.log('webinar mode'); playerOptions.smallPlayButton = false; //disable play/pause at the bottom-left corner if ( webinar_till_start < 0 ) { playerOptions.time = -1*webinar_till_start; console.log('starting webinar from [' + -1*webinar_till_start + ']'); } } window._wq.push({ id: "iob8vu6tb2", options: playerOptions, onHasData: function(video) { popinController.video = video; video.bind("secondchange", function(s) { if (((s - popinController.lastGoodPlaySecond) < 3 )||(popinController.lastGoodPlaySecond == 0)) { popinController.lastGoodPlaySecond = s; } popinController.timeMonitor(s); //console.log("s:" + s); }); video.bind("silentplaybackmodechange", function (inSilentPlaybackMode) { console.log("Is ’Click For Sound' visible?", inSilentPlaybackMode ? "yes" : "no"); }); if ( ( typeof currentUserEmail != 'undefined' ) && ( currentUserEmail.length > 0 ) ) { video.email( currentUserEmail ); } if ( is_ha_webinar ) { if (!video_allow_pause) { popinController.disablePauseWistia(video); } if ( !video_enable_controls ) { video.bind("seek", function(currentTime, lastTime) { if (Math.abs(currentTime - lastTime) > 3) { console.log("reseek to " + popinController.lastGoodPlaySecond ); popinController.video.time( popinController.lastGoodPlaySecond ); } }); } video.bind("end", function() { popinController.processWebinarEnded(); }); if (( webinar.is_replay )&&(!webinar.is_public_replay)) { video.bind("pause", function() { jQuery("#pre_replay_counter").show(300); }); video.bind("play", function() { jQuery("#pre_replay_counter").hide(300); }); } } popinController.processResume(); } }); } //----------------------------------------------------------------------- popinController.processResume = function () { if (webinar.is_replay) { this.position_from_cookies = parseInt(readCookie(popinController.resume_cookie_name)); if (this.position_from_cookies > 0) { jQuery('#replay_resume_offer').fadeIn(300); } } } //----------------------------------------------------------------------- popinController.resumeFromSaved = function() { jQuery('#replay_resume_offer').fadeOut(300); this.video.time(this.position_from_cookies) this.video.play(); } //----------------------------------------------------------------------- popinController.resumeFromStart = function() { jQuery('#replay_resume_offer').fadeOut(300); this.video.time(0); this.video.play(); } //----------------------------------------------------------------------- popinController.processWebinarEnded = function() { //jQuery(".wistia_responsive_wrapper").html("
Thank you!The event is Over."); popinController.video.suppressPlay(true); } //----------------------------------------------------------------------- popinController.initPlayer = function() { //this.initPlayerJW(); if (PLAYER_VENDOR == 'wistia') return this.initPlayerWistia(); if (PLAYER_VENDOR == 'vidalytics') return this.initPlayerVidalytics(); console.error('Unkown Player Vendor.'); }; //----------------------------------------------------------------------- popinController.initPopins = function() { if (typeof(popins_dynamic) != 'undefined') { this.popins = this.popins.concat(popins_dynamic); } for (key in this.popins) { var popinId = this.popins[key].divId; var popinShown = jQuery('#' + popinId).is(':visible'); this.popins[key].shown = popinShown; } } //----------------------------------------------------------------------- popinController.startWebinar = function() { console.log("Starting the webinar!!!"); jQuery("#countdown_timer_webinar").hide(); jQuery("#pre_webinar_block_00").hide(); jQuery("#pre_webinar_block_01").hide(); jQuery("#pre_webinar_block_02").hide(); jQuery("#pre_webinar_block_03").hide(); jQuery(".wistia-responsive-block").show(); jQuery(".video-responsive-block").show(); jQuery(".webinar-video-top-border").show(); jQuery(".webinar-video-bottom-border").show(); this.injectWebinarVideo(); } //----------------------------------------------------------------------- popinController.initWebinar = function() { if ( webinar.is_replay && ( webinar.replay_valid_for > 0 ) && (!webinar.is_public_replay) ) { //alert(webinar.replay_valid_for); this.injectPreReplayCounter( webinar.replay_valid_for ); } if ( webinar_till_start <= 0 ) { this.startWebinar(); } else { var that = this; setTimeout( function() { that.startWebinar(); }, webinar_till_start * 1000 ); this.injectPreWebinarCounter(webinar_till_start); jQuery("#pre_webinar_block_00").show(); jQuery("#pre_webinar_block_01").show(); jQuery("#pre_webinar_block_02").show(); jQuery("#pre_webinar_block_03").show(); } } //----------------------------------------------------------------------- popinController.startVSL = function() { this.injectWebinarVideo(); } //----------------------------------------------------------------------- popinController.initVSL = function() { this.startVSL(); } //----------------------------------------------------------------------- popinController.process_not_ok_to_play = function(webinar) { //Hide player, show messages for expired replay or webinar, that has been ended } //----------------------------------------------------------------------- popinController.add_query_param = function(original_link, param_name, param_value) { var url = new URL(original_link); url.searchParams.append(param_name, param_value); return url.href; } //----------------------------------------------------------------------- popinController.attach_get_vars_to_popup_links = function() { if (typeof(currentUserEmail) == 'undefined' || currentUserEmail == "") return 0; var links = jQuery("div.webinar-video-top-border, div.easy-container-right-of-video, div.easy-container-under-video, div.easy-container-under-video").find("a"); jQuery.each(links,function(index,value) { var $this = $(this); var _href = $this.attr("href"); $this.attr("href", popinController.add_query_param(_href,'Email',currentUserEmail)); }); } //----------------------------------------------------------------------- jQuery(function() { if (ok_to_play && PLAYER_VENDOR == 'vidalytics') { popinController.initPlayer(); //For vidalytics - ok to wait } popinController.initPopins(); if (is_ha_webinar) { if (webinar.ok_to_play) { popinController.initWebinar(); } else { popinController.process_not_ok_to_play(webinar); } } else { popinController.initVSL(); } popinController.attach_get_vars_to_popup_links(); }); var ok_to_play = true; if (is_ha_webinar && !webinar.ok_to_play) ok_to_play = false; if (ok_to_play && PLAYER_VENDOR == 'wistia') { popinController.initPlayer(); //For wistia - don't wait - call right away } //-----------------------------------------------------------------------