redblood redblood - 3 months ago 26
Javascript Question

is there anyway to find the ad loading time using javascript

I am working an project where i need the starting time when an ad request made and end time when ad is completely loaded. So that i can compute latency time for ad. I am using google dfp and doubleclick.

i don't want to call my website from external library like Phantomjs . I want some javascript solution so that i can edit my js files and get the latency time for ad loading. Thanx


Could you get the current time right before you send the request and the current time right after you finish loading it and subtract those times?

var timeAfter;
var timeBefore = new Date().getTime() / 1000;
//make requests //
function callBack(){
    // Completely load ad//
    timeAfter = new Date().getTime() / 1000;
var latency = timeAfter - timeBefore;

That's in seconds, but you can play with the math and get milliseconds.