Skip to content

A platform for community discussion. Free, open, simple.

FEATURE: Introduce 'google_site_verification_token' site setting (#35229)

David Taylorfd4cdf862d50
diff --git a/app/views/layouts/_head.html.erb b/app/views/layouts/_head.html.erb
index 71772c93697..1011a8340a6 100644
--- a/app/views/layouts/_head.html.erb
+++ b/app/views/layouts/_head.html.erb
@@ -15,4 +15,7 @@
<% end %>
<%= canonical_link_tag %>
<%= render_sitelinks_search_tag %>
+<% if SiteSetting.google_site_verification_token.present? %>
+ <meta name="google-site-verification" content="<%= SiteSetting.google_site_verification_token %>">
+<% end %>
<link rel="search" type="application/opensearchdescription+xml" href="<%= Discourse.base_url %>/opensearch.xml" title="<%= SiteSetting.title %> Search">
diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml
index 1586605aece..71c9514315a 100644
--- a/config/locales/server.en.yml
+++ b/config/locales/server.en.yml
@@ -1888,6 +1888,7 @@ en:
ga_universal_domain_name: "Google Universal Analytics domain name, eg: mysite.com; see <a href='https://google.com/analytics' target='_blank'>https://google.com/analytics</a>"
ga_universal_auto_link_domains: "Enable Google Universal Analytics cross-domain tracking. Outgoing links to these domains will have the client id added to them. See <a href='https://support.google.com/analytics/answer/1034342?hl=en' target='_blank'>Google's Cross-Domain Tracking guide.</a>"
gtm_container_id: "Google Tag Manager container id. eg: GTM-ABCD12E. <br/>Note: To use GTM when the Content Security Policy (CSP) is enabled, see the documentation on meta: <a href='https://meta.discourse.org/t/use-nonces-in-google-tag-manager-scripts/188296' target='_blank'>Use nonces in Google Tag Manager scripts</a>."
+ google_site_verification_token: Google search console verification token. Will be included as a meta tag in the HTML head.
enable_escaped_fragments: "Fall back to Google's Ajax-Crawling API if no webcrawler is detected. See <a href='https://developers.google.com/webmasters/ajax-crawling/docs/learn-more' target='_blank'>https://developers.google.com/webmasters/ajax-crawling/docs/learn-more</a>"
moderators_manage_categories: "Allow moderators to create and manage categories"
moderators_manage_groups: "Allow moderators to create and manage groups"
diff --git a/config/site_settings.yml b/config/site_settings.yml
index afe8b38ae7c..6cc19f486da 100644
--- a/config/site_settings.yml
+++ b/config/site_settings.yml
@@ -238,6 +238,9 @@ basic:
default: ""
regex: "^GTM-"
area: "analytics"
+ google_site_verification_token:
+ default: ""
+ area: "analytics"
top_menu:
client: true
refresh: true
diff --git a/spec/requests/application_controller_spec.rb b/spec/requests/application_controller_spec.rb
index 102164c8aac..04ae21442de 100644
--- a/spec/requests/application_controller_spec.rb
+++ b/spec/requests/application_controller_spec.rb
@@ -1855,4 +1855,30 @@ RSpec.describe ApplicationController do
end
end
end
+
+ describe "google site verification" do
+ it "is omitted by default" do
+ get "/"
+ expect(response.body).not_to include("google-site-verification")
+ end
+
+ it "is included when the site setting is set" do
+ SiteSetting.google_site_verification_token = "verification_token"
+ get "/"
+ expect(response.body).to include(
+ '<meta name="google-site-verification" content="verification_token">',
+ )
+
+ SiteSetting.login_required = true
+ get "/"
+ expect(response.body).to include(
+ '<meta name="google-site-verification" content="verification_token">',
+ )
+
+ get "/", headers: { "User-Agent" => "Googlebot" }
+ expect(response.body).to include(
+ '<meta name="google-site-verification" content="verification_token">',
+ )
+ end
+ end
end