Site search usage on your WordPress site
Use the following data layer variables to access data about the term the visitor was searching for on your site. All three are added on search results pages only.
The three variables come from a single option, called Search data, in the Search data group of the Page variables section on the plugin settings screen. The option is switched off by default, so if these variables are missing from your data layer, enable it first.
You do not need these variables to report internal site search in Google Analytics 4. WordPress passes the search term in the s query parameter, and site search in enhanced measurement watches that parameter by default, so Google Analytics records the search on its own. Use the variables below when you need more than that, for example your own trigger, a remarketing audience or a custom parameter on another tag.
This page describes GTM4WP 2.0.0 and newer. Features introduced by that release are marked New in 2.0.0 and are not available in the legacy 1.x versions. Where 1.x behaved differently, the older behavior is marked with a bold GTM4WP 1.x: lead-in.
GTM4WP 1.x: the same option lived in the Basic data tab of the settings screen.
siteSearchTerm
The term the visitor entered, as a string, read from the s query parameter of the current URL. You may want to use this variable to track certain micro conversions or remarketing conditions based on what the visitor was looking for.
siteSearchFrom
The address of the page the search was started from. If your search box sits in a sidebar widget, this variable holds the URL of the page where the visitor entered the search term.
The value comes from the referrer reported by the browser, and it is normalized: the part of the referring URL before the question mark, followed by the query string in URL encoded form when the referring URL had one. The variable holds an empty string when the browser sends no referrer, which is also the case when someone opens a search results URL from a bookmark or types it in. If a visitor arrives at your search results page from another website, the variable holds that external address instead of a page of yours.
siteSearchResults
The number of results, as a number. It counts the results listed on the page currently shown, not the total number of matches, so on a site that lists 10 posts per page a search matching 40 posts reports 10, and the second page of those results reports 10 again.
On a search that matched nothing the value is 0. Use it together with the search term to track empty result pages, so that you can see what information visitors look for and cannot find on your site.
To report the total number of matches, enable the Post count option as well. It adds postCountTotal with the total number of posts the search matched, and postCountOnPage, which holds the same value as siteSearchResults on a search results page.
Sites with full page caching
New in 2.0.0. The Cache-safe data layer option, which has a panel of its own on the settings screen and is marked as experimental, changes the way the first two variables reach Google Tag Manager. Full page caching serves the HTML built for one visitor to everyone else, and the referring page differs from visitor to visitor, so it cannot be written into a cached page.
With the option enabled, the plugin leaves siteSearchTerm and siteSearchFrom out of the HTML and lets the browser work both of them out, from the address of the page and from the referrer. They are pushed into the data layer under the same names as part of the gtm4wp.visitorData event, and no extra request is made for them. Tags that read these two variables have to fire on that custom event instead of the page view.
siteSearchResults is not affected. It is the same for every visitor of a given search results URL, so it stays in the HTML of the page.
Related pages
pagePostType holds search-results on a search results page, even when the search data option and the post type option are switched off, so you can build triggers on it without enabling anything. It is described together with the other content variables on the page and post attributes page. The post count variables are described on the page and post listings page.

