统计代码在load结束之后执行优先保证业务逻辑 code review by hf
Showing
1 changed file
with
43 additions
and
29 deletions
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> |
4 | - (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], | ||
6 | - 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); | ||
8 | - })(window,document,'script','dataLayer','GTM-W958MG'); | ||
9 | -</script> | ||
10 | -<!-- End Google Tag Manager --> | ||
11 | -<script type="text/javascript"> | ||
12 | - var _hmt = _hmt || []; | ||
13 | - (function() { | ||
14 | - var hm = document.createElement("script"); | ||
15 | - hm.src = "//hm.baidu.com/hm.js?c6ee7218b8321cb65fb2e98f284d8311"; | ||
16 | - hm.async = 1; | ||
17 | - var s = document.getElementsByTagName("script")[0]; | ||
18 | - s.parentNode.insertBefore(hm, s); | ||
19 | - })(); | ||
20 | -</script> | ||
21 | -<script> | ||
22 | - var _hmt = _hmt || []; | ||
23 | - (function() { | ||
24 | - var hm = document.createElement("script"); | ||
25 | - hm.src = "//hm.baidu.com/hm.js?65dd99e0435a55177ffda862198ce841"; | ||
26 | - hm.async = 1; | ||
27 | - var s = document.getElementsByTagName("script")[0]; | ||
28 | - s.parentNode.insertBefore(hm, s); | ||
29 | - })(); | ||
30 | -</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> | 5 | +(function() { |
6 | + function async_load(){ | ||
7 | + (function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start': | ||
8 | + new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0], | ||
9 | + j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src= | ||
10 | + '//www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f); | ||
11 | + })(window,document,'script','dataLayer','GTM-W958MG'); | ||
12 | + | ||
13 | + (function() { | ||
14 | + var hm = document.createElement("script"); | ||
15 | + hm.src = "//hm.baidu.com/hm.js?c6ee7218b8321cb65fb2e98f284d8311"; | ||
16 | + hm.async = 1; | ||
17 | + var s = document.getElementsByTagName("script")[0]; | ||
18 | + s.parentNode.insertBefore(hm, s); | ||
19 | + })(); | ||
20 | + | ||
21 | + (function() { | ||
22 | + var hm = document.createElement("script"); | ||
23 | + hm.src = "//hm.baidu.com/hm.js?65dd99e0435a55177ffda862198ce841"; | ||
24 | + hm.async = 1; | ||
25 | + var s = document.getElementsByTagName("script")[0]; | ||
26 | + s.parentNode.insertBefore(hm, s); | ||
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 | +})(); | ||
46 | +</script> |
-
Please register or login to post a comment