Rich-text Reply

Search submissions based on hitting the “enter” key in Optimizely

snehav27 03-17-16

Search submissions based on hitting the “enter” key in Optimizely

How can I create custom event in optimizely without doing code changes in my code.

Basically I want record search submissions based on hitting the “enter” key in a search text field.

 

I dnt want to do changes in my code.

 

I have gone through it but it says need to do code changes in my website to add script so that tracking can be enable

https://help.optimizely.com/hc/en-us/articles/200039925

 

How can I record search submissions based on hitting the “enter” key in a search text field without code change

 

Level 2

JDahlinANF 03-17-16
 

Re: Search submissions based on hitting the “enter” key in Optimizely

Have you tried adding a listener?
http://stackoverflow.com/questions/7060750/detect-the-enter-key-in-a-text-input-field

This can be added to your variation's code and where the function says "// Do Something" you would call a trigger which is something that can be a goal that Optimizely listens for as described here:
https://help.optimizely.com/hc/en-us/articles/200039925
snehav27 03-17-16
 

Re: Search submissions based on hitting the “enter” key in Optimizely

[ Edited ]

tried :
since i have moved the text box optimizely has created two textbox with two same elements :
Note: the following changes are declared in custom javascript on page change and page load.
I have tried following still was not able to print in the console.
$(".search-form").submit(function(ev) {
console.log('I am here');
});
$("input[name=keywords]").keyup(function (e) {
console.log('I am here too');
if (e.keyCode == 13) {
console.log('I am here');
}
});

on $('input[name=keywords]') browser show two input elements. I assume since I moved the text box to some other place in the page I find two physical copies in the console i.e two input searcg box.

Is there something wrong in what I am doing ?

Level 2
JDahlinANF 03-17-16
 

Re: Search submissions based on hitting the “enter” key in Optimizely

@snehav27:

The code you are using works fine in the console, so that is not the issue.  The issue is that "console" does not exist within the scope of an experiment's variation code.  This means that when the experiment tries to evaluate what it is supposed to do, it is trying to act on an undefined item, so nothing happens.  You will need to use "window.console" instead, like this:

 

$("input[name=keywords]").keyup(function (e) {
  window.console.log('key up');
  if (e.keyCode == 13) {
    window.console.log('key up was the [Enter] key');
  }
});

Note: the above is presuming that you are including jQuery on your page via Optimizely and that the version you are loading supports the "keyup" method.  If you are relying on your own site's jQuery, you will need to add a "window." to the first line of this block of code.

snehav27 03-17-16
 

Re: Search submissions based on hitting the “enter” key in Optimizely

[ Edited ]

oops I was placing the javascript in a wrong now I am able to detect the search key word. Will try setting goals and check if it works 

i.e I have checked if search box exits in the dom then applying this property.

No changes in my website only in optimizely

Level 2