Sunday 15 May 2011

google analytics - javascript variable referencing -



google analytics - javascript variable referencing -

so trying set metric universal analytics. here javascript using:

function setcustommetric(index, value){ if(typeof index === "number" && index > 0 && typeof value === "number"){ var metricindex = 'metric' + index; ga('set', {metricindex: value}); } }

when send function 1 , 5 respective parameters homecoming problem is sending ga("set", {metricindex: 5}); rather ga("set", {metric1: 5}); utilize switch statement 20 possible indexes rather not have hard code of possibilities. ideas?

try this:

var metricindex = 'metric' + index; var myobject={}; myobject[metricindex]=value; ga('set', myobject);

javascript google-analytics

No comments:

Post a Comment