mirror of
https://github.com/discourse/discourse.git
synced 2024-12-13 01:03:59 +08:00
09b8a61f65
Per Google, sites are encouraged to upgrade from Universal Analytics v3 `analytics.js` to v4 `gtag.js` for Google Analytics tracking. We're giving admins the option to stay on the v3 API or migrate to v4. Admins can change the implementation they're using via the `ga_version` site setting. Eventually Google will deprecate v3, but our implementation gives admins the choice on what to use for now. We chose this implementation to make the change less error prone, as many site admins are using custom events via the v3 UA API. With the site stetting defaulted to `v3_analytics`, site analytics won't break until the admin is ready to make the migration. Additionally, in the v4 implementation, we do not enable automatic pageview tracking (on by default in the v4 API). Instead we rely on Discourse's page change API to report pageviews on transition to avoid double-tracking.
13 lines
552 B
Plaintext
13 lines
552 B
Plaintext
<%= tag.meta id: 'data-ga-universal-analytics', data: {
|
|
tracking_code: SiteSetting.ga_universal_tracking_code,
|
|
json: ga_universal_json,
|
|
auto_link_domains: SiteSetting.ga_universal_auto_link_domains
|
|
} %>
|
|
|
|
<% if SiteSetting.ga_version == "v3_analytics" %>
|
|
<%= preload_script "google-universal-analytics-v3" %>
|
|
<% elsif SiteSetting.ga_version == "v4_gtag" %>
|
|
<script async src="https://www.googletagmanager.com/gtag/js?id=<%= SiteSetting.ga_universal_tracking_code %>"></script>
|
|
<%= preload_script "google-universal-analytics-v4" %>
|
|
<% end %>
|