Google Analytics & this.selectedIndex: la información no aparece

I'm trying to track a onChange action on a select list. I need to return a selectedIndex, seams not working.

Aquí está mi código:

<select name="triOrdre" id="triOrdre" 
    onchange="_gaq.push(['_trackEvent','Outils','Trier',this.selectedIndex]);">
    <option value="myURL0">Option0</option>
    <option value="myURL1">Option1</option>
    <option value="myURL2">Option2</option>
    <option value="myURL3">Option3</option>                  
    <option value="myURL4">Option4</option>
</select>

The information I need is 0, 1, 2, 3 or 4, regarding to the selectedIndex. If I put this.value, I get the selectedValue (so myURL0, 2, ...). But nothing is working with selectedIndex.

BUT: If I try on Chrome with the GA debug pluggin, the pluggin see the trackevent with the expected values. Ex: ['_trackEvent','Outils','Trier',1] but nothing appear in firebug or HTTPFox pluggin.

Thanks reading, and thanks for you future help.

Jim

preguntado el 31 de julio de 12 a las 13:07

Is that your real code? You are missing the opening quote on Outils'. You ought to be seeing console errors about that... -

No it's not. There is no missing quotes in my real code. I edited the post. -

2 Respuestas

Different browsers handle script/html syntax errors differently. As Michael suggested in your comments, try closing your single quote appropriately on your Event Category.

onchange="_gaq.push(['_trackEvent', 'Outils', 'Trier', this.selectedIndex]);"

Fixing this will help you find any other problems if they exist as you will get more consistent debugger results.

ACTUALIZACIÓN

It could be how your onchange event is handling this.selectedIndex. You could try putting that code in a separate function and using console.debug(this.selectedIndex) to make sure its getting the expected value.

onchange="trackEvent(this)"

Entonces...

function trackEvent(selectBox) {

 var selectIndex = selectBox.selectedIndex;
 console.debug(selectIndex);

 _gaq.push(['_trackEvent', 'Outils', 'Trier', selectIndex ]);

}

This may help you debug the problem. One other thing that may help is to ensure that if the selected index is the GA Value you are trying to track, make sure its an integer and not a string.

Respondido 31 Jul 12, 14:07

Sorry, there is no missing quote in the real code. It's a copy/past error while writing the question. - Dekx

this.selectedIndex where giving the correct value. It was not the issue. Check my answer for more details. But thanks for your help. - Dekx

Finaly, I got the answer.

this.selectedIndex is an Integer, and the GA API seams expect only sting values.

So I need to convert the Int value into String like that:

_gaq.push(['_trackEvent','Outils','Trier',this.selectedIndex.toString()]);

Gracias por tu ayuda.

Respondido 31 Jul 12, 15:07

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.