ua-google-analytics-rails 1.0.0
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 +7 -0
- data/.gitignore +7 -0
- data/.travis.yml +23 -0
- data/.yardopts +1 -0
- data/CHANGELOG.markdown +42 -0
- data/Gemfile +24 -0
- data/README.markdown +107 -0
- data/Rakefile +12 -0
- data/google-analytics-rails.gemspec +21 -0
- data/lib/google-analytics-rails.rb +60 -0
- data/lib/google-analytics/async_tracking_queue.rb +42 -0
- data/lib/google-analytics/events.rb +9 -0
- data/lib/google-analytics/events/event.rb +27 -0
- data/lib/google-analytics/events/event_collection.rb +33 -0
- data/lib/google-analytics/events/event_collection_renderer.rb +14 -0
- data/lib/google-analytics/events/event_renderer.rb +33 -0
- data/lib/google-analytics/events/events.rb +230 -0
- data/lib/google-analytics/rails/railtie.rb +12 -0
- data/lib/google-analytics/rails/view_helpers.rb +208 -0
- data/lib/google-analytics/version.rb +6 -0
- data/lib/ua-google-analytics-rails.rb +1 -0
- data/test/async_tracking_queue_test.rb +94 -0
- data/test/event_collection_renderer_test.rb +23 -0
- data/test/event_collection_test.rb +42 -0
- data/test/event_renderer_test.rb +27 -0
- data/test/gaq_events_test.rb +147 -0
- data/test/rails/views_helper_test.rb +133 -0
- data/test/test_helper.rb +9 -0
- metadata +82 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d0b7457b09b8246e0abe9775ccfba083c88e324c
|
4
|
+
data.tar.gz: a86f20da16f5596a659a6def9368e3390c4ef6e8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 89c5a81dbfc6e0dfbcadac5106db3872cb8db8c490d914f798d7a2047db7183d7428f68aaa696a10ae4c555bcec988f20cfe28f193d675c52f8f7547cf70cc49
|
7
|
+
data.tar.gz: cf71fbd291e672b44f1203df38b83832acc2af0d2cebcaa43643f4a4fab7e7538d40ed2176eb8af749a2d681b90473dacc48886194ba0ccefa6f856ea227c8d9
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
language: ruby
|
2
|
+
bundler_args: --without development
|
3
|
+
rvm:
|
4
|
+
- 1.9.2
|
5
|
+
- 1.9.3
|
6
|
+
- 2.0.0
|
7
|
+
- 2.1
|
8
|
+
- 2.2.1
|
9
|
+
- rbx-2
|
10
|
+
- ruby-head
|
11
|
+
matrix:
|
12
|
+
include:
|
13
|
+
- rvm: jruby-18mode
|
14
|
+
env: JRUBY_OPTS="$JRUBY_OPTS --debug"
|
15
|
+
- rvm: jruby-19mode
|
16
|
+
env: JRUBY_OPTS="$JRUBY_OPTS --debug"
|
17
|
+
- rvm: jruby-head
|
18
|
+
env: JRUBY_OPTS="$JRUBY_OPTS --debug"
|
19
|
+
allow_failures:
|
20
|
+
- rvm: jruby-head
|
21
|
+
- rvm: rbx-2
|
22
|
+
- rvm: ruby-head
|
23
|
+
fast_finish: true
|
data/.yardopts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
-m markdown --no-private --plugin rails
|
data/CHANGELOG.markdown
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
1.0.0
|
2
|
+
=====
|
3
|
+
|
4
|
+
* Converting to Universal Analytics
|
5
|
+
|
6
|
+
0.0.6
|
7
|
+
=====
|
8
|
+
|
9
|
+
* Add support for sending `custom_vars` in proper sequence while doing `analytics_init` [PR#20](https://github.com/bgarret/google-analytics-rails/pull/20) (thanks to @yonda).
|
10
|
+
* Make switching between DoubleClick and default `ga.js` simpler. [PR#23](https://github.com/bgarret/google-analytics-rails/pull/23) (thanks to @rafamanzo).
|
11
|
+
* Start testing the library regularly against Ruby 1.8.7, 1.9.2, 1.9.3, 2.0.0, 2.1, JRuby-1.8mode and JRuby-1.9mode.
|
12
|
+
|
13
|
+
0.0.5
|
14
|
+
=====
|
15
|
+
|
16
|
+
* Enhanced link attribution.
|
17
|
+
|
18
|
+
0.0.4
|
19
|
+
=====
|
20
|
+
|
21
|
+
* Support for custom analytics script src (DoubleClick is supported).
|
22
|
+
* Add a `:domain` option to `analytics_init`.
|
23
|
+
|
24
|
+
0.0.3
|
25
|
+
=====
|
26
|
+
|
27
|
+
* Fix #8, the directives were in the wrong order in development mode (thanks to @garnould).
|
28
|
+
* Add support for the `_anonymizeIp` event (thanks to @rmoriz).
|
29
|
+
* Add support for the `_deleteCustomVar` directive (thanks to @eirc).
|
30
|
+
|
31
|
+
0.0.2
|
32
|
+
=====
|
33
|
+
|
34
|
+
* Documentation updates
|
35
|
+
* Custom variable support (thanks to @asm).
|
36
|
+
* `_setSiteSpeedSampleRate()` method support (thanks to @nikosd).
|
37
|
+
* Event collection `size` method (thanks to @brundage).
|
38
|
+
|
39
|
+
0.0.1
|
40
|
+
=====
|
41
|
+
|
42
|
+
Initial release.
|
data/Gemfile
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
|
3
|
+
gem 'rake'
|
4
|
+
gem 'yard'
|
5
|
+
gem 'i18n', '< 0.7.0'
|
6
|
+
gem 'activesupport', "~> 3.0"
|
7
|
+
|
8
|
+
group :development do
|
9
|
+
gem 'pry'
|
10
|
+
platforms :ruby_19, :ruby_20, :ruby_21 do
|
11
|
+
gem 'pry-stack_explorer'
|
12
|
+
gem 'redcarpet'
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
group :test do
|
17
|
+
gem 'test-unit'
|
18
|
+
gem 'json'
|
19
|
+
gem "codeclimate-test-reporter", :require => nil
|
20
|
+
end
|
21
|
+
|
22
|
+
# Specify your gem's dependencies in google-analytics-rails.gemspec
|
23
|
+
gemspec
|
24
|
+
|
data/README.markdown
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
[](https://codeclimate.com/github/spodlecki/ua-google-analytics-rails)
|
2
|
+
[](https://codeclimate.com/github/spodlecki/ua-google-analytics-rails/coverage)
|
3
|
+
[](https://travis-ci.org/spodlecki/ua-google-analytics-rails)
|
4
|
+
|
5
|
+
|
6
|
+
Fast Google Analytics setup for Rails using Universal Analytics code. This gem is mostly intended for small to medium websites with a simple analytics strategy.
|
7
|
+
|
8
|
+
**Note:**
|
9
|
+
|
10
|
+
Original [Google Analytics Rails Project](https://github.com/bgarret/google-analytics-rails) has been MIA to update to Universal Analytics. The project is essentially a direct port from the old repo.
|
11
|
+
|
12
|
+
|
13
|
+
Installation
|
14
|
+
============
|
15
|
+
|
16
|
+
Add the following to your `Gemfile`:
|
17
|
+
|
18
|
+
gem 'ua-google-analytics-rails'
|
19
|
+
|
20
|
+
Then run:
|
21
|
+
|
22
|
+
bundle install
|
23
|
+
|
24
|
+
Upgrade Notes
|
25
|
+
============
|
26
|
+
|
27
|
+
__Upgrading this gem from 0.0.6?__
|
28
|
+
|
29
|
+
Use `analytics_init` to send submissions to Analytics if you are using multiple trackers. You can supply a name to tracker by passing `:name` option.
|
30
|
+
|
31
|
+
**GoogleAnalytics::Events::SetAllowLinker** is no longer supported as an external variable being set. You can submit as normal in the `:add_events` array, but using the new `:setup` config is preferable so no extra array searching has to happen.
|
32
|
+
|
33
|
+
**GoogleAnalytics::Events::SetCustomVar** is no longer supported by Universal Analytics. These have been changed to SetCustomDimension & SetCustomMetric. By default if you use SetCustomVar, it applies as a Dimension
|
34
|
+
|
35
|
+
**GoogleAnalytics::Events::DeleteCustomVar** has been removed
|
36
|
+
|
37
|
+
**Added Event Helpers**
|
38
|
+
|
39
|
+
- GoogleAnalytics::Events::ExperimentId
|
40
|
+
- GoogleAnalytics::Events::ExperimentVariation
|
41
|
+
|
42
|
+
**TODO:** Add Double Click Snippet Support
|
43
|
+
While the code is there, and it looks like it is simply changing the end path to the JS, this feature has not been tested.
|
44
|
+
|
45
|
+
**Ruby 1.8.7 Support** While it should work on Ruby 1.8.7. No longer running test suite for it for CodeClimate Gem Requirements.
|
46
|
+
|
47
|
+
|
48
|
+
Documentation
|
49
|
+
=============
|
50
|
+
|
51
|
+
Example configurations
|
52
|
+
======================
|
53
|
+
|
54
|
+
Production only
|
55
|
+
---------------
|
56
|
+
|
57
|
+
`config/environments/production.rb`:
|
58
|
+
|
59
|
+
# replace this with your tracker code
|
60
|
+
GA.tracker = "UA-xxxxxx-x"
|
61
|
+
|
62
|
+
`app/views/layout/application.html.erb`, in the `<head>` tag :
|
63
|
+
|
64
|
+
<%= analytics_init if Rails.env.production? %>
|
65
|
+
|
66
|
+
With DoubleClick instead of vanilla Google Analytics script
|
67
|
+
-----------------------------------------------------------
|
68
|
+
|
69
|
+
`config/environments/production.rb`:
|
70
|
+
|
71
|
+
# replace this with your tracker code
|
72
|
+
GA.tracker = "UA-xxxxxx-x"
|
73
|
+
GA.script_source = :doubleclick
|
74
|
+
|
75
|
+
`app/views/layout/application.html.erb`, in the `<head>` tag :
|
76
|
+
|
77
|
+
<%= analytics_init if Rails.env.production? %>
|
78
|
+
|
79
|
+
Different accounts for development and production
|
80
|
+
-------------------------------------------------
|
81
|
+
|
82
|
+
`config/environments/production.rb`:
|
83
|
+
|
84
|
+
# replace this with your production tracker code
|
85
|
+
GA.tracker = "UA-xxxxxx-x"
|
86
|
+
|
87
|
+
`config/environments/development.rb`:
|
88
|
+
|
89
|
+
# replace this with your development tracker code
|
90
|
+
GA.tracker = "UA-xxxxxx-x"
|
91
|
+
|
92
|
+
`app/views/layout/application.html.erb`, in the `<head>` tag :
|
93
|
+
|
94
|
+
<%= analytics_init :local => Rails.env.development? %>
|
95
|
+
|
96
|
+
License
|
97
|
+
=======
|
98
|
+
|
99
|
+
[ua-google-analytics-rails](https://github.com/spodlecki/ua-google-analytics-rails) is released under the MIT license:
|
100
|
+
|
101
|
+
* http://www.opensource.org/licenses/MIT
|
102
|
+
|
103
|
+
Original Repo:
|
104
|
+
|
105
|
+
[google-analytics-rails](https://github.com/bgarret/google-analytics-rails) is released under the MIT license:
|
106
|
+
|
107
|
+
* http://www.opensource.org/licenses/MIT
|
data/Rakefile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "google-analytics/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "ua-google-analytics-rails"
|
7
|
+
s.version = GoogleAnalytics::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Benoit Garret", "Ufuk Kayserilioglu", "Steven Podlecki"]
|
10
|
+
s.email = ["benoit.garret@gadz.org", "ufuk@paralaus.com", "s.podlecki@gmail.com"]
|
11
|
+
s.homepage = "https://github.com/spodlecki/ua-google-analytics-rails"
|
12
|
+
s.summary = %q{Rails helpers to manage google analytics tracking}
|
13
|
+
s.description = %q{Google Analytics setup for Rails using Universal Analytics code}
|
14
|
+
|
15
|
+
s.rubyforge_project = "ua-google-analytics-rails"
|
16
|
+
|
17
|
+
s.files = `git ls-files`.split("\n")
|
18
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
|
+
s.require_paths = ["lib"]
|
21
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require 'google-analytics/async_tracking_queue'
|
4
|
+
require 'google-analytics/events'
|
5
|
+
|
6
|
+
module GoogleAnalytics
|
7
|
+
# @private
|
8
|
+
PLACEHOLDER_TRACKER = "UA-xxxxxx-x"
|
9
|
+
# GA sources.
|
10
|
+
# Allowing easy switch between DEFAULT and DoubleClick scripts.
|
11
|
+
# @see http://support.google.com/analytics/bin/answer.py?hl=en&answer=2444872 for more info
|
12
|
+
#
|
13
|
+
# @private
|
14
|
+
SCRIPT_SOURCES = {
|
15
|
+
:default => "'//www.google-analytics.com/analytics.js'",
|
16
|
+
:doubleclick => "'//stats.g.doubleclick.net/dc.js'",
|
17
|
+
}
|
18
|
+
|
19
|
+
# Get the current tracker id (*UA-xxxxxx-x*).
|
20
|
+
# @return [String]
|
21
|
+
def self.tracker
|
22
|
+
@@tracker ||= PLACEHOLDER_TRACKER
|
23
|
+
end
|
24
|
+
|
25
|
+
# Set the current tracker id.
|
26
|
+
# @param [String] tracker The tracker id (ie. "*UA-xxxxxx-x*").
|
27
|
+
def self.tracker=(tracker)
|
28
|
+
@@tracker = tracker
|
29
|
+
end
|
30
|
+
|
31
|
+
# @return [Boolean]
|
32
|
+
def self.valid_tracker?
|
33
|
+
tracker.nil? || tracker == "" || tracker == PLACEHOLDER_TRACKER ? false : true
|
34
|
+
end
|
35
|
+
|
36
|
+
# @return [String]
|
37
|
+
def self.script_source
|
38
|
+
@@src ||= SCRIPT_SOURCES[:default]
|
39
|
+
end
|
40
|
+
|
41
|
+
# Set the current ga src.
|
42
|
+
# @return [String]
|
43
|
+
def self.script_source=(src)
|
44
|
+
if SCRIPT_SOURCES.has_key?(src)
|
45
|
+
@@src = SCRIPT_SOURCES[src]
|
46
|
+
else
|
47
|
+
@@src = src
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
# Alias for {GoogleAnalytics}
|
53
|
+
GA = GoogleAnalytics
|
54
|
+
|
55
|
+
if defined?(Rails)
|
56
|
+
require 'google-analytics/rails/railtie'
|
57
|
+
|
58
|
+
# Alias for {GoogleAnalytics::Rails}
|
59
|
+
GAR = GoogleAnalytics::Rails
|
60
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
module GoogleAnalytics
|
4
|
+
class AsyncTrackingQueue
|
5
|
+
def initialize
|
6
|
+
@events = []
|
7
|
+
end
|
8
|
+
|
9
|
+
def <<(event)
|
10
|
+
push(event)
|
11
|
+
end
|
12
|
+
|
13
|
+
def push(event, tracker_id = nil)
|
14
|
+
@events << renderer_for_event(event, tracker_id)
|
15
|
+
end
|
16
|
+
|
17
|
+
def to_s
|
18
|
+
<<-JAVASCRIPT
|
19
|
+
<script type="text/javascript">
|
20
|
+
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
|
21
|
+
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
|
22
|
+
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
|
23
|
+
})(window,document,'script',#{GoogleAnalytics.script_source},'ga');
|
24
|
+
#{@events.map { |event| event.to_s }.join("\n")}
|
25
|
+
</script>
|
26
|
+
JAVASCRIPT
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def renderer_for_event(event, tracker_id)
|
32
|
+
case event
|
33
|
+
when SingleEvent then EventRenderer.new(event, tracker_id)
|
34
|
+
when Event then EventRenderer.new(event, tracker_id)
|
35
|
+
when EventCollection then EventCollectionRenderer.new(event, tracker_id)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
# Alias for {GoogleAnalytics::AsyncTrackingQueue}
|
42
|
+
GAQ = GoogleAnalytics::AsyncTrackingQueue
|
@@ -0,0 +1,9 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
module GoogleAnalytics
|
4
|
+
autoload :Events, 'google-analytics/events/events'
|
5
|
+
autoload :Event, 'google-analytics/events/event'
|
6
|
+
autoload :EventRenderer, 'google-analytics/events/event_renderer'
|
7
|
+
autoload :EventCollection, 'google-analytics/events/event_collection'
|
8
|
+
autoload :EventCollectionRenderer, 'google-analytics/events/event_collection_renderer'
|
9
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
module GoogleAnalytics
|
4
|
+
class Event
|
5
|
+
attr_reader :action, :name, :params
|
6
|
+
|
7
|
+
def initialize(action, name, *params)
|
8
|
+
@action = action
|
9
|
+
@name = name
|
10
|
+
@params = params
|
11
|
+
end
|
12
|
+
|
13
|
+
def single_event?
|
14
|
+
false
|
15
|
+
end
|
16
|
+
end
|
17
|
+
class SingleEvent
|
18
|
+
attr_reader :action, :name, :params
|
19
|
+
def initialize(action, *params)
|
20
|
+
@action = action
|
21
|
+
@params = params
|
22
|
+
end
|
23
|
+
def single_event?
|
24
|
+
true
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
module GoogleAnalytics
|
4
|
+
class EventCollection
|
5
|
+
include Enumerable
|
6
|
+
|
7
|
+
class InvalidEventError < StandardError
|
8
|
+
def initialize(non_event)
|
9
|
+
super("EventCollection#<< expects instances of Event, you passed #{non_event}")
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def initialize
|
14
|
+
@events = []
|
15
|
+
end
|
16
|
+
|
17
|
+
def <<(event)
|
18
|
+
raise InvalidEventError.new(event) unless event.is_a?(Event) || event.is_a?(SingleEvent)
|
19
|
+
|
20
|
+
@events << event
|
21
|
+
end
|
22
|
+
|
23
|
+
def each
|
24
|
+
@events.each { |e| yield e }
|
25
|
+
end
|
26
|
+
|
27
|
+
def length
|
28
|
+
@events.length
|
29
|
+
end
|
30
|
+
alias_method :size, :length
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
module GoogleAnalytics
|
4
|
+
class EventCollectionRenderer
|
5
|
+
def initialize(event_collection, tracker_id)
|
6
|
+
@event_collection = event_collection
|
7
|
+
@tracker_id = tracker_id
|
8
|
+
end
|
9
|
+
|
10
|
+
def to_s
|
11
|
+
@event_collection.map { |event| EventRenderer.new(event, @tracker_id).to_s }.join("\n")
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|