Watch: Portfolio Builder: Lesson 2

! ( function ( r, u, m, b, l, e ) {
( r._Rumble = b ),
r[ b ] ||
( r[ b ] = function () {
( r[ b ]._ = r[ b ]._ || [] ).push( arguments );
if ( r[ b ]._.length == 1 ) {
( l = u.createElement( m ) ),
( e = u.getElementsByTagName( m )[ 0 ] ),
( l.async = 1 ),
( l.src=”https://rumble.com/embedJS/ulkdw1″ +
/* replace [PUBID] */ ( arguments[ 1 ].video
? ‘.’ + arguments[ 1 ].video
: ” ) +
‘/?url=” +
encodeURIComponent( location.href ) +
“&args=” +
encodeURIComponent(
JSON.stringify( [].slice.apply( arguments ) )
) ),
e.parentNode.insertBefore( l, e );
}
} );
} )( window, document, “script’, ‘Rumble’ );
/* In this function you return the URL to the ad. The ‘ad’ variable will be the ad requested, which in this example can be ‘preroll_1’, ‘preroll_2’, etc.
* This function gets called in bursts, with all the waterfall IDs of a given ad in succession
* It will be called again with the next ad unit 5 seconds after the first waterfall ad is needed by the player in the current ad
*/
function request_ad( ad, callback ) {
// console.log( ‘prepare ad ‘ + ad );

/* when ad is ready you use the callback function with the vast tag URL */
callback( ad );
}

( function () {
/* configuration section */
var DEBUG = true;
var video_id = ‘vkem7z’
? ‘vkem7z’
: ”;
var player_id = ‘vkem7z’ ? ‘videoplayer-‘ + ‘vkem7z’ : ”;
var ad_timeout = 1500; /* number of ms the player will wait for an ad, not the same as prebid timeout */
var player_div = document.getElementById( player_id );
var autoplay_control=”2″;
var mute_control=””;
var setup_ads = function () {
/* set up ad points for each new video, you can change this based on your needs, this is just an example */

/* in the array of ads you can provide a URL or an ID to signify which ad we need */
insert_ad( 0, [
‘https://pubads.g.doubleclick.net/gampad/ads?iu=/57452754/Rumble_Video&description_url=http%3A%2F%2Fmoneysense.ca&tfcd=0&npa=0&sz=400×300%7C640x480&gdfp_req=1&output=vast&unviewed_position_start=1&env=vp&impl=s&correlator=”,
] );

// insert_ad( “25%’, [ ‘midroll_25_1’ ] );

// if ( player_div.clientWidth > 600 ) {
// insert_ad( ‘50%’, [ ‘midroll_50_big_1’, ‘midroll_50_big_2’ ] );
// } else {
// insert_ad( ‘50%’, [ ‘midroll_50_1’ ] );
// }
};

/* Do not change below: code implementing prebid support, you should not have to change what is below */

var api;
var ads_queue = []; /* all ads defined, we will request next set of ads as the previous one is done */
var ready_ads = {}; /* as ads become ready, we will populate this for the player to use */
var prepare_on;

var loaded_new_video = function () {
if ( DEBUG )
// console.log( ‘Setting up ad cuepoints’ );
ready_ads = {};
ads_queue = [];

api.clearAds();
setup_ads();

prepare_next_ads();
};

var insert_ad = function ( timecode, waterfall ) {
// if ( DEBUG )
// console.log(
// ‘insert_ad timecode: ‘ +
// timecode +
// ‘ , waterfall: ‘ +
// waterfall.length +
// ‘ ads’
// );

ads_queue.push( waterfall );
api.insertAd( timecode, waterfall );
};

var ads_request = function ( ad ) {
var id = ad.url;
var timeout;

// if ( DEBUG ) console.log( ‘player is ready for: ‘ + id );
if ( prepare_on && prepare_on == id ) {
prepare_on = false;
setTimeout( function () {
prepare_next_ads();
}, 5000 );
}

if ( typeof ready_ads[ id ] == ‘string’ ) {
/* ad is ready, let the player use it */
return ready_ads[ id ];
}

ready_ads[ id ] = function ( url ) {
if ( timeout ) {
clearTimeout( timeout );
timeout = 0;
}

ad.callback( url );

ready_ads[ id ] = true;
};

timeout = setTimeout( function () {
// if ( DEBUG ) console.log( ‘Ad : ‘ + id + ‘ has timed out’ );
ready_ads[ id ] = true;

ad.callback( false );
}, ad_timeout );

/* ask the player to wait */
return true;
};

var prepare_next_ads = function () {
if ( ads_queue.length == 0 ) return;

var next_ads = ads_queue.shift();

// if ( DEBUG ) console.log( ‘Preparing next ad’ );

/* we will prepare next set of ads based on this ad gets requested by the player */
prepare_on = next_ads[ 0 ];

/* go through the waterfall asking for ads */
for ( i = 0; i < next_ads.length; i++ ) {
simple_request_ad( next_ads[ i ] );
}
};

var simple_request_ad = function ( id ) {
request_ad( id, function ( url ) {
ad_ready( id, url );
} );
};

var ad_ready = function ( id, url ) {
if ( typeof ready_ads[ id ] == 'function' ) {
/* looks like the player is already waiting for an ad */
ready_ads[ id ]( url.md );
} else if ( ready_ads[ id ] ) {
/* already an ad defined with that id, or the player timed out on it */
return;
}

/* have it ready for the player when its needed */
ready_ads[ id ] = url;
};
// Not load anything if video id is not entered.
if ( ! video_id ) {
console.log('Please set rumble video id!');
return false;
}
/* You can configure the player as you see fit, just leave the player_id and api lines intact */
if ( autoplay_control ) {
Rumble( 'play', {
video: video_id,
div: player_id,
autoplay: '2',
api: function ( api_object ) {
/* the following 4 lines are required and should not be changed */
api = api_object;
if ( ! mute_control ) {
api.mute();
} else {
api.unmute();
}
api.on( 'loadVideo', loaded_new_video );
api.on( 'adRequest', ads_request );
loaded_new_video();
},
} );
} else {
Rumble( 'play', {
video: video_id,
div: player_id,
api: function ( api_object ) {
/* the following 4 lines are required and should not be changed */
api = api_object;
if ( ! mute_control ) {
api.mute();
} else {
api.unmute();
}
api.on( 'loadVideo', loaded_new_video );
api.on( 'adRequest', ads_request );
loaded_new_video();
},
} );
}
} )();

The post Portfolio Builder: Lesson 2 appeared first on MoneySense.

MoneySense Editors

Source link

You May Also Like

Smart Money Podcast: How to Have Difficult Money Conversations with Friends and Partners featuring Nicole Lapin – NerdWallet

Welcome to NerdWallet’s Smart Money podcast, where we answer your real-world money…

UPS drivers are finally getting air conditioning

After years of tolerating potentially deadly heat on their routes, UPS drivers…

Inflation is driving up gift prices. Here’s how to avoid overspending this holiday.

It’s not even Halloween and some retailers are already slashing prices on…

Some part-time UPS workers say

A tentative agreement between UPS and its unionized workforce was hailed as “historic”…