Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Specifying a callback parameter
Code Block
languagejs
/**
 * This example suppose that the provided scope is 'testscope' and the parametersparameter to be included in the options parameter is arethe lang:'en',
 * scope:'desktop', user:'8212e2d6-fcbd-4879-9878-b06299ee785e', session: '3087bd26-2e69-4e84-84c3-e130e06e4888' parameter with value 'en' 
 **/

var options = {
    lang:'en',
    scope:'desktop',
    user:'8212e2d6-fcbd-4879-9878-b06299ee785e',
    session: '3087bd26-2e69-4e84-84c3-e130e06e4888'
}


empathyTAG.trackQuery('test', 10, 1, 'testscope', options,function(responseData){
    alert('test');
});
Without a callback (No functions will be executed after tracking the data)
Code Block
languagejs
/**
 * This example suppose that the provided scope is 'testscope' and the parametersparameter to be included in the options parameter areis the lang:'en',
 * scope:'desktop', user:'8212e2d6-fcbd-4879-9878-b06299ee785e', session: '3087bd26-2e69-4e84-84c3-e130e06e4888' parameter with value 'en' 
 **/

var options = {
    lang:'en',
    scope:'desktop',
   
user:'8212e2d6-fcbd-4879-9878-b06299ee785e',
    session: '3087bd26-2e69-4e84-84c3-e130e06e4888'
}
empathyTAG.trackQuery('test', 10, 1, 'testscope', options);

...

  • Prevent partial queries applying a delay before sending the trackQuery information, the delay time in the following example will be 2000 ms (2 seconds).

    Code Block
    languagejs
    var _timeoutID;
    var options = {
    	lang:'en',
        scope:'desktop',
        user:'8212e2d6-fcbd-4879-9878-b06299ee785e',
        session:
    '3087bd26-2e69-4e84-84c3-e130e06e4888'
    }
    window.clearTimeout(_timeoutID);
    _timeoutID = window.setTimeout(function(){
    	empathyTAG.trackQuery('test', 10, 1, 'testscope', options, function(responseData){
        	alert('test');
    	});
    },2000);


  • Prevent partial queries filtering the query length to be considered as valid. For this example, it will be used 3 characters as minimal length.

    Code Block
    languagejs
    //This variable should be filled with the query typed by the user
    var userQuery = 'test';
    var _timeoutID;
    var options = {
    	lang:'en',
        scope:'desktop',
        user:'8212e2d6-fcbd-4879-9878-b06299ee785e',
        session: '3087bd26-2e69-4e84-84c3-e130e06e4888'
    }
    if (userQuery.length > 3){
        window.clearTimeout(_timeoutID);
        _timeoutID = window.setTimeout(function(){
        empathyTAG.trackQuery('test', 10, 1, 'testscope',options, function(responseData){
                    alert('test');
                });
    	},2000);
    }    


  • Remember send queries when search engine returns 0 results. It's very important for future actions in search engine.

    Code Block
    languagejs
     /**
     * This example suppose that the provided scope is 'testscope' and the parameter to be included in the options parameter is the lang
     * parameter with value 'en' 
     **/
    
    
    var options = {
    	lang:'en',
        scope:'desktop',
        user:'8212e2d6-fcbd-4879-9878-b06299ee785e',
        session: '3087bd26-2e69-4e84-84c3-e130e06e4888'
    }
    
    empathyTAG.trackQuery('test', 10, 0, 'testscope',{lang:'en'}options);


  • Blank queries: Do not send a query without characters. Usually when users click in search button without write nothing in search box.

    • In this case be careful to not send the placeholder text (i.e. "Search...")

...