Are there any functions we can use on the front-end?
-
Hello and thank you for your efforts providing us with this great plugin!
Are there any functions we can use in the front-end, or at least, is there an easy way to query the data saved by Search Analytics?
Thanks!
-
Hi there,
Thanks for reaching out.
I am currently working on rewriting and optimizing the codebase for the plugin. There were some blocks and widgets in plan but, as the plugin appeared as a personal need I did not think it to be super extendable from the beginning. And that is something that needs to be addressed now that the active installs count is on the rise.
Regarding your question, there is a method for pulling the search queries, the one that is used for creating the admin dashboard widget.
However, those methods are currently only being included in the admin panel.
The file that is holding the methods for pulling data from the database is: search-analytics/admin/includes/class.history-data.php and you can look through those methods and see how the queries are done.
Another solution would be for you to tell me what kind of stats you’d like to display in the front-end and I can provide the code for you to be able to do those or, maybe even better, I can release an update that would add the required things to the plugin.
Honestly, I’ve been waiting for someone to ask for front-end stats display for a while now because I have no idea what kind of stats you’d need ( I don’t display anything search related on my own websites ).
Looking forward to hearing from you,
CornelThank you for the swift reply!
So, what I would be currently looking for the front-end is something like the following:
– Show ‘similar searches’ (obviously that PRODUCE results) – This would be priceless, however, I am not really sure if and how it could be done.
– Show most common X number of searches
– Show current user’s last X number of searchesRegarding the ‘similar searches feature, since the plugin already reports if there are results or not, it would be great if it could look up for ‘similar search terms’ – getting ‘similar search terms based on posts’ would be an overkill I guess -let alone I am not really sure if this depends on WordPress since I am using a different search engine (ElasticSearch through the ElasticPress plugin). The usecase scenario is to populate empty ‘search result’ pages.
So for example -using my specific context – if someone searched for ‘Opel Corsa’ and got no results, it would be great if they could be proposed something like ‘Opel Astra’ that was previously reported to produce results. This could bring more new problems to the surface like, another proposed term that USED to produce results, now, no longer does, etc
This is more or less, what eBay is using for suggestions if there are no results.
Looking forward to your reply!
These 2 are pretty easy to achieve:
– Show most common X number of searches
– Show current user’s last X number of searchesHowever, for the similar searched one, I think it would bloat the plugin and move it away from being the front-end impact-less plugin that we all know.
That being said, I really like your idea and I will consider building another plugin that would come as an add-on to the Search Analytics.
I will release a plugin update next week that will include the details you need. Thinking of having it in the form of a shortcode and maybe also a widget/block.
I hope that will, at least partially, suit your needs!
CornelHello again and I apologize for taking too long to respond!
I really appreciate your efforts into pleasing me! Looking forward to your next update!
Regarding the ‘similar terms’ it would really be awesome if you could implement at some point in the future!
Have a nice day!
Hello @scooterlord ,
I just wanted to let you know that I am a bit behind schedule with the update but it will come out soon.
Have a nice day!
Hello @cornelraiu-1 !
Thanks for keeping me up to date, looking forward to your updates! ??
Have a nice day yourself!
NS
Hello @scooterlord ,
I have updated the GitHub repository of the plugin with the latest set of changes including the shortcode and added the shortcode documentation. You can find the repo here: https://github.com/cornelRaiu/search-analytics
I still need to run some tests before releasing the next version to everyone. In case you are available, I would really appreciate it if you could help me test the version that is currently on the GitHub. This way you can tell me if the shortcode I prepared is ok and what other changes you think I should make for it to be super useful to you.
Looking forward to your reply.
Thank you,
CornelHello @cornelraiu-1 !
I will try to follow up with you in the next couple of days to help you test. I only had a quick view of the repo, but seems like you nailed it for a first version ??
Will get back to you after I installed and tested. Thanks!
Hello @cornelraiu-1 and sorry for my late response, a lot of things going on these days.
So, I got to try the shortcode… works awesome!
Excluding the debugging code, I to go forward I would expect the plugin to do the following – gracefully going from the most important to the least important:
– Have the output somehow templatized – meaning, I could specify the markup for each item – an optional wrapper would be also nice, for example I would like to have the output like:
<ul> <li><a href="<?php echo $item_search_link; ?>" class="someclass"><?php echo $search_term; ?></a></li> ... </ul>
– The above would be ideal, but I am sure it would be already good enough if you could provide the option to have links (true/false) and a link class (string), eg
<a href="<?php echo $item_search_link; ?>" class="<?php echo $search_link_class"><?php echo $search_term; ?></a>
From then onwards, the most awesome thing to do would be to somehow show ‘relevant’ results, eg, if you looked for a term, look for terms that look like the one you searched for.
Thank you in advance for putting all this effort not only for the plugin, but also for fulfilling my personal requests.
Hi @scooterlord ,
Thank you for taking the time to test. I will push an update without the debug code to the repo soon ??
Regarding the templating, I already thought about that. There is an undocumented ( yet ) filter in the shortcode output:
apply_filters( 'mwtsa_display_search_stats_shortcode_output', $html, $atts, $data );
This one allows you to make it output whatever HTML you want.
The filter attributes are as it follows:
$html = the current HTML output of the shortcode
$atts = the attributes of the shortcode
$data = returns an array with 2 keys:Array ( [most_searched] => Array ( [0] => Array ( [id] => 1 [term] => Test [count] => 18 [results_count] => 0.7222 [last_search_date] => 2020-07-08 11:11:20 ) [1] => Array ( [id] => 2 [term] => moth [count] => 17 [results_count] => 0.8824 [last_search_date] => 2020-11-07 15:39:02 ) [user_searches] => Array ( [0] => Array ( [id] => 2 [term] => moth [count] => 5 [results_count] => 0.6000 [last_search_date] => 2020-11-07 15:39:02 ) [1] => Array ( [id] => 4 [term] => terrace [count] => 2 [results_count] => 0.5000 [last_search_date] => 2020-07-09 10:04:55 ) [2] => Array ( [id] => 5 [term] => hello [count] => 1 [results_count] => 1.0000 [last_search_date] => 2020-11-07 14:34:48 ) ) )
You can then loop over these results and output whatever HTML you want based on those results.
Please let me know if that makes sense. I will also add the info about this filter to the documentation.
Regarding the ‘relevant’ searches thing, I will think about that and maybe setup a new shortcode in a future version that would pull relevant/similar search strings.
I really enjoy doing this and seeing my plugin in use on so many websites ??
Hello again @cornelraiu-1.
Yes, it surely makes sense, I will try to test it sometime later today or tomorrow and report back. So, since this is already implemented, then clean the debugging outcome and head on for release! ??
I can appreciate the enjoyment of having something you made used by a lot of people! Keep it up!
@scooterlord I just pushed another commit to the GitHub repo for you to check
@scooterlord Great! I will finish documenting the new filter and make some adjustments to the plugin strings ( to fully prepare it for translation ) because others requested that and then I will release it.
Thanks again for helping me test this!
Hello @scooterlord ,
Thank you again for helping me with testing the shortcode!
I really appreciate it!The update has just been released. Let me know if you have any other ideas ??
Have a great weekend!
CornelHello @cornelraiu-1 !
Sorry it took me so long to respond, awesome work!
Here is a link with how it ended up looking:
Only thing – I really think you should document the filter and how to use it, I found my way through but it would be a waste if people didn’t know how to use it!
Really, I am looking forward for your future posts and updates! And (fingers crossed) if you find a way to extend it using the similar searches would be awesome!
- The topic ‘Are there any functions we can use on the front-end?’ is closed to new replies.