0

google chrome 调试器在以下 GA 电子商务跟踪代码中显示 SyntaxError: Unexpected Identifier:

<?php 
if($this->tx_id == true && $this->rd['total'] == true) { 
?>
    _gaq.push(['_addTrans',
                    <?=$this->tx_id ?>,
                    '',
                    <?=$this->rd['total']?>,
                    '',
                    '',
                    '',
                    '',
                    ''
                ]);

    <!------Items purchased------>
<?php 
    foreach($this->dd as $sku=>$val) {
        $i++;
        $product_title= $this->pp[$sku]['title'];
        $qty = $val['pt']['qty']; 
        ?>
            _gaq.push(['_addItem',
                        <?= $this->tx_id ?>,
                        <?= $sku ?>,
                        <?= $this->pp[$sku]['title'] ?>, 
                        '',
                        <?= $this->pp[$sku]['price']?>,
                        <?= $qty ?>
                    ]);
    <?php 
    }
    ?>

    _gaq.push(['_trackTrans']);  
<?php  
}
?>  

你能帮忙吗?

4

1 回答 1

0

您缺少 ga_addTrans_addItem命令的参数周围的单引号。

它应该是这样的:

<?php 
if($this->tx_id == true && $this->rd['total'] == true) { 
?>
    _gaq.push(['_addTrans',
                    '<?=$this->tx_id ?>', /* <-- Surrounded with single quotes */
                    '',
                    '<?=$this->rd['total']?>', /* <-- Surrounded with single quotes */
                    '',
                    '',
                    '',
                    '',
                    ''
                ]);

    <!------Items purchased------>
<?php 
    foreach($this->dd as $sku=>$val) {
        $i++;
        $product_title= $this->pp[$sku]['title'];
        $qty = $val['pt']['qty']; 
        ?>
            _gaq.push(['_addItem',
                        '<?= $this->tx_id ?>', /* <-- Surrounded with single quotes */
                        '<?= $sku ?>', /* <-- Surrounded with single quotes */
                        '<?= $this->pp[$sku]['title'] ?>',  /* <-- Surrounded with single quotes */
                        '',
                        '<?= $this->pp[$sku]['price']?>', /* <-- Surrounded with single quotes */
                        '<?= $qty ?>' /* <-- Surrounded with single quotes */
                    ]);
    <?php 
    }
    ?>

    _gaq.push(['_trackTrans']);  
<?php  
}
?>  

于 2012-09-22T16:33:30.453 回答