Add `userId` to GA tracking

This commit is contained in:
Robin Ward 2015-04-07 13:09:49 -04:00
parent 293ff05e3b
commit 65bfa574ce
2 changed files with 10 additions and 1 deletions

View File

@ -15,6 +15,15 @@ module ApplicationHelper
include ConfigurableUrls
include GlobalPath
def ga_universal_json
cookie_domain = SiteSetting.ga_universal_domain_name.gsub(/^http(s)?:\/\//, '')
result = {cookieDomain: cookie_domain}
if current_user.present?
result[:userId] = current_user.id
end
result.to_json.html_safe
end
def shared_session_key
if SiteSetting.long_polling_base_url != '/'.freeze && current_user
sk = "shared_session_key"

View File

@ -4,7 +4,7 @@
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', '<%= SiteSetting.ga_universal_tracking_code %>', '<%= SiteSetting.ga_universal_domain_name.gsub(/^http(s)?:\/\//, '') %>');
ga('create', '<%= SiteSetting.ga_universal_tracking_code %>', <%= ga_universal_json %>);
ga('send', 'pageview');
</script>