Hide Adsense on localhost

I have a site created in Ruby On Rails that has a lot of ads in different templates and views. It is hard to really remove every ad between tests and deployments.

I don’t know if Google approves of many impressions (even if without clicks) on localhost.

How do you deal with this problem?

Perhaps this is a good solution to set a variable / constant available to enable / disable declarations. Do you think this is a good solution? If so, how to declare a global variable for views?

+3
source share
2 answers

, , . , .

, / . .

, :

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

ad code here.

<% end %>

, :

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

:

<% if display_ads? %>

ad code here.

<% end %>
+7

, , Allowed Sites AdSense ( AdSense Setup > Allowed Sites) " ", , AdSense, localhost , .

, , , .

, , AdSense.

+9

Source: https://habr.com/ru/post/1717019/