diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index acebf3057..1281f0cfd 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -40,6 +40,12 @@ module ApplicationHelper javascript_tag("Modernizr.mq('(min-width:0)') || document.write(unescape('#{j javascript_include_tag("mbp-respond.min")}'));") end + # This will *only* fire if analytics are configured (don't panic!) + def include_advanced_segments + segment = current_user ? current_user.role_name : "unauthenticated" + javascript_tag("if(window._gaq) { _gaq.push([1, 'Role', '#{segment}']) }") + end + # Require jQuery from CDN if possible, falling back to vendored copy, and require # vendored jquery_ujs def jquery_include_tag diff --git a/app/models/user.rb b/app/models/user.rb index 62a3a472e..5489ac733 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -433,6 +433,10 @@ class User < ActiveRecord::Base Role.is_admin?(self.person) end + def role_name + role = Role.find_by_person_id(self.person.id) + role ? role.name : "user" + end def guard_unconfirmed_email self.unconfirmed_email = nil if unconfirmed_email.blank? || unconfirmed_email == email diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index 049dd2872..c7ad46c08 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -40,6 +40,7 @@ = set_current_user_in_javascript = translation_missing_warnings = current_user_atom_tag + = include_advanced_segments = yield(:head) = csrf_meta_tag diff --git a/app/views/layouts/post.html.haml b/app/views/layouts/post.html.haml index 25e7711da..b995d03d5 100644 --- a/app/views/layouts/post.html.haml +++ b/app/views/layouts/post.html.haml @@ -45,6 +45,8 @@ = set_asset_host = translation_missing_warnings = current_user_atom_tag + = include_advanced_segments + - if @post.present? %link{:rel => 'alternate', :type => "application/json+oembed", :href => "#{oembed_url(:url => post_url(@post))}"} = og_page_specific_tags(@post)