gpt4 book ai didi

javascript - Analytics + Facebook 跟踪 Javascript 问题与 document.getElementsByTagName ('script' )[0]

转载 作者:行者123 更新时间:2023-11-30 18:08:16 25 4
gpt4 key购买 nike

我试图通过将 Facebook 的跟踪代码放在与 Analytics 相同的页面上来了解代码中是否存在冲突,因为这行出现在两个脚本中:

document.getElementsByTagName('script')[0]

相关代码如下:

<head>
<link rel="stylesheet" type="text/css" href="stylesheet.css">

<!---- START OF FACEBOOK TRACKING SCRIPT -->
<script type="text/javascript">
var fb_param = {};
fb_param.pixel_id = '6008770441xxx';
fb_param.value = '123.00';
(function(){
var fpw = document.createElement('script');
fpw.async = true;
fpw.src = '//connect.facebook.net/en_US/fp.js';

这里的这一行:

      var ref = document.getElementsByTagName('script')[0];
ref.parentNode.insertBefore(fpw, ref);
})();
</script>
<noscript><img height="1" width="1" alt="" style="display:none" src="https://www.facebook.com/offsite_event.php?id=600877044xxx&amp;value=0" /></noscript>

<!---- START OF ANALYTICS TRACKING SCRIPT -->
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-2725xxx-3']);
_gaq.push(['_trackPageview']);
_gaq.push(['_addTrans',
'456', // order ID - required
'xxx', // affiliation or store name
'123', // total - required
'', // tax
'10', // shipping
', // city
'', // state or province
'Australia' // country
]);
_gaq.push(['_trackTrans']); //submits transaction to the Analytics servers

(function() {
var ga = document.createElement('script');
ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';

又是这一行:

    var s = document.getElementsByTagName('script')[0]; 
s.parentNode.insertBefore(ga, s);
})();

</script>
</head>

最佳答案

请引用该行之后的下一行,

var s = document.getElementsByTagName('script')[0]; 
s.parentNode.insertBefore(ga, s);

现在,这会将元素插入到 First CHild Place 中,第一个将成为第二个,

所以这只是在运行时插入脚本,根本不会冲突

:)

关于javascript - Analytics + Facebook 跟踪 Javascript 问题与 document.getElementsByTagName ('script' )[0],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15263723/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com