简体   繁体   English

根据用户代理切换Google Adsense广告(移动还是常规)

[英]Switch google adsense ad (mobile vs regular) based on user agent

I'm optimizing a site so that on a mobile browser it only shows the mobile adsense ad, and on desktop it only shows the regular one. 我正在优化一个网站,以便在移动浏览器上仅显示移动adsense广告,在桌面上仅显示常规广告。 Problem is the google code leaves a white space where these ads are on the page. 问题是Google代码在页面上的空白处留有空白。

I want to know if there is an easy way to programmatically insert the ad (JS) based on the user agent. 我想知道是否有一种简单的方法可以根据用户代理以编程方式插入广告(JS)。

Thanks. 谢谢。

It's very simple, see Masquerading Your Browser for details on how the User-Agent header works. 这非常简单,请参见伪装浏览器以获取有关User-Agent标头如何工作的详细信息。 See also the HTTP specification . 另请参见HTTP规范

You haven't said which server side language you're using. 您尚未说出正在使用哪种服务器端语言。 In PHP you would look at the value of $_SERVER['HTTP_USER_AGENT'] . 在PHP中,您将查看$_SERVER['HTTP_USER_AGENT']

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM