By default WordPress has a search built in. Any search performed on a website ends with a ?s= query parameter. In your address bar one can see something like this:
![]()
It’s really useful to keep track of search using Google Analytics. In order to do so, go to Admin (cogwheel bottom left), View Settings -> scroll to the bottom.
Enable Site search Tracking and put an s for the query parameter. Check the box Strip query parameters out of the URL. Follow this screenshot for guidance:

Reference:
https://www.monsterinsights.com/how-to-set-up-site-search-tracking-in-wordpress-step-by-step/