lytix 0.1.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.
- data/.document +5 -0
- data/.gitignore +21 -0
- data/LICENSE +20 -0
- data/README.rdoc +17 -0
- data/Rakefile +53 -0
- data/VERSION +1 -0
- data/init.rb +1 -0
- data/lib/lytix.rb +7 -0
- data/lib/lytix/account.rb +33 -0
- data/lib/lytix/configuration.rb +23 -0
- data/lib/lytix/controller_methods.rb +36 -0
- data/lib/lytix/method_list.rb +27 -0
- data/lib/lytix/snippet.rb +56 -0
- data/lytix.gemspec +60 -0
- data/test/helper.rb +10 -0
- data/test/test_lytix.rb +7 -0
- metadata +81 -0
data/.document
ADDED
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Steve Richert
|
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.rdoc
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
= lytix
|
2
|
+
|
3
|
+
Description goes here.
|
4
|
+
|
5
|
+
== Note on Patches/Pull Requests
|
6
|
+
|
7
|
+
* Fork the project.
|
8
|
+
* Make your feature addition or bug fix.
|
9
|
+
* Add tests for it. This is important so I don't break it in a
|
10
|
+
future version unintentionally.
|
11
|
+
* Commit, do not mess with rakefile, version, or history.
|
12
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
13
|
+
* Send me a pull request. Bonus points for topic branches.
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2010 laserlemon. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
require 'rake/testtask'
|
4
|
+
require 'rake/rdoctask'
|
5
|
+
|
6
|
+
begin
|
7
|
+
require 'jeweler'
|
8
|
+
Jeweler::Tasks.new do |gem|
|
9
|
+
gem.name = 'lytix'
|
10
|
+
gem.summary = %(Easily include Google Analytics in your Rails app)
|
11
|
+
gem.description = %(Easily include Google Analytics in your Rails app)
|
12
|
+
gem.email = 'steve.richert@gmail.com'
|
13
|
+
gem.homepage = 'http://github.com/laserlemon/lytix'
|
14
|
+
gem.authors = ['Steve Richert']
|
15
|
+
gem.add_development_dependency 'shoulda', '>= 0'
|
16
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
17
|
+
end
|
18
|
+
Jeweler::GemcutterTasks.new
|
19
|
+
rescue LoadError
|
20
|
+
puts 'Jeweler (or a dependency) not available. Install it with: gem install jeweler'
|
21
|
+
end
|
22
|
+
|
23
|
+
Rake::TestTask.new(:test) do |test|
|
24
|
+
test.libs << 'lib' << 'test'
|
25
|
+
test.pattern = 'test/**/test_*.rb'
|
26
|
+
test.verbose = true
|
27
|
+
end
|
28
|
+
|
29
|
+
begin
|
30
|
+
require 'rcov/rcovtask'
|
31
|
+
Rcov::RcovTask.new do |test|
|
32
|
+
test.libs << 'test'
|
33
|
+
test.pattern = 'test/**/test_*.rb'
|
34
|
+
test.verbose = true
|
35
|
+
end
|
36
|
+
rescue LoadError
|
37
|
+
task :rcov do
|
38
|
+
abort 'RCov is not available. In order to run rcov, you must: gem install rcov'
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
task :test => :check_dependencies
|
43
|
+
|
44
|
+
task :default => :test
|
45
|
+
|
46
|
+
Rake::RDocTask.new do |rdoc|
|
47
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : nil
|
48
|
+
|
49
|
+
rdoc.rdoc_dir = 'rdoc'
|
50
|
+
rdoc.title = ['lytix', version].compact.join(' ')
|
51
|
+
rdoc.rdoc_files.include('README*')
|
52
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
53
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'lib', 'lytix')
|
data/lib/lytix.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
module Lytix
|
2
|
+
class Account
|
3
|
+
attr_reader :key, :name
|
4
|
+
|
5
|
+
def initialize(key, name = nil)
|
6
|
+
@key, @name = key, name
|
7
|
+
end
|
8
|
+
|
9
|
+
def tracker(*args, &block)
|
10
|
+
if block_given?
|
11
|
+
@tracker_configuration = block
|
12
|
+
else
|
13
|
+
returning(MethodList.new) do |tracker|
|
14
|
+
if @tracker_configuration
|
15
|
+
@tracker_configuration.bind(tracker).call(*args)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def transaction(*args, &block)
|
22
|
+
if block_given?
|
23
|
+
@transaction_configuration = block
|
24
|
+
else
|
25
|
+
returning(MethodList.new) do |transaction|
|
26
|
+
if @transaction_configuration
|
27
|
+
@transaction_configuration.bind(transaction).call(*args)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Lytix
|
2
|
+
module Configuration
|
3
|
+
class << self
|
4
|
+
def accounts
|
5
|
+
@accounts ||= []
|
6
|
+
end
|
7
|
+
|
8
|
+
def account(*args, &block)
|
9
|
+
value = (args.size > 1 ? args : args.first)
|
10
|
+
new_accounts = case value
|
11
|
+
when Array then value.inject([]){|a,v| a += account(v) }
|
12
|
+
when String then [Account.new(value)]
|
13
|
+
when Hash then value.map{|k,v| Account.new(v, k) }
|
14
|
+
end
|
15
|
+
|
16
|
+
new_accounts.each{|a| block.bind(a).call } if block_given?
|
17
|
+
|
18
|
+
accounts
|
19
|
+
@accounts += new_accounts
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Lytix
|
2
|
+
module ControllerMethods
|
3
|
+
def self.included(base)
|
4
|
+
base.class_eval do
|
5
|
+
extend ClassMethods
|
6
|
+
include InstanceMethods
|
7
|
+
|
8
|
+
before_filter :google_analytics
|
9
|
+
after_filter :insert_google_analytics
|
10
|
+
|
11
|
+
helper_method :google_analytics
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
module ClassMethods
|
16
|
+
def skip_google_analytics
|
17
|
+
skip_before_filter :google_analytics
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
module InstanceMethods
|
22
|
+
def google_analytics(options = {})
|
23
|
+
@google_analytics = Snippet.new(options).to_s
|
24
|
+
nil
|
25
|
+
end
|
26
|
+
|
27
|
+
def insert_google_analytics
|
28
|
+
if @google_analytics && request.format.html? && response.body.respond_to?(:sub!)
|
29
|
+
response.body.sub!(/([ \t]*)<\/body>/i){ [($1 + @google_analytics.to_s), $&].reject(&:blank?).join($/) }
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
ActionController::Base.send(:include, Lytix::ControllerMethods)
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Lytix
|
2
|
+
class MethodList
|
3
|
+
def list
|
4
|
+
@list ||= []
|
5
|
+
end
|
6
|
+
|
7
|
+
def snippet(tracker_name)
|
8
|
+
list.map do |method, args|
|
9
|
+
method_name = method.to_s.camelize(:lower)
|
10
|
+
formatted_args = args.map{|a| format_argument(a) }.join(', ')
|
11
|
+
"#{tracker_name}.#{method_name}(#{formatted_args});"
|
12
|
+
end.join(' ')
|
13
|
+
end
|
14
|
+
|
15
|
+
def method_missing(symbol, *args)
|
16
|
+
list << [symbol, args]
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
def format_argument(arg)
|
21
|
+
case arg
|
22
|
+
when Symbol then arg.to_s
|
23
|
+
else arg.to_json
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
module Lytix
|
2
|
+
class Snippet
|
3
|
+
attr_reader :options
|
4
|
+
|
5
|
+
def initialize(options = {})
|
6
|
+
@options = options.symbolize_keys.reverse_merge(
|
7
|
+
:tracker => true,
|
8
|
+
:transaction => false
|
9
|
+
)
|
10
|
+
end
|
11
|
+
|
12
|
+
def to_s
|
13
|
+
intro = %(<script type="text/javascript">var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www."); document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));</script><script type="text/javascript">try{)
|
14
|
+
outro = %(} catch(err) {}</script>)
|
15
|
+
[intro, trackers, transactions, outro].reject(&:blank?).join(' ')
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
def accounts
|
20
|
+
only, except = Array(options[:only]), Array(options[:except])
|
21
|
+
|
22
|
+
@accounts ||= begin
|
23
|
+
accounts = Configuration.accounts
|
24
|
+
accounts = accounts.select{|a| only.include?(a.name) || only.include?(a.key) } if only.present?
|
25
|
+
accounts = accounts.reject{|a| except.include?(a.name) || except.include?(a.key) } if except.present?
|
26
|
+
accounts
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def tracker_name(account)
|
31
|
+
index = accounts.size > 1 ? accounts.index(account) + 1 : nil
|
32
|
+
"pageTracker#{index}"
|
33
|
+
end
|
34
|
+
|
35
|
+
def trackers
|
36
|
+
returning([]) do |lines|
|
37
|
+
accounts.each do |account|
|
38
|
+
tracker = options[:tracker] == true ? account.tracker : account.tracker(*options[:tracker])
|
39
|
+
name = tracker_name(account)
|
40
|
+
lines << %(var #{name} = _gat._getTracker("#{account.key}");)
|
41
|
+
lines << tracker.snippet(name)
|
42
|
+
lines << "#{name}._trackPageview();"
|
43
|
+
end
|
44
|
+
end.reject(&:blank?).join(' ')
|
45
|
+
end
|
46
|
+
|
47
|
+
def transactions
|
48
|
+
return '' unless options[:transaction]
|
49
|
+
|
50
|
+
accounts.map do |account|
|
51
|
+
transaction = options[:transaction] == true ? account.transaction : account.transaction(*options[:transaction])
|
52
|
+
transaction.snippet(tracker_name(account))
|
53
|
+
end.reject(&:blank?).join(' ')
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
data/lytix.gemspec
ADDED
@@ -0,0 +1,60 @@
|
|
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{lytix}
|
8
|
+
s.version = "0.1.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Steve Richert"]
|
12
|
+
s.date = %q{2010-02-15}
|
13
|
+
s.description = %q{Easily include Google Analytics in your Rails app}
|
14
|
+
s.email = %q{steve.richert@gmail.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".gitignore",
|
22
|
+
"LICENSE",
|
23
|
+
"README.rdoc",
|
24
|
+
"Rakefile",
|
25
|
+
"VERSION",
|
26
|
+
"init.rb",
|
27
|
+
"lib/lytix.rb",
|
28
|
+
"lib/lytix/account.rb",
|
29
|
+
"lib/lytix/configuration.rb",
|
30
|
+
"lib/lytix/controller_methods.rb",
|
31
|
+
"lib/lytix/method_list.rb",
|
32
|
+
"lib/lytix/snippet.rb",
|
33
|
+
"lytix.gemspec",
|
34
|
+
"test/helper.rb",
|
35
|
+
"test/test_lytix.rb"
|
36
|
+
]
|
37
|
+
s.homepage = %q{http://github.com/laserlemon/lytix}
|
38
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
39
|
+
s.require_paths = ["lib"]
|
40
|
+
s.rubygems_version = %q{1.3.5}
|
41
|
+
s.summary = %q{Easily include Google Analytics in your Rails app}
|
42
|
+
s.test_files = [
|
43
|
+
"test/helper.rb",
|
44
|
+
"test/test_lytix.rb"
|
45
|
+
]
|
46
|
+
|
47
|
+
if s.respond_to? :specification_version then
|
48
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
49
|
+
s.specification_version = 3
|
50
|
+
|
51
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
52
|
+
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
53
|
+
else
|
54
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
55
|
+
end
|
56
|
+
else
|
57
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
data/test/helper.rb
ADDED
data/test/test_lytix.rb
ADDED
metadata
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: lytix
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Steve Richert
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2010-02-15 00:00:00 -05:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: shoulda
|
17
|
+
type: :development
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
version:
|
25
|
+
description: Easily include Google Analytics in your Rails app
|
26
|
+
email: steve.richert@gmail.com
|
27
|
+
executables: []
|
28
|
+
|
29
|
+
extensions: []
|
30
|
+
|
31
|
+
extra_rdoc_files:
|
32
|
+
- LICENSE
|
33
|
+
- README.rdoc
|
34
|
+
files:
|
35
|
+
- .document
|
36
|
+
- .gitignore
|
37
|
+
- LICENSE
|
38
|
+
- README.rdoc
|
39
|
+
- Rakefile
|
40
|
+
- VERSION
|
41
|
+
- init.rb
|
42
|
+
- lib/lytix.rb
|
43
|
+
- lib/lytix/account.rb
|
44
|
+
- lib/lytix/configuration.rb
|
45
|
+
- lib/lytix/controller_methods.rb
|
46
|
+
- lib/lytix/method_list.rb
|
47
|
+
- lib/lytix/snippet.rb
|
48
|
+
- lytix.gemspec
|
49
|
+
- test/helper.rb
|
50
|
+
- test/test_lytix.rb
|
51
|
+
has_rdoc: true
|
52
|
+
homepage: http://github.com/laserlemon/lytix
|
53
|
+
licenses: []
|
54
|
+
|
55
|
+
post_install_message:
|
56
|
+
rdoc_options:
|
57
|
+
- --charset=UTF-8
|
58
|
+
require_paths:
|
59
|
+
- lib
|
60
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
61
|
+
requirements:
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: "0"
|
65
|
+
version:
|
66
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: "0"
|
71
|
+
version:
|
72
|
+
requirements: []
|
73
|
+
|
74
|
+
rubyforge_project:
|
75
|
+
rubygems_version: 1.3.5
|
76
|
+
signing_key:
|
77
|
+
specification_version: 3
|
78
|
+
summary: Easily include Google Analytics in your Rails app
|
79
|
+
test_files:
|
80
|
+
- test/helper.rb
|
81
|
+
- test/test_lytix.rb
|