0Localização de links Amazon Afiliados

Eu ocasionalmente referência produtos em meus vários sites, e, geralmente, associá-los a Amazon para qualquer pessoa interessada em comprá-los. Há muito tempo que eu usei para ligar com um afiliados amazon ligar, mas nunca ganhou nada com isso como meus leitores típico é bem distribuída ao redor do mundo. Infelizmente Amazon não fornecem uma maneira de redirecionar os visitantes para o seu site amazon locais, mantendo a pagamentos afiliadas. Existem várias soluções lá fora, mas todos os que eu encontrados tive problemas com eles, so I developed my own.

I could devel­op it into a plu­gin for release if there is suf­fi­cient demand. Entretanto, the code is below. You will need to make some modi­fic­a­tions to make it match your site address and your amazon affil­i­ates codes

<?php
/**
* Plugin Name: Amazon Affiliates Redirect
* Plugin URI: https://diymediahome.org/
* Descrição: Redirects all amazon affiliates links to a local amazon store depending on visitors location.
* Versão: 1.0
* Author: Jon P Scaife
* Author URI: https://jonscaife.com
* License: GPL12
*/
function process_link()
{
$debug=false;

//Detect visitor location from IP

se (isset($_SERVIDOR['HTTP_CLIENT_IP']))
{
$real_ip_address = $_SERVER['HTTP_CLIENT_IP'];
}

se (isset($_SERVIDOR['HTTP_X_FORWARDED_FOR']))
{
$real_ip_address = $_SERVER['HTTP_X_FORWARDED_FOR'];
}
outro
{
$real_ip_address = $_SERVER['REMOTE_ADDR'];
}

function curl_get_contents($url)
{
$CH = curl_init();

curl_setopt($CH, CURLOPT_HEADER, 0);
curl_setopt($CH, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($CH, CURLOPT_URL, $url);

$data = curl_exec($CH);
curl_close($CH);

return $data;
}

$iptolocation = 'http://ip-api.com/php/' . $real_ip_address;
$ipreply = @unserialize(curl_get_contents($iptolocation));
$iplocation = $ipreply['countryCode'];

//Detect visitor language from browser

$browserlang= substr($_SERVIDOR['HTTP_ACCEPT_LANGUAGE'], 0, 2);

//Detect language of page visitor is using

if (isset($_GET['lang']))
{
$userlang= $_GET['lang'];
}
outro
{
$userlang= "EN";
}

//was a link passed

if (isset($_GET['addr']))
{
$original_link= $_GET['addr'];
}

//Decide best amazon site based on data detected

$linkpartone= $_GET['creativeASIN'];

interruptor ($iplocation)
{
case 'GB':
        $link="https://www.amazon.co.uk/dp/".$linkpartone."/ref=nosim?tag=dimeho-21";
        break;
case 'IE':
        $link="https://www.amazon.co.uk/dp/".$linkpartone."/ref=nosim?tag=dimeho-21";
break;
case 'US':
        $link="https://www.amazon.com/dp/".$linkpartone."/ref=nosim?tag=jonstech-20";
break;
case 'CA':
        $link="https://www.amazon.ca/dp/".$linkpartone."/ref=nosim?tag=dimeho-20";
break;
case 'CN':
        $link="https://www.amazon.cn/dp/".$linkpartone."/ref=nosim?tag=";
break;
case 'HK':
        $link="https://www.amazon.cn/dp/".$linkpartone."/ref=nosim?tag=";
break;
case 'MO':
        $link="https://www.amazon.cn/dp/".$linkpartone."/ref=nosim?tag=";
break;
case 'IN':
        $link="https://www.amazon.in/dp/".$linkpartone."/ref=nosim?tag=";
break;
case 'JP':
        $link="https://www.amazon.co.jp/dp/".$linkpartone."/ref=nosim?tag=";
break;
case 'FR':
        $link="https://www.amazon.fr/dp/".$linkpartone."/ref=nosim?tag=Dimeho02-21";
break;
case 'CH':
        $link="https://www.amazon.fr/dp/".$linkpartone."/ref=nosim?tag=Dimeho02-21";
break;
case 'BE':
        $link="https://www.amazon.fr/dp/".$linkpartone."/ref=nosim?tag=Dimeho02-21";
break;
case 'MC':
        $link="https://www.amazon.fr/dp/".$linkpartone."/ref=nosim?tag=Dimeho02-21";
break;
case 'LU':
        $link="https://www.amazon.fr/dp/".$linkpartone."/ref=nosim?tag=Dimeho02-21";
break;
case 'DE':
        $link="https://www.amazon.de/dp/".$linkpartone."/ref=nosim?tag=dimeho0f-21";
break;
case 'CZ':
        $link="https://www.amazon.de/dp/".$linkpartone."/ref=nosim?tag=dimeho0f-21";
break;
case 'IT':
        $link="https://www.amazon.it/dp/".$linkpartone."/ref=nosim?tag=diymediahome-21";
break;
case 'NL':
        $link="https://www.amazon.nl/dp/".$linkpartone."/ref=nosim?tag=";
break;
case 'ES':
        $link="https://www.amazon.es/dp/".$linkpartone."/ref=nosim?tag=diymediahom05-21";
break;
case 'MX':
        $link="https://www.amazon.com.mx/dp/".$linkpartone."/ref=nosim?tag=";
break;
case 'AU':
        $link="https://www.amazon.com.au/dp/".$linkpartone."/ref=nosim?tag=";
break;
case 'BR':
        $link="https://www.amazon.com.br/dp/".$linkpartone."/ref=nosim?tag=";
break;
omissão:
$link="https://www.amazon.com/dp/".$linkpartone."/ref=nosim?tag=jonstech-20";
}


se($debug==true)
{
eco "1. $iplocation.  2. $browserlang.  3. $userlang.  4. $link";
}
outro
{
cabeçalho('Location: '.$link);
die();
}

}
se (isset($_GET['addr'])) process_link();

//create filter to replace amazon links with internal redirect inc a random code to prevent caching

function modify_amazon_affiliate_links($conteúdo)
{
$content= str_replace('<um rel ="nofollow" href ="https://www.amazon', '<escrita>var ran_var= Math.random();</escrita><a style="fundo: nenhum;" rel ="nofollow" onclick="location.href=this.href+\'?ran=\'+ran_var;return false;" target="_blank" href ="https://jonscaife.com/wp-content/plugins/amazon-affiliates-redirect.php?addr=', $conteúdo);
return str_replace('<um href ="https://www.amazon', '<escrita>var ran_var= Math.random();</escrita><a style="fundo: nenhum;" rel ="nofollow" onclick="location.href=this.href+\'?ran=\'+ran_var;return false;" target="_blank" href ="https://jonscaife.com/wp-content/plugins/amazon-affiliates-redirect.php?addr=', $conteúdo);
}
add_filter( 'o conteúdo', 'modify_amazon_affiliate_links' )

?>

Note — the code is cur­rently early draft.  It works, but it does­n’t make use of some of the detec­tion that it can do.  It does­n’t have a set­tings page for the asso­ci­ate IDs, and it uses a hard­coded site address, rather than an invis­ible redir­ect.  It DOES how­ever use cli­ent-side javas­cript to gen­er­ate a unique redir­ect url every time to pre­vent any cach­ing sys­tems from caus­ing incor­rect loc­a­tion detec­tion.

Por favor envie-nos a sua opinião comentando abaixo! Se você deseja se inscrever, use o link de inscrição no menu no canto superior direito. Você também pode compartilhar isso com seus amigos usando os links sociais abaixo. Felicidades.

Deixe uma resposta