SyntaxError:意外的标识符。适用于Google电子商务跟踪代码的Google Chrome调试器

时间:2012-05-03 22:55:23

标签: google-analytics

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  
}
?>  

你能协助吗?

1 个答案:

答案 0 :(得分: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  
}
?>