0亚马逊关联链接本地化

我偶尔会参考产品对我的各种网站, 通常将它们链接到亚马逊的人有兴趣购买它们. 很久以前,我曾经有一个亚马逊子公司链接到链接,但我的典型读者是在世界各地分布均匀从来没有获得来自任何东西. 不幸的是亚马逊没有提供一种方式来将访问者重定向到其本地亚马逊网站,同时保留对子公司支付. 有各种不同的解决方案在那里,但所有我发现那些有问题与他们, 所以我开发了我自己.

我可以发展成发布一个插件,如果有足够的需求. 在平均时间, 代码是下面. 您将需要进行一些修改,使之符合您的网站地址和亚马逊子公司代码

<?PHP
/**
* Plugin Name: Amazon Affiliates Redirect
* Plugin URI: HTTPS://diymediahome.org/
* 描述: Redirects all amazon affiliates links to a local amazon store depending on visitors location.
* 版本: 1.0
* Author: 乔恩·P·斯卡夫
* Author URI: HTTPS://jonscaife.com
* License: GPL12
*/
function process_link()
{
$debug=false;

//Detect visitor location from 知识产权

如果 (isset($_服务器['HTTP_CLIENT_IP']))
{
$real_ip_address = $_SERVER['HTTP_CLIENT_IP'];
}

如果 (isset($_服务器['HTTP_X_FORWARDED_FOR']))
{
$real_ip_address = $_SERVER['HTTP_X_FORWARDED_FOR'];
}
其他
{
$real_ip_address = $_SERVER['REMOTE_ADDR'];
}

function curl_get_contents($网址)
{
$CH = curl_init();

curl_setopt($CH, CURLOPT_HEADER, 0);
curl_setopt($CH, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($CH, CURLOPT_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($_服务器['HTTP_ACCEPT_LANGUAGE'], 0, 2);

//Detect language of page visitor is using

if (isset($_GET['lang']))
{
$userlang= $_GET['lang'];
}
其他
{
$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'];

开关 ($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;
默认:
$link="HTTPS://www.amazon.com/dp/".$linkpartone."/ref=nosim?tag=jonstech-20";
}


如果($debug==true)
{
回声 "1. $iplocation.  2. $browserlang.  3. $userlang.  4. $链接";
}
其他
{
头('Location: '.$link);
die();
}

}
如果 (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($内容)
{
$content= str_replace(“<a rel="nofollow" HREF ="HTTPS://www.amazon', “<脚本>var ran_var= Math.random();</脚本><a style="背景: 没有;" 相对="nofollow" onclick="location.href=this.href+\'?ran=\'+ran_var;返回false;" target="_blank" HREF ="HTTPS://jonscaife.com/wp-content/plugins/amazon-affiliates-redirect.php?addr=', $内容);
return str_replace(“<A HREF ="HTTPS://www.amazon', “<脚本>var ran_var= Math.random();</脚本><a style="背景: 没有;" 相对="nofollow" onclick="location.href=this.href+\'?ran=\'+ran_var;返回false;" target="_blank" HREF ="HTTPS://jonscaife.com/wp-content/plugins/amazon-affiliates-redirect.php?addr=', $内容);
}
的add_filter( '内容', 'modify_amazon_affiliate_links' )

?>

注 - 代码是目前早期草案.  有用, 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, 它使用硬编码的站点地址, 而不是一个无形的重定向.  然而,这确实使用客户端的JavaScript生成一个唯一的重定向URL每一次,以防止任何缓存系统从导致不正确的位置检测.

你怎么看? 请给我们一个评论如下! 如果您想订阅,请使用菜单上的订阅链接右上方. 您还可以通过使用下面的链接社会分享这与你的朋友. 干杯.

发表评论