Last active
December 30, 2024 15:46
-
-
Save ConversionSciences/a850d4e46b3b09fb67817ca5333bec29 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name CS VWO Info | |
// @version 1.1 | |
// @description Show info on running VWO experiments | |
// @author Conversion Sciences | |
// @include /^https?:\/\/.*/ | |
// @grant none | |
// @noframes | |
// @downloadURL https://d2t92d45b68dnb.cloudfront.net/TM/VWO.js | |
// ==/UserScript== | |
(function() { | |
window['cs_getVWOgoals'] = function(exp) { | |
var goals = document.cookie.match(new RegExp('_vis_opt_exp_' + exp + '_goal_[0-9]*=1(;|$)', 'g')); | |
var goals_out = []; | |
if (goals !== null) | |
goals.forEach(function(val, ind) { | |
goals_out.push(val.match(/_goal_([0-9]*\d)=1;/)[1]); | |
}); | |
return goals_out; | |
}; | |
window.cs_toggle_vwo_vis = function() { | |
var el = document.getElementById('cs_vwo_div'); | |
if (!el) | |
return; | |
if (el.className.indexOf('cs_vis') > -1) | |
el.className = el.className.replace(' cs_vis', ''); | |
else | |
el.className = el.className + ' cs_vis'; | |
}; | |
window['cs_checkVWO'] = function(show_cs_vwo, hide_log) { | |
this.log = function(s) { if(hide_log) return; console.log(s); } | |
var $ = $; | |
if (typeof _vwo_code == 'undefined' && typeof window._vwo_acc_id == 'undefined') return ('VWO Code not defined'); | |
else this.log('VWO Code found'); | |
//if (!_vwo_code.libExecuted) console.log('VWO Library not excecuted'); | |
if (typeof vwo_$ == 'undefined') { | |
this.log('VWO Library not loaded'); | |
$ = jQuery; | |
} else $ = vwo_$; | |
var account_id = ($('script:contains("_vwo_code")').length > 0) ? $('script:contains("_vwo_code")').first().html().match(/account_id?([ ]*)=?([ ]*)([0-9]*\d)/)[3] : (typeof _vwo_acc_id != 'undefined' ? _vwo_acc_id : 'Not Found'); | |
this.log('--------VWO Info------------ \nVWO account id: ' + account_id + '\n'+ 'vwo_$ jQuery Version: ' + ((typeof vwo_$ != 'undefined') ? vwo_$.fn.jquery : 'Not defined.') + '\n' + '$ jQuery Version: ' + ((typeof $ != 'undefined' && typeof $.fn != 'undefined') ? $.fn.jquery : 'Not defined') + '\n' + 'jQuery Version: ' + ((typeof jQuery != 'undefined') ? jQuery.fn.jquery : 'Not defined.')); | |
if (typeof _vwo_exp != 'undefined') { | |
var expIn = ''; | |
var expOut = ''; | |
var inCount = 0; | |
var outCount = 0; | |
var expInHTML = ''; | |
var expOutHTML = ''; | |
Object.keys(_vwo_exp).forEach(function(key, ind) { | |
var exp = 'Exp ' + key + ((typeof _vwo_exp[key].combination_chosen != 'undefined') ? ' : ' + _vwo_exp[key].combination_chosen : '') + ' | "' + _vwo_exp[key].name + '"'; | |
if (typeof _vwo_exp[key].combination_chosen != 'undefined') { | |
expIn = expIn + exp + ((cs_getVWOgoals(key).length > 0) ? (' | Goals: ' + cs_getVWOgoals(key).join(', ')) : '') + '\n'; | |
expInHTML = expInHTML + '<div class="cs_vwo_exp cs_in"><span class="cs_exp_name">' + _vwo_exp[key].name + '</span> <span class="cs_exp_id">(Exp: ' + key + ')</span><div class="cs_exp_var">Variation: ' + _vwo_exp[key].combination_chosen + '</div><div class="cs_exp_goals">' + ((cs_getVWOgoals(key).length > 0) ? ('Goals: ' + cs_getVWOgoals(key).join(', ')) : '') + '</div></div>'; | |
inCount++; | |
} else { | |
expOut = expOut + exp + ((cs_getVWOgoals(key).length > 0) ? (' | Goals: ' + cs_getVWOgoals(key).join(', ')) : '') + '\n'; | |
expOutHTML = expOutHTML + '<div class="cs_vwo_exp cs_out"><span class="cs_exp_name">' + _vwo_exp[key].name + '</span> <span class="cs_exp_id">(Exp: ' + key + ')</span><div class="cs_exp_goals">' + ((cs_getVWOgoals(key).length > 0) ? ('Goals: ' + cs_getVWOgoals(key).join(', ')) : '') + '</div></div>'; | |
outCount++; | |
} | |
}); | |
expOut = ((expOut.length > 0) ? '----Excluded From---------- \n' + expOut : ''); | |
this.log('--------VWO ExpID : Var | Exp Name | Goal IDs--------- \n' + expIn + expOut); | |
if (show_cs_vwo) { | |
var o_class = (document.getElementById('cs_vwo_div') ? document.getElementById('cs_vwo_div').className : ''); | |
var cs_vwo_div = document.getElementById('cs_vwo_div') || document.createElement('div'); | |
cs_vwo_div.id = 'cs_vwo_div'; | |
cs_vwo_div.innerHTML = '<style>#cs_vwo_div.cs_hidden { display: none; } .cs_vert_middle { vertical-align: middle; cursor: pointer; margin-right: 15px; } #cs_vwo_close { cursor: pointer; margin-left: 15px; color: #333; }#cs_vwo_close:hover { color: red; } #cs_vwo_div * { box-sizing: border-box; } #cs_vwo_div.cs_hidden { display: none; } #cs_vwo_div { box-sizing: border-box; position: fixed; left: 10px; bottom: 0; z-index: 999999999;} #cs_vwo_button { display: inline-block; background-color: magenta; color: white; padding: 0px 10px; } .cs_vwo_button_title { cursor: pointer; padding: 6px 0px; display: inline-block; } #cs_vwo_info { display: none; border: 1px solid magenta; background-color: white; max-height: 300px; overflow: hidden; overflow-y: auto; } #cs_vwo_div.cs_vis #cs_vwo_info { display: block; } .cs_vwo_exp { background-color: white; border-bottom: 1px solid magenta; padding: 10px;} .cs_vwo_exp.cs_out { background-color: #ccc; }</style><div id="cs_vwo_button"><img class="cs_vert_middle" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAQAAAC1+jfqAAAAAmJLR0QA/4ePzL8AAAAJcEhZcwAACxMAAAsTAQCanBgAAAAHdElNRQfhBA0RLAVCmUr8AAABDklEQVQoz2XRP0ubARAG8N/7tm66C01pUITEIVunbPkgpW1QcGihkJuT2RPMVJBCxO/g0iVjx6JLdYn/2kB3l4IFO5gYk95wHPfc89wdTwEhxYaOlle4NrSbo5CiV0zgI2/Mx2G+j55uEVKcaqDvIM+Juh0f8NsqZYpDDbcq+ck5OMuPKu6sQhnr3qJuTGKStyw9bHqug36On66Pnu60LrVwEE/h/gxG/In7OfbCM6X7+Ub+N3BF1BZ5M6VnzU2v/c2viwPfxOfmcbNaxJoRKsY5z3/pBtUyLwxw5sVUNqDiB77kdRmy7cSKX7GvBmqx76dl33M7TM0aeLdwxCDbIRWPdq/raKkqXBrae7Cbfz7QVDXXX6phAAAAAElFTkSuQmCC" title="Refresh Info" onclick="cs_checkVWO(true);" /><span class="cs_vwo_button_title" onclick="cs_toggle_vwo_vis();">VWO Experiments: ' + (inCount + outCount) + ' (' + inCount + ')</span> <span id="cs_vwo_close" onclick="document.getElementById(\'cs_vwo_div\').className = \'cs_hidden\';" title="Close">X</span></div><div id="cs_vwo_info">' + expInHTML + expOutHTML + '</div>'; | |
if (!document.getElementById('cs_vwo_div')) | |
document.getElementsByTagName('body')[0].appendChild(cs_vwo_div); | |
cs_vwo_div.className = o_class; | |
} | |
} else this.log('No experiments running on this page.'); | |
}; | |
if (typeof window.onload == 'undefined' || document.readyState !== 'complete') //Check if running in tampermonkey or document is not ready, and wait for DOM if so. | |
window.addEventListener('load', function() { | |
cs_checkVWO(true); | |
window.VWO = window.VWO || []; | |
window.VWO.push(['onEventReceive', 'rC', function(data) { cs_checkVWO(true, true); console.log('VWO Goal Fired. '+ data[1] + ': '+data[2]); }]); | |
window.VWO.push(['onVariationApplied', 'rC', function(data) { cs_checkVWO(true, true); console.log('VWO Test Running. '+ data[1] + ': '+data[2]); }]); | |
}); | |
else cs_checkVWO(true); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment