clicktale 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Railsware LLC
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/README ADDED
@@ -0,0 +1,12 @@
1
+ Clicktale
2
+ =========
3
+ You should specify Clicktale.project_id and Clicktale.ratio in your environment.
4
+
5
+ 1. Put your settings into initializer
6
+ Example: config/initializers/clicktale.rb
7
+ Clicktale.project_id = '1212'
8
+ Clicktale.ratio = '0.5'
9
+
10
+ 2. Call <%= clicktale_tracker %> from view.
11
+
12
+ Copyright (c) 2009 Railsware LLC, released under the MIT license
data/Rakefile ADDED
@@ -0,0 +1,37 @@
1
+ require 'rake'
2
+ require 'spec/rake/spectask'
3
+ require 'rake/rdoctask'
4
+
5
+ desc 'Default: run unit tests.'
6
+ task :default => :spec
7
+
8
+ desc 'Generate documentation for the clicktale plugin.'
9
+ Rake::RDocTask.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'Clicktale'
12
+ rdoc.options << '--line-numbers' << '--inline-source'
13
+ rdoc.rdoc_files.include('README')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ desc "Run all specifications"
18
+ Spec::Rake::SpecTask.new('spec') do |t|
19
+ t.spec_files = FileList['spec/*.rb']
20
+ end
21
+
22
+ begin
23
+ require 'jeweler'
24
+ Jeweler::Tasks.new do |gemspec|
25
+ gemspec.name = "clicktale"
26
+ gemspec.summary = "Use ClickTale analytics service with rails sites that require sessions"
27
+ gemspec.description = "Use ClickTale (http://www.clicktale.com/) analytics service with rails sites that require sessions (user authentication for example)"
28
+ gemspec.email = "al@railsware.com"
29
+ gemspec.homepage = "http://github.com/railsware/clicktale"
30
+ gemspec.description = IO.read "README"
31
+ gemspec.authors = ["Railsware LLC"]
32
+ end
33
+ Jeweler::GemcutterTasks.new
34
+ rescue LoadError
35
+ puts "Jeweler not available. Install it with: sudo gem install jeweler"
36
+ end
37
+
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.0.0
data/clicktale.gemspec ADDED
@@ -0,0 +1,63 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{clicktale}
8
+ s.version = "1.0.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Railsware LLC"]
12
+ s.date = %q{2010-03-31}
13
+ s.description = %q{Clicktale
14
+ =========
15
+ You should specify Clicktale.project_id and Clicktale.ratio in your environment.
16
+
17
+ 1. Put your settings into initializer
18
+ Example: config/initializers/clicktale.rb
19
+ Clicktale.project_id = '1212'
20
+ Clicktale.ratio = '0.5'
21
+
22
+ 2. Call <%= clicktale_tracker %> from view.
23
+
24
+ Copyright (c) 2009 Railsware LLC, released under the MIT license}
25
+ s.email = %q{al@railsware.com}
26
+ s.extra_rdoc_files = [
27
+ "README"
28
+ ]
29
+ s.files = [
30
+ "MIT-LICENSE",
31
+ "README",
32
+ "Rakefile",
33
+ "VERSION",
34
+ "clicktale.gemspec",
35
+ "init.rb",
36
+ "lib/clicktale.rb",
37
+ "lib/clicktale_helper.rb",
38
+ "spec/clicktale_helper_spec.rb",
39
+ "spec/clicktale_spec.rb",
40
+ "spec/lib/attribute_accessors.rb"
41
+ ]
42
+ s.homepage = %q{http://github.com/railsware/clicktale}
43
+ s.rdoc_options = ["--charset=UTF-8"]
44
+ s.require_paths = ["lib"]
45
+ s.rubygems_version = %q{1.3.6}
46
+ s.summary = %q{Use ClickTale analytics service with rails sites that require sessions}
47
+ s.test_files = [
48
+ "spec/clicktale_helper_spec.rb",
49
+ "spec/clicktale_spec.rb",
50
+ "spec/lib/attribute_accessors.rb"
51
+ ]
52
+
53
+ if s.respond_to? :specification_version then
54
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
55
+ s.specification_version = 3
56
+
57
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
58
+ else
59
+ end
60
+ else
61
+ end
62
+ end
63
+
data/init.rb ADDED
@@ -0,0 +1,5 @@
1
+ require 'clicktale'
2
+ require 'clicktale_helper'
3
+
4
+ ActionController::Base.session_options[:expire_after] = 1.year
5
+ ActionView::Base.send(:include, ClicktaleHelper)
data/lib/clicktale.rb ADDED
@@ -0,0 +1,8 @@
1
+ class Clicktale
2
+ @@project_id = '0'
3
+ cattr_accessor :project_id
4
+
5
+
6
+ @@ratio = '0'
7
+ cattr_accessor :ratio
8
+ end
@@ -0,0 +1,26 @@
1
+ module ClicktaleHelper
2
+ def clicktale_tracker
3
+ <<-EOS
4
+ <!-- ClickTale Bottom part -->
5
+ <div id="ClickTaleDiv" style="display: none;"></div>
6
+ <script src="http://s.clicktale.net/WRb.js" type="text/javascript"></script>
7
+ <script type="text/javascript">
8
+ if(typeof ClickTale=='function'){
9
+ #{clicktale_fetch_from}
10
+ ClickTale(#{Clicktale.project_id}, #{Clicktale.ratio});
11
+ }
12
+ </script>
13
+ <!-- ClickTale end of Bottom part -->
14
+ EOS
15
+ end
16
+
17
+ def clicktale_fetch_from
18
+ url = if request.request_uri.index Regexp.new("^(.*)(\\?|\\&)#{controller.request.session_options[:session_key]}=(.*)(\\&|\\z)")
19
+ "#{request.protocol}#{request.host}#{request.request_uri}".
20
+ gsub(Regexp.new("#{controller.request.session_options[:session_key]}=(.*)(\\&|\\z)"), "#{controller.request.session_options[:session_key]}=#{session.session_id}")
21
+ else
22
+ "#{request.protocol}#{request.host}#{request.request_uri}#{request.request_uri.index(/\?/) ? '&' : '?'}#{controller.request.session_options[:session_key]}=#{session.session_id}"
23
+ end
24
+ "ClickTaleFetchFrom = '#{url}'"
25
+ end
26
+ end
@@ -0,0 +1,48 @@
1
+ require File.dirname(__FILE__) + "/lib/attribute_accessors"
2
+ require File.dirname(__FILE__) + '/../lib/clicktale'
3
+ require File.dirname(__FILE__) + '/../lib/clicktale_helper'
4
+
5
+ context "ClicktaleHelper instance" do
6
+ include ClicktaleHelper
7
+
8
+ before(:each) do
9
+ Clicktale.project_id = '8001'
10
+ Clicktale.ratio = '0.25'
11
+ end
12
+
13
+ it "should build fetch url" do
14
+ lambda {
15
+ result = clicktale_fetch_from
16
+ result.should match(/param1=value1/)
17
+ result.should match(/param2=value2/)
18
+ result.should match(/_session=1234567890/)
19
+ }.should_not raise_error
20
+ end
21
+
22
+ it "should build tracker code" do
23
+ lambda {
24
+ result = clicktale_tracker
25
+ result.should match(/ClickTaleFetchFrom = 'http:\/\/test.uri\/some_controller\/some_action\?param1=value1&param2=value2&_session=1234567890/)
26
+ result.should match(/ClickTale\(8001, 0\.25\)/)
27
+ }.should_not raise_error
28
+ end
29
+
30
+ protected
31
+ def request
32
+ methods = {
33
+ :request_uri => "/some_controller/some_action?param1=value1&param2=value2&_session=111000111",
34
+ :protocol => "http://",
35
+ :host => "test.uri",
36
+ :session_options => { :session_key => '_session' }
37
+ }
38
+ mock('Request', methods)
39
+ end
40
+
41
+ def session
42
+ mock('Session', { :session_id => '1234567890' })
43
+ end
44
+
45
+ def controller
46
+ mock('Controller', { :request => request })
47
+ end
48
+ end
@@ -0,0 +1,11 @@
1
+ require File.dirname(__FILE__) + "/lib/attribute_accessors"
2
+ require File.dirname(__FILE__) + '/../lib/clicktale'
3
+
4
+ context "Clicktale class" do
5
+ ["project_id", "ratio"].each do |attr|
6
+ it "should have #{attr} class attribute" do
7
+ Clicktale.singleton_methods.should include("#{attr}=")
8
+ Clicktale.singleton_methods.should include(attr)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,61 @@
1
+ # Extends the class object with class and instance accessors for class attributes,
2
+ # just like the native attr* accessors for instance attributes.
3
+ #
4
+ # class Person
5
+ # cattr_accessor :hair_colors
6
+ # end
7
+ #
8
+ # Person.hair_colors = [:brown, :black, :blonde, :red]
9
+
10
+ class Array
11
+ def extract_options!
12
+ last.is_a?(::Hash) ? pop : {}
13
+ end
14
+ end
15
+
16
+ class Class
17
+ def cattr_reader(*syms)
18
+ syms.flatten.each do |sym|
19
+ next if sym.is_a?(Hash)
20
+ class_eval(<<-EOS, __FILE__, __LINE__)
21
+ unless defined? @@#{sym} # unless defined? @@hair_colors
22
+ @@#{sym} = nil # @@hair_colors = nil
23
+ end # end
24
+ #
25
+ def self.#{sym} # def self.hair_colors
26
+ @@#{sym} # @@hair_colors
27
+ end # end
28
+ #
29
+ def #{sym} # def hair_colors
30
+ @@#{sym} # @@hair_colors
31
+ end # end
32
+ EOS
33
+ end
34
+ end
35
+
36
+ def cattr_writer(*syms)
37
+ options = syms.extract_options!
38
+ syms.flatten.each do |sym|
39
+ class_eval(<<-EOS, __FILE__, __LINE__)
40
+ unless defined? @@#{sym} # unless defined? @@hair_colors
41
+ @@#{sym} = nil # @@hair_colors = nil
42
+ end # end
43
+ #
44
+ def self.#{sym}=(obj) # def self.hair_colors=(obj)
45
+ @@#{sym} = obj # @@hair_colors = obj
46
+ end # end
47
+ #
48
+ #{" #
49
+ def #{sym}=(obj) # def hair_colors=(obj)
50
+ @@#{sym} = obj # @@hair_colors = obj
51
+ end # end
52
+ " unless options[:instance_writer] == false } # # instance writer above is generated unless options[:instance_writer] == false
53
+ EOS
54
+ end
55
+ end
56
+
57
+ def cattr_accessor(*syms)
58
+ cattr_reader(*syms)
59
+ cattr_writer(*syms)
60
+ end
61
+ end
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: clicktale
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 1
7
+ - 0
8
+ - 0
9
+ version: 1.0.0
10
+ platform: ruby
11
+ authors:
12
+ - Railsware LLC
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-03-31 00:00:00 +03:00
18
+ default_executable:
19
+ dependencies: []
20
+
21
+ description: |-
22
+ Clicktale
23
+ =========
24
+ You should specify Clicktale.project_id and Clicktale.ratio in your environment.
25
+
26
+ 1. Put your settings into initializer
27
+ Example: config/initializers/clicktale.rb
28
+ Clicktale.project_id = '1212'
29
+ Clicktale.ratio = '0.5'
30
+
31
+ 2. Call <%= clicktale_tracker %> from view.
32
+
33
+ Copyright (c) 2009 Railsware LLC, released under the MIT license
34
+ email: al@railsware.com
35
+ executables: []
36
+
37
+ extensions: []
38
+
39
+ extra_rdoc_files:
40
+ - README
41
+ files:
42
+ - MIT-LICENSE
43
+ - README
44
+ - Rakefile
45
+ - VERSION
46
+ - clicktale.gemspec
47
+ - init.rb
48
+ - lib/clicktale.rb
49
+ - lib/clicktale_helper.rb
50
+ - spec/clicktale_helper_spec.rb
51
+ - spec/clicktale_spec.rb
52
+ - spec/lib/attribute_accessors.rb
53
+ has_rdoc: true
54
+ homepage: http://github.com/railsware/clicktale
55
+ licenses: []
56
+
57
+ post_install_message:
58
+ rdoc_options:
59
+ - --charset=UTF-8
60
+ require_paths:
61
+ - lib
62
+ required_ruby_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ segments:
67
+ - 0
68
+ version: "0"
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ segments:
74
+ - 0
75
+ version: "0"
76
+ requirements: []
77
+
78
+ rubyforge_project:
79
+ rubygems_version: 1.3.6
80
+ signing_key:
81
+ specification_version: 3
82
+ summary: Use ClickTale analytics service with rails sites that require sessions
83
+ test_files:
84
+ - spec/clicktale_helper_spec.rb
85
+ - spec/clicktale_spec.rb
86
+ - spec/lib/attribute_accessors.rb