简体   繁体   English

如何使用javascript衡量第三方广告的加载时间?

[英]How do you measure 3rd party ads load time using javascript?

I have a 3 rd party advertisement block on my webpage. 我有我的网页上的第三方广告块。 Using javascript , how do I measure the total time it takes to load, parse response and render the advertisement block? 使用javascript ,如何衡量加载,解析响应和呈现广告块所需的总时间?

I want to send this timing information back to my server to do reports. 我想将此时间信息发送回我的服务器以进行报告。

You cannot rely solely on javascript to provide you with the solution you are after. 您不能仅仅依靠javascript来为您提供所需的解决方案。 the biggest problem is the the difficulty in programatically figuring out when the events load , parse and render occur. 最大的问题是以编程方式确定事件何时加载解析呈现的难度。 The closest you can come is recording the time between sending the request and then periodically checking for content in the advertisement container. 您最接近的是记录发送请求之间的时间,然后定期检查广告容器中的内容。

Now, if you definitely know the exact template of content that the ad provider will return, you will need to use a script that will periodically check if all the items in the template have loaded and thus measure the time. 现在,如果您肯定知道广告提供商将返回的确切内容模板,您将需要使用一个脚本来定期检查模板中的所有项目是否已加载,从而衡量时间。

Another technique is to use Ajax . 另一种技术是使用Ajax If you are able to load the provider's advertisement using ajax , you could always calculate the time it took using callbacks and then dynamically add the advert into the page. 如果您能够使用ajax加载提供者的广告,您可以始终使用回调计算所花费的时间,然后将广告动态添加到页面中。 (also see: How to measure time taken by a function to execute ) To go beyond this, you will need the ad provider to provide you with an api or callbacks that you could hook into. (另请参阅: 如何衡量函数执行所需的时间 )除此之外,您还需要广告提供商为您提供可以挂钩的apicallbacks


I would suggest taking a look at Boomerang as it helps to measure the performance of your website from your end user's point of view. 我建议看看Boomerang,因为它有助于从最终用户的角度衡量您网站的性能。 Other than that, you are at the mercy of external tools like: 除此之外,您将受到以下外部工具的支配:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM