On same Webpage, Custom Variables gets appended always to the previous ones

(Sulabh) #1

Q. How can we remove index information of previous tracking attempt’s
indexed information, from cvar,scope=‘page’ variable ?

Scenario :

I am working currently on project that includes Liferay Portal integrated
with Springs and hibernate.

There are two sections on single page

  1. Search section
  2. Browse section

Search section has one integrated button of Download. In download section,
we have applied tracking for few things by using ‘setCustomVariable’ of
piwik.js, and output of call to piwik.php comes like

cvar output(through HTTPFox) :

{“1”:[“Initiate Download”,“155231”],“3”:[“source”,“portal”]}

Now when we apply tracking through ‘setCustomVariable’ in Browse
section(on same page), we get

“1”:[“Initiate Download”,“155231”]…

appended to our new piwik.php call. Comes like :


Expected Output :


In next tracking attempt(Browse on same page where search has been done).


function trackCustVar(index,name,val,type,title,callback)
if(typeof(piwikTrackingEnabled) != “undefined” && piwikTrackingEnabled==“true”) {
_paq.push([‘deleteCustomVariable’, 1, “page”]); // added this but getting blank strings for index 1.
if(typeof(userId) != “undefined” && typeof(ssoToken) != “undefined” && userId != “” && ssoToken !="") {

Search section/button’s java-script code :

if (filesToPrint.length == 0){
} else {
$("#btn_save").removeClass(‘hide’).on(‘click’, function(){

					var downloadlist = '';
						downloadlist +=$(v).attr("data-content-id")+',';
					downloadlist = downloadlist.substr(0,downloadlist.length-1);
					       trackCustVar(1, 'Initiate Download', downloadlist , 'page', 'Document Tab');



cvar output(through HTTPFox) :

{“1”:[“Initiate Download”,“155231”],“3”:[“source”,“portal”]}

Browse section/button’s js code :

        $(".dropdown-menu-unstyled li a.listItemLabel").on("click", function() {
            var $this = $(this),
                assetid = [],
                url = '',
                data_column = parseInt($this.parents('.filter-col-browse').data('column')),
                perspective = $this.data('perspective');
            switch (data_column){
            case 1: assetid.push($this.data('conceptid'));
            		      trackCustVar (9, $this.data('perspective') , assetid[0] , 'page', 'Portal Filters');
                        url = 'some_URL';
            case 2: assetid.push($this.data('conceptid'));
                    assetid.push($this.parents('.filter-col-browse').siblings('div[data-column="1"]').find('li.active a:first-child').data('conceptid'));
                                 trackCustVar (9, $this.data('perspective') , assetid[1]  +';' + assetid[0] , 'page', 'Portal Filters');
                    if(perspective == "COUNTRY") {
                        url = 'some_URL';
                    } else {
                        url = 'some_URL';
            window.location = url;

cvar’s output :


 I want to remove ("1":["Initiate Download","155231"],"3":["source","portal"],) part from last output. It gets appended by default. and when we remove custom variable, the value of index still gets displayed with blank strings like ({"1":["",""],"3":["source","portal"],"9":["Initiate Download,551996","37"]}).