Help us understand the problem. What is going on with this article?

EC-CUBE - Google Analytics eコマースタグの設定

More than 5 years have passed since last update.

ユニバーサルアナリティクス用の eコマースタグの設定です。

電車の中で書いたので、まだ動作確認していません。ご利用は自己責任でm(_ _)m

data/class/pages/shopping/LC_Page_Shopping_Complete.php

    /**
     * Page のアクション.
     *
     * @return void
     */
    public function action()
    {
        $this->arrInfo = SC_Helper_DB_Ex::sfGetBasisData();
        $objPurchase = new SC_Helper_Purchase_Ex();
        // eコマースコンバージョンタグ用設定
        if (is_numeric($_SESSION['order_id'])) {
            $this->arrOrder = $objPurchase->getOrder($_SESSION['order_id']);
            $this->arrOrderDetail = $objPurchase->getOrderDetail($_SESSION['order_id']);
        }
    }

2.4系の場合は以下の処理でいけるはず

        // 2.4系の場合は以下 120行目付近
        $objQuery = new SC_Query();
        $arrOrder = $objQuery->select('*', 'dtb_order', 'order_id = ?', array($_SESSION['order_id']));
        $this->arrOrder = $arrOrder[0];
        $this->arrOrderDetail = $objQuery->select('*', 'dtb_order_detail', 'order_id = ?', array($_SESSION['order_id']));

data/Smarty/templates/xxxx/site_main.tpl

body 直下に配置します.
PC用、スマートフォン用それぞれのテンプレートに設定します。

        <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', 'ecommerce.js');
          ga('send', 'pageview');

          <!--{if $smarty.server.$PHP_SELF == "`$smarty.const.ROOT_URLPATH`shopping/complete.php" && $arrOrder|@count > 0 && $arrOrderDetail|@count > 0}-->
            ga('ecommerce:addTransaction', {
               'id': '<!--{$arrOrder.order_id|h}-->',              // Transaction ID. Required.
               'affiliation': '<!--{$arrSiteInfo.shop_name|h}-->', // Affiliation or store name.
               'revenue': '<!--{$arrOrder.payment_total|h}-->',    // Grand Total.
            });

            <!--{foreach from=$arrOrderDetail item=orderDetail name=orderDetail}-->
                ga('ecommerce:addItem', {
                   'id': '<!--{$arrOrder.order_id|h}-->',          // Transaction ID. Required.
                   'name': '<!--{$orderDetail.product_name|h}--><!--{if $orderDetail.classcategory_name1 != ""}--> / <!--{$orderDetail.classcategory_name1|h}--><!--{/if}--><!--{if $orderDetail.classcategory_name2 != ""}--> / <!--{$orderDetail.classcategory_name2|h}--><!--{/if}-->', // Product name. Required.
                   'sku': '<!--{$orderDetail.product_code|h}-->',  // SKU/code.
                   'price': '<!--{$orderDetail.price|h}-->',       // Unit price.
                   'quantity': '<!--{$orderDetail.quantity|h}-->'  // Quantity.
                });
            <!--{/foreach}-->
            ga('ecommerce:send');
          <!--{/if}-->
        </script>

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした