Adding javascript to a php page

I am new to web design.  I have a php page at www.mauitradewinds.com/TripAdvisor.php and it redirects traffic to another site when visitors click a certain button on my navigation menu.  I would like to track the usage of that button, so I inserted javascript tracking code, but it isn't working.  Please advise. TripAdvisor.php
ddantesAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
gr8gonzoConnect With a Mentor ConsultantCommented:
There's an order in which things occur in PHP pages. Before any Javascript and HTML are sent to the visitor's computer, the PHP is executed first. So in your code, you have PHP code that redirects to another site (the "header" line). This redirect occurs before any of your Javascript tracking code is seen by the browser, so the browser doesn't run that Javascript code.

You could always remove the PHP redirect and then use the window.location Javascript command to perform the same redirect:

<script type="text/javascript">
<!--
window.location = "http....Hawaii.html";
-->
</script>
<noscript>
      <a href="http....Hawaii.html">Click here if you are not automatically redirected.</a>
</noscript>
0
 
ddantesAuthor Commented:
Thank you, that is a very nice recommendation.  I will accept that solution after verifying that the revised redirect page is being tracked.
0
 
ddantesAuthor Commented:
I don't think the new page is tracking.  I placed the javascript for the tracking after the javascript for the redirect.  Is that placement critical?   The revised redirect page is at www.mauitradewinds.com/TripAdvisor.htm   
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
ddantesAuthor Commented:
I tried placing the tracking script before the redirect script.  Either way, the page is not being tracked.  Can you please have another look?
0
 
gr8gonzoConsultantCommented:
Can you show the code for that page now?
0
 
Ray PaseurCommented:
Here it the general design I would use (no JavaScript here).

Make the link in your navigation go to one of your pages.  Inside that page, write a row into a data base table with the DATETIME, and the client IP address.  Then use header("Location") to redirect to the foreign URL.
0
 
ddantesAuthor Commented:
Thank you both for your comments.  gr8gonzo:  I was mistaken, and the page is tracking, now that I placed the javascript before the redirect code.  Thank you for your help!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.