0

我有一些从我的 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>
 ");

如您所见,此代码还将相关的 Google 跨域跟踪属性添加到链接和表单,但问题是我的再营销转换脚本不起作用。没有 Javascript 错误,但也没有人出现在我的再营销列表中,我们每隔几分钟就会有大约 50 次访问我们的网站,所以他们应该在那里......

拼命寻求解决方案。

希望收到某人的来信

戴夫

4

1 回答 1

0

戴维齐,

首先,您使用的是什么版本的 jQuery,因为我不认为$H(domains).each它是 jQuery 函数。Mootools 中有一个$H函数,但jQuery 没有

如果你想遍历一个 jQuery 对象,你需要使用

$.each(your_array, function(index, value){}

(这也适用于您在第 59 行的位 - $(\"a[href*='\"+val+\"']\").each

其次,如果您console.log的代码中有任何条目,IE 将会崩溃,请仅在开发环境中使用它们......

希望有帮助。

图森

于 2012-05-12T20:00:17.853 回答