Docs

Setting up the plugin, reading the statistics, and the details behind what gets recorded.

Getting started

Install Search Analytics for WP from Plugins → Add New in your WordPress admin, or download it from WordPress.org. Recording starts as soon as you activate it. There’s no account to create and no API key.

Run a search on your site, then open Search Analytics in the admin menu to see it.

One setting is worth changing on day one: keep your own searches out, so your tests don’t count. Go to Search Analytics → Settings and check your role under “Ignore search queries for these user roles”. See Keeping your own searches out for the rest.

The plugin needs WordPress 4.7 or later and PHP 5.6 or later. The blocks need WordPress 5.6.

What gets recorded

The plugin records searches that load your site’s search results page, the ?s= address. That covers the standard WordPress search, the search boxes most themes add, and the WooCommerce product search. wpForo forum searches are recorded too.

Each search is saved with the term, the date and time, and the number of results it found.

Some searches are skipped on purpose:

  • Searches from the roles and IP addresses you ignore, terms shorter than the minimum length, and terms that contain a blocked word.
  • The same search repeated by the same visitor within the interval you set.
  • Searches made by bots, and junk searches. See Bots and junk searches.
  • Opening page 2 of the results, or the search feed. Neither is a new search.
  • Following a term’s link in the Popular Searches or Latest Searches block, unless you turned on counting those clicks.

WooCommerce

WooCommerce’s product search box opens the normal search results page, so each product search is recorded with the number of products it found, like a blog search. A live search that only shows results in a dropdown needs one line of code, covered in the next section.

A live search asks for results every few keystrokes. If it sends its requests to an address the plugin already records, such as FiboSearch, or a custom live search with its parameter listed in the settings, those requests are merged: requests from the same visitor that follow each other within 20 seconds count as one search. Typing “sofa” records “sofa” and not “sof” as well, and pressing Enter right after doesn’t count it a second time.

A live search that shows results without loading the search results page, and without a parameter you can add in the settings, has to record its searches itself. Call this from the code that handles it:

if ( function_exists( 'mwtsa_process_search_term' ) ) {
	mwtsa_process_search_term( $term, $result_count );
}

mwtsa_process_search_term() applies the same settings as a normal search and the same merging, so it can be called on every request the live search makes. It returns whether the search was saved.

Custom search parameters

If your search form uses its own URL parameter instead of s, such as Toolset’s wpv_post_search, add it under “Add custom search parameters for recording the searches”. REST API requests that use one of these parameters are recorded too.

Finding searches with no results

On the Search Analytics page, click Only Without Results and pick a time range. Then sort by No. of Searches to put the most common dead ends first.

Each one is something visitors expected to find. Sometimes the page is missing. Often it exists and uses different words: visitors type “opening hours” while the page says “business hours”. Either way, the list tells you what to write or rename next.

Keeping your own searches out

In Search Analytics → Settings:

  • Ignore search queries for these user roles. Check Administrator, Editor or any role whose searches shouldn’t count.
  • Ignore search queries for the above user roles even after the user has logged out. This sets a cookie in the browser when someone with one of those roles logs in, so their searches stay out after they log out.
  • Exclude searches made from the following IP addresses. Useful for an office. The settings page shows your current IP address.
  • Exclude doubled search for same user if interval is lower than (minutes). Skips the same search repeated by the same visitor. This sets a cookie in the visitor’s browser.
  • Only record searches with at least the number of characters.
  • Exclude search in case it contains certain substring. A comma-separated list of words to block.

If your own role is ignored, test in a private browser window.

Bots and junk searches

Searches made by search engine crawlers, AI assistants, link previews, monitoring tools and scripts are skipped. They are recognized by their user agent, so a bot that presents itself as a normal browser still gets through. If one keeps coming back, add its IP address to the excluded ones.

Searches that contain a link or HTML, or that are longer than 100 characters, are skipped too, because they are almost always spam or probes. Both checks are on by default, under “Ignore searches made by bots” and “Ignore junk searches”. Turn the second one off if your visitors search for web addresses or HTML tags, as on a web development site.

Reading the statistics

The Search Statistics page lists every term with its number of searches, the average number of results and the last search date. From there:

  • Time filters go from the last 24 hours to all time, or any date range you pick.
  • Results filters show all searches, only those with results, or only those without.
  • Group By lists terms, or every single search in order with “No Group”.
  • Click a term to see its history by date or by hour.

The statistics page also has a chart that compares the period with the one before it, and the When people search chart, which shows the searches of the last 4 weeks by day of the week and time of day, with the busiest day and time.

Dates are shown as UTC by default. Uncheck “Show results dates as UTC” in the settings to use your site’s timezone.

Exporting to CSV

The Export Data button downloads what you’re looking at as a CSV file, with the same time range, filters and grouping.

The dashboard widget

The Search Analytics widget on the WordPress dashboard shows the last 7 days against the 7 days before: the number of searches, searches with no results and unique terms, the last search, a bar per day, trending terms, top searches and top searches with no results. It also shows the busiest day and time of the last 4 weeks.

Showing searches on your site

Add the Popular Searches or Latest Searches block to a page, a post or a widget area. The editor shows a live preview, and a block with nothing to list stays hidden on your site.

The same lists are available as shortcodes:

  • [mwtsa_display_search_stats] lists the most searched terms, plus the visitor’s own recent searches if they’re logged in and “Save Search By User” is on.
  • [mwtsa_display_latest_searches] lists the most recent search terms.

Both hide terms with no results by default. The main options:

Option What it does
unit, amount The period: unit is day, week or month, amount how many of them. The default is one week.
count How many terms the latest searches list shows. most_searched_count and user_searches_count do the same for the other shortcode.
link_terms="true" Links each term to its search results. The blocks do this unless you turn it off.
count_link_clicks="true" Records searches opened from those links. Off by default, so the listed terms don’t keep themselves on top.
show_label="false" Leaves out the text above the list.

For example, [mwtsa_display_latest_searches unit="month" count="5"] shows the five most recent terms from the past month.

Paste one of these shortcodes into the block editor and it becomes the matching block with the same settings. A Shortcode block can be turned into one too. With classic widgets, put the shortcode in a Text widget.

Two settings add more to each search. Both are off by default.

  • Save Search Country adds the visitor’s country. To find it, the visitor’s IP address is sent to the service picked under “Country lookup service”: ip-api.com, the default, which uses HTTP and only allows non-commercial use, or ip2c.org, which uses HTTPS and only supports IPv4. Each IP address is looked up at most once a day, private and reserved addresses are never sent, and a lookup gives up after 2 seconds.
  • Save Search By User links logged-in users’ searches to their accounts.

Privacy and stored data

Here is everything the plugin keeps and shares, so you can check it against the GDPR or your local rules:

  • Each search is saved with the term, the date and time, and the number of results. IP addresses are not saved.
  • Search terms are whatever visitors type, which now and then includes a name or an email address. You can delete any term from the statistics page.
  • With “Save Search Country” on, the visitor’s IP address is sent to the lookup service, and the country is cached for a day under a hash of the IP address.
  • With “Save Search By User” on, logged-in users’ searches are linked to their accounts.
  • A cookie is only set if you use the repeat-search interval or the “even after the user has logged out” option.
  • To merge the requests of a live search, the plugin keeps a note of the last term under a hash of the visitor’s IP address and browser. The note expires after one minute, and nothing about the visitor is saved with the search.

Nothing is sent anywhere unless you turn on the country lookup.

Performance

Only searches do any work. Each search is saved with a few small database queries. Other pages only check whether they are a search, and the plugin loads no scripts or styles on the front end.

The history table grows with every search and nothing is deleted automatically. To trim it, use “Delete data older than” in the Erase History section of the settings.

Removing data

  • Delete data older than removes the searches older than the number of days you pick.
  • Erase All Data removes every search.
  • Deactivating the plugin keeps your data. To remove it when you uninstall, check “Delete all search data and settings when the plugin is deleted”, then delete the plugin from the Plugins screen. On multisite, each site’s data is only removed if that site has the setting checked.

Who can see the statistics

“Only display the statistics page for these user roles” and “Only display the settings page for these user roles” decide who can view the statistics and who can change the settings.

For developers

To record searches from your own code, call mwtsa_process_search_term( $term, $result_count ). See Live search.

Filters:

  • mwtsa_do_not_save_search, mwtsa_exclude_term, mwtsa_extra_exclude_conditions: skip searches.
  • mwtsa_is_bot, mwtsa_is_junk_term: change the bot and junk checks.
  • mwtsa_result_count: change the number of results saved.
  • mwtsa_live_search_merge_seconds: the live search merge window, 20 seconds by default. 0 turns merging off.
  • mwtsa_export_filename: the CSV file name.
  • mwtsa_term_search_link: the link of each term in the blocks and shortcodes.
  • Filters on the shortcode output, which apply to the blocks too.

Actions: mwtsa_after_term_save, mwtsa_after_history_term_save.

The code is on GitHub.

Getting help

Questions and feature requests go to the support forum or GitHub issues.

Report security issues through the Patchstack Vulnerability Disclosure Program, not in public.