From 68713edd6184ac316c50e4eee1892247c8ad5b8b Mon Sep 17 00:00:00 2001 From: KMY Date: Mon, 27 Mar 2023 12:23:49 +0900 Subject: [PATCH] Add google ads tags --- app/views/shared/_web_app.html.haml | 9 +++++++++ config/initializers/content_security_policy.rb | 9 +++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/app/views/shared/_web_app.html.haml b/app/views/shared/_web_app.html.haml index 998cee9fa9..1964173bb5 100644 --- a/app/views/shared/_web_app.html.haml +++ b/app/views/shared/_web_app.html.haml @@ -9,6 +9,15 @@ = render_initial_state = javascript_pack_tag 'application', crossorigin: 'anonymous' + %script(src="https://www.googletagmanager.com/gtag/js?id=AW-11130587137" async) + + :javascript + window.dataLayer = window.dataLayer || []; + function gtag(){dataLayer.push(arguments);} + gtag('js', new Date()); + + gtag('config', 'AW-11130587137'); + .notranslate.app-holder#mastodon{ data: { props: Oj.dump(default_props) } } %noscript = image_pack_tag 'logo.svg', alt: 'Mastodon' diff --git a/config/initializers/content_security_policy.rb b/config/initializers/content_security_policy.rb index cb56293376..beefa5c1cf 100644 --- a/config/initializers/content_security_policy.rb +++ b/config/initializers/content_security_policy.rb @@ -16,6 +16,11 @@ media_host ||= host_to_url(ENV['S3_CLOUDFRONT_HOST']) media_host ||= host_to_url(ENV['S3_HOSTNAME']) if ENV['S3_ENABLED'] == 'true' media_host ||= assets_host +google_host = 'https://www.googletagmanager.com' +google_host2 = 'https://googleads.g.doubleclick.net' +google_host3 = 'https://www.googleadservices.com' +google_tag_script_hash = "'sha256-CS1WvLDd3zJOdxpEk+N+VigcWMa6V345p2HS0WYiFWE='" + Rails.application.config.content_security_policy do |p| p.base_uri :none p.default_src :none @@ -32,12 +37,12 @@ Rails.application.config.content_security_policy do |p| webpacker_urls = %w(ws http).map { |protocol| "#{protocol}#{Webpacker.dev_server.https? ? 's' : ''}://#{Webpacker.dev_server.host_with_port}" } p.connect_src :self, :data, :blob, assets_host, media_host, Rails.configuration.x.streaming_api_base_url, *webpacker_urls - p.script_src :self, :unsafe_inline, :unsafe_eval, assets_host + p.script_src :self, :unsafe_inline, :unsafe_eval, assets_host, google_host, google_host2, google_host3 p.child_src :self, :blob, assets_host p.worker_src :self, :blob, assets_host else p.connect_src :self, :data, :blob, assets_host, media_host, Rails.configuration.x.streaming_api_base_url - p.script_src :self, assets_host, "'wasm-unsafe-eval'" + p.script_src :self, assets_host, "'wasm-unsafe-eval'", google_host, google_host2, google_host3, google_tag_script_hash p.child_src :self, :blob, assets_host p.worker_src :self, :blob, assets_host end