Issue with View Counter not updating for AJAX Content
-
Hi
I have an issue where the counter does not update when posts are accessed through AJAX using FancyBox. It supposed to track views for posts opened via FancyBox modals, and while the AJAX request seems to be successful (indicating no errors in the console), the view counter for the posts does not reflect the new views.
Here are the details of my implementation and debugging efforts:
- AJAX Request Setup: I’ve set up an AJAX call that triggers when a post link is clicked. The request is sent to
wp_ajax_nopriv_tptn_tracker
andwp_ajax_tptn_tracker
actions with the post ID andactivate_counter
set to11
, mirroring the behavior observed when accessing posts directly. - Debugging Logs: Adding debug logging to the
update_count
function within the plugin’sclass-tracker.php
file shows that the function is called with the correct post ID andactivate_counter
. However, the view counter still does not update. - Response Handling: The AJAX response handling in JavaScript uses
response.text()
and logs a success message, but it does not display any response data, suggesting that the server-side handler might not be sending back data as expected. - Direct Page Access: When accessing a post directly (not through AJAX/FancyBox), the counter updates as expected, with
activate_counter
received as11
in the debug log, indicating that direct access correctly triggers the counter update.
I think there is an issue with how AJAX requests are handled or how view counts are updated and cached. How do I ensure that views from AJAX-loaded content are correctly tracked and reflected by the plugin?
- AJAX Request Setup: I’ve set up an AJAX call that triggers when a post link is clicked. The request is sent to
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Issue with View Counter not updating for AJAX Content’ is closed to new replies.