简体   繁体   中英

event tracking for php print in google analytics

Below is a segment of php code from my website. I have google analytics plugged in and i'd like to use event tracking or something else in analytics to show me when a user ends up seeing the statement below shown on the webpage. This statement occurs when the user enters a non matching suburb into a form on the home page. Im using POST method so the URL is not unique unfortunately.

if($row_cnt == 0)
{
    PRINT "<p align='middle'>Unfortunately we do not have an online price for the     suburb you entered.</p><p align='middle'>We may still provide our service to your area though.</p><p align='middle'>Please call our office on xxxxx to make an over the phone booking.</p>"; 
 }

else

You can try to simple place the event tracking code inside the PRINT function so that it fires when it is printed on page. Something like this might work, but you'll have to test

if($row_cnt == 0)
{
    PRINT "<p align='middle'>Unfortunately we do not have an online price for the     suburb you entered.</p><p align='middle'>We may still provide our service to your area though.</p><p align='middle'>Please call our office on xxxxx to make an over the phone booking.</p>
<script type="text/javascript">
    _gaq.push(['_trackEvent', 'eventCategory', 'eventAction', 'eventLabel ']);
</script>"; 
 }
 else  

Or to be cleaner you could simply put the event code off page and call it by the ID of the element. In which case I would wrap the entire thing into a div, give the div an ID and then use the getElementById("DIV-ID"); method.

Let me know if it works.

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