使用html javascript向搜索引擎流量显示Google AdSense广告
Display Google AdSense ads to search engine traffic using html javascript
我使用以下PHP代码只为搜索引擎访问者显示AdSense广告。
但现在我需要在搜索引擎访问者上显示广告的HTML/JavaScript代码。
我正在尝试创建HTML/JavaScript代码,但失败了。
我可以修改/创建这个HTML/JavaScript代码吗?
有什么解决方案吗?或者有HTML/JavaScript代码吗?
<?php
$referrer = $_SERVER['HTTP_REFERER'];
$my_domain = "example.com";
$search_engines = "google|yahoo|bing|altavista|digg";
$pattern = "((http(s)?://)('w+?'.)?(?!{$my_domain})({$search_engines}))";
if (preg_match("/{$search_engines}/i", $referrer) != false) {
echo <<<END
<script type="text/javascript"><!--
google_ad_client = "xx-xx-xxxxxxxxxxxxxxxxxx";
/* xxxxxxxx xxxxxx xxx xxx xxx xx xxxxxx */
google_ad_slot = "xxxxxxxxxxxxxx";
google_ad_width = xxx;
google_ad_height = xxx;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
END;
} else {
// Show something to visitors not referred by a search engine
}
?>
请帮帮我,先生。
这有点愚蠢,但您可以将其转换为js:
<script type="text/javascript">
if (document.referrer.match(/google|yahoo|bing|altavista|digg/)) {
google_ad_client = "xx-xx-xxxxxxxxxxxxxxxxxx";
/* xxxxxxxx xxxxxx xxx xxx xxx xx xxxxxx */
google_ad_slot = "xxxxxxxxxxxxxx";
google_ad_width = xxx;
google_ad_height = xxx;
var script = document.createElement("script");
script.setAttribute("src", src);
document.getElementsByTagName("head")[0].appendChild(script);
} else {
// Show something to visitors not referred by a search engine
}
</script>
相关文章:
- 在angularjs/google地图中显示分支最近的路线
- 使用API在我的网站Google-Map上显示搜索地址的纬度和经度
- 来自单个Google Sheet的多个图表赢得't显示
- 在一个C#页面上显示多个Google图表
- 仅显示 Google 表格中来自 api 调用的最新数据行
- 在Highcharts.js上显示Google Analytics的30天流量
- JQuery 发布到 .NET MVC 应用程序以显示 Google 图表
- 显示 Google 地图上的标记数量和该标记的数据
- 使用 StageWebView.loadString() 在 AIR for iOS 上显示 Google 地图
- 在 Rails 应用程序中显示 Google Maps v3 上的标记 - 使用 Javascript 和 JSON
- 显示Google Analytics热门帖子
- 如何使用JSON以HTML格式显示Google工作表
- 突出显示Google地图api中最后单击的按钮
- 当使用Geocoder()时,MarkerWithLabel仅显示google地图api中的最后一个值
- 如何在用户按下按钮或图像后显示Google Picker API对话框
- 在GWT框架中显示Google登录页面
- 仅向搜索引擎访问者显示Google AdSense广告
- 使用html javascript向搜索引擎流量显示Google AdSense广告
- 在自定义网站上显示Google Maps Javascript API使用统计数据
- 在InfoWindow中显示Google地图标记的纬度和经度