So I am trying to set a metric for Universal Analytics. Here is the JavaScript that I am using:
function setCustomMetric(index, value){
if(typeof index === "number" && index > 0 && typeof value === "number"){
var metricIndex = 'metric' + index;
ga('set', {metricIndex: value});
}
}
When I send the function 1 and 5 as the respective parameters I get this return My problem is that it is sending ga("set", {metricIndex: 5}); rather than ga("set", {metric1: 5}); I could use a switch statement for the 20 possible indexes but I would rather not have to hard code all of the possibilities. Any ideas?