简体   繁体   中英

How to Add Google Analytics Event Tracking Code to download link in php?

I Added below Google Analytics Event Tracking Code to download link

onClick="ga('send', 'event', 'Redirected2dl', 'QPRedirect');"

i Added the code directly to the php file as shown below . But when i tried to load the webpage the web page does not display!

<?php
$url = $_GET['url'];
echo 
'<p style="text-align: center;"> Your QuestionPaper Will Be Diplayed Here.
<a id="downloadLink" href="http://www.questionspaper.in/wait.php?url='.urldecode($url).'" onClick="ga('send', 'event', 'Redirected2dl', 'QPRedirect');"  >click     here to Download Your QuestionPaper</a>
if (isset ($url)) 
{
echo 
'<iframe ... src="http://docs.google.com/gview?url='.urldecode($url).'&embedded=true"     height="800" width="900" ></iframe>';
 }
 else {
 echo '<iframe ... src="
$url" height="1000" width="1000"></iframe>';
 }
?>

Can Anyone Help me to rectify the problem.Thank you

The above Php File can Be veiwed here http://questionspaper.in/myiframe.php?url=

You need to escape the single quotes in the string you are echoing. You also want to urlencode the url parameter, not decode it.

<?php
    $url = $_GET['url'];
    echo '<p style="text-align: center;">Your Question Paper Will Be Diplayed Here. 
    <a id="downloadLink" href="http://www.questionspaper.in/wait.php?url='.urlencode($url).'" onClick="ga(\'send\', \'event\', \'Redirected2dl\', \'QPRedirect\');"  >click here to Download Your QuestionPaper</a>';
    if (isset ($url)) 
    {
        echo '<iframe ... src="http://docs.google.com/gview?url='.urldecode($url).'&embedded=true"     height="800" width="900" ></iframe>';
    } else {
        echo '<iframe ... src=" $url" height="1000" width="1000"></iframe>';
    }
?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM