谷歌再营销Javascript

时间:2012-05-09 15:03:25

标签: javascript magento prototypejs google-adwords

我有一些从我的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次,所以他们应该在那里......

拼命寻求解决方案。

希望收到某人的回复

戴夫

1 个答案:

答案 0 :(得分:0)

Davzie,

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

如果要遍历jQuery对象,则需要使用

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

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

其次,如果您的代码中有任何console.log条目,IE将会失败,只能在开发环境中使用这些条目....

希望有所帮助。

Touson

相关问题