This is how I am using a Search Results page to record individual Users Search Queries in a list. Each Search Query is displayed as how the user typed them in.
What I’ll explain is how we can grab the URL from the Search Results and strip out the unnecessary code to display only the User’s Search Query.
This Search Result URL:
Will be converted to display only what the user has typed in the Search Box, which in this example, is: “pdf“.
Each time a user types in a Search, their query is recorded with their name, date and keywords typed.
Once you have this configured it and you can see the users data added to the HitCounter List , we can now modify the HitCounterAndStarRatingForSharePoint.js file to include the Users keywords entered.
1: First create a new column within the HitCounter list call it UserKeywords. Add this column to your default view.
2: Edit the HitCounterAndStarRatingForSharePoint.js and scroll down to about line 218: //Add item. Within that block of code you will see the column variables, make a new line under ReferringURL:refURL, and type in the new column name which is attached to the variable as such:
3: Then under the following code at about Line: 152
// Get url and referrer
refURL = document.referrer;
Add the following lines of code:
searchURL = window.location.search; //returns string ?k=Users%20Search%20String modURL = searchURL.substring(3); //removes characters ?k= from string decodedURL = decodeURIComponent(modURL); //decode URL to translate encoded characters from string searchQuery = decodedURL.split('&'); //removes characters all after &
4: Now you can test the Search Results page by entering in a Search Query and then checking the HitCounter List.
The UserKeywords column will now display the Search Keywords exactly how they are typed by the user.
Any questions, please comment below, thanks for reading.