Overview

Instructions to send queries information using the Javascript Tagging Library.

Step-by-step guide

You can send query data to the dashboard using the trackQuery function.

trackQuery(terms, results, page, scope, options, callback)


Parameters

ParameterDescriptionData TypeMandatory
termsThe query typed by the userStringYes
resultsNumber of results returned by the search engineIntegerYes
pageThe page numberIntegerYes
scopeThis parameter is used for separate analytic data between two or more different scenariosStringNo*
optionsObject that may contain information about filters and other required dataObjectNo
callbackFunction that will be executed after sending dataFunctionNo

*This parameters are not mandatory for the service but necessary for the statistics


The callback function receives an object with the following content:

{
	totalHits: results,
    page: page,
    q: terms,
    scope: scope,
    referrer: document.referrer
}

The callback also receives 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 samples

Normal Usage

Specifying a callback parameter
/**
 * 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'
}

empathyTAG.trackQuery('test', 10, 1, 'testscope', options,function(responseData){
    alert('test');
});
Without a callback (No functions will be executed after tracking the data)
/**
 * 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'
}
empathyTAG.trackQuery('test', 10, 1, 'testscope', options);

Best practices

In most of the cases, you should implement one of these solutions to prevent receiving partial queries:


Related articles