Say I have the link:
<a href="http://www.google.com">google</a>
Is there any way I can record the click (with php/sql)? For example an onclick event to load ajax? Would the ajax run before the page redirects? I want to avoid:
<a href="record_click.php?url=http://www.google.com">google</a>
You could change your link to:
And then use the function:
You could then wait for the AJAX request to complete before using the document.location part. However I would suggest simply using a separate file to log clicks like you have already suggested because it is an immediate action that doesn’t require JS to be on, and that provides immediate feedback.