FEATURE: cross-domain tracking for Google universal analytics

This commit is contained in:
Neil Lalonde 2017-07-13 15:21:44 -04:00
parent 7fb62bdab4
commit 3ebd8838af
4 changed files with 13 additions and 0 deletions

View File

@ -23,6 +23,9 @@ module ApplicationHelper
if current_user.present?
result[:userId] = current_user.id
end
if SiteSetting.ga_universal_auto_link_domains.present?
result[:allowLinker] = true
end
result.to_json.html_safe
end

View File

@ -5,4 +5,10 @@
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', '<%= SiteSetting.ga_universal_tracking_code %>', <%= ga_universal_json %>);
<% if SiteSetting.ga_universal_auto_link_domains.present? %>
ga('require', 'linker');
ga('linker:autoLink', <%= raw SiteSetting.ga_universal_auto_link_domains.split('|').to_json %>);
<% end %>
</script>

View File

@ -1035,6 +1035,7 @@ en:
ga_domain_name: "OBSOLETE: Google analytics (ga.js) domain name, eg: mysite.com; see http://google.com/analytics"
ga_universal_tracking_code: "Google Universal Analytics (analytics.js) tracking code code, eg: UA-12345678-9; see http://google.com/analytics"
ga_universal_domain_name: "Google Universal Analytics (analytics.js) domain name, eg: mysite.com; see http://google.com/analytics"
ga_universal_auto_link_domains: "Enable Google Universal Analytics (analytics.js) cross-domain tracking. Outgoing links to these domains will have the client id added to them. See Google's Cross-Domain Tracking guide."
gtm_container_id: "Google Tag Manager container id. eg: GTM-ABCDEF"
enable_escaped_fragments: "Fall back to Google's Ajax-Crawling API if no webcrawler is detected. See https://developers.google.com/webmasters/ajax-crawling/docs/learn-more"
allow_moderators_to_create_categories: "Allow moderators to create new categories"

View File

@ -103,6 +103,9 @@ basic:
ga_universal_domain_name:
client: true
default: 'auto'
ga_universal_auto_link_domains:
default: ''
type: list
ga_tracking_code:
client: true
default: ''