google_analytics_on_rails 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +18 -0
- data/LICENSE.rdoc +20 -0
- data/Manifest +23 -0
- data/README.rdoc +7 -0
- data/Rakefile +52 -0
- data/google_analytics_on_rails.gemspec +37 -0
- data/init.rb +1 -0
- data/install.rb +1 -0
- data/lib/google_analytics_on_rails.rb +47 -0
- data/lib/google_analytics_on_rails/controller_mixin.rb +58 -0
- data/lib/google_analytics_on_rails/java_script_builder.rb +100 -0
- data/lib/google_analytics_on_rails/version.rb +31 -0
- data/rails/init.rb +5 -0
- data/tasks/google_analytics_on_rails_tasks.rake +4 -0
- data/test/controller_mixin_test.rb +56 -0
- data/test/fixtures/mixin/ga.html.erb +0 -0
- data/test/fixtures/mixin/ga_tracking_code.html.erb +1 -0
- data/test/fixtures/mixin/google_analytics_tracking_code.html.erb +1 -0
- data/test/google_analytics_on_rails_test.rb +9 -0
- data/test/google_analytics_test.rb +21 -0
- data/test/java_script_builder_test.rb +52 -0
- data/test/test_helper.rb +26 -0
- data/uninstall.rb +1 -0
- metadata +111 -0
data/CHANGELOG.rdoc
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
= Changelog
|
2
|
+
|
3
|
+
|
4
|
+
== Release 0.1.2
|
5
|
+
|
6
|
+
* FIXED: GitHub now requires the Manifest file to be included in the repos.
|
7
|
+
|
8
|
+
* CHANGED: GitHub Gem Building is defunct. The gem is now hosted on Gemcutter (see http://github.com/blog/515-gem-building-is-defunct)
|
9
|
+
|
10
|
+
|
11
|
+
== Release 0.1.1
|
12
|
+
|
13
|
+
* Bumped release number to force GitHub to publish the GEM.
|
14
|
+
|
15
|
+
|
16
|
+
== Release 0.1.0
|
17
|
+
|
18
|
+
* Initial version
|
data/LICENSE.rdoc
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2008-2009 Simone Carletti
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Manifest
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
CHANGELOG.rdoc
|
2
|
+
google_analytics_on_rails.gemspec
|
3
|
+
init.rb
|
4
|
+
install.rb
|
5
|
+
lib/google_analytics_on_rails/controller_mixin.rb
|
6
|
+
lib/google_analytics_on_rails/java_script_builder.rb
|
7
|
+
lib/google_analytics_on_rails/version.rb
|
8
|
+
lib/google_analytics_on_rails.rb
|
9
|
+
LICENSE.rdoc
|
10
|
+
Manifest
|
11
|
+
rails/init.rb
|
12
|
+
Rakefile
|
13
|
+
README.rdoc
|
14
|
+
tasks/google_analytics_on_rails_tasks.rake
|
15
|
+
test/controller_mixin_test.rb
|
16
|
+
test/fixtures/mixin/ga.html.erb
|
17
|
+
test/fixtures/mixin/ga_tracking_code.html.erb
|
18
|
+
test/fixtures/mixin/google_analytics_tracking_code.html.erb
|
19
|
+
test/google_analytics_on_rails_test.rb
|
20
|
+
test/google_analytics_test.rb
|
21
|
+
test/java_script_builder_test.rb
|
22
|
+
test/test_helper.rb
|
23
|
+
uninstall.rb
|
data/README.rdoc
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
require 'echoe'
|
4
|
+
|
5
|
+
$:.unshift(File.dirname(__FILE__) + "/lib")
|
6
|
+
require 'google_analytics_on_rails'
|
7
|
+
|
8
|
+
|
9
|
+
PKG_NAME = ENV['PKG_NAME'] || GoogleAnalyticsOnRails::GEM
|
10
|
+
PKG_VERSION = ENV['PKG_VERSION'] || GoogleAnalyticsOnRails::VERSION
|
11
|
+
PKG_SUMMARY = "A Ruby on Rails plugin to integrate Google Analytics features in your application."
|
12
|
+
PKG_FILES = FileList.new("{lib,rails,tasks,test}/**/*") do |files|
|
13
|
+
files.include %w(*.{rdoc,rb})
|
14
|
+
files.include %w(Rakefile)
|
15
|
+
end
|
16
|
+
RUBYFORGE_PROJECT = nil
|
17
|
+
|
18
|
+
if ENV['SNAPSHOT'].to_i == 1
|
19
|
+
PKG_VERSION << "." << Time.now.utc.strftime("%Y%m%d%H%M%S")
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
Echoe.new(PKG_NAME, PKG_VERSION) do |p|
|
24
|
+
p.author = "Simone Carletti"
|
25
|
+
p.email = "weppos@weppos.net"
|
26
|
+
p.summary = PKG_SUMMARY
|
27
|
+
p.description = <<-EOD
|
28
|
+
GoogleAnalyticsOnRails is a Ruby on Rails plugin designed to make easier \
|
29
|
+
to integrate Google Analytics features in your application.
|
30
|
+
EOD
|
31
|
+
p.url = "http://code.simonecarletti.com/googleanalyticsonrails"
|
32
|
+
p.project = RUBYFORGE_PROJECT
|
33
|
+
|
34
|
+
p.need_zip = true
|
35
|
+
p.rcov_options = ["--main << README.rdoc -x Rakefile -x rcov"]
|
36
|
+
p.rdoc_pattern = /^(lib|CHANGELOG.rdoc|README.rdoc|LICENSE.rdoc)/
|
37
|
+
|
38
|
+
p.development_dependencies += ["rake >=0.8",
|
39
|
+
"echoe >=3.1"]
|
40
|
+
end
|
41
|
+
|
42
|
+
|
43
|
+
begin
|
44
|
+
require 'code_statistics'
|
45
|
+
desc "Show library's code statistics"
|
46
|
+
task :stats do
|
47
|
+
CodeStatistics.new(["GoogleAnalyticsOnRails", "lib"],
|
48
|
+
["Tests", "test"]).to_s
|
49
|
+
end
|
50
|
+
rescue LoadError
|
51
|
+
puts "CodeStatistics (Rails) is not available"
|
52
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{google_analytics_on_rails}
|
5
|
+
s.version = "0.1.2"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["Simone Carletti"]
|
9
|
+
s.date = %q{2009-10-28}
|
10
|
+
s.description = %q{ GoogleAnalyticsOnRails is a Ruby on Rails plugin designed to make easier to integrate Google Analytics features in your application.
|
11
|
+
}
|
12
|
+
s.email = %q{weppos@weppos.net}
|
13
|
+
s.extra_rdoc_files = ["CHANGELOG.rdoc", "lib/google_analytics_on_rails/controller_mixin.rb", "lib/google_analytics_on_rails/java_script_builder.rb", "lib/google_analytics_on_rails/version.rb", "lib/google_analytics_on_rails.rb", "LICENSE.rdoc", "README.rdoc"]
|
14
|
+
s.files = ["CHANGELOG.rdoc", "google_analytics_on_rails.gemspec", "init.rb", "install.rb", "lib/google_analytics_on_rails/controller_mixin.rb", "lib/google_analytics_on_rails/java_script_builder.rb", "lib/google_analytics_on_rails/version.rb", "lib/google_analytics_on_rails.rb", "LICENSE.rdoc", "Manifest", "rails/init.rb", "Rakefile", "README.rdoc", "tasks/google_analytics_on_rails_tasks.rake", "test/controller_mixin_test.rb", "test/fixtures/mixin/ga.html.erb", "test/fixtures/mixin/ga_tracking_code.html.erb", "test/fixtures/mixin/google_analytics_tracking_code.html.erb", "test/google_analytics_on_rails_test.rb", "test/google_analytics_test.rb", "test/java_script_builder_test.rb", "test/test_helper.rb", "uninstall.rb"]
|
15
|
+
s.homepage = %q{http://code.simonecarletti.com/googleanalyticsonrails}
|
16
|
+
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Google_analytics_on_rails", "--main", "README.rdoc"]
|
17
|
+
s.require_paths = ["lib"]
|
18
|
+
s.rubygems_version = %q{1.3.5}
|
19
|
+
s.summary = %q{A Ruby on Rails plugin to integrate Google Analytics features in your application.}
|
20
|
+
s.test_files = ["test/controller_mixin_test.rb", "test/google_analytics_on_rails_test.rb", "test/google_analytics_test.rb", "test/java_script_builder_test.rb", "test/test_helper.rb"]
|
21
|
+
|
22
|
+
if s.respond_to? :specification_version then
|
23
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
24
|
+
s.specification_version = 3
|
25
|
+
|
26
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
27
|
+
s.add_development_dependency(%q<rake>, [">= 0.8"])
|
28
|
+
s.add_development_dependency(%q<echoe>, [">= 3.1"])
|
29
|
+
else
|
30
|
+
s.add_dependency(%q<rake>, [">= 0.8"])
|
31
|
+
s.add_dependency(%q<echoe>, [">= 3.1"])
|
32
|
+
end
|
33
|
+
else
|
34
|
+
s.add_dependency(%q<rake>, [">= 0.8"])
|
35
|
+
s.add_dependency(%q<echoe>, [">= 3.1"])
|
36
|
+
end
|
37
|
+
end
|
data/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'rails', 'init')
|
data/install.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# Install hook code here
|
@@ -0,0 +1,47 @@
|
|
1
|
+
#
|
2
|
+
# = Google Analytics on Rails
|
3
|
+
#
|
4
|
+
# A Ruby on Rails plugin to integrate Google Analytics features in your application.
|
5
|
+
#
|
6
|
+
#
|
7
|
+
# Category:: Rails
|
8
|
+
# Package:: GoogleAnalyticsOnRails
|
9
|
+
# Author:: Simone Carletti <weppos@weppos.net>
|
10
|
+
# License:: MIT License
|
11
|
+
#
|
12
|
+
#--
|
13
|
+
# SVN: $Id$
|
14
|
+
#++
|
15
|
+
|
16
|
+
|
17
|
+
require 'google_analytics_on_rails/controller_mixin'
|
18
|
+
require 'google_analytics_on_rails/java_script_builder'
|
19
|
+
require 'google_analytics_on_rails/version'
|
20
|
+
|
21
|
+
|
22
|
+
module GoogleAnalyticsOnRails
|
23
|
+
|
24
|
+
NAME = 'Google Analytics on Rails'
|
25
|
+
GEM = 'google_analytics_on_rails'
|
26
|
+
AUTHOR = 'Simone Carletti <weppos@weppos.net>'
|
27
|
+
|
28
|
+
|
29
|
+
class Error < RuntimeError; end
|
30
|
+
class InvalidProfile < Error; end
|
31
|
+
|
32
|
+
class GoogleAnalytics
|
33
|
+
|
34
|
+
attr_accessor :tracker_id
|
35
|
+
|
36
|
+
def initialize(*args)
|
37
|
+
options = args.extract_options!
|
38
|
+
@tracker_id = args.shift
|
39
|
+
end
|
40
|
+
|
41
|
+
def validate!
|
42
|
+
raise InvalidProfile, "TrackerId is missing or invalid" if tracker_id.blank?
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
#
|
2
|
+
# = Google Analytics on Rails
|
3
|
+
#
|
4
|
+
# A Ruby on Rails plugin to integrate Google Analytics features in your application.
|
5
|
+
#
|
6
|
+
#
|
7
|
+
# Category:: Rails
|
8
|
+
# Package:: GoogleAnalyticsOnRails
|
9
|
+
# Author:: Simone Carletti <weppos@weppos.net>
|
10
|
+
# License:: MIT License
|
11
|
+
#
|
12
|
+
#--
|
13
|
+
# SVN: $Id$
|
14
|
+
#++
|
15
|
+
|
16
|
+
|
17
|
+
module GoogleAnalyticsOnRails
|
18
|
+
|
19
|
+
module ControllerMixin
|
20
|
+
|
21
|
+
def self.included(base)
|
22
|
+
base.extend(ClassMethods)
|
23
|
+
end
|
24
|
+
|
25
|
+
module ClassMethods
|
26
|
+
|
27
|
+
def google_analytics(*args)
|
28
|
+
class_eval <<-RUBY
|
29
|
+
include GoogleAnalyticsOnRails::ControllerMixin::InstanceMethods
|
30
|
+
helper GoogleAnalyticsOnRails::ControllerMixin::HelperMethods
|
31
|
+
|
32
|
+
attr_accessor :google_analytics
|
33
|
+
helper_method :google_analytics
|
34
|
+
RUBY
|
35
|
+
|
36
|
+
prepend_before_filter do |controller|
|
37
|
+
controller.send(:google_analytics=, GoogleAnalytics.new(*args))
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
module InstanceMethods
|
43
|
+
end
|
44
|
+
|
45
|
+
module HelperMethods
|
46
|
+
|
47
|
+
def ga
|
48
|
+
GoogleAnalyticsOnRails::JavaScriptBuilder.new(self, google_analytics)
|
49
|
+
end
|
50
|
+
|
51
|
+
def google_analytics_tracking_code
|
52
|
+
ga.tracking_code
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,100 @@
|
|
1
|
+
#
|
2
|
+
# = Google Analytics on Rails
|
3
|
+
#
|
4
|
+
# A Ruby on Rails plugin to integrate Google Analytics features in your application.
|
5
|
+
#
|
6
|
+
#
|
7
|
+
# Category:: Rails
|
8
|
+
# Package:: GoogleAnalyticsOnRails
|
9
|
+
# Author:: Simone Carletti <weppos@weppos.net>
|
10
|
+
# License:: MIT License
|
11
|
+
#
|
12
|
+
#--
|
13
|
+
# SVN: $Id$
|
14
|
+
#++
|
15
|
+
|
16
|
+
|
17
|
+
module GoogleAnalyticsOnRails
|
18
|
+
|
19
|
+
class JavaScriptBuilder
|
20
|
+
|
21
|
+
def initialize(context, profile)
|
22
|
+
@context = context
|
23
|
+
@profile = profile
|
24
|
+
end
|
25
|
+
|
26
|
+
# Returns the Google Analytics tracking code for the tracker_id stored in current @profile.
|
27
|
+
#
|
28
|
+
# Important: this method tried to keep the original Google Analytics
|
29
|
+
# tracking code unchanged as much as possibile. For this reason, this method
|
30
|
+
# return the tracking code already wrapped by all required <script></script> tags.
|
31
|
+
#
|
32
|
+
# JavaScriptBuilder.new(context, GoogleAnalytics.new('ua_123456').get_tracker
|
33
|
+
# # => <script> var gaJsHost = ... </script>
|
34
|
+
#
|
35
|
+
# This method returns the new Google Analytics tracking code, the one based
|
36
|
+
# on ga.js inclusion. The old urchin.js file is no longer supported.
|
37
|
+
#
|
38
|
+
# Last updated on January 16, 2009. To lean more visit
|
39
|
+
# http://analytics.blogspot.com/2009/01/short-answer-is-you-dont-have-to-change.html
|
40
|
+
#
|
41
|
+
# TODO: update the code to be based on javascript_tag helper.
|
42
|
+
#
|
43
|
+
# ==== Raises
|
44
|
+
#
|
45
|
+
# GoogleAnalyticsOnRails::InvalidProfile:: If @profile is missing +tracker_id+
|
46
|
+
#
|
47
|
+
def tracking_code
|
48
|
+
<<-EOT
|
49
|
+
<script type="text/javascript">
|
50
|
+
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
|
51
|
+
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
|
52
|
+
</script>
|
53
|
+
<script type="text/javascript">
|
54
|
+
try {
|
55
|
+
var pageTracker = _gat.#{get_tracker};
|
56
|
+
pageTracker._trackPageview();
|
57
|
+
} catch(err) {}</script>
|
58
|
+
EOT
|
59
|
+
end
|
60
|
+
|
61
|
+
# Returns a _getTracker statement for the tracker_id stored in current @profile.
|
62
|
+
#
|
63
|
+
# JavaScriptBuilder.new(context, GoogleAnalytics.new('ua_123456').get_tracker
|
64
|
+
# # => _getTracker('ua_123456')
|
65
|
+
#
|
66
|
+
# ==== Raises
|
67
|
+
#
|
68
|
+
# GoogleAnalyticsOnRails::InvalidProfile:: If @profile is missing +tracker_id+
|
69
|
+
#
|
70
|
+
def get_tracker
|
71
|
+
require_valid_profile!
|
72
|
+
get_tracker_for(@profile.tracker_id)
|
73
|
+
end
|
74
|
+
|
75
|
+
|
76
|
+
private
|
77
|
+
|
78
|
+
# Returns a _getTracker statement for +tracker_id+.
|
79
|
+
# This method is essentially available to take advantage of the memoization feature
|
80
|
+
# available in Rails >= 2.2
|
81
|
+
def get_tracker_for(tracker_id)
|
82
|
+
"_getTracker('#{tracker_id}')"
|
83
|
+
end
|
84
|
+
# Leave memoization disabled for now until benchmarks are available.
|
85
|
+
# memoize :get_tracker_for
|
86
|
+
|
87
|
+
# Validates profile and raises a GoogleAnalyticsOnRails::InvalidProfile
|
88
|
+
# on invalid instance.
|
89
|
+
# See GoogleAnalyticsOnRails::InvalidProfile#validate! for more details.
|
90
|
+
#
|
91
|
+
# ==== Raises
|
92
|
+
#
|
93
|
+
# GoogleAnalyticsOnRails::InvalidProfile:: If @profile is invalid.
|
94
|
+
#
|
95
|
+
def require_valid_profile!
|
96
|
+
@profile.validate!
|
97
|
+
end
|
98
|
+
|
99
|
+
end
|
100
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
#
|
2
|
+
# = Google Analytics on Rails
|
3
|
+
#
|
4
|
+
# A Ruby on Rails plugin to integrate Google Analytics features in your application.
|
5
|
+
#
|
6
|
+
#
|
7
|
+
# Category:: Rails
|
8
|
+
# Package:: GoogleAnalyticsOnRails
|
9
|
+
# Author:: Simone Carletti <weppos@weppos.net>
|
10
|
+
# License:: MIT License
|
11
|
+
#
|
12
|
+
#--
|
13
|
+
# SVN: $Id$
|
14
|
+
#++
|
15
|
+
|
16
|
+
|
17
|
+
module GoogleAnalyticsOnRails
|
18
|
+
|
19
|
+
module Version
|
20
|
+
MAJOR = 0
|
21
|
+
MINOR = 1
|
22
|
+
TINY = 2
|
23
|
+
|
24
|
+
STRING = [MAJOR, MINOR, TINY].join('.')
|
25
|
+
end
|
26
|
+
|
27
|
+
VERSION = Version::STRING
|
28
|
+
STATUS = 'dev'
|
29
|
+
BUILD = '$Id$'.match(/(\d+)/).to_a.first
|
30
|
+
|
31
|
+
end
|
data/rails/init.rb
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class MixinController < ActionController::Base
|
4
|
+
def self.controller_name; "mixin"; end
|
5
|
+
def self.controller_path; "mixin"; end
|
6
|
+
layout false
|
7
|
+
|
8
|
+
google_analytics 'ua_001122'
|
9
|
+
|
10
|
+
def method_missing(method, *args)
|
11
|
+
if method =~ /^action_(.*)/
|
12
|
+
render :action => $1
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def rescue_action(e) raise end
|
17
|
+
end
|
18
|
+
|
19
|
+
MixinController.view_paths = [ File.dirname(__FILE__) + "/fixtures/" ]
|
20
|
+
|
21
|
+
|
22
|
+
class ControllerMixinTest < ActiveSupport::TestCase
|
23
|
+
include GoogleAnalyticsOnRails
|
24
|
+
|
25
|
+
def setup
|
26
|
+
@controller = MixinController.new
|
27
|
+
@controller.logger = Logger.new(nil)
|
28
|
+
@request = ActionController::TestRequest.new
|
29
|
+
@response = ActionController::TestResponse.new
|
30
|
+
|
31
|
+
@request.host = "test.host"
|
32
|
+
@tracker_id = 'ua_001122'
|
33
|
+
|
34
|
+
@context = stub()
|
35
|
+
@profile = GoogleAnalytics.new('ua_001122')
|
36
|
+
@builder = JavaScriptBuilder.new(@context, @profile)
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
def test_ga
|
41
|
+
get :action_ga
|
42
|
+
assert_not_nil(assigns(:google_analytics))
|
43
|
+
assert_equal(@tracker_id, assigns(:google_analytics).tracker_id)
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_google_analytics_tracking_code
|
47
|
+
get :action_google_analytics_tracking_code
|
48
|
+
assert_equal(@builder.tracking_code, @response.body)
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_ga_tracking_code
|
52
|
+
get :action_ga_tracking_code
|
53
|
+
assert_equal(@builder.tracking_code, @response.body)
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= ga.tracking_code %>
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= google_analytics_tracking_code %>
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class GoogleAnalyticsTest < ActiveSupport::TestCase
|
4
|
+
include GoogleAnalyticsOnRails
|
5
|
+
|
6
|
+
def test_initialize_should_set_tracker_id
|
7
|
+
assert_equal('id_123456', GoogleAnalytics.new('id_123456').tracker_id)
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_initialize_should_allow_empty_tracker_id
|
11
|
+
assert_equal(nil, GoogleAnalytics.new.tracker_id)
|
12
|
+
assert_equal(nil, GoogleAnalytics.new(nil).tracker_id)
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_validate_bang_should_raise_invalidprofile_with_blank_tracker_id
|
16
|
+
assert_raise(InvalidProfile) { GoogleAnalytics.new().validate! }
|
17
|
+
assert_raise(InvalidProfile) { GoogleAnalytics.new('').validate! }
|
18
|
+
assert_raise(InvalidProfile) { GoogleAnalytics.new(nil).validate! }
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class JavaScriptBuilderTest < ActiveSupport::TestCase
|
4
|
+
include GoogleAnalyticsOnRails
|
5
|
+
|
6
|
+
def setup
|
7
|
+
@context = stub()
|
8
|
+
@profile = GoogleAnalytics.new('ua_123456')
|
9
|
+
@builder = JavaScriptBuilder.new(@context, @profile)
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_initialize_should_require_context_and_profile
|
13
|
+
assert_raise(ArgumentError) { JavaScriptBuilder.new }
|
14
|
+
assert_raise(ArgumentError) { JavaScriptBuilder.new(@context) }
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
TRACKING_CODE_TEMPLATE = <<EOT
|
19
|
+
<script type="text/javascript">
|
20
|
+
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
|
21
|
+
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
|
22
|
+
</script>
|
23
|
+
<script type="text/javascript">
|
24
|
+
try {
|
25
|
+
var pageTracker = _gat._getTracker('{{tracker_id}}');
|
26
|
+
pageTracker._trackPageview();
|
27
|
+
} catch(err) {}</script>
|
28
|
+
EOT
|
29
|
+
|
30
|
+
def test_tracking_code_should_returns_tracking_code_for_current_profile
|
31
|
+
assert_equal(TRACKING_CODE_TEMPLATE.gsub('{{tracker_id}}', 'ua_123456'),
|
32
|
+
@builder.tracking_code)
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
def test_get_tracker_should_return_tracker_for_profile
|
37
|
+
assert_equal("_getTracker('#{@profile.tracker_id}')", @builder.get_tracker)
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
%w(tracking_code get_tracker).each do |method|
|
42
|
+
|
43
|
+
define_method "test_#{method}_should_raise_invalidprofile_with_missing_tracker_id" do
|
44
|
+
assert_raise(InvalidProfile) do
|
45
|
+
@builder = JavaScriptBuilder.new(@context, GoogleAnalytics.new(nil))
|
46
|
+
@builder.send(method)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'test/unit'
|
3
|
+
require 'mocha'
|
4
|
+
|
5
|
+
require 'active_support'
|
6
|
+
require 'active_support/test_case'
|
7
|
+
require 'action_controller'
|
8
|
+
require 'action_controller/cgi_ext'
|
9
|
+
require 'action_controller/test_process'
|
10
|
+
require 'action_view/test_case'
|
11
|
+
|
12
|
+
$:.unshift File.dirname(__FILE__) + '/../lib'
|
13
|
+
|
14
|
+
RAILS_ROOT = '.' unless defined? RAILS_ROOT
|
15
|
+
RAILS_ENV = 'test' unless defined? RAILS_ENV
|
16
|
+
RAILS_DEFAULT_LOGGER = Logger.new(STDOUT) unless defined? RAILS_DEFAULT_LOGGER
|
17
|
+
|
18
|
+
# simulate the inclusion as Rails does loading the init.rb file.
|
19
|
+
require 'google_analytics_on_rails'
|
20
|
+
require File.dirname(__FILE__) + '/../init.rb'
|
21
|
+
|
22
|
+
ActionController::Base.logger = nil
|
23
|
+
ActionController::Routing::Routes.reload rescue nil
|
24
|
+
|
25
|
+
# Unit tests for Helpers are based on unit tests created and developed by Rails core team.
|
26
|
+
# See action_pack/test/abstract_unit for more details.
|
data/uninstall.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# Uninstall hook code here
|
metadata
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: google_analytics_on_rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Simone Carletti
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-10-28 00:00:00 +01:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: rake
|
17
|
+
type: :development
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0.8"
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: echoe
|
27
|
+
type: :development
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: "3.1"
|
34
|
+
version:
|
35
|
+
description: " GoogleAnalyticsOnRails is a Ruby on Rails plugin designed to make easier to integrate Google Analytics features in your application.\n"
|
36
|
+
email: weppos@weppos.net
|
37
|
+
executables: []
|
38
|
+
|
39
|
+
extensions: []
|
40
|
+
|
41
|
+
extra_rdoc_files:
|
42
|
+
- CHANGELOG.rdoc
|
43
|
+
- lib/google_analytics_on_rails/controller_mixin.rb
|
44
|
+
- lib/google_analytics_on_rails/java_script_builder.rb
|
45
|
+
- lib/google_analytics_on_rails/version.rb
|
46
|
+
- lib/google_analytics_on_rails.rb
|
47
|
+
- LICENSE.rdoc
|
48
|
+
- README.rdoc
|
49
|
+
files:
|
50
|
+
- CHANGELOG.rdoc
|
51
|
+
- google_analytics_on_rails.gemspec
|
52
|
+
- init.rb
|
53
|
+
- install.rb
|
54
|
+
- lib/google_analytics_on_rails/controller_mixin.rb
|
55
|
+
- lib/google_analytics_on_rails/java_script_builder.rb
|
56
|
+
- lib/google_analytics_on_rails/version.rb
|
57
|
+
- lib/google_analytics_on_rails.rb
|
58
|
+
- LICENSE.rdoc
|
59
|
+
- Manifest
|
60
|
+
- rails/init.rb
|
61
|
+
- Rakefile
|
62
|
+
- README.rdoc
|
63
|
+
- tasks/google_analytics_on_rails_tasks.rake
|
64
|
+
- test/controller_mixin_test.rb
|
65
|
+
- test/fixtures/mixin/ga.html.erb
|
66
|
+
- test/fixtures/mixin/ga_tracking_code.html.erb
|
67
|
+
- test/fixtures/mixin/google_analytics_tracking_code.html.erb
|
68
|
+
- test/google_analytics_on_rails_test.rb
|
69
|
+
- test/google_analytics_test.rb
|
70
|
+
- test/java_script_builder_test.rb
|
71
|
+
- test/test_helper.rb
|
72
|
+
- uninstall.rb
|
73
|
+
has_rdoc: true
|
74
|
+
homepage: http://code.simonecarletti.com/googleanalyticsonrails
|
75
|
+
licenses: []
|
76
|
+
|
77
|
+
post_install_message:
|
78
|
+
rdoc_options:
|
79
|
+
- --line-numbers
|
80
|
+
- --inline-source
|
81
|
+
- --title
|
82
|
+
- Google_analytics_on_rails
|
83
|
+
- --main
|
84
|
+
- README.rdoc
|
85
|
+
require_paths:
|
86
|
+
- lib
|
87
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: "0"
|
92
|
+
version:
|
93
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: "1.2"
|
98
|
+
version:
|
99
|
+
requirements: []
|
100
|
+
|
101
|
+
rubyforge_project:
|
102
|
+
rubygems_version: 1.3.5
|
103
|
+
signing_key:
|
104
|
+
specification_version: 3
|
105
|
+
summary: A Ruby on Rails plugin to integrate Google Analytics features in your application.
|
106
|
+
test_files:
|
107
|
+
- test/controller_mixin_test.rb
|
108
|
+
- test/google_analytics_on_rails_test.rb
|
109
|
+
- test/google_analytics_test.rb
|
110
|
+
- test/java_script_builder_test.rb
|
111
|
+
- test/test_helper.rb
|