gace 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +32 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +1 -0
  5. data/CONTRIBUTING.md +67 -0
  6. data/Gemfile +4 -0
  7. data/LICENSE.txt +22 -0
  8. data/README.md +67 -0
  9. data/Rakefile +13 -0
  10. data/gace.gemspec +29 -0
  11. data/lib/gace.rb +5 -0
  12. data/lib/gace/controller_helpers.rb +26 -0
  13. data/lib/gace/railtie.rb +11 -0
  14. data/lib/gace/version.rb +3 -0
  15. data/lib/gace/view_helpers.rb +22 -0
  16. data/spec/dummy/README.rdoc +28 -0
  17. data/spec/dummy/Rakefile +6 -0
  18. data/spec/dummy/app/assets/images/.keep +0 -0
  19. data/spec/dummy/app/assets/javascripts/application.js +13 -0
  20. data/spec/dummy/app/assets/stylesheets/application.css +15 -0
  21. data/spec/dummy/app/controllers/application_controller.rb +5 -0
  22. data/spec/dummy/app/controllers/concerns/.keep +0 -0
  23. data/spec/dummy/app/controllers/examples_controller.rb +5 -0
  24. data/spec/dummy/app/experiments/test_pricing/expensive/examples/show.html.erb +1 -0
  25. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  26. data/spec/dummy/app/mailers/.keep +0 -0
  27. data/spec/dummy/app/models/.keep +0 -0
  28. data/spec/dummy/app/models/concerns/.keep +0 -0
  29. data/spec/dummy/app/views/examples/show.html.erb +1 -0
  30. data/spec/dummy/app/views/layouts/application.html.erb +15 -0
  31. data/spec/dummy/bin/bundle +3 -0
  32. data/spec/dummy/bin/rails +4 -0
  33. data/spec/dummy/bin/rake +4 -0
  34. data/spec/dummy/config.ru +4 -0
  35. data/spec/dummy/config/application.rb +29 -0
  36. data/spec/dummy/config/boot.rb +5 -0
  37. data/spec/dummy/config/database.yml +25 -0
  38. data/spec/dummy/config/environment.rb +5 -0
  39. data/spec/dummy/config/environments/development.rb +37 -0
  40. data/spec/dummy/config/environments/production.rb +78 -0
  41. data/spec/dummy/config/environments/test.rb +39 -0
  42. data/spec/dummy/config/initializers/assets.rb +8 -0
  43. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  44. data/spec/dummy/config/initializers/cookies_serializer.rb +3 -0
  45. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  46. data/spec/dummy/config/initializers/inflections.rb +16 -0
  47. data/spec/dummy/config/initializers/mime_types.rb +4 -0
  48. data/spec/dummy/config/initializers/session_store.rb +3 -0
  49. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  50. data/spec/dummy/config/locales/en.yml +23 -0
  51. data/spec/dummy/config/routes.rb +57 -0
  52. data/spec/dummy/config/secrets.yml +22 -0
  53. data/spec/dummy/lib/assets/.keep +0 -0
  54. data/spec/dummy/log/.keep +0 -0
  55. data/spec/dummy/public/404.html +67 -0
  56. data/spec/dummy/public/422.html +67 -0
  57. data/spec/dummy/public/500.html +66 -0
  58. data/spec/dummy/public/favicon.ico +0 -0
  59. data/spec/dummy/spec/controllers/examples_controller_spec.rb +27 -0
  60. data/spec/rails_helper.rb +52 -0
  61. data/spec/spec_helper.rb +85 -0
  62. data/spec/support/render_views.rb +3 -0
  63. metadata +251 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: daa51fe76dd40742233606f9f42522d7d25cbc0d
4
+ data.tar.gz: 8637b97fad5ebe838843c8e33b90eafb3cc1eef2
5
+ SHA512:
6
+ metadata.gz: 39ec8cc47378d74b7d7254db905a281110e13705f1e60eebc41b406af1ba4b86fe57b0ac29c83be06ea82c35fec5b0ca060aff9bc5bf9a87599a9616ec29a9bb
7
+ data.tar.gz: 959ad4d43b34fbed2bc009d400636e6ff0819643419a767f9110d22e2ffcc20da8c0c8f796f16d1b6af7f2919d051266746b2a0d0884a526ea77192d38ad6484
@@ -0,0 +1,32 @@
1
+ # documentation
2
+ /.yardoc
3
+ /_yardoc/
4
+ /doc/
5
+
6
+ # temp files
7
+ /tmp/
8
+ *.so
9
+ *.o
10
+ *.a
11
+ mkmf.log
12
+
13
+ # test files
14
+ /coverage/
15
+ /spec/reports/
16
+
17
+ # OSX files
18
+ .DS_Store
19
+
20
+ # bundler files
21
+ /pkg/
22
+ /.bundle/
23
+ /Gemfile.lock
24
+ *.bundle
25
+
26
+ # dummy app files
27
+ log/*.log
28
+ spec/dummy/db/*.sqlite3
29
+ spec/dummy/db/*.sqlite3-journal
30
+ spec/dummy/log/*.log
31
+ spec/dummy/tmp/
32
+ spec/dummy/.sass-cache
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
@@ -0,0 +1 @@
1
+ language: ruby
@@ -0,0 +1,67 @@
1
+ # Development Workflow
2
+
3
+ ## Resources
4
+ * [Git Workflow Presentation](https://docs.google.com/presentation/d/1euOiki_e4OQ4jymGhS-o3xcET8-KZhDONUolDlOVT30/edit?usp=sharing)
5
+ * [The Garage git extensions gem](https://github.com/thegarage/thegarage-gitx)
6
+
7
+ ## Step 1: Create feature branch...
8
+
9
+ ```bash
10
+ $ git start my-feature-branch
11
+ ```
12
+
13
+ * The `start` command ensures your branch name is valid and your codebase is uptodate.
14
+ * Use a descriptive branch name to help other developers (ex: fix-login-screen, api-refactor, payment-reconcile, etc)
15
+
16
+ ## Step 2: Implement the requested change...
17
+ Use [Test Driven Development](http://en.wikipedia.org/wiki/Test-driven_development) to ensure that the feature has proper code coverage.
18
+
19
+ * **RED** - Write tests for the desired behavior...
20
+ * **GREEN** - Write just enough code to get the tests to pass...
21
+ * **REFACTOR** - Cleanup for clarity and DRY-ness...
22
+
23
+
24
+ ### Development Protips™
25
+ * Follow [best practices](http://robots.thoughtbot.com/post/48933156625/5-useful-tips-for-a-better-commit-message) for git commit messages to communicate your changes.
26
+ * Add [ticket references to commits to automatically trigger product management workflows](http://help.sprint.ly/knowledgebase/articles/108139-available-scm-vcs-commands)
27
+ * Only write the **minimal** amount of code necessary to accomplish the given task.
28
+ * Ensure branch stays up-to-date with latest changes that are merged into master by using: `$ git update`
29
+ * Changes that are not directly related to the current feature should be cherry-picked into their own branch and merged separately.
30
+
31
+ ### Testing Protips™
32
+ * Every line of code should have associated unit tests. If it's not tested, it's probably broken and you just don't know it yet...
33
+ * Use [BetterSpecs.org](http://betterspecs.org/) as reference for writing readable and maintainable unit tests.
34
+
35
+
36
+ ## Step 3: Peer Review (aka Pull Request)...
37
+
38
+ ```
39
+ $ git review
40
+ ```
41
+
42
+ * Describe high level overview of the branch in pull request description. Include links to relevant resources.
43
+ * Record **artifacts** created by this feature (ex: screenshots of UI changes, screencasts of UX changes, logs from database migrations, etc)
44
+ * Document **follow-up** items/tasks that need to be addressed post-release
45
+
46
+ ### Questions to ask...
47
+ * Is there a simpler way to accomplish the task at hand?
48
+ * Are we solving the problems of today and not over engineering for the problems of tomorrow?
49
+
50
+ ## Step 4: QA
51
+
52
+ > With great power comes great responsibility…
53
+
54
+ * You are responsible to test your changes locally and in production environments as necessary
55
+ * Test changes in local development environment using the same process used by Continuous Integration with: `$ rake ci`
56
+ * Smoketest all changes locally and in staging environment when appropriate with: `$ git integrate staging`
57
+
58
+ ## Step 5: Sign-off and release
59
+
60
+ ```
61
+ $ git release
62
+ ```
63
+
64
+ * Ensure that build is green before releasing branch
65
+ * Pull requests must be signed off by team leads before release (preferrably via :shipit: emoji)
66
+
67
+ ## Step 5: Profit?
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in gace.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 The Garage
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,67 @@
1
+ [![Build Status](https://travis-ci.org/thegarage/gace.svg?branch=master)](https://travis-ci.org/thegarage/gace)
2
+
3
+ # GACE
4
+ > Google Analytics Content Experiments + Rails = AWESOME
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'gace'
12
+ ```
13
+
14
+ Update your view layout to include the necessary javascript.
15
+ **Make sure to include the javascript at the very top of your head element** (per Google Analytics installation instructions).
16
+
17
+ ```html
18
+ <<!DOCTYPE html>
19
+ <html>
20
+ <head>
21
+ <%= gace_javascript_include %>
22
+ </head>
23
+ <body>
24
+ </body>
25
+ </html>
26
+ ```
27
+
28
+ ## Usage
29
+
30
+ #### Setup experiment in Google Analytics
31
+ Configure each variation with a different `gace_var` parameter value.
32
+
33
+ example:
34
+ * control: `http://mysite.com/signup`
35
+ * variation one: `http://mysite.com/signup?gace_var=expensive`
36
+ * variation two: `http://mysite.com/signup?gace_var=cheap`
37
+
38
+ Make sure to record the newly created experiment ID.
39
+
40
+
41
+ #### Configure the experiment within Rails
42
+ ```ruby
43
+ class UsersController < ApplicationController
44
+ def show
45
+ define_experiment :test_pricing, '28391929-0'
46
+ end
47
+ end
48
+ ```
49
+
50
+ #### Create views for experiment variations
51
+
52
+ 1. Create a directory for the experiment: `app/experiments/EXPERIMENT_NAME` (ex: app/experiments/test_pricing)
53
+ 2. Create a directory for each experiment variation. The directory name **must match** the `gace_var` parameter
54
+ used when setting up the experiment in Google Analytics. (ex: `app/experiments/test_pricing/expensive` and `app/experiments/test_pricing/cheap`)
55
+ 3. Create any views/partials to be used for that variation. Each directory should mirror structure used by app/views and will override
56
+ the default views if one exists. (ex: `app/experiments/test_pricing/expensive/users/show.html.erb`)
57
+
58
+ ## Contributing
59
+
60
+ 1. Fork it ( https://github.com/thegarage/gace/fork )
61
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
62
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
63
+ 4. Push to the branch (`git push origin my-new-feature`)
64
+ 5. Create a new Pull Request
65
+
66
+ ## Related Projects
67
+ * [weebo](https://github.com/clemens/weebo)
@@ -0,0 +1,13 @@
1
+ require 'bundler/setup'
2
+ require "bundler/gem_tasks"
3
+
4
+ APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
5
+ load 'rails/tasks/engine.rake'
6
+
7
+ begin
8
+ require 'rspec/core/rake_task'
9
+ RSpec::Core::RakeTask.new(:spec)
10
+ rescue LoadError
11
+ end
12
+
13
+ task default: :spec
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'gace/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'gace'
8
+ spec.version = Gace::VERSION
9
+ spec.authors = ['Ryan Sonnek']
10
+ spec.email = ['ryan@codecrate.com']
11
+ spec.summary = %q(Rails integration for Google Analytics Content Experiments)
12
+ spec.description = %q(GACE is a simple way to integrate content experiments into your Rails application)
13
+ spec.homepage = 'https://github.com/thegarage/gace'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_development_dependency 'rails', '>= 4.1'
22
+
23
+ spec.add_development_dependency 'bundler', '~> 1.7'
24
+ spec.add_development_dependency 'rake', '~> 10.0'
25
+ spec.add_development_dependency 'rspec-rails'
26
+ spec.add_development_dependency 'sqlite3'
27
+ spec.add_development_dependency 'shoulda-matchers'
28
+ spec.add_development_dependency 'pry'
29
+ end
@@ -0,0 +1,5 @@
1
+ require 'gace/version'
2
+ require 'gace/railtie'
3
+
4
+ module Gace
5
+ end
@@ -0,0 +1,26 @@
1
+ module Gace
2
+ module ControllerHelpers
3
+ extend ActiveSupport::Concern
4
+
5
+ included do |base|
6
+ base.send(:attr_reader, :experiment_key)
7
+ base.helper_method :experiment_key
8
+ base.helper_method :experiment_control?
9
+ end
10
+
11
+ private
12
+
13
+ def experiment_control?
14
+ experiment_key && !params[:gace_var]
15
+ end
16
+
17
+ def define_experiment(name, experiment_key)
18
+ @experiment_key = experiment_key
19
+
20
+ if params[:gace_var]
21
+ variation_path = Rails.root.join('app/experiments', name.to_s, params[:gace_var])
22
+ prepend_view_path(variation_path)
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,11 @@
1
+ require 'gace/view_helpers'
2
+ require 'gace/controller_helpers'
3
+
4
+ module Gace
5
+ class Railtie < Rails::Railtie
6
+ initializer 'gace.view_helpers' do |app|
7
+ ActionView::Base.send :include, Gace::ViewHelpers
8
+ ActionController::Base.send :include, Gace::ControllerHelpers
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,3 @@
1
+ module Gace
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,22 @@
1
+ module Gace
2
+ module ViewHelpers
3
+ def gace_javascript_include
4
+ return unless experiment_control?
5
+ script = <<-EOS.strip_heredoc
6
+ <script>function utmx_section(){}function utmx(){}(function(){var
7
+ k='#{experiment_key}',d=document,l=d.location,c=d.cookie;
8
+ if(l.search.indexOf('utm_expid='+k)>0)return;
9
+ function f(n){if(c){var i=c.indexOf(n+'=');if(i>-1){var j=c.
10
+ indexOf(';',i);return escape(c.substring(i+n.length+1,j<0?c.
11
+ length:j))}}}var x=f('__utmx'),xx=f('__utmxx'),h=l.hash;d.write(
12
+ '<sc'+'ript src="'+'http'+(l.protocol=='https:'?'s://ssl':
13
+ '://www')+'.google-analytics.com/ga_exp.js?'+'utmxkey='+k+
14
+ '&utmx='+(x?x:'')+'&utmxx='+(xx?xx:'')+'&utmxtime='+new Date().
15
+ valueOf()+(h?'&utmxhash='+escape(h.substr(1)):'')+
16
+ '" type="text/javascript" charset="utf-8"><\/sc'+'ript>')})();
17
+ </script><script>utmx('url','A/B');</script>
18
+ EOS
19
+ script.html_safe
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,28 @@
1
+ == README
2
+
3
+ This README would normally document whatever steps are necessary to get the
4
+ application up and running.
5
+
6
+ Things you may want to cover:
7
+
8
+ * Ruby version
9
+
10
+ * System dependencies
11
+
12
+ * Configuration
13
+
14
+ * Database creation
15
+
16
+ * Database initialization
17
+
18
+ * How to run the test suite
19
+
20
+ * Services (job queues, cache servers, search engines, etc.)
21
+
22
+ * Deployment instructions
23
+
24
+ * ...
25
+
26
+
27
+ Please feel free to use a different markup language if you do not plan to run
28
+ <tt>rake doc:app</tt>.
@@ -0,0 +1,6 @@
1
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
2
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
+
4
+ require File.expand_path('../config/application', __FILE__)
5
+
6
+ Rails.application.load_tasks
File without changes
@@ -0,0 +1,13 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
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.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file.
9
+ //
10
+ // Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require_tree .
@@ -0,0 +1,15 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
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.
7
+ *
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.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
@@ -0,0 +1,5 @@
1
+ class ApplicationController < ActionController::Base
2
+ # Prevent CSRF attacks by raising an exception.
3
+ # For APIs, you may want to use :null_session instead.
4
+ protect_from_forgery with: :exception
5
+ end
@@ -0,0 +1,5 @@
1
+ class ExamplesController < ApplicationController
2
+ def show
3
+ define_experiment :test_pricing, '28391929-0'
4
+ end
5
+ end
@@ -0,0 +1 @@
1
+ This is the expensive variation template
@@ -0,0 +1,2 @@
1
+ module ApplicationHelper
2
+ end
File without changes
File without changes
File without changes
@@ -0,0 +1 @@
1
+ This is the control template
@@ -0,0 +1,15 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <%= gace_javascript_include %>
5
+ <title>Dummy</title>
6
+ <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
7
+ <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
8
+ <%= csrf_meta_tags %>
9
+ </head>
10
+ <body>
11
+
12
+ <%= yield %>
13
+
14
+ </body>
15
+ </html>