Rich-text Reply

I'm using Javascript to split test my cart button across all product detail pages help!

kchilites 03-17-16

I'm using Javascript to split test my cart button across all product detail pages help!

Hi, 

 

I, like many others, am simply trying to split test the color on my "Add to Cart" button across all my product detail pages. I've tried to use URL targeting (Substring match) to apply the change (button color) to all my product details pages. I don't know if its how our urls are structured or differences in the HTML on each of the pages but it didn't work.

 

Next I had my developers write a script for me, see below:

<script type="text/javascript">
jQuery(document).ready(function(){
    var btn = '<img src="<?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_SKIN)."frontend/kchilites/default/images/btns/yellowaddtocartbutton.png";?>"  height="34" label="add to cart button"/>'
    jQuery(".add-to-cart .btn-cart").html(btn);
});
</script>

The thought was to insert this Javascript into the Variation #1 to override all the "Add to Cart" buttons on the product detail pages, but I'm getting a bunch of errors including the one below:

Screen Shot 2016-03-17 at 1.51.55 PM.png

 

I'm thinking the Javascript should be insert into the header section? If so, how do I go about doing that?

Is this the correct approach?

 

Thanks in advanced!

 

 

JDahlinANF 03-18-16
 

Re: I'm using Javascript to split test my cart button across all product detail pages help!

@kchilites - Your variation code should be pure JavaScript, not a mix of PHP and JavaScript (PHP runs on the web server, not within the Browser, so it won't work in this context). 

 

Your code should look like this:

 

jQuery(document).ready(function(){
    var btn = '<img src="//somepathhere.com/frontend/kchilites/default/images/btns/yellowaddtocartbutton.png"  height="34" label="add to cart button"/>'
    jQuery(".add-to-cart .btn-cart").html(btn);
});

 

 

Also, notice that your code should not include the <script> tags.  For this to work, you will need to know the path to the object when you write the JavaScript or be able to determine the pathusing nothing but javascript.

 

Is there any reason you are not taking the same approach as you did the "[PDP] Add To Cart Button" experiment? Where you replace the Add to Cart button with an image that you've uploaded to Optimizely?