Versions Compared

Key

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

Overview

Instructions to send browse information using the Javascript Tagging Library.

Step-by-step guide

Browsing data can be sent to Empathy using the trackBrowseCategory function including the parameters detailed below. This function should be executed each time a product category page is loaded.

Code Block
languagejs
trackBrowseCategory( categoryid, results, page, scope, options, callback)


Parameters

ParameterDescriptionData TypeMandatory
categoryidThe ID of the category the Product Category Page loadedStringYes
resultsNumber of results displayed in the categoryIntegerYes
pageThe page numberIntegerYesscopeThis parameter is used for separate analytic data between two or more different scenariosStringNo*
optionsObject that may contain information about filters and other required data like session and userIDObjectNo*
callbackFunction that will be executed after sending dataFunctionNo

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

Options

The options object should contains additional parameters not passed as parameters but also necessary such as language. Also section, userID and sessionID that must be included if they're available or requiredin function call:

Code Block
languagejs
{    
	lang: LANGUAGUE,
	scope: SCOPE,
	section: SECTION,
	user: USER_ID,
	session: SESSION_ID
}


Parameter
Description
Data Type
Mandatory
langLanguage identifier (es, en...)StringNo
scopeScope identifier (desktop, mobile, android app, iOS app...)StringNo
sectionSection value if it is required for the projectStringNo
userUserID used for user based servicesString*No
sessionSessionID used for user based servicesStringNo

*UserID should be an UUID identifier.

NOTE: The values for scope and lang will be provided by the Empathy Team.


The callback function receives will receive an object with the following contentcontents. Also params sent in options will be included:

Code Block
languagejs
{
	categoryId: categoryid,
    totalHits: results,
    page: page,
    scope: scope,
    referrer: document.referrer
}

...

NOTE: The values for scope and options parameters will be provided by the Empathy Team.

Code samples

Normal Usage

Specifying a callback parameter
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' . UserID and SessionID are also included.
 **/

var options = {
    lang:'en',
	session: 'q1w2e3r4t5y6',
	scope: 'testscope',
	user: 'u1s2e3r',
}

empathyTAG.trackBrowseCategory('myCatID', 48, 1, 'testscope', options,function(responseData){
    alert('test');
});

...

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' . UserID and SessionID are also included.
 **/

var options = {
    lang:'en',
	session: 'q1w2e3r4t5y6',
	scope: 'testscope',
	user: 'u1s2e3r',
}

empathyTAG.trackBrowseCategory('myCatID', 48, 1, 'testscope', 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
    languagejs
    var _timeoutID;
    var options = {
        	lang:'en',
    	session: 'q1w2e3r4t5y6',
    	scope: 'testscope',
    	user: 'u1s2e3r',
    }
    window.clearTimeout(_timeoutID);
    _timeoutID = window.setTimeout(function(){
    	empathyTAG.trackBrowseCategory('myCatID', 48, 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',
    	session: 'q1w2e3r4t5y6',
    	scope: 'testscope',
    	user: 'u1s2e3r',
    }
    if (userQuery.length > 3){
        window.clearTimeout(_timeoutID);
        _timeoutID = window.setTimeout(function(){
        empathyTAG.trackBrowseCategory('myCatID', 48, 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',
    	session: 'q1w2e3r4t5y6',
    	scope: 'testscope',
    	user: 'u1s2e3r',
    }
    empathyTAG.trackBrowseCategory('myCatID', 48, 1, 'testscope', options);


  • Blank queries: Do not send a category 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...")

...