Skip to content

Instantly share code, notes, and snippets.

@kprimdal-dk
Last active December 12, 2015 07:58
Show Gist options
  • Save kprimdal-dk/4740497 to your computer and use it in GitHub Desktop.
Save kprimdal-dk/4740497 to your computer and use it in GitHub Desktop.
Partner Visual Website Optimizer
<script type="text/javascript">
// *****
// SET DEFAULT AUTHOR ID
// *****
var vwoAuthor = '1324';
var _vwo_code, account_id,
ownDomain = location.hostname,
referrerDomain = document.referrer.split('/')[2];
if ( ownDomain != referrerDomain) {
var script = document.createElement('script');
script.src = '//marketers.dk/json/?url='+ encodeURIComponent( document.referrer ) +'&callback=muxSetAuthorCookie';
document.getElementsByTagName('head')[0].appendChild(script);
}
if ( ownDomain == referrerDomain ) {
var author = muxGetCookie( 'partnerOptimizerId' );
if ( author == null || author == false ) {
author = vwoAuthor;
}
muxOptimizer( author );
}
function muxSetAuthorCookie( data ) {
var exdate = new Date(),
exdays = 1,
value = data['userId'] == false ? vwoAuthor : data['userId'],
cookie = 'partnerOptimizerId',
exdate = new Date();
muxOptimizer( value );
exdate.setDate(exdate.getDate() + exdays);
var c_value = escape(value) + (( exdays == null ) ? "" : "; expires="+exdate.toUTCString());
document.cookie=cookie + "=" + c_value;
}
function muxGetCookie( cookie ) {
var i,x,y,ARRcookies=document.cookie.split(";");
for ( i=0; i<ARRcookies.length; i++ ) {
x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
x=x.replace(/^\s+|\s+$/g,"");
if (x==cookie) {
return unescape(y);
}
}
}
function muxOptimizer( author ) {
_vwo_code = (function(){
account_id = author,
settings_tolerance=2000,
library_tolerance=1500,
use_existing_jquery=false,
f=false,d=document;return{use_existing_jquery:function(){return use_existing_jquery;},library_tolerance:function(){return library_tolerance;},finish:function(){if(!f){f=true;var a=d.getElementById('_vis_opt_path_hides');if(a)a.parentNode.removeChild(a);}},finished:function(){return f;},load:function(a){var b=d.createElement('script');b.src=a;b.type='text/javascript';b.innerText;b.onerror=function(){_vwo_code.finish();};d.getElementsByTagName('head')[0].appendChild(b);},init:function(){settings_timer=setTimeout('_vwo_code.finish()',settings_tolerance);this.load('//dev.visualwebsiteoptimizer.com/j.php?a='+account_id+'&u='+encodeURIComponent(d.URL)+'&r='+Math.random());var a=d.createElement('style'),b='body{opacity:0 !important;filter:alpha(opacity=0) !important;background:none !important;}',h=d.getElementsByTagName('head')[0];a.setAttribute('id','_vis_opt_path_hides');a.setAttribute('type','text/css');if(a.styleSheet)a.styleSheet.cssText=b;else a.appendChild(d.createTextNode(b));h.appendChild(a);return settings_timer;}};}());_vwo_settings_timer=_vwo_code.init();
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment