I need to setup Average search result count in Internal search for a website.
I created a URL variable called search_term to catch the search term and custom JS variable called resultCount to catch the search result count,
Custom JS variable as follows:
function getTotalResults() {
var totalResultsElement = document.querySelector('.total-results');
var totalResultsValue = parseInt(totalResultsElement.textContent);
if (isNaN(totalResultsValue)) {
return 0;
} else {
console.log(totalResultsValue); // Output: 2090
return totalResultsValue;
}
}`
But the value of this resultCount variable does not reflect within following function I created as a tag.
_paq.push([‘trackSiteSearch’,{{ search_term }},‘’,{{ resultCount}});
I’m using page view trigger for this tag. what is the reason for this and how can I solve this.
Thanks
I tried by changing the trigger type and it does not work.