...
The callback function receives an object with the following content:
Code Block | ||
---|---|---|
| ||
{ terms totalHits: termsresults, results page: resultspage, page q: pageterms, scope : scope, options:options }referrer: document.referrer } |
The callback receives too the parameter lang, user, session and the other params sent in options.
NOTE: The values for scope and options parameters will be provided by the EmpathyBroker Team.
...
Code Block | ||
---|---|---|
| ||
/** * This example suppose that the provided scope is 'testscope' and the parameterparameters to be included in the options parameter is the lang parameter with value 'enare lang:'en', * scope:'desktop', user:'8212e2d6-fcbd-4879-9878-b06299ee785e', session: '3087bd26-2e69-4e84-84c3-e130e06e4888' **/ var options = { lang:'en', scope:'desktop', user:'8212e2d6-fcbd-4879-9878-b06299ee785e', session: '3087bd26-2e69-4e84-84c3-e130e06e4888' } empathyTAG.trackQuery('test', 10, 1, 'testscope',{lang:'en'} options,function(responseData){ alert('test'); }); |
...
Code Block | ||
---|---|---|
| ||
/** * This example suppose that the provided scope is 'testscope' and the parameterparameters to be included in the options parameter is the lang parameter with value 'enare lang:'en', * scope:'desktop', user:'8212e2d6-fcbd-4879-9878-b06299ee785e', session: '3087bd26-2e69-4e84-84c3-e130e06e4888' **/ var options = { lang:'en', scope:'desktop', user:'8212e2d6-fcbd-4879-9878-b06299ee785e', session: '3087bd26-2e69-4e84-84c3-e130e06e4888' } empathyTAG.trackQuery('test', 10, 1, 'testscope',{lang:'en'} options); |
Best practices
In most of the cases, you should implement one of these solutions to prevent receiving partial queries:
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 language js 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',{lang:'en'}, 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 language js //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',{lang:'en'},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 language js /** * 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'});
...