//haven.com natural traffic script

function gup( name ){  

name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");  

var regexS = "[\\?&]"+name+"=([^&#]*)";  

var regex = new RegExp( regexS );  

var results = regex.exec( window.location.href );  

if( results == null )    return "";  

else    return results[1];

}



var marketing_identifier = 'wachannel'; // set this to the value mediaplex passes through on all marketing urls - eg mpch=ads

var redirect_identifier = 'pid'; // set this to the name of the variable containing the mplex placement id for the redirect

var referringurl = document.referrer.toLowerCase();

var	landingpage = document.URL.toLowerCase();

var pixel = '';

var rnd = Math.floor(Math.random()*1000000000000000000);



// if landing page contains marketing id and also contains the redirect parameter write the redirect id to the page

if(landingpage.indexOf(redirect_identifier) >= 0) {

var redirect = gup('pid');

						

	pixel = "<img width='1' height='1' src='https://web.haven.com/cm/ck/" + redirect + "'/>"; 

	document.writeln(pixel);

	
}



else {



if(referringurl != '') {

		if(referringurl.indexOf('://www.caravancamping.co.uk') >= 0 || referringurl.indexOf('://caravancamping.co.uk') >= 0) {// if a haven.com page exit script

		}

		else if (referringurl=='blockedReferrer'){

		pixel = '<img width="1" height="1" src="https://web.haven.com/cm/tr/13792-94811-29592-0?page=' + escape(landingpage) + '&mpt=' + rnd + '"/>'; 

		document.writeln(pixel); 

		}

		else 	{// if there is a referring url and it is not a haven page

					if(landingpage.indexOf(marketing_identifier) <= 0) {

					document.write('<iframe frameborder="0" width="1" height="1" src="http://reporting.blmquantum.co.uk/haven-touring/ns/?ref=' + escape(referringurl) +'&page=' + escape(landingpage) + '&rnd=' + rnd + '"/></iframe>');

					}

					else {// if marketing traffic but not a redirect then we ignore it

					}

	

				}

}	

else {// NO REFERRING URL ==> DIRECT TRAFFIC ==> IMPRESSION TRACKER

pixel = "<img width='1' height='1' src='https://web.haven.com/cm/tr/13792-94809-29592-0?ref=" + escape(referringurl) +"&page=" + escape(landingpage) +"&mpt=" + rnd + "'/>"; 

document.writeln(pixel); 

}

}
