Rich-text Reply

How do I call 'shared code' from a variation?

marcsmits 11-02-17

How do I call 'shared code' from a variation?

Dear all,

My client tends to make changes to copy, images etc. I would like to keep code and data on one location.

Please consider the following shared code in an experiment:

products = ['Audi', 'BMW', 'Toyota'];

function changeProduct(thisProduct) {
    $('.some-element').html(products[thisProduct]);
}

 

Now the call from the variation code:

 

changeProduct(thisProduct);

 

How do I make this work?

 

JasonDahlin 11-02-17
 

Re: How do I call 'shared code' from a variation?

Does it not work?
I have created functions in Project Level Code and in Experiment Level Code and called them from within a variation just fine.
--Jason Dahlin
Analytics and Testing Guru Smiley Happy


Experimentation Hero
dkim 02-21-19
 

Re: How do I call 'shared code' from a variation?

[ Edited ]

I was having a similar issue calling a function from a variation, when that function lived within the "Shared Code".

 

This was solved by binding the function to the window object.

 

Ex: 

Shared Code:

window.sayHello = function() {

alert("Hello User!");
}

 

Variation Code Editor:

sayHello();

Level 1