我一直試圖找出這個問題幾天,現在幾乎沒有任何進展,我感覺問題在於試圖從PHP調用JavaScript函數。我需要開始跟蹤我們公司網站上的文件下載,並且我已經在GA的常規HTML中工作,但是我們很多文件都是通過php從數據庫中提取的,我希望能夠使用這些文件處理這些標記。沒有什麼是通過遺傳算法,當我看到FireFox中的源代碼時,我可以看到有一個錯誤。感謝您的任何見解。PHP中的Google Analytics事件跟蹤onclick標註
這是讓我頭痛的代碼行。 <a target='_blank' href='/$file' onclick='_gaq.push(['_trackEvent', 'Downloads', 'Datasheet', '$filetext']);'><img alt='$filetext' src='/$image' border='0'/></a>
火狐紅色顯示代碼錯誤的這一部分,如果我拿出的onclick部分錯誤消失,頁面顯示正常,但就像我之前提到的沒有被髮送到GA:
<a target='_blank' href='/images/datasheets/IDS-66 Amphe-10G.pdf' onclick='_gaq.push(['_trackEvent', 'Downloads', 'Datasheet', 'Amphe-10G']);'>
以下是完整的PHP代碼:
<div class="download01">
<div class="download02"></div>
<table style="width: 100%" border="0" cellpadding="0" cellspacing="0">
<tbody>
<?
// Make a MySQL Connection
mysql_connect("localhost", "amphenol_web", "ampheweb") or die(mysql_error());
mysql_select_db("amphenol_sheets") or die(mysql_error());
// Retrieve all the data from the "distributors" table
$query = "SELECT * FROM datasheets ORDER BY filetext";
$result = mysql_query($query) or die(mysql_error());
$cols = 6; // Here we define the number of columns
echo "<table>"; // The container table with $cols columns
do{
echo "<tr>";
for($i=1;$i<=$cols;$i++){ // All the rows will have $cols columns even if
// the records are less than $cols
$row=mysql_fetch_array($result);
?>
<?
$file = $row['file'];
$image = $row['image'];
$filetext = $row['filetext'];
if ($file == ""){echo "<td> </td>";}
else {echo
"<td valign='top'>
<table>
<tr valign='top'>
<td width='120'>
<div align='center'><a target='_blank' href='/$file' onclick='_gaq.push(['_trackEvent', 'Downloads', 'Datasheet', '$filetext']);'><img alt='$filetext' src='/$image' border='0'/></a><br /><a target='_blank' href='/$file' onclick='_gaq.push(['_trackEvent', 'Downloads', 'Datasheet', '$filetext']);'>$filetext</a></div>
</td>
<tr>
<td height='25'> </td>
</tr>
</table>
</td>";
}
}
// else{
// echo "<td> </td>"; //If there are no more records at the end, add a blank column
}
// }
// }
while($row);
echo "</table>";
?>
</tr>
</tbody>
</table>
</div>
請不要鏈接到您的網站。閱讀:http://meta.stackexchange.com/questions/125997/something-in-my-web-site-or-project-doesnt-work-can-i-just-paste-a-link-to-it –
請顯示您的實際呈現的HTML。這與您的PHP源代碼無關。 –
對不起,我刪除了鏈接併發布了FireFox展示的內容。 – Martin