analytics-rails 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/MIT-LICENSE +1 -1
  3. data/README.md +13 -7
  4. data/Rakefile +1 -14
  5. data/lib/analytics/rails.rb +2 -1
  6. data/lib/analytics/rails/extensions/action_view/base.rb +38 -0
  7. data/lib/analytics/rails/railtie.rb +4 -2
  8. data/lib/analytics/rails/version.rb +1 -1
  9. data/test/dummy/Rakefile +1 -2
  10. data/test/dummy/app/assets/javascripts/application.js +2 -2
  11. data/test/dummy/app/assets/stylesheets/application.css +6 -4
  12. data/test/dummy/app/views/layouts/application.html.erb +9 -12
  13. data/test/dummy/bin/bundle +1 -0
  14. data/test/dummy/bin/rails +2 -1
  15. data/test/dummy/bin/rake +1 -0
  16. data/test/dummy/bin/setup +30 -0
  17. data/test/dummy/config.ru +1 -1
  18. data/test/dummy/config/application.rb +6 -2
  19. data/test/dummy/config/boot.rb +1 -1
  20. data/test/dummy/config/environment.rb +1 -1
  21. data/test/dummy/config/environments/development.rb +14 -5
  22. data/test/dummy/config/environments/production.rb +18 -26
  23. data/test/dummy/config/environments/test.rb +10 -12
  24. data/test/dummy/config/initializers/assets.rb +11 -0
  25. data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
  26. data/test/dummy/config/initializers/mime_types.rb +1 -2
  27. data/test/dummy/config/initializers/session_store.rb +1 -1
  28. data/test/dummy/config/routes.rb +2 -2
  29. data/test/dummy/config/secrets.yml +22 -0
  30. data/test/dummy/log/test.log +108 -0
  31. data/test/dummy/public/404.html +58 -55
  32. data/test/dummy/public/422.html +58 -55
  33. data/test/dummy/public/500.html +57 -54
  34. data/test/tag_test.rb +47 -0
  35. data/test/test_helper.rb +5 -14
  36. metadata +21 -46
  37. data/lib/analytics/rails/action_view/base.rb +0 -43
  38. data/test/dummy/README.rdoc +0 -28
  39. data/test/dummy/config/database.yml +0 -25
  40. data/test/dummy/config/initializers/secret_token.rb +0 -13
  41. data/test/dummy/db/schema.rb +0 -16
  42. data/test/dummy/tmp/cache/assets/test/sprockets/13fe41fee1fe35b49d145bcc06610705 +0 -0
  43. data/test/dummy/tmp/cache/assets/test/sprockets/2f5173deea6c795b8fdde723bb4b63af +0 -0
  44. data/test/dummy/tmp/cache/assets/test/sprockets/357970feca3ac29060c1e3861e2c0953 +0 -0
  45. data/test/dummy/tmp/cache/assets/test/sprockets/cffd775d018f68ce5dba1ee0d951a994 +0 -0
  46. data/test/dummy/tmp/cache/assets/test/sprockets/d771ace226fc8215a3572e0aa35bb0d6 +0 -0
  47. data/test/dummy/tmp/cache/assets/test/sprockets/f7cbd26ba1d28d48de824f0e94586655 +0 -0
  48. data/test/include_tag_test.rb +0 -28
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cd3ba70669af4c236ff581a4e5b9df6c61e99294
4
- data.tar.gz: 1e43ef66ac86dc5f545e765d756e8a083b40e61a
3
+ metadata.gz: 080f8fc44db20a350e36c321e1a3356e78680e8d
4
+ data.tar.gz: 61190bd2756867548d6013d0c78cf9bc5bbd4e1a
5
5
  SHA512:
6
- metadata.gz: 386df7ea2f9d7b2af60fc41450ddc4be24cd8b070fa62d1e9489a164ee837c702b09d1a4782b584b448ddc74937006d543d62941cb84cd0a05bfe1dcf8da5b3f
7
- data.tar.gz: 5f4fe4012d83c6b4ab85f777754baf0b083b9749a37b0e8344242d856d3bf266bc5e903ed6d90e80c5b1497e44a65cc18cb54b44291c5eacca14c662215eb053
6
+ metadata.gz: 65e11c64e560b197ac9a1e10c3e0d73153fa3d81acc7b4ba7a927781823c2b82a45952aa0ee6c37db8b030b837d8e113f5663b4c2ddf4c41b4ec4477d0699d2a
7
+ data.tar.gz: 55b42cd6c6c5f58b80aca7cf6f941fbdae8c124f9616747724135f492e6bcee735c32c190a596bc07bbb65da938bee52bc9d35e1e4749f9d272463f24b94ddf6
@@ -1,4 +1,4 @@
1
- Copyright 2015 Mathías Montossi
1
+ Copyright 2016 Mathías Montossi
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -5,7 +5,13 @@
5
5
 
6
6
  # Analytics Rails
7
7
 
8
- Adds a simple helper to create the google analytics include tag.
8
+ Adds a helper to create the google analytics script in rails.
9
+
10
+ ## Why
11
+
12
+ I did this gem to:
13
+
14
+ - Have a simple but versatile way to include google analytics.
9
15
 
10
16
  ## Install
11
17
 
@@ -21,22 +27,22 @@ $ bundle
21
27
 
22
28
  ## Usage
23
29
 
24
- In your layout add a line like this in your head:
30
+ In your layout add a line like this in your head or before close body:
25
31
  ```erb
26
32
  <%= google_analytics_include_tag 'your-id' %>
27
33
  ```
28
34
 
29
- You can add custom events:
35
+ You can add variables:
30
36
  ```erb
31
- <%= google_analytics_include_tag 'your-id', events: [['Popup', 'Click']] %>
37
+ <%= google_analytics_include_tag 'your-id', user: 1 %>
32
38
  ```
33
39
 
34
- And custom variables:
40
+ And custom events after the include tag:
35
41
  ```erb
36
- <%= google_analytics_include_tag 'your-id', variables: [[1, 'Member', 'Yes', 1]] %>
42
+ <%= google_analytics_event_tag 'popup', 'click' %>
37
43
  ```
38
44
 
39
- NOTE: Will only show the include tag in production environment.
45
+ NOTE: Will only show the tags in production environment.
40
46
 
41
47
  ## Credits
42
48
 
data/Rakefile CHANGED
@@ -4,19 +4,6 @@ rescue LoadError
4
4
  puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
5
  end
6
6
 
7
- require 'rdoc/task'
8
-
9
- RDoc::Task.new(:rdoc) do |rdoc|
10
- rdoc.rdoc_dir = 'rdoc'
11
- rdoc.title = 'AnalyticsRails'
12
- rdoc.options << '--line-numbers'
13
- rdoc.rdoc_files.include('README.rdoc')
14
- rdoc.rdoc_files.include('lib/**/*.rb')
15
- end
16
-
17
-
18
-
19
-
20
7
  Bundler::GemHelper.install_tasks
21
8
 
22
9
  require 'rake/testtask'
@@ -26,7 +13,7 @@ Rake::TestTask.new(:test) do |t|
26
13
  t.libs << 'test'
27
14
  t.pattern = 'test/**/*_test.rb'
28
15
  t.verbose = false
16
+ t.warning = false
29
17
  end
30
18
 
31
-
32
19
  task default: :test
@@ -1,5 +1,6 @@
1
- require 'analytics/rails/action_view/base'
1
+ require 'analytics/rails/extensions/action_view/base'
2
2
  require 'analytics/rails/railtie'
3
+ require 'analytics/rails/version'
3
4
 
4
5
  module Analytics
5
6
  module Rails
@@ -0,0 +1,38 @@
1
+ module Analytics
2
+ module Rails
3
+ module Extensions
4
+ module ActionView
5
+ module Base
6
+
7
+ def google_analytics_include_tag(*args)
8
+ if ::Rails.env.production?
9
+ options = args.extract_options!
10
+ id = args.first
11
+ variables = options.to_json
12
+ content_tag :script, <<-SCRIPT.strip_heredoc.html_safe, type: 'text/javascript'
13
+ (function(i,s,o,g,r,a,m){i["GoogleAnalyticsObject"]=r;i[r]=i[r]||function(){
14
+ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
15
+ m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
16
+ })(window,document,"script","https://www.google-analytics.com/analytics.js","ga");
17
+ ga("create", "#{id}", "auto");
18
+ ga("send", "pageview", #{variables});
19
+ SCRIPT
20
+ end
21
+ end
22
+
23
+ def google_analytics_event_tag(*args)
24
+ if ::Rails.env.production?
25
+ options = args.extract_options!
26
+ args = args.map(&:to_json).join(', ')
27
+ variables = options.to_json
28
+ content_tag :script, <<-SCRIPT.strip_heredoc.html_safe, type: 'text/javascript'
29
+ ga("send", "event", #{args}, #{variables});
30
+ SCRIPT
31
+ end
32
+ end
33
+
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -2,8 +2,10 @@ module Analytics
2
2
  module Rails
3
3
  class Railtie < ::Rails::Railtie
4
4
 
5
- initializer 'analytics.rails' do
6
- ::ActionView::Base.send :include, Analytics::Rails::ActionView::Base
5
+ initializer :analytics do
6
+ ::ActionView::Base.include(
7
+ Analytics::Rails::Extensions::ActionView::Base
8
+ )
7
9
  end
8
10
 
9
11
  end
@@ -1,7 +1,7 @@
1
1
  module Analytics
2
2
  module Rails
3
3
 
4
- VERSION = '0.2.1'
4
+ VERSION = '0.3.0'
5
5
 
6
6
  end
7
7
  end
@@ -2,5 +2,4 @@
2
2
  # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
3
 
4
4
  require File.expand_path('../config/application', __FILE__)
5
-
6
- Dummy::Application.load_tasks
5
+ Rails.application.load_tasks
@@ -2,12 +2,12 @@
2
2
  // listed below.
3
3
  //
4
4
  // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
- // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
5
+ // or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
6
6
  //
7
7
  // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
8
  // compiled file.
9
9
  //
10
- // Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
10
+ // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
11
11
  // about supported directives.
12
12
  //
13
13
  //= require_tree .
@@ -3,11 +3,13 @@
3
3
  * listed below.
4
4
  *
5
5
  * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
- * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
6
+ * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
7
  *
8
- * You're free to add application-wide styles to this file and they'll appear at the top of the
9
- * compiled file, but it's generally better to create a new file per style scope.
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any styles
10
+ * defined in the other CSS/SCSS files in this directory. It is generally better to create a new
11
+ * file per style scope.
10
12
  *
11
- *= require_self
12
13
  *= require_tree .
14
+ *= require_self
13
15
  */
@@ -1,15 +1,12 @@
1
1
  <!DOCTYPE html>
2
2
  <html>
3
- <head>
4
- <title>Dummy</title>
5
- <%= stylesheet_link_tag 'application', media: 'all' %>
6
- <%= javascript_include_tag 'application' %>
7
- <%= google_analytics_include_tag 'your-id' %>
8
- <%= csrf_meta_tags %>
9
- </head>
10
- <body>
11
-
12
- <%= yield %>
13
-
14
- </body>
3
+ <head>
4
+ <title>Dummy</title>
5
+ <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
6
+ <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+ <%= yield %>
11
+ </body>
15
12
  </html>
@@ -1,3 +1,4 @@
1
1
  #!/usr/bin/env ruby
2
+
2
3
  ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
3
4
  load Gem.bin_path('bundler', 'bundle')
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
- APP_PATH = File.expand_path('../../config/application', __FILE__)
2
+
3
+ APP_PATH = File.expand_path('../../config/application', __FILE__)
3
4
  require_relative '../config/boot'
4
5
  require 'rails/commands'
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+
2
3
  require_relative '../config/boot'
3
4
  require 'rake'
4
5
  Rake.application.run
@@ -0,0 +1,30 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'pathname'
4
+
5
+ # path to your application root.
6
+ APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
7
+
8
+ Dir.chdir APP_ROOT do
9
+ # This script is a starting point to setup your application.
10
+ # Add necessary setup steps to this file:
11
+
12
+ puts '== Installing dependencies =='
13
+ system 'gem install bundler --conservative'
14
+ system 'bundle check || bundle install'
15
+
16
+ # puts "\n== Copying sample files =="
17
+ # unless File.exist?('config/database.yml')
18
+ # system 'cp config/database.yml.sample config/database.yml'
19
+ # end
20
+
21
+ puts "\n== Preparing database =="
22
+ system 'bin/rake db:setup'
23
+
24
+ puts "\n== Removing old logs and tempfiles =="
25
+ system 'rm -f log/*'
26
+ system 'rm -rf tmp/cache'
27
+
28
+ puts "\n== Restarting application server =="
29
+ system 'touch tmp/restart.txt'
30
+ end
@@ -1,4 +1,4 @@
1
1
  # This file is used by Rack-based servers to start the application.
2
2
 
3
- require ::File.expand_path('../config/environment', __FILE__)
3
+ require ::File.expand_path('../config/environment', __FILE__)
4
4
  run Rails.application
@@ -1,6 +1,11 @@
1
1
  require File.expand_path('../boot', __FILE__)
2
2
 
3
- require 'rails/all'
3
+ require 'active_model/railtie'
4
+ require 'action_controller/railtie'
5
+ require 'action_mailer/railtie'
6
+ require 'action_view/railtie'
7
+ require 'sprockets/railtie'
8
+ require 'rails/test_unit/railtie'
4
9
 
5
10
  Bundler.require(*Rails.groups)
6
11
  require 'analytics-rails'
@@ -20,4 +25,3 @@ module Dummy
20
25
  # config.i18n.default_locale = :de
21
26
  end
22
27
  end
23
-
@@ -1,5 +1,5 @@
1
1
  # Set up gems listed in the Gemfile.
2
2
  ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../../Gemfile', __FILE__)
3
3
 
4
- require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
4
+ require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
5
5
  $LOAD_PATH.unshift File.expand_path('../../../../lib', __FILE__)
@@ -2,4 +2,4 @@
2
2
  require File.expand_path('../application', __FILE__)
3
3
 
4
4
  # Initialize the Rails application.
5
- Dummy::Application.initialize!
5
+ Rails.application.initialize!
@@ -1,4 +1,4 @@
1
- Dummy::Application.configure do
1
+ Rails.application.configure do
2
2
  # Settings specified here will take precedence over those in config/application.rb.
3
3
 
4
4
  # In the development environment your application's code is reloaded on
@@ -10,7 +10,7 @@ Dummy::Application.configure do
10
10
  config.eager_load = false
11
11
 
12
12
  # Show full error reports and disable caching.
13
- config.consider_all_requests_local = true
13
+ config.consider_all_requests_local = true
14
14
  config.action_controller.perform_caching = false
15
15
 
16
16
  # Don't care if the mailer can't send.
@@ -19,11 +19,20 @@ Dummy::Application.configure do
19
19
  # Print deprecation notices to the Rails logger.
20
20
  config.active_support.deprecation = :log
21
21
 
22
- # Raise an error on page load if there are pending migrations
23
- config.active_record.migration_error = :page_load
24
-
25
22
  # Debug mode disables concatenation and preprocessing of assets.
26
23
  # This option may cause significant delays in view rendering with a large
27
24
  # number of complex assets.
28
25
  config.assets.debug = true
26
+
27
+ # Asset digests allow you to set far-future HTTP expiration dates on all assets,
28
+ # yet still be able to expire them through the digest params.
29
+ config.assets.digest = true
30
+
31
+ # Adds additional error checking when serving assets at runtime.
32
+ # Checks for improperly declared sprockets dependencies.
33
+ # Raises helpful error messages.
34
+ config.assets.raise_runtime_errors = true
35
+
36
+ # Raises error for missing translations
37
+ # config.action_view.raise_on_missing_translations = true
29
38
  end
@@ -1,30 +1,28 @@
1
- Dummy::Application.configure do
1
+ Rails.application.configure do
2
2
  # Settings specified here will take precedence over those in config/application.rb.
3
3
 
4
4
  # Code is not reloaded between requests.
5
5
  config.cache_classes = true
6
6
 
7
7
  # Eager load code on boot. This eager loads most of Rails and
8
- # your application in memory, allowing both thread web servers
8
+ # your application in memory, allowing both threaded web servers
9
9
  # and those relying on copy on write to perform better.
10
10
  # Rake tasks automatically ignore this option for performance.
11
11
  config.eager_load = true
12
12
 
13
13
  # Full error reports are disabled and caching is turned on.
14
- config.consider_all_requests_local = false
14
+ config.consider_all_requests_local = false
15
15
  config.action_controller.perform_caching = true
16
16
 
17
17
  # Enable Rack::Cache to put a simple HTTP cache in front of your application
18
18
  # Add `rack-cache` to your Gemfile before enabling this.
19
- # For large-scale production use, consider using a caching reverse proxy like nginx, varnish or squid.
19
+ # For large-scale production use, consider using a caching reverse proxy like
20
+ # NGINX, varnish or squid.
20
21
  # config.action_dispatch.rack_cache = true
21
22
 
22
- # Disable Rails's static asset server (Apache or nginx will already do this).
23
- if Rails::VERSION::MAJOR == 4 && Rails::VERSION::MINOR >= 2
24
- config.serve_static_files = false
25
- else
26
- config.serve_static_assets = false
27
- end
23
+ # Disable serving static files from the `/public` folder by default since
24
+ # Apache or NGINX already handles this.
25
+ config.serve_static_files = ENV['RAILS_SERVE_STATIC_FILES'].present?
28
26
 
29
27
  # Compress JavaScripts and CSS.
30
28
  config.assets.js_compressor = :uglifier
@@ -33,21 +31,22 @@ Dummy::Application.configure do
33
31
  # Do not fallback to assets pipeline if a precompiled asset is missed.
34
32
  config.assets.compile = false
35
33
 
36
- # Generate digests for assets URLs.
34
+ # Asset digests allow you to set far-future HTTP expiration dates on all assets,
35
+ # yet still be able to expire them through the digest params.
37
36
  config.assets.digest = true
38
37
 
39
- # Version of your assets, change this if you want to expire all your assets.
40
- config.assets.version = '1.0'
38
+ # `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb
41
39
 
42
40
  # Specifies the header that your server uses for sending files.
43
- # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache
44
- # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx
41
+ # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache
42
+ # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX
45
43
 
46
44
  # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
47
45
  # config.force_ssl = true
48
46
 
49
- # Set to :debug to see everything in the log.
50
- config.log_level = :info
47
+ # Use the lowest log level to ensure availability of diagnostic information
48
+ # when problems arise.
49
+ config.log_level = :debug
51
50
 
52
51
  # Prepend all log lines with the following tags.
53
52
  # config.log_tags = [ :subdomain, :uuid ]
@@ -59,26 +58,19 @@ Dummy::Application.configure do
59
58
  # config.cache_store = :mem_cache_store
60
59
 
61
60
  # Enable serving of images, stylesheets, and JavaScripts from an asset server.
62
- # config.action_controller.asset_host = "http://assets.example.com"
63
-
64
- # Precompile additional assets.
65
- # application.js, application.css, and all non-JS/CSS in app/assets folder are already added.
66
- # config.assets.precompile += %w( search.js )
61
+ # config.action_controller.asset_host = 'http://assets.example.com'
67
62
 
68
63
  # Ignore bad email addresses and do not raise email delivery errors.
69
64
  # Set this to true and configure the email server for immediate delivery to raise delivery errors.
70
65
  # config.action_mailer.raise_delivery_errors = false
71
66
 
72
67
  # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
73
- # the I18n.default_locale when a translation can not be found).
68
+ # the I18n.default_locale when a translation cannot be found).
74
69
  config.i18n.fallbacks = true
75
70
 
76
71
  # Send deprecation notices to registered listeners.
77
72
  config.active_support.deprecation = :notify
78
73
 
79
- # Disable automatic flushing of the log to improve performance.
80
- # config.autoflush_log = false
81
-
82
74
  # Use default logging formatter so that PID and timestamp are not suppressed.
83
75
  config.log_formatter = ::Logger::Formatter.new
84
76
  end