在本地主机上隐藏 Adsense
我有一个用 Ruby On Rails 构建的网站,其中有许多不同模板和视图中的广告。实际上很难在测试和部署之间删除每个广告。
我不知道 Google 是否批准本地主机上的许多展示次数(即使没有点击)。
您如何处理这个问题?
也许设置一个随处可用的变量/常量以轻松启用/禁用广告是一个很好的解决方案。 您认为这是一个好的解决方案吗?如果是这样,如何为视图声明全局变量?
I have a site built in Ruby On Rails which has many ads in different templates and views. It is hard to actualy remove each ad between tests and deployments.
I don't know whether Google approves many impressions (even if without clicks) on localhost.
How do you deal with this issue?
Maybe it is a good solution to set a variable/constant available everywere to enable/disable ads easily.
Do you think it is a good solution? If so, how do I declare a global variable for views?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以做的一件事是转到 AdSense 的允许的网站设置(位于AdSense 设置 > 允许的网站选项卡)并选中“仅允许某些网站为我的帐户展示广告”选项,然后添加允许显示 AdSense 的所有域,不包括
localhost 或任何其他开发、临时或非生产域。
这样,您就可以在开发环境中投放广告,而不必担心意外点击您的广告,也不会影响您的 AdSense 统计数据。
One thing you can do is go to the Allowed Sites settings at AdSense (it’s in the AdSense Setup > Allowed Sites tab) and check the “only allow certain sites to show ads for my account” option, and then add all the domains where AdSense is allowed to appear, without including
localhost
or any other development, staging or non-production domains, obviously.That way you can have ads in your development environment without worrying about accidentally clicking on your ads, and without skewing your AdSense stats.
我很确定只要您不点击广告,在本地展示广告就可以。我已经在几个项目上本地展示了广告,但我还没有被那个人关闭。
我没有完全相同的问题,我为不同类型的帐户启用/禁用了广告 - 我只是将广告代码放在一部分中。
您可以创建这样的部分代码:
如果您在多个地方执行此操作,我会创建一个辅助方法:
那么您的部分代码将变成这样:
I'm pretty sure displaying ads locally is fine as long as you don't click them. I've displayed ads locally on a few projects and I have yet to be shut down by the man.
I don't have the exact same issue, I have ads enabled/disabled for different types of accounts - I just put the ad code in a partial.
You could create a partial like this:
If you're doing this in more than one place I'd create a helper method:
Then your partial code would become this: