grazies / analytics-issues

Automatically exported from code.google.com/p/analytics-issues
0 stars 1 forks source link

Code not working #780

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
---------------------------------------------------------------------------
NOTE: This tool is not designed to request help. It is only for reporting
issues and requesting features for the Google Analytics libraries.

If you are a developer and you need help, visit:
https://developers.google.com/analytics/help/

If you are not a developer and you need help, visit:
https://support.google.com/analytics
---------------------------------------------------------------------------
Name of affected component: Web Tracking (analytics.js)

Issue summary:
I try to send in the transaction information under eCommerce, however, is not 
working. Code as below:

<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-49935530-1', 'auto');

        ga('require', 'ecommerce');

        <?php
        if (isset($id))
        {
            // Transaction Data
            $trans = Transaction::find($id);

            $coupon = DB::table('transaction AS a')
            ->select('b.coupon_amount')
            ->leftJoin('transaction_coupon AS b','a.id', '=', 'b.transaction_id')
            ->where('a.id', '=', $id)
            ->first();

            $point = DB::table('transaction AS a')
            ->leftJoin('transaction_point AS b','a.id', '=', 'b.transaction_id')
            ->where('a.id', '=', $id)
            ->where('b.status', '=', '1')
            ->sum('b.amount');

            $total = $trans->total_amount - $coupon->coupon_amount - $point + $trans->gst_total;

            $trans = array('id'=>$id, 'revenue'=>$total, 'shipping'=>$trans->delivery_charges, 'tax'=>$trans->gst_total);

            // List of Items Purchased.
            $transD = DB::table('transaction_details AS a')
            ->leftJoin('products AS b', 'b.id', '=', 'a.product_id')'a.product_id')
            ->leftJoin('categories AS c', 'c.product_id', '=', 'a.product_id')
            ->leftJoin('products_category AS d', 'c.category_id', '=', 'd.id')
            ->where('a.transaction_id', '=', $id)
            ->groupBy('a.id')
            ->get();

            foreach ($transD as $details)
            {
                $pro_name = $details->name . '/' . $details->price_label;
                $pro_price = $details->total - $details->disc + $details->gst_amount;

                $items[] = array('sku'=>$details->sku, 'name'=>$pro_name, 'category'=>$details->category_name, 'price'=>$pro_price, 'quantity'=>$details->unit);
            }

            // echo "<pre>";
            // var_dump($trans); echo "<br>";
            // var_dump($items); echo "<br>";

        }
        ?>

        ga('ecommerce:addTransaction', {
          'id': <?php echo "'" . $trans['id'] . "'" ?>,
          'revenue': <?php echo "'" . $trans['revenue'] . "'" ?>,
          'shipping': <?php echo "'" . $trans['shipping'] . "'" ?>,
          'tax': <?php echo "'" . $trans['tax'] . "'" ?>
        });

        <?php
        foreach ($items as &$item)
        {
        ?>

        ga('ecommerce:addItem', {
          'id': <?php echo "'" . $trans['id'] . "'" ?>,
          'name': <?php echo "'" . str_replace("'", "",$item['name']) . "'" ?>,
          'sku': <?php echo "'" . $item['sku'] . "'" ?>,
          'category': <?php echo "'" . str_replace("'", "",$item['category']) . "'" ?>,
          'price': <?php echo "'" . $item['price'] . "'" ?>,
          'quantity': <?php echo "'" . $item['quantity'] . "'" ?>
        });

        <?php
        }
        ?>

        ga('ecommerce:send');

        ga('send', 'pageview');
        </script>

Expected output:
The data should be reflected in Google Analytics - Conversion - Ecommerce

Actual results:
Nothing

Original issue reported on code.google.com by eugene.j...@gmail.com on 5 Nov 2015 at 6:50

GoogleCodeExporter commented 8 years ago
Manage to fix it, but how to close this issue?

Original comment by eugene.j...@gmail.com on 5 Nov 2015 at 9:04

GoogleCodeExporter commented 8 years ago
Stackoverflow is a great place to get help with this sort of issue. There are 
two tags which we monitor google-analytics and google-analytics-api

Original comment by mcoh...@google.com on 5 Nov 2015 at 4:15