Rich-text Reply

WalkME AB test

shansmith01 07-08-16

WalkME AB test

Hi I am trying to add some external JS to the website form walkme to test. I have read the docs but don't understand how to add the code the snippet you proved below

 

/*
 * Usage
 *    This function will append an external JavaScript to the head of the document.
 *
 *  @param {String} location - The location of the file you'd like to load.
 *  @param {Function} callback - [OPTIONAL] A function to call when the script has completed downloading.
 *
 */

 var loadScript = function(location, callback){
   var fileRef = document.createElement('script');
   fileRef.setAttribute('type','text/javascript');

   if (callback) {
     if (fileRef.readyState) {  // IE
       fileRef.onreadystatechange = function() {
         if (fileRef.readyState == 'loaded' || fileRef.readyState == 'complete') {
           fileRef.onreadystatechange = null;
           callback();
         }
       };
     } else {  // Non-IE
       fileRef.onload = function(){
         callback();
       };
     }
   }

   fileRef.setAttribute('src', location);
   document.head.appendChild(fileRef);
 };

 loadScript('http://www.example.com/test.js', function() {
   // CALLBACK - code that does something with the data returned by loading the script
 });

The code I am trying to add to the <head> of  my variation is this

 

<script type="text/javascript">(function() {var walkme = document.createElement('script'); walkme.type = 'text/javascript'; walkme.async = true; walkme.src='http://cdn.walkme.com/users/cb643dab0d6f4c7cbc9d436e7c06f719/walkme_cb643dab0d6f4c7cbc9d436e7c06f719.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(walkme, s); window._walkmeConfig = {smartLoad:true}; })();</script>

Can i get some help please?

robertchan 07-08-16
 

Re: WalkME AB test

You can try this:

 

 /* _optimizely_evaluate=force */
function loadScript(content){
	var head   = document.head || document.getElementsByTagName('head')[0],
		fileRef = document.createElement('script');
		fileRef.setAttribute('type', 'text/javascript');
		fileRef.setAttribute('src', content);
		fileRef.async = true;
		head.appendChild(fileRef);
		window._walkmeConfig = {
	        smartLoad: true
	    };
}

loadScript('//cdn.walkme.com/users/cb643dab0d6f4c7cbc9d436e7c06f719/walkme_cb643dab0d6f4c7cbc9d436e7c06f719.js');
/* _optimizely_evaluate=safe */

Place that in the variant you want the script to run on and look in console log to check that WalkMe has appended all its scripts on the fly.

Robert Chan