Rich-text Reply

Can I add events in the code editor?

djarsoftware 08-27-14

Can I add events in the code editor?

Hello Everyone,

 

My goal is to add a custom event to a submit button that tracks on the keydown (person hitting the enter button).

 

window.optimizely.push(["trackEvent", "eventName"]);

 

I am wanting to add an event to a button.  Something like this: 

 

$("#mr-field-element-806903675897").on('keydown', function(){ window.alert('Hello!'); });

 

but when I add that code to the code editor and apply it I get this error:

 

Error evaluating variation javascript:
TypeError: $(...).on is not a function

 

I am following the insturction on this page: https://help.optimizely.com/hc/en-us/articles/200039925.

 

Is there something that I am overlooking?  Just let me know.

 

Thanks

 

siherron 08-27-14
 

Re: Can I add events in the code editor?

[ Edited ]

The error you are getting is probably for the "on();" method. Optimizely uses an older version of jQuery (I think it's 1.6.4)

To add the event in the code editor try something like this:

$("#mr-field-element-806903675897").bind('keydown', function(){
window.optimizely.push(["trackEvent", "eventName"]);
window.alert('Hello!');
});



Hope that helps?


Simon Herron
Optimisation Consultant
Level 2

Re: Can I add events in the code editor?

Hello Simon,

Thank you - that did help.

Chad