2015-07-06 59 views
0

我想在Opencart的跟蹤交易定義,但我得到這個消息:GAQ不Opencart的2.0

Uncaught ReferenceError: _gaq is not defined(anonymous function) 

這是我想做的跟蹤我

catalog/view/theme/default/template/common/success.tpl` 


     <!--THIS IS THE START OF THE TRACKING MOD--> 
    <?php if($order_tracker){ 
     echo "SUCESSO"; 
     $tracking_info = '<script type="text/javascript">'; 

     //ADD TOP LEVEL TRACKING INFO 
    $tracking_info .= "_gaq.push(['_addTrans', '" . $order_tracker['order_id'] . "', '" . $order_tracker['store_name'] . "', '" . $order_tracker['total'] . "', '" . $order_tracker['tax'] . "', '" . $order_tracker['shipping'] . "', '" . $order_tracker['city'] . "', '" . $order_tracker['state'] . "', '" . $order_tracker['country'] . "']);"; 

     //ADD INFO FOR EACH PRODUCT 
     foreach($order_tracker['products'] as $product){ 
      $tracking_info .= "_gaq.push(['_addItem', '" . $product['order_id'] . "', '" . $product['model'] . "', '" . $product['name'] . "', '', '" . $product['price'] . "', '" . $product['quantity'] . "']);"; 
     } 

     //ADD THE CURRENCY OF THE TRANSACTION 
     $tracking_info .= "_gaq.push(['_set', 'currencyCode', '" . $order_tracker['currency'] . "']);"; 

     $tracking_info .= '</script>'; 

     print $tracking_info; 

    } ?> 
    <!--THIS IS THE END OF THE TRACKING MOD--> 

這是它如何被解釋在Chrome控制檯

<!--THIS IS THE START OF THE TRACKING MOD--> 
    <script type="text/javascript">_gaq.push(['_addTrans', '17', 'Zelulares', '805.0000', '', '5.0000', 'Sao Paulo', 'São Paulo', 'Brazil']);_gaq.push(['_addItem', '17', 'Product 16', 'MacBook', '', '500.00', '1']);_gaq.push(['_addItem', '17', 'Product 14', 'iMac', '', '100.00', '3']);_gaq.push(['_set', 'currencyCode', 'USD']);</script> <!--THIS IS THE END OF THE TRACKING MOD--> 

編輯:

這是我列入Opencart的管理員在analytics.js代碼:

<script> 
    (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ 
    (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), 
    m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) 
    })(window,document,'script','//www.google-analytics.com/analytics.js','ga'); 

    ga('create', 'UA-XXXXXXX-X', 'auto'); 
    ga('send', 'pageview'); 

</script> 
+1

您是否包含[GA base code](https://developers.google.com/analytics/devguides/collection/gajs/#tracking-code-quickstart)?或者您是否可能使用[Universal Analytics](https://developers.google.com/analytics/devguides/collection/analyticsjs/#quickstart)(analytics.js),並且您的代碼仍使用舊樣式(ga.js) 。 – MisterPhilip

回答

1

由於MisterPhillip指出您的交易代碼使用不同的(舊的)版本比你的代碼用於創建一個跟蹤器和需求要被更新。您需要「要求」電子商務庫(在創建跟蹤器之後但在添加交易或產品之前)並將跟蹤代碼轉換爲新版本。您正在尋找看起來像這樣(完整的例子)輸出:

<script> 
    (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ 
    (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), 
    m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) 
    })(window,document,'script','//www.google-analytics.com/analytics.js','ga'); 

    ga('create', 'UA-XXXXXXX-X', 'auto'); 
    ga('require', 'ecommerce'); 

    ga('ecommerce:addTransaction', { 
     'id': '17',      // Transaction ID. Required. 
     'affiliation': 'Zelulares', // Affiliation or store name. 
     'revenue': '805.0000',    // Grand Total. 
     'shipping': '',     // Shipping. 
     'tax': '5.0000'      // Tax. 
    }); 

    ga('ecommerce:addItem', { 
     'id': '17',      // Transaction ID. Required. 
     'name': 'MacBook', // Product name. Required. 
     'sku': 'Product 16',     // SKU/code. 
     'price': '500',     // Unit price. 
     'quantity': '1'     // Quantity. 
    }); 

    ga('ecommerce:send'); 

    ga('send', 'pageview'); 

</script> 

注意的是,在交易geograpical信息不再是通用Analytics(分析)存在,則需要重新創建這樣的自定義維度。此外,這是假設標準的電子商務跟蹤(還有一個「增強」版本,這是一個更復雜的設置)。