在本地主机上隐藏 Adsense

发布于 2024-08-03 22:26:33 字数 215 浏览 8 评论 0原文

我有一个用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

沉默的熊 2024-08-10 22:26:33

您可以做的一件事是转到 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.

If you put your ad code on a page not on this list, ads will still show, but impressions and clicks will not be recorded.

That way you can have ads in your development environment without worrying about accidentally clicking on your ads, and without skewing your AdSense stats.

染墨丶若流云 2024-08-10 22:26:33

我很确定只要您不点击广告,在本地展示广告就可以。我已经在几个项目上本地展示了广告,但我还没有被那个人关闭。

我没有完全相同的问题,我为不同类型的帐户启用/禁用了广告 - 我只是将广告代码放在一部分中。

您可以创建这样的部分代码:

<% unless ENV['RAILS_ENV'] == "development" %>

ad code here.

<% end %>

如果您在多个地方执行此操作,我会创建一个辅助方法:

def display_ads?
  ENV['RAILS_ENV'] != "development"
end

那么您的部分代码将变成这样:

<% if display_ads? %>

ad code here.

<% end %>

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:

<% unless ENV['RAILS_ENV'] == "development" %>

ad code here.

<% end %>

If you're doing this in more than one place I'd create a helper method:

def display_ads?
  ENV['RAILS_ENV'] != "development"
end

Then your partial code would become this:

<% if display_ads? %>

ad code here.

<% end %>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文