Note that there are some explanatory texts on larger screens.

plurals
  1. POGoogle Analytics Event Tracking onclick callout within PHP
    primarykey
    data
    text
    <p>I have been trying to figure out this problem for a few days now with little to no progress, I have a feeling the problem resides in trying to call a javascript function from php. I need to start tracking file downloads on our company website and I've got this working in regular HTML for GA but a lot of our files pull from a database through php and I would like to get this tag working with those files. Nothing is passing through to GA and I can see there is an error when I look at the source in FireFox. Thanks for any insight.</p> <p>Here is the line of code that's giving me headaches. <code>&lt;a target='_blank' href='/$file' onclick='_gaq.push(['_trackEvent', 'Downloads', 'Datasheet', '$filetext']);'&gt;&lt;img alt='$filetext' src='/$image' border='0'/&gt;&lt;/a&gt;</code></p> <p>FireFox shows this part of the code in red as an error, if I take out the onclick portion the error goes away, the page displays fine but nothing is being sent to GA like I mentioned before: </p> <pre><code>&lt;a target='_blank' href='/images/datasheets/IDS-66 Amphe-10G.pdf' onclick='_gaq.push(['_trackEvent', 'Downloads', 'Datasheet', 'Amphe-10G']);'&gt; </code></pre> <p>Here is the full PHP code:</p> <pre><code>&lt;div class="download01"&gt; &lt;div class="download02"&gt;&lt;/div&gt; &lt;table style="width: 100%" border="0" cellpadding="0" cellspacing="0"&gt; &lt;tbody&gt; &lt;? // 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 "&lt;table&gt;"; // The container table with $cols columns do{ echo "&lt;tr&gt;"; for($i=1;$i&lt;=$cols;$i++){ // All the rows will have $cols columns even if // the records are less than $cols $row=mysql_fetch_array($result); ?&gt; &lt;? $file = $row['file']; $image = $row['image']; $filetext = $row['filetext']; if ($file == ""){echo "&lt;td&gt;&amp;nbsp;&lt;/td&gt;";} else {echo "&lt;td valign='top'&gt; &lt;table&gt; &lt;tr valign='top'&gt; &lt;td width='120'&gt; &lt;div align='center'&gt;&lt;a target='_blank' href='/$file' onclick='_gaq.push(['_trackEvent', 'Downloads', 'Datasheet', '$filetext']);'&gt;&lt;img alt='$filetext' src='/$image' border='0'/&gt;&lt;/a&gt;&lt;br /&gt;&lt;a target='_blank' href='/$file' onclick='_gaq.push(['_trackEvent', 'Downloads', 'Datasheet', '$filetext']);'&gt;$filetext&lt;/a&gt;&lt;/div&gt; &lt;/td&gt; &lt;tr&gt; &lt;td height='25'&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/td&gt;"; } } // else{ // echo "&lt;td&gt;&amp;nbsp;&lt;/td&gt;"; //If there are no more records at the end, add a blank column } // } // } while($row); echo "&lt;/table&gt;"; ?&gt; &lt;/tr&gt; &lt;/tbody&gt; &lt;/table&gt; &lt;/div&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload