Authored by 梁志锋

统计代码在load结束之后执行优先保证业务逻辑 code review by hf

1 <!-- Google Tag Manager --> 1 <!-- Google Tag Manager -->
2 <noscript><iframe src="//www.googletagmanager.com/ns.html?id=GTM-W958MG" height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript> 2 <noscript><iframe src="//www.googletagmanager.com/ns.html?id=GTM-W958MG" height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
  3 +
3 <script> 4 <script>
  5 +(function() {
  6 + function async_load(){
4 (function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start': 7 (function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
5 new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0], 8 new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
6 j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src= 9 j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
7 '//www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f); 10 '//www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
8 })(window,document,'script','dataLayer','GTM-W958MG'); 11 })(window,document,'script','dataLayer','GTM-W958MG');
9 -</script>  
10 -<!-- End Google Tag Manager -->  
11 -<script type="text/javascript">  
12 - var _hmt = _hmt || []; 12 +
13 (function() { 13 (function() {
14 var hm = document.createElement("script"); 14 var hm = document.createElement("script");
15 hm.src = "//hm.baidu.com/hm.js?c6ee7218b8321cb65fb2e98f284d8311"; 15 hm.src = "//hm.baidu.com/hm.js?c6ee7218b8321cb65fb2e98f284d8311";
@@ -17,9 +17,7 @@ @@ -17,9 +17,7 @@
17 var s = document.getElementsByTagName("script")[0]; 17 var s = document.getElementsByTagName("script")[0];
18 s.parentNode.insertBefore(hm, s); 18 s.parentNode.insertBefore(hm, s);
19 })(); 19 })();
20 -</script>  
21 -<script>  
22 - var _hmt = _hmt || []; 20 +
23 (function() { 21 (function() {
24 var hm = document.createElement("script"); 22 var hm = document.createElement("script");
25 hm.src = "//hm.baidu.com/hm.js?65dd99e0435a55177ffda862198ce841"; 23 hm.src = "//hm.baidu.com/hm.js?65dd99e0435a55177ffda862198ce841";
@@ -27,6 +25,22 @@ @@ -27,6 +25,22 @@
27 var s = document.getElementsByTagName("script")[0]; 25 var s = document.getElementsByTagName("script")[0];
28 s.parentNode.insertBefore(hm, s); 26 s.parentNode.insertBefore(hm, s);
29 })(); 27 })();
  28 +
  29 + (function() {
  30 + var hm = document.createElement("script");
  31 + hm.src = "http://static.yohobuy.com/js/analytics/analysis.js";
  32 + var s = document.getElementsByTagName("script")[0];
  33 + s.parentNode.insertBefore(hm, s);
  34 + })();
  35 +
  36 + (function() {
  37 + var hm = document.createElement("script");
  38 + hm.src = "http://static.yohobuy.com/m/v1/js/om_code.js";
  39 + hm.async = 1;
  40 + var s = document.getElementsByTagName("script")[0];
  41 + s.parentNode.insertBefore(hm, s);
  42 + })();
  43 + }
  44 + window.addEventListener('load', async_load, false);
  45 +})();
30 </script> 46 </script>
31 -<script src="http://static.yohobuy.com/js/analytics/analysis.js" async="async"></script>  
32 -<script src="http://static.yohobuy.com/m/v1/js/om_code.js" async="async"></script>