mirror of
https://github.com/discourse/discourse.git
synced 2026-08-04 10:39:43 +08:00
**Previously**, loading Discourse inside a full app embed iframe caused the host page's `GTM`, Google Analytics, and Adobe Analytics scripts to fire a second time, doubling pageviews and re-injecting ad pixels. **In this update**, introduce the `suppress_third_party_analytics_in_embed` site setting (default on) which omits those script tags from responses served with `?embed_mode=true`.
33 lines
1 KiB
Ruby
Vendored
33 lines
1 KiB
Ruby
Vendored
# frozen_string_literal: true
|
|
|
|
module CommonHelper
|
|
def render_google_universal_analytics_code
|
|
return if suppress_analytics_in_embed?
|
|
if Rails.env.production? && SiteSetting.ga_universal_tracking_code.present?
|
|
render partial: "common/google_universal_analytics"
|
|
end
|
|
end
|
|
|
|
def render_google_tag_manager_head_code
|
|
return if suppress_analytics_in_embed?
|
|
render partial: "common/google_tag_manager_head" if SiteSetting.gtm_container_id.present?
|
|
end
|
|
|
|
def render_google_tag_manager_body_code
|
|
return if suppress_analytics_in_embed?
|
|
render partial: "common/google_tag_manager_body" if SiteSetting.gtm_container_id.present?
|
|
end
|
|
|
|
def render_adobe_analytics_tags_code
|
|
return if suppress_analytics_in_embed?
|
|
if SiteSetting.adobe_analytics_tags_url.present?
|
|
content_tag(:script, "", src: SiteSetting.adobe_analytics_tags_url, async: true)
|
|
end
|
|
end
|
|
|
|
private
|
|
|
|
def suppress_analytics_in_embed?
|
|
params[:embed_mode].present? && SiteSetting.suppress_third_party_analytics_in_embed
|
|
end
|
|
end
|