2012-05-09 2 views
0

私はMagentoインストールから印刷されたすばらしいJavaScriptを持っています。ドメインのリストを取得することができます。リマーケティングリストがある場合、JSがそのドメインにいることをJSが検出したときにリマーケティングを開始するための詳細を入力することができます。GoogleリマーケティングJavascript

はHERESにコード:あなたが見ることができるように

$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回訪問するので、そこにいるはずです。

必死に解決を求めています。

・ホープ誰か

から聞くデイブ

+0

どうやらそれが十分*魔法ではありません* ...あなたの洞察力にコメントを –

+1

感謝:) – davzie

答えて

0

私はjQueryの関数として$H(domains).each認識していないとして、使用しているのjQueryのバージョンDavzie、まず

、。 Mootoolsには$H関数がありますが、nothing in jQueryです。

あなたはjQueryオブジェクトを反復処理したい場合は、

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

を使用する必要があります(これは、ライン59上のビットに適用される - $(\"a[href*='\"+val+\"']\").each

第二に、IEが倒れますあなたのコードにconsole.logのエントリがある場合は、dev環境でのみこれらを使用してください。

希望に役立ちます。

Touson