我有一些奇特的JavaScript是从我的Magento安装打印出来的。它允许我们有自己的域名列表,如果他们有再营销列表,当JS检测到我们在那个域名上时,我们可以输入详细信息来启动再营销。
代码如下:
$protocol = Mage::app()->getStore()->isCurrentlySecure() ? 'https' : 'http';
if (!Mage::getStoreConfigFlag('google/analytics/active')) {
return '';
}
$this->addText('<script src="'.$protocol.'://www.googleadservices.com/pagead/conversion.js" type="text/javascript"></script>');
$this->addText("
<script type=\"text/javascript\">
// This section finds all links that are outside of the current domain and adds a Google Analytics Cross-Domain Tracking Script
// THIS IS ABSOLUTELY MAGICAL, SOMETIMES I LAUGH AT HOW CLEVER THIS LITTLE SNIPPET IS
// I need to get out more
var domains = {
'whitestores.co.uk':false,
'bbqsdirect.co.uk':false,
'resinweavegardenfurniture-direct.co.uk':{
'google_conversion_id':1069311156,
'google_conversion_label':'BDWlCMy72AIQtMnx_QM'
},
'metalgardenfurnituredirect.co.uk':false,
'teakgardenfurniture-direct.co.uk':false,
'bistrosets-direct.co.uk':false,
'firepits-direct.co.uk':false,
'cushions-direct.co.uk':false,
'benches-direct.co.uk':false,
'parasols-direct.co.uk':false,
'covers-direct.co.uk':false,
'gardenbeanbags-direct.co.uk':false,
'chimineas-direct.co.uk':false,
'outdoorfurniture-direct.co.uk':false,
'stores-direct.co.uk':false
};
// Get the current domain name
var current_domain = document.domain.replace('www.','');
// Go through each of the domain lists above, check that we aren't going to be affecting links
// to the domain that we are currently on as this would be unnecessary.
\$H(domains).each(function(pair){
var val = pair.key;
var options = pair.value;
if(val == current_domain && options){
console.log('This domain has remarketers');
<!-- Google Code for Resin Weave Visitors Remarketing List -->
var google_conversion_id = options['google_conversion_id'];
var google_conversion_language = \"en\";
var google_conversion_format = \"3\";
var google_conversion_color = \"ffffff\";
var google_conversion_label = \"options['google_conversion_label']\";
var google_conversion_value = 0;
}
if(val != current_domain){
// Check to see if there are 'a' elements in the code with any of the domains above in the HREF
// If there is, go through each of them and add an on-click event utilising Google's link tracking feature
if($(\"a[href*='\"+val+\"']\")){
$(\"a[href*='\"+val+\"']\").each(function(elemindex,elem){
$(elem).click(function(){
_gaq.push(['_link',this.href]);
return false;
});
});
}
// Do the same for forms
if($(\"form[action*='\"+val+\"']\")){
$(\"form[action*='\"+val+\"']\").each(function(elemindex,elem){
$(elem).attr('onSubmit',\"_gaq.push(['_linkByPost',this])\");
});
}
}
});
</script>
<script type=\"text/javascript\">
//<![CDATA[
var _gaq = _gaq || [];
_gaq.push(['_setAccount','UA-9852071-15']);
_gaq.push(['_setDomainName', 'none']);
_gaq.push(['_setAllowLinker', true]);
_gaq.push(['_trackPageview']);
".$this->getQuoteOrdersHtml()."
(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>
");正如您所看到的,这段代码还向链接和表单添加了相关的Google跨域跟踪属性,但问题是我的重新营销转换脚本不起作用。没有Javascript错误,但也没有人在我的转售列表中显示,我们的网站每几分钟就有大约50次访问,所以他们应该在那里……
拼命寻找解决方案。
希望能收到某人的来信
戴夫
发布于 2012-05-13 04:00:18
戴夫
首先,您使用的是什么版本的jQuery,因为我没有将$H(domains).each识别为jQuery函数。在Mootools中有一个$H函数,但是nothing in jQuery。
如果希望遍历jQuery对象,则需要使用
$.each(your_array, function(index, value){}
(这也适用于59 -$(\"a[href*='\"+val+\"']\").each行上的bit )
其次,如果你的代码中有任何console.log条目,IE将会崩溃,只在开发环境中使用这些条目。
希望这能有所帮助。
图森
https://stackoverflow.com/questions/10518770
复制相似问题