rails_apps_pages 0.5.10 → 0.5.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 411a616d74ea7b99e02125bb75a26957a8416546
4
- data.tar.gz: 9f138530b4f0e14f3245bd86af8c119788325d9c
3
+ metadata.gz: ac955e637bfab4fc99212eecbc77ee7f023259fe
4
+ data.tar.gz: 7c9c85e7ad13f9e704fecb946017ddeae7c584ec
5
5
  SHA512:
6
- metadata.gz: 52cf84181e1006582ca95ba56e95a2a6166beec4d7954499cfb5c41c42e656b5e7a81cfaae662ceb5f85edfa77445de39dc48dea587e1f13e3b334944a787b61
7
- data.tar.gz: 591a92b991e7a6bef8779b0121fb61764e0893000a28c44bc86f63983e25bd38a967dc217fa0ea2ed0d2d619430e8b6f95bc5298ce06e8d2f1db304b39f9b00b
6
+ metadata.gz: 1bc31829fc1aa05646134672e903ff2cb8d0a35927819fb9a22661e8d426b5590f6ef1b211491f4d3c435f1ea030b8ed8111e8c09f2df440ce77fdb6cdc8a8d6
7
+ data.tar.gz: 3a77c433b7720495cb919dbebfd465502821ed193f11ad730d0331bb721903dcd5fb7d5d126a98786069f70a859636ff2a83b81cc3a71f2dc9e61e56d7a1b67c
data/CHANGELOG.textile CHANGED
@@ -1,5 +1,9 @@
1
1
  h1. CHANGELOG
2
2
 
3
+ h3. 0.5.11 July 13, 2014
4
+
5
+ * generate JavaScript for analytics
6
+
3
7
  h3. 0.5.10 July 2, 2014
4
8
 
5
9
  * don't generate a home page if it already exists
data/README.textile CHANGED
@@ -131,6 +131,20 @@ Remove commented lines and multiple blank lines from the file *config/routes.rb*
131
131
  $ rails generate clean:routes
132
132
  </pre>
133
133
 
134
+ h2. Generate Analytics Files
135
+
136
+ Add a file containing JavaScript code to set up page-view tracking with "Google Analytics":http://www.google.com/analytics/:
137
+
138
+ <pre>
139
+ $ rails generate analytics:google
140
+ </pre>
141
+
142
+ Add a file containing JavaScript code to set up page-view tracking with "Segment.io":https://segment.io/:
143
+
144
+ <pre>
145
+ $ rails generate analytics:segmentio
146
+ </pre>
147
+
134
148
  h2. Issues
135
149
 
136
150
  Any issues? Please create an "issue":http://github.com/RailsApps/rails_apps_pages/issues on GitHub. Reporting issues (and patching!) helps everyone.
@@ -0,0 +1,16 @@
1
+ require 'rails/generators'
2
+
3
+ module Analytics
4
+ module Generators
5
+ class GoogleGenerator < ::Rails::Generators::Base
6
+ source_root File.expand_path("../templates", __FILE__)
7
+
8
+ desc "add Google Analytics to a Rails application"
9
+
10
+ def add_google_analytics
11
+ copy_file 'google_analytics.js.coffee', 'app/assets/javascripts/google_analytics.js.coffee'
12
+ end
13
+
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ require 'rails/generators'
2
+
3
+ module Analytics
4
+ module Generators
5
+ class SegmentioGenerator < ::Rails::Generators::Base
6
+ source_root File.expand_path("../templates", __FILE__)
7
+
8
+ desc "add Segment.io tracking to a Rails application"
9
+
10
+ def add_segmentio
11
+ copy_file 'segmentio.js', 'app/assets/javascripts/segmentio.js'
12
+ end
13
+
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,44 @@
1
+ # thanks to Jonathon Wolfe at http://reed.github.io/turbolinks-compatibility/google_analytics.html
2
+
3
+ class @GoogleAnalytics
4
+
5
+ @load: ->
6
+ # Google Analytics depends on a global _gaq array. window is the global scope.
7
+ window._gaq = []
8
+ window._gaq.push ["_setAccount", GoogleAnalytics.analyticsId()]
9
+
10
+ # Create a script element and insert it in the DOM
11
+ ga = document.createElement("script")
12
+ ga.type = "text/javascript"
13
+ ga.async = true
14
+ ga.src = ((if "https:" is document.location.protocol then "https://ssl" else "http://www")) + ".google-analytics.com/ga.js"
15
+ firstScript = document.getElementsByTagName("script")[0]
16
+ firstScript.parentNode.insertBefore ga, firstScript
17
+
18
+ # If Turbolinks is supported, set up a callback to track pageviews on page:change.
19
+ # If it isn't supported, just track the pageview now.
20
+ if typeof Turbolinks isnt 'undefined' and Turbolinks.supported
21
+ document.addEventListener "page:change", (->
22
+ GoogleAnalytics.trackPageview()
23
+ ), true
24
+ else
25
+ GoogleAnalytics.trackPageview()
26
+
27
+ @trackPageview: (url) ->
28
+ unless GoogleAnalytics.isLocalRequest()
29
+ if url
30
+ window._gaq.push ["_trackPageview", url]
31
+ else
32
+ window._gaq.push ["_trackPageview"]
33
+ window._gaq.push ["_trackPageLoadTime"]
34
+
35
+ @isLocalRequest: ->
36
+ GoogleAnalytics.documentDomainIncludes "local"
37
+
38
+ @documentDomainIncludes: (str) ->
39
+ document.domain.indexOf(str) isnt -1
40
+
41
+ @analyticsId: ->
42
+ 'UA-XXXXXXX-XX'
43
+
44
+ GoogleAnalytics.load()
@@ -0,0 +1,58 @@
1
+ // Create a queue, but don't obliterate an existing one!
2
+ window.analytics = window.analytics || [];
3
+
4
+ // A list of the methods in Analytics.js to stub.
5
+ window.analytics.methods = ['identify', 'group', 'track',
6
+ 'page', 'pageview', 'alias', 'ready', 'on', 'once', 'off',
7
+ 'trackLink', 'trackForm', 'trackClick', 'trackSubmit'];
8
+
9
+ // Define a factory to create stubs. These are placeholders
10
+ // for methods in Analytics.js so that you never have to wait
11
+ // for it to load to actually record data. The `method` is
12
+ // stored as the first argument, so we can replay the data.
13
+ window.analytics.factory = function(method){
14
+ return function(){
15
+ var args = Array.prototype.slice.call(arguments);
16
+ args.unshift(method);
17
+ window.analytics.push(args);
18
+ return window.analytics;
19
+ };
20
+ };
21
+
22
+ // For each of our methods, generate a queueing stub.
23
+ for (var i = 0; i < window.analytics.methods.length; i++) {
24
+ var key = window.analytics.methods[i];
25
+ window.analytics[key] = window.analytics.factory(key);
26
+ }
27
+
28
+ // Define a method to load Analytics.js from our CDN,
29
+ // and that will be sure to only ever load it once.
30
+ window.analytics.load = function(key){
31
+ if (document.getElementById('analytics-js')) return;
32
+
33
+ // Create an async script element based on your key.
34
+ var script = document.createElement('script');
35
+ script.type = 'text/javascript';
36
+ script.id = 'analytics-js';
37
+ script.async = true;
38
+ script.src = ('https:' === document.location.protocol
39
+ ? 'https://' : 'http://')
40
+ + 'cdn.segment.io/analytics.js/v1/'
41
+ + key + '/analytics.min.js';
42
+
43
+ // Insert our script next to the first script element.
44
+ var first = document.getElementsByTagName('script')[0];
45
+ first.parentNode.insertBefore(script, first);
46
+ };
47
+
48
+ // Add a version to keep track of what's in the wild.
49
+ window.analytics.SNIPPET_VERSION = '2.0.9';
50
+
51
+ // Load Analytics.js with your key, which will automatically
52
+ // load the tools you've enabled for your account. Boosh!
53
+ window.analytics.load('SEGMENTIO_API_KEY');
54
+
55
+ // accommodate Turbolinks and make the first page call to load the integrations.
56
+ $(document).on('ready page:change', function() {
57
+ window.analytics.page();
58
+ })
@@ -1,3 +1,3 @@
1
1
  module RailsAppsPages
2
- VERSION = "0.5.10"
2
+ VERSION = "0.5.11"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_apps_pages
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.10
4
+ version: 0.5.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Kehoe
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-02 00:00:00.000000000 Z
11
+ date: 2014-07-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -54,6 +54,10 @@ files:
54
54
  - LICENSE.txt
55
55
  - README.textile
56
56
  - Rakefile
57
+ - lib/generators/analytics/google_generator.rb
58
+ - lib/generators/analytics/segmentio_generator.rb
59
+ - lib/generators/analytics/templates/google_analytics.js.coffee
60
+ - lib/generators/analytics/templates/segmentio.js
57
61
  - lib/generators/clean/gemfile_generator.rb
58
62
  - lib/generators/clean/routes_generator.rb
59
63
  - lib/generators/pages/about/about_generator.rb