Permalink
Browse files

Google tracking id for analytics

  • Loading branch information...
1 parent 62ca903 commit 17f6a01c6074e6afe589221e3f3f2ed2d85ce75e @penso committed Jan 12, 2013
View
4 app/controllers/application_controller.rb
@@ -16,6 +16,10 @@ def set_photographer
host_for_query_without_www = "#{request.server_name}"
host_for_query_without_www.gsub!(/^www\./, '')
+ logger.info request.server_name
+ logger.info host_for_query
+ logger.info host_for_query_without_www
+
@current_photographer = @photographer = User.first(:conditions => ['specific_url = ? OR specific_url = ? OR internal_url = ? OR internal_url = ?',
host_for_query, host_for_query_without_www, host_for_query, host_for_query_without_www],
:include => [:stories])
View
2 app/models/user.rb
@@ -54,5 +54,5 @@ def generate_permalink
# Setup accessible (or protected) attributes for your model
attr_accessible :email, :password, :password_confirmation, :remember_me,
:name, :description, :facebook_url, :specific_url, :twitter_url,
- :blog_url, :user_avatar
+ :blog_url, :user_avatar, :google_tracking_id
end
View
16 app/views/layouts/story.html.erb
@@ -57,5 +57,21 @@
<%= render :partial => 'shared/footer' unless params[:controller] == 'stories' %>
<%= yield :scripts %>
+
+ <% if @photographer.google_tracking_id %>
+ <script type="text/javascript">
+
+ var _gaq = _gaq || [];
+ _gaq.push(['_setAccount', '<%= @photographer.google_tracking_id %>']);
+ _gaq.push(['_trackPageview']);
+
+ (function() {
+ var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
+ ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
+ var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
+ })();
+
+ </script>
+ <% end %>
</body>
</html>
View
8 db/migrate/20130112235607_google_tracking_id.rb
@@ -0,0 +1,8 @@
+class GoogleTrackingId < ActiveRecord::Migration
+ def up
+ add_column :users, :google_tracking_id, :string
+ end
+
+ def down
+ end
+end

0 comments on commit 17f6a01

Please sign in to comment.