0Localisation des liens Amazon Affiliés

Je fais référence à l'occasion des produits sur mes sites, et de les relier habituellement Amazon pour tous ceux intéressés à les acheter. Il y a longtemps que je l'habitude de créer un lien avec un lien, mais affiliés amazon jamais gagné quoi que ce soit de ce que mon lectorat typique est bien répartie dans le monde entier. Malheureusement, Amazon ne fournit pas un moyen de rediriger les visiteurs vers leur site amazon locale tout en conservant les paiements affiliés. Il existe différentes solutions là-bas, mais tous ceux que je trouvais eu des problèmes avec eux, so I developed my own.

I could devel­op it into a plu­gin for release if there is suf­fi­cient demand. Dans le temps moyen, 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/
* La description: Redirects all amazon affiliates links to a local amazon store depending on visitors location.
* Version: 1.0
* Author: Jon P Foulard
* Author URI: https://jonscaife.com
* License: GPL12
*/
function process_link()
{
$debug=false;

//Detect visitor location from IP

si (disparu($_SERVEUR['HTTP_CLIENT_IP']))
{
$real_ip_address = $_SERVER['HTTP_CLIENT_IP'];
}

si (disparu($_SERVEUR['HTTP_X_FORWARDED_FOR']))
{
$real_ip_address = $_SERVER['HTTP_X_FORWARDED_FOR'];
}
autre
{
$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 = 'https://ip-api.com/php/' . $real_ip_address;
$ipreply = @unserialize(curl_get_contents($iptolocation));
$iplocation = $ipreply['countryCode'];

//Detect visitor language from browser

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

//Detect language of page visitor is using

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

//was a link passed

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

//Decide best amazon site based on data detected

$linkpartone= $_GET['creativeASIN'];

commutateur ($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;
défaut:
$link="https://www.amazon.com/dp/".$linkpartone."/ref=nosim?tag=jonstech-20";
}


si($debug==true)
{
écho "1. $iplocation.  2. $browserlang.  3. $userlang.  4. $lien";
}
autre
{
tête('Location: '.$link);
die();
}

}
si (disparu($_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($teneur)
{
$content= str_replace(»<un rel ="nofollow" href ="https://www.amazon', »<scénario>var ran_var= Math.random();</scénario><a style="Contexte: aucun;" 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=', $teneur);
return str_replace(»<un href ="https://www.amazon', »<scénario>var ran_var= Math.random();</scénario><a style="Contexte: aucun;" 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=', $teneur);
}
add_filter( «The_content ', '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 detection.

Laisser un commentaire