After previously discussing this issue, I have conducted further research and attempted to resolve the problem, but unfortunately, a solution still eludes me...
My website (www.seatgeek.com) incorporates numerous links that are loaded via AJAX. Whenever a user clicks on one of these links, I intend to track it as a goal by attaching pageTracker._trackPageview() to the onClick attribute of the links. However, Google Analytics (GA) fails to register these clicks, leaving me puzzled. Here's an example of the code for such a link:
<a href="<?php echo $tickets[$x][3] ?>" target = "_blank" class="buyTicketsLink" onClick="pageTracker._trackPageview('/outgoing/event4.php');">BUY TICKETS</a>
I have tested the above code with links not fetched via AJAX, and it works seamlessly, affirming that the issue pertains specifically to AJAX-loaded content. Furthermore, in my attempts to troubleshoot, I have experimented with programmatically adding onclick events like so:
<script>
function attach_goal_tracking() {
var links = document.getElementsByClassName("buyTicketsLink");
for(var i=0; i<links.length; i++) {
links[i].onclick = record_goal;
}
}
function record_goal() {
pageTracker._trackPageview('/event/outgoing');
}
</script>
Regrettably, this approach also yields no results. Nevertheless, inserting a test alert box within the record_goal() function confirms that the function executes successfully. For instance, when altering the function as follows:
function record_goal() {
alert('Hello');
pageTracker._trackPageview('/event/outgoing');
}
The 'Hello' alert box pops up upon clicking a link. Despite this, the pageview data for '/event/outgoing' remains unrecorded.
This conundrum has left me completely perplexed. Any guidance or insights on resolving this matter would be immensely valued.