prebid timeout depending on time of day

123 Views Asked by At

Anyone know how I can have:

var PREBID_TIMEOUT = 1700;

change on the time of day, so as 1700 is for 10am to 11am, then 1500 from 11am to 12am etc.

I want to modify the timeout effects bids and price depending on time of day, i.e longer timeout when USA is "awake", smaller when "asleep" etc

Or if anyone has already tested that, any info would be useful and appreciated.

1

There are 1 best solutions below

0
On

This is how you can detect the current hours in js:

var date = new Date();
var hours = date.getHours();

After that you can use hours variable to pick the right timing. The trick here is that you may need to use this logic for US users only and use a predefined constant for others - you'll need server-side support for that.

I.e. use the maxmind database (https://www.maxmind.com/en/geoip2-databases) to map user's ip into his country and pass this variable into html/js

Here's the pseudocode of the solution you might end up with:

var isUserInUS = true;    // server-side generated value
var prebidTimeout = 1700; // the default value
if (isUserInUS) {
  var date = new Date();
  var hours = date.getHours();
  var hoursTimeouts = {
     // here's your mapping
     10: 1700,
     11: 1500,
     // etc for every hour
  };
  prebidTimeout = hoursTimeouts[hours];
} 
// use prebidTimeout value in prebid settings