Scroll to top

Cum sa trimiti GCLID catre 2performant.com din site-ul propriu (Script JS)

Script-ul modifica doar linkurile puse direct catre 2performant (cele ce incep cu event.2performant.com), link-urile mascate/redirectionate nu sunt afectate.

Adaugati codul javascript in footer (partea de jos a site-ului), inainte de inchiderea tag-ului body “</body>”.

Modificati valoarea parametrului marketplusGclidCookieTime in numarul de ore cat vreti sa pastrati cookie-ul gclid.

Daca cookie-ul gclid este prezent si intr-o vizita directa sau din alta sursa, acesta este trimis catre 2performant.

<script>
var marketplusGclidCookieTime = 48; // How many hours will the cookie with the specific gclid last

function marketPlusSetCookie(cname, cvalue, exhours) {
  const d = new Date();
  d.setTime(d.getTime() + (exhours*60*60*1000));
  let expires = "expires="+ d.toUTCString();
  document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
}

function marketPlusGetParam(p){
	var match = RegExp('[?&]' + p + '=([^&]*)').exec(window.location.search);
	return match && decodeURIComponent(match[1].replace(/\+/g, ' '));
}

function marketPlusGetCookie(cname) {
  let name = cname + "=";
  let decodedCookie = decodeURIComponent(document.cookie);
  let ca = decodedCookie.split(';');
  for(let i = 0; i <ca.length; i++) {
    let c = ca[i];
    while (c.charAt(0) == ' ') {
      c = c.substring(1);
    }
    if (c.indexOf(name) == 0) {
      return c.substring(name.length, c.length);
    }
  }
  return false;
}

var marketPlusGclidCookie = false; // Do not change it
if(marketPlusGetParam('gclid'))
{	
	marketPlusGclidCookie = marketPlusGetParam('gclid');
	marketPlusSetCookie('marketPlusGclidCookie', marketPlusGclidCookie, marketplusGclidCookieTime);
}
else
{
	marketPlusGclidCookie = marketPlusGetCookie('marketPlusGclidCookie');
}

if(marketPlusGclidCookie)
{
	Array.from(document.getElementsByTagName("a")).forEach(function(element){
		
		if(element.href)
		{
			if(element.href.indexOf('event.2performant.com') != -1)
			{
				if(element.href.indexOf('st=') != -1)
					element.href = element.href.replace('st=','st='+marketPlusGclidCookie+',');
				else
					element.href = element.href.replace('?','?st='+marketPlusGclidCookie+'&');
			}	
		}
  
	});    
}
</script>
Author avatar
razvypp
https://marketplus.io/blog

Post a comment

Your email address will not be published. Required fields are marked *

seven + eight =