谷歌重新营销Javascript

谷歌重新营销Javascript,javascript,magento,prototypejs,google-ads-api,Javascript,Magento,Prototypejs,Google Ads Api,我有一些从我的Magento安装中打印出来的花式JavaScript。它允许我们有我们的域名列表,如果他们有重新营销列表,我们可以输入详细信息,当JS检测到我们在该域名上时,启动重新营销 代码如下: $protocol = Mage::app()->getStore()->isCurrentlySecure() ? 'https' : 'http'; if (!Mage::getStoreConfigFlag('google/analytics/active')) {

我有一些从我的Magento安装中打印出来的花式JavaScript。它允许我们有我们的域名列表,如果他们有重新营销列表,我们可以输入详细信息,当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>
 ");
$protocol=Mage::app()->getStore()->isCurrentlySecure()?'https':'http';
如果(!Mage::getStoreConfigFlag('google/analytics/active')){
返回“”;
}
$this->addText(“”);
$this->addText(“
//本节查找当前域之外的所有链接,并添加Google Analytics跨域跟踪脚本
//这绝对是不可思议的,有时我会嘲笑这段小片段是多么聪明
//我需要多出去走走
变量域={
“whitestores.co.uk”:错误,
“bbqsdirect.co.uk”:错误,
“resinweavegardenfurniture direct.co.uk”:{
“谷歌转换id”:1069311156,
“谷歌转换标签”:“BDWlCMy72AIQtMnx\U QM”
},
“metalgardfurnituredirect.co.uk”:错误,
“teakgardenfurniture direct.co.uk”:false,
'bistrosets direct.co.uk':错误,
“firfits direct.co.uk”:错误,
“buffers direct.co.uk”:错误,
“benches direct.co.uk”:错误,
“parasols direct.co.uk”:错误,
“covers direct.co.uk”:false,
“gardenbeanbags direct.co.uk”:错误,
“chimineas direct.co.uk”:错误,
“outdoorfurniture direct.co.uk”:错误,
“stores direct.co.uk”:错误
};
//获取当前域名
var current_domain=document.domain.replace('www.,'');
//浏览上面的每个域列表,检查我们不会影响链接
//到我们当前所在的域,因为这是不必要的。
\$H(域)。每个(函数(对){
var val=pair.key;
var选项=pair.value;
if(val==当前_域和选项){
log('此域有重新标记者');
var google_conversion_id=选项['google_conversion_id'];
var google_conversion_language=\“en\”;
var google_conversion_format=\“3\”;
var google\u conversion\u color=\“ffffff\”;
var google\u conversion\u label=\“选项['google\u conversion\u label']\”;
var google_转换_值=0;
}
if(val!=当前_域){
//检查HREF中是否有上述任何域的代码中的“a”元素
//如果有的话,浏览每一个网站,利用谷歌的链接跟踪功能添加点击事件
如果($(\“a[href*='\'+val+\']\”)){
$(\“a[href*='\''+val+\']\”)。每个(函数(elemindex,elem){
$(元素)。单击(函数(){
_gaq.push([''链接',this.href]);
返回false;
});
});
}
//对表单执行同样的操作
if($(\“form[action*='\'+val+\']\”)){
$(\“form[action*='\'+val+\']\”)。每个(函数(elemindex,elem){
$(elem).attr('onSubmit',\“\u gaq.push([''u linkByPost',this])\”;
});
}
}
});
//
");
正如您所看到的,这段代码还向链接和表单添加了相关的Google跨域跟踪属性,但问题是我的重新营销转换脚本不起作用。没有Javascript错误,也没有人出现在我的重新营销列表中,我们每隔几分钟就有50次访问我们的网站,所以他们应该在那里

拼命寻找解决办法

希望收到某人的来信

戴夫

首先,您使用的是哪个版本的jQuery,因为我不认识
$H(域)。每个
都是jQuery函数。Mootools中有一个
$H
函数,但是

如果要迭代jQuery对象,需要使用

$。每个(您的_数组、函数(索引、值){}

(这也适用于第59行的位-
$(\“a[href*='\'“+val+\']\”)。每个

其次,如果你有
控制台,IE就会崩溃。在你的代码中记录
条目,只在开发环境中使用它们

希望有帮助


图森

显然这还不够神奇……谢谢你富有洞察力的评论:)