Rahul
Rahul

Reputation: 2597

When function is pushed in googletag.cmd.push will be invoked

Use case

I want to check when requests for ads are being sent from GPT.

Suppose for any ad slot s1, ad request sent at time t1 then I would like to print t1-pageLoadTime on the console.

googletag.cmd.push(function () {
   // log time
});

But, I am not sure whether the function pushed into googletag.cmd.push will be called before sending an ad requests or after sending all ad request.

Upvotes: 0

Views: 1231

Answers (1)

rabsom
rabsom

Reputation: 859

According to the official documentation googletag.cmd is just "the global command queue for asynchronous execution of GPT-related calls."

I wouldn't rely on this knowing Google Publisher Tags provide events such as :

  • googletag.events.SlotRequestedEvent : "This event is fired when an ad has been requested for a particular slot." (here)

  • googletag.events.SlotResponseReceived : "This event is fired when an ad response has been received for a particular slot" (here)

Launch a timer between slotResquestedEvent and slotResponseReceived, you will be able to get the duration between those 2 events. If you want to play whith events, take a look at this sample page.

If you are interested in getting the ad load duration, I would recommend you to watch for the googletag.apiReady flag, which indicates wether the API is fully ready to be used or not (here). Combined with the slotResponseReceived, you should be able to get the data you are looking for.

Last : you might be interested in googletag.pubadsReady which indicates when the GPT service has been enabled (here)

Upvotes: 0

Related Questions