Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › Statistics issue when user presses 'return'
This topic contains 12 replies, has 2 voices, and was last updated by Ernest Marcinko 1 year, 4 months ago.
- AuthorPosts
- October 17, 2021 at 2:42 pm #35186
Hi there,
I have enabled statistics on the plugin so I can use the ‘popular searches’ widget. It is working fine but I have noticed that when the user enters their query and presses the return key on the keyboard, the search is not logged and is not seen in the statistics. They are only logged if the user clicks the search icon or clicks a result in the preview.
Is there a fix for this?
Thanks
October 18, 2021 at 1:43 pm #35198Hi,
You are right, those queries should be recorded too. I think there is a bypass solution to it though.
Try adding this code to the functions.php file in your theme/child theme directory – make sure to have a full server back-up first for safety. For more details you can check the safe coding guidelines.
Best,add_action('asp_results', 'asp_add_stat_noajax', 10, 4); function asp_add_stat_noajax($results, $id, $is_ajax, $args) { if ( !$is_ajax ) { asp_statistics::addKeyword($id, $args['s']); } }
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
October 19, 2021 at 6:31 pm #35222Hi,
The code doesn’t seem to fix it. I have tested searches with a return key press and they still do not appear in statistics. The code also breaks the plugin preview results.
The access link is still usable, please let me know if you need any more informationOctober 20, 2021 at 3:18 pm #35227Can you please try this variation instead:
add_filter('asp_results', 'asp_add_stat_noajax', 10, 4); function asp_add_stat_noajax($results, $id, $is_ajax, $args) { if ( !$is_ajax ) { asp_statistics::addKeyword($id, $args['s']); } return $results; }
Also, make sure the search override feature is enabled, otherwise the plugin may not trigger.
Best,
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
October 20, 2021 at 3:48 pm #35228Hi ernest,
Thanks for the update.
Maybe this helps – I’ve noticed that the issue of searches not being logged only occurs when the return key is pressed very fast (so before the preview results have even appeared). If the user types their query, waits a second for preview to load and appear, then presses return, it will be logged in statistics as normal. This is without any custom code applied.
So currently the custom code (old and new variation) does not have any impact on the fast return key presses.
Thanks again.
October 21, 2021 at 7:54 am #35236You cannot access this content. Best,
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
October 21, 2021 at 11:00 am #35243OK, that would be great 🙂
Thanks
November 13, 2021 at 1:22 am #35526Hi Ernest, is there an ETA for when this will be fixed?
Thanks
November 15, 2021 at 8:38 am #35543Hi,
It had been fixed within release 4.21.4 about two weeks ago, if you update to the latest release (4.21.5), it should be okay now.
Best,
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
November 15, 2021 at 7:50 pm #35568Am currently on 4.21.5 and it doesn’t look like anything has changed. A fast search query before results are previewed does not appear in statistics.
November 16, 2021 at 10:22 am #35575Do you have the search override feature enabled?
Best,
Make sure to turn it on, otherwise the plugin search override may not trigger when redirecting to the results page.
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
November 16, 2021 at 3:45 pm #35594Ah, sorry I missed this. Not able to use the override otherwise my results filtering breaks. So to confirm, search override has to be enabled in order to catch the fast search queries in statistics?
November 18, 2021 at 9:33 am #35609I’m afraid yes, but maybe with a custom code there is a way to trigger it whenever the search results page is displayed.
Best,add_action('posts_results', 'asp_trigger_search_stat'); function asp_trigger_search_stat() { if ( is_search() && isset($_GET['s']) && $_GET['s'] != '' ) { asp_statistics::addKeyword(-1, $_GET['s']); } }
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
- AuthorPosts
You must be logged in to reply to this topic.