1

I have built this custom search page for use in our customer portal:

enter image description here

I was wondering if there would be a way to track the search terms that are entered. Would like to get an insight for what our customers are searching for. I have no idea if this is feasible or not and don't even know where to start.

Here is code for the form where search term is entered

  <div id="search-box">
   <form name="frmSearch" id="search-form">
      <script type="text/javascript">
       function noenter(e){
            if(window.event){
            key = window.event.keyCode; 
            } else{
            key = e.which; //firefox
            }
            if(key == 13) {
            var ele=document.getElementById("search-button");
            ele.click();
            return false;
            } else{
            return true;
             }
           }
    </script> 
      <input type="text" id="search-text" name="searchText" value="{!portalSearchModel.searchTerm}" onkeypress="return noenter(event);" placeholder="What are you looking for?" />
      <input type="button" id="search-button" name="btnSearch" value="Search" onclick="insertSearchTerm()" />
  </form>
 </div>


<script type='text/javascript'> <!--executes search by passing search term to URL-->
    function insertSearchTerm(){
        var searchTerm = document.getElementById("search-text").value; 
        var url="https://c.na11.visual.force.com/apex/portalcasesearch?s="+searchTerm; 
        window.location = url; 
        return false;
    }                
</script>
1
  • Slick looking form by the way. I like it. Mar 8 '13 at 21:11
3

It all really depends on what your portalcasesearch page does. I don't see why you couldn't create a custom object that you create every time someone searches. I would use an autoincrement field for the name and then a text field for the search term. You could then just create a custom report that groups a record count by that text field to find which search terms get used the most.

3
  • Probably, could have a number field on the object. See in the database if the search term exists and increment it if present else create a new record if not. This would help to handle duplicate search term records while creating records for the object. Mar 9 '13 at 7:49
  • @ShaileshDeshpande that is a really good idea too Mar 9 '13 at 17:32
  • @JesseAltman Thanks for the reply. My apex knowledge is fairly novice and have been trying to figure out how I would go about creating a new record for custom object from apex each time search is executed. Could you provide a very basic example to at least get me in the right direction or point me to a resource that could help me along?
    – samadhi
    Mar 21 '13 at 18:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.