Rich-text Reply

Error: Error evaluating variation javascript: TypeError: undefined is not a func

jyau 10-09-14
Accepted Solution

Error: Error evaluating variation javascript: TypeError: undefined is not a func

I'm attempting to run a test with and without the Geotrust SSL seal in my cart. I attempt to insert it by clicking in a white space area, and Insert HTML. I paste the code below, and then get this error after clicking Done.

 

Error:

Error evaluating variation javascript:
TypeError: undefined is not a function (in function HTMLScriptElement, line 32, col 434)

 

 

Javascript, direct from the Geotrust seal code generator (https://www.geotrust.com/support/seal/agreement/installation-instructions/):

 

<table width="135" border="0" cellpadding="2" cellspacing="0" title="Click to Verify - This site chose GeoTrust SSL for secure e-commerce and confidential communications.">
<tr>
<td width="135" align="center" valign="top"><script type="text/javascript" src="https://seal.geotrust.com/getgeotrustsslseal?host_name=www.obscured.com&amp;size=M&amp;lang=en"></sc... />
<a href="http://www.geotrust.com/ssl/" target="_blank" style="color:#000000; text-decoration:none; font:bold 7px verdana,sans-serif; letter-spacing:.5px; text-align:center; margin:0px; padding:0px;"></a></td>
</tr>
</table>

 

What's going on here?

Level 2

Kathryn 10-10-14
 

Re: Error: Error evaluating variation javascript: TypeError: undefined is not a func

Hi JYAU,

This error most commonly pops up when you reference a function or variation in your code which is not yet defined when the page is loaded into the Optimizely editor. Alternatively, this error can appear if you reference a jQuery function which is not included in the version of jQuery included in the Optimizely snippet.

Saying that, I couldn't see anything in the code you are adding which would cause this to occur. I tried pasting the same code you provided into a sample experiment on my own account and did not see the error. If you could provide the experiment ID, though, I can take a closer look and let you know my findings.

Best wishes,
Kathryn
Optimizely
jyau 10-10-14
 

Re: Error: Error evaluating variation javascript&colon; TypeError: undefined is not a func

Sure thing. Experiment ID: 2099790021

 

Look forward to seeing what you find.

Level 2
jyau 10-10-14
 

Re: Error: Error evaluating variation javascript: TypeError: undefined is not a func

It's also worth noting that this is the first experiment I've deployed with raw HTML code. I wasn't clear on whether I was supposed to replace the placeholder .. within the div or replace all of the code including the divs. Based on the javascript it's generating ,it seems like the latter. Even when I try doing that, I still get this error, though.
Level 2
jyau 10-10-14
 

Re: Error: Error evaluating variation javascript: TypeError: undefined is not a func

Here is a second attempt replacing all of the placeholder text in the dialog:
Experiment #2102820050
Level 2
Kathryn 10-13-14
 

Re: Error: Error evaluating variation javascript&colon; TypeError: undefined is not a func

Hi there!

 

I've taken a look at the experiment for you and have done a bit of research into why you're getting the error. The issue is the way you are adding the <script> element. Script elements need to be appended to the body or the head of a document rather than inside a div or similar element to prevent cross-scripting attacks. If you remove that portion of the code, you'll see that everything works a treat.

 

What I'd recommend is the following:

 

1. Remove the script element from the code snippet
2. Use jQuery's append() function to append the script to the head of the document, like so:

 

$("head").append( "<script>My script</script>");

 

You can place the above code either in the Edit Code field of your variation or else in the Global Javascript of the experiment. If you choose to place the script in the Global JS, the code will be executed as soon as Optimizely runs, which may get around any potential timing issues you might have.

 

You can test how everything in your experiment will look live by following the instructions in our support article on setting a test cookie. If things still aren't looking quite right after trying the above instructions, feel free to get back to me.

 

Hope this helps!

Kathryn

Optimizely
jyau 10-17-14
 

Re: Error: Error evaluating variation javascript&colon; TypeError: undefined is not a func

Unfortunately, this didn't work. I got the same error even after following your instructions and placing it in the global field. We ended up working around the issue by putting it into production, and then using Optimizely to remove the element from the page. 

Level 2