Tracking-code, old website with 7000-pages


I have an ‘old school’ application that was set up in 1999,it consists of roughly 7000 html-pages. - where the search-input-field is.
searching for instance ‘tussilago’ gives a search-page: xx
and the visitor probalby clicks the first link andnd ends up on the tussfar.html-page (the species-page):

I have only added tracking-code to a Single-Page-application before.

How should I think when it comes to this site:
Should I put a tracking-code on the first page and I will get information about which search-word the user has written - and should I also put a tracking-code on every species-page to see if the user has clicked one of the many links on the page ? - adding the code with some linux-scripting ?

best, i