0
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-08-04 10:39:43 +08:00
discourse/app/helpers/common_helper.rb
Rafael dos Santos Silva 4ce1685a72
FIX: Skip third-party analytics tags in full app embed iframes (#39534)
**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`.
2026-04-24 14:58:45 -03:00

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