2

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.

UPDATE: 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

redblood
  • 542
  • 1
  • 4
  • 19

7 Answers7

3

Try using PhantomJS.

It's a headless browser. You can use it like a browser, but programatically and get info from it.

Lucas Katayama
  • 4,445
  • 27
  • 34
2

PhantomJS, CasperJS, or write a node script. If you're doing this more ad hoc in the browser, having the network tab open when the page loads should tell you how long the request took.

dwbartz
  • 886
  • 10
  • 13
2

Describing the basic method, as you didn't give any code.

In the function that loads the ad, set a variable with current milliseconds (eg startTime = Date.now())

Then depending on the media you are loading, you can use the onload event (for images) or the loadstart and loadeddata events for video, adio, etc. If it's called via XHR, then you should already have a load event to insert the ad into the dom. Grab Date.now() once more, and subtract the startime from it.

There's your load time.

Patrick Denny
  • 290
  • 1
  • 5
1

I would recommend to use the chrome dev tools. Use cntr+shift+i in your browser and navigate to timeline or network

You can't use the tools to call a function in your JS code, but it's a pretty nice view on the speed of your side.

jflepp
  • 79
  • 5
1

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.

Henrique Donati
  • 317
  • 2
  • 7
0

Answers for this Question is already available stack itself.

Please refer these links. those might be answer for question hopefully.

Calculating Page Load Time In JavaScript

Page load time with JavaScript

What is the best way to measure Client Side page load times?

Community
  • 1
  • 1
Mahesh K
  • 1,689
  • 3
  • 23
  • 36
0

You might be looking for something like the chrome.webRequest API. AppNexus's Headerbid Expert Chrome extension is a great example of how this can be used to examine network traffic. You're probably going to need to roll your own pattern matchers for network traffic based on the demand side, but maybe you can get clever and parse "doubleclick.net" traffic to automate that process. Mozilla and IE each have their own way of doing this.

If a plug-in isn't what you're looking for, then you can simply overwrite request prototypes. You'll tend to find examples of this kind of code in javascript test tools, such as Sonin. There you'll typically also find examples of timing things.

Community
  • 1
  • 1
mgamba
  • 1,189
  • 8
  • 10