Rich-text Reply

Loading external scripts through Optimizeley (social media sharing scripts)

chrisgosling 06-04-14
Accepted Solution

Loading external scripts through Optimizeley (social media sharing scripts)

Does anyone have experience running tests on a feature generated by an external script?  I want to test a few different variations of social media sharing options.  One example is that I want to run a test to see how having a pinterest sharing button that appears over images affects conversion rates and sharing.  To add this feature to a site I would normally just include the script link that pinterest supplies and have the button:

<!-- Please call pinit.js only once per page -->
<script type="text/javascript" async data-pin-color="white" data-pin-height="28" data-pin-hover="true" src="//assets.pinterest.com/js/pinit.js"></script>

 

via http://business.pinterest.com/en/widget-builder#do_pin_it_button

If I was working on this site alone I would probably just hard code that into the site and run a test to remove the button for some of the users and allow a few users visibility.  (Is this even a good idea?) However, I am working with developers and I would rather not have to continue pestering them with adding in scripts for my tests.  Is there a way that I can implement these scripts directly through optimizely?

Thanks!

Amanda 06-04-14
 

Re: Loading external scripts through Optimizeley (social media sharing scripts)

 

Good question! I found some instructions on adding a Pinterest button here. Looks like you need to add the actual "Pin It" button to the HTML for every location you want it to show up and then you need to call the JS file only once. 

 

To do this, you can either add the button images directly to your site's HTML, or you can click on the location you want to add the button and use the "Insert HTML" feature. Make sure you do not add <script> tags here, just add the button itself. 

 

Then, to insert an external JavaScript file onto your page using Optimizely, simply add the line of code below into the "Edit Code" section of the editor. 

 

$(function(){var fileRef = document.createElement('script'); fileRef.setAttribute("type","text/javascript"); fileRef.setAttribute("src", "//assets.pinterest.com/js/pinit.js"); document.body.appendChild(fileRef);});

 

See attached for reference as well. Let me know if this does the trick for you or if you have any questions. 

 

 

 



Screen Shot 2014-06-04 at 3.23.18 PM.png
Optimizely

Re: Loading external scripts through Optimizeley (social media sharing scripts)

Thanks!
jklaiber 09-19-16
 

Re: Loading external scripts through Optimizeley (social media sharing scripts)

Hi Amanda
I have the problem, that I want to implement JS code for a MailChimp PopUp (the code is generated by MailChimp) with Optimizely on my site. Now when I paste in the code in the editor it does not work.
Do you think my problem could be solved with your solution of "load external JS"?
I already opened a discussion (https://community.optimizely.com/t5/Using-Optimizely/Insert-JS-Code-from-MailChimp-with-Optimizely/m...) but haven't found a solution yet.
Thanks for your answers!
Best, Johannes
Level 2