omniture_rails3 0.0.1
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/Gemfile +2 -0
- data/MIT-LICENSE +20 -0
- data/README.textile +3 -0
- data/Rakefile +25 -0
- data/app/helpers/omniture_rails3/controller_helper.rb +7 -0
- data/app/helpers/omniture_rails3/view_helper.rb +55 -0
- data/lib/omniture_rails3/action_controller_extension.rb +20 -0
- data/lib/omniture_rails3/config.rb +59 -0
- data/lib/omniture_rails3/engine.rb +18 -0
- data/lib/omniture_rails3.rb +12 -0
- metadata +150 -0
data/Gemfile
ADDED
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2011 YOURNAME
|
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.textile
ADDED
@@ -0,0 +1,3 @@
|
|
1
|
+
h1. Omniture Rails 3
|
2
|
+
|
3
|
+
This engine is meant to help app developers easily set Omniture sprops. It uses "Higml":https://github.com/flyingmachine/higml to configure custom variables based on controller, action, and whatever other params are present. It also allows you to provide a mapping between your custom variable names and their omniture name - i.e. you can refer to "prop34" as "search\_origin" in your code and in your configuration.
|
data/Rakefile
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'rubygems'
|
3
|
+
begin
|
4
|
+
require 'bundler/setup'
|
5
|
+
rescue LoadError
|
6
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
7
|
+
end
|
8
|
+
|
9
|
+
require 'rake'
|
10
|
+
require 'rake/rdoctask'
|
11
|
+
|
12
|
+
require 'rspec/core'
|
13
|
+
require 'rspec/core/rake_task'
|
14
|
+
|
15
|
+
RSpec::Core::RakeTask.new(:spec)
|
16
|
+
|
17
|
+
task :default => :spec
|
18
|
+
|
19
|
+
Rake::RDocTask.new(:rdoc) do |rdoc|
|
20
|
+
rdoc.rdoc_dir = 'rdoc'
|
21
|
+
rdoc.title = 'OmnitureRails3'
|
22
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
23
|
+
rdoc.rdoc_files.include('README.rdoc')
|
24
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
25
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
module OmnitureRails3
|
2
|
+
module ViewHelper
|
3
|
+
def omniture_html
|
4
|
+
<<-EOS
|
5
|
+
<!-- SiteCatalyst code version: H.1. Copyright 1997-2005 Omniture, Inc. More info available at http://www.omniture.com -->
|
6
|
+
<script language="JavaScript"><!--
|
7
|
+
#{omniture_javascript}
|
8
|
+
//--></script>
|
9
|
+
<script language="JavaScript"><!--
|
10
|
+
if(navigator.appVersion.indexOf('MSIE')>=0)document.write(unescape('%3C')+'\!-'+'-')
|
11
|
+
//--></script><noscript><img
|
12
|
+
src="#{OmnitureRails3.config.noscript_img_src}"
|
13
|
+
height="1" width="1" border="0" alt="" /></noscript><!--/DO NOT REMOVE/-->
|
14
|
+
<!-- End SiteCatalyst code version: H.1. -->
|
15
|
+
EOS
|
16
|
+
end
|
17
|
+
|
18
|
+
def omniture_javascript
|
19
|
+
<<-EOS
|
20
|
+
var s_account="#{OmnitureRails3.config.tracking_account}";
|
21
|
+
var s=s_gi(s_account);
|
22
|
+
|
23
|
+
$.extend(s, #{sprops_json})
|
24
|
+
|
25
|
+
/* WARNING: Changing the visitor namespace will cause drastic changes
|
26
|
+
to how your visitor data is collected. Changes should only be made
|
27
|
+
when instructed to do so by your account manager.*/
|
28
|
+
s.visitorNamespace="#{OmnitureRails3.config.visitor_namespace}"
|
29
|
+
|
30
|
+
/************* DO NOT ALTER ANYTHING BELOW THIS LINE ! **************/
|
31
|
+
var s_code=s.t();if(s_code)document.write(s_code)
|
32
|
+
EOS
|
33
|
+
end
|
34
|
+
|
35
|
+
def sprops_json
|
36
|
+
sprops = Higml.
|
37
|
+
values_for(omniture_input, OmnitureRails3::TREES[controller_name.to_sym], self, omniture_priority_map || {}).
|
38
|
+
delete_if{|k,v| !v}
|
39
|
+
|
40
|
+
transform_sprops(sprops)
|
41
|
+
|
42
|
+
sprops.inject({}){|return_value, value| return_value[value[0]] = h(value[1]); return_value }. #html escape
|
43
|
+
to_json.
|
44
|
+
gsub(/,\s*"/,",\n\"") #put each variable on a separate line
|
45
|
+
end
|
46
|
+
|
47
|
+
def transform_sprops(sprops)
|
48
|
+
OmnitureRails3.config.prop_map.each do |internal_name, omniture_name|
|
49
|
+
sprops[omniture_name] = sprops[internal_name]
|
50
|
+
sprops.delete(internal_name)
|
51
|
+
end
|
52
|
+
sprops
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module OmnitureRails3
|
2
|
+
module ActionControllerExtension
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
included do
|
5
|
+
attr_accessor :omniture_input, :omniture_priority_map
|
6
|
+
helper_attr :omniture_input, :omniture_priority_map
|
7
|
+
|
8
|
+
before_filter :set_omniture_input
|
9
|
+
end
|
10
|
+
|
11
|
+
module ClassMethods
|
12
|
+
end
|
13
|
+
|
14
|
+
module InstanceMethods
|
15
|
+
def set_omniture_input
|
16
|
+
self.omniture_input = params
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
module OmnitureRails3
|
2
|
+
class Config
|
3
|
+
include Singleton
|
4
|
+
OPTIONS = %w{higml_directory prop_map tracking_account visitor_namespace noscript_img_src}
|
5
|
+
attr_accessor *OPTIONS.collect{|o|o.to_sym}
|
6
|
+
|
7
|
+
def higml_directory
|
8
|
+
@higml_directory ||= File.join(Rails.root, "app", "omniture")
|
9
|
+
end
|
10
|
+
|
11
|
+
def set(config)
|
12
|
+
case config
|
13
|
+
when Hash: set_with_hash(config)
|
14
|
+
when IO: set_with_io(config)
|
15
|
+
when String: set_with_string(config)
|
16
|
+
end
|
17
|
+
|
18
|
+
Higml.config.set({
|
19
|
+
"global_pairs" => {
|
20
|
+
:visitor_namespace => visitor_namespace,
|
21
|
+
:tracking_account => tracking_account,
|
22
|
+
:noscript_img_src => noscript_img_src
|
23
|
+
},
|
24
|
+
"higml_directory" => self.higml_directory
|
25
|
+
})
|
26
|
+
end
|
27
|
+
|
28
|
+
def set_with_hash(config)
|
29
|
+
OPTIONS.each do |option|
|
30
|
+
self.send("#{option}=", config[option]) if config[option]
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
# String should be either a filename or YAML
|
35
|
+
def set_with_string(config)
|
36
|
+
if File.exists?(config)
|
37
|
+
set_with_yaml(File.read(config))
|
38
|
+
else
|
39
|
+
set_with_yaml(config)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def set_with_io(config)
|
44
|
+
set_with_yaml(config)
|
45
|
+
config.close
|
46
|
+
end
|
47
|
+
|
48
|
+
def set_with_yaml(config)
|
49
|
+
set_with_hash(YAML.load(config)[Rails.env])
|
50
|
+
end
|
51
|
+
|
52
|
+
def to_hash
|
53
|
+
OPTIONS.inject({}){ |hash, option|
|
54
|
+
hash[option] = self.send(option)
|
55
|
+
hash
|
56
|
+
}
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module OmnitureRails3
|
2
|
+
class Engine < Rails::Engine
|
3
|
+
initializer 'omniture_rails_3.helper' do |app|
|
4
|
+
ActionView::Base.send :include, OmnitureRails3::ViewHelper
|
5
|
+
ActionController::Base.send :include, OmnitureRails3::ActionControllerExtension
|
6
|
+
|
7
|
+
OmnitureRails3.config.set(File.join(Rails.root, "config", "omniture.yml"))
|
8
|
+
# Parse Higml trees and store them so we don't have to do this every request
|
9
|
+
|
10
|
+
OmnitureRails3::TREES = Dir[File.join(OmnitureRails3.config.higml_directory, '*.higml')].inject({}) do |hash, filename|
|
11
|
+
puts filename
|
12
|
+
hash[File.basename(filename, ".higml").to_sym] = Higml::Parser.new(File.read(filename)).to_tree
|
13
|
+
hash
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require "higml"
|
2
|
+
require "omniture_rails3/action_controller_extension"
|
3
|
+
require "omniture_rails3/config"
|
4
|
+
require "omniture_rails3/engine"
|
5
|
+
|
6
|
+
module OmnitureRails3
|
7
|
+
class << self
|
8
|
+
def config
|
9
|
+
@config ||= OmnitureRails3::Config.instance
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
metadata
ADDED
@@ -0,0 +1,150 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: omniture_rails3
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Daniel Higginbotham
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-06-09 00:00:00 -04:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: rails
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 7
|
30
|
+
segments:
|
31
|
+
- 3
|
32
|
+
- 0
|
33
|
+
version: "3.0"
|
34
|
+
type: :runtime
|
35
|
+
version_requirements: *id001
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: higml
|
38
|
+
prerelease: false
|
39
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - "="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
hash: 29
|
45
|
+
segments:
|
46
|
+
- 0
|
47
|
+
- 0
|
48
|
+
- 1
|
49
|
+
version: 0.0.1
|
50
|
+
type: :runtime
|
51
|
+
version_requirements: *id002
|
52
|
+
- !ruby/object:Gem::Dependency
|
53
|
+
name: capybara
|
54
|
+
prerelease: false
|
55
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
56
|
+
none: false
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
hash: 15
|
61
|
+
segments:
|
62
|
+
- 0
|
63
|
+
- 4
|
64
|
+
- 0
|
65
|
+
version: 0.4.0
|
66
|
+
type: :development
|
67
|
+
version_requirements: *id003
|
68
|
+
- !ruby/object:Gem::Dependency
|
69
|
+
name: rspec-rails
|
70
|
+
prerelease: false
|
71
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
hash: 3
|
77
|
+
segments:
|
78
|
+
- 0
|
79
|
+
version: "0"
|
80
|
+
type: :development
|
81
|
+
version_requirements: *id004
|
82
|
+
- !ruby/object:Gem::Dependency
|
83
|
+
name: ruby-debug
|
84
|
+
prerelease: false
|
85
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
86
|
+
none: false
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
hash: 3
|
91
|
+
segments:
|
92
|
+
- 0
|
93
|
+
version: "0"
|
94
|
+
type: :development
|
95
|
+
version_requirements: *id005
|
96
|
+
description: Insert OmnitureRails3 description.
|
97
|
+
email: daniel@flyingmachinestudios.com
|
98
|
+
executables: []
|
99
|
+
|
100
|
+
extensions: []
|
101
|
+
|
102
|
+
extra_rdoc_files: []
|
103
|
+
|
104
|
+
files:
|
105
|
+
- app/helpers/omniture_rails3/controller_helper.rb
|
106
|
+
- app/helpers/omniture_rails3/view_helper.rb
|
107
|
+
- lib/omniture_rails3/action_controller_extension.rb
|
108
|
+
- lib/omniture_rails3/config.rb
|
109
|
+
- lib/omniture_rails3/engine.rb
|
110
|
+
- lib/omniture_rails3.rb
|
111
|
+
- MIT-LICENSE
|
112
|
+
- Rakefile
|
113
|
+
- Gemfile
|
114
|
+
- README.textile
|
115
|
+
has_rdoc: true
|
116
|
+
homepage:
|
117
|
+
licenses: []
|
118
|
+
|
119
|
+
post_install_message:
|
120
|
+
rdoc_options: []
|
121
|
+
|
122
|
+
require_paths:
|
123
|
+
- lib
|
124
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
125
|
+
none: false
|
126
|
+
requirements:
|
127
|
+
- - ">="
|
128
|
+
- !ruby/object:Gem::Version
|
129
|
+
hash: 3
|
130
|
+
segments:
|
131
|
+
- 0
|
132
|
+
version: "0"
|
133
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
134
|
+
none: false
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
hash: 3
|
139
|
+
segments:
|
140
|
+
- 0
|
141
|
+
version: "0"
|
142
|
+
requirements: []
|
143
|
+
|
144
|
+
rubyforge_project:
|
145
|
+
rubygems_version: 1.3.7
|
146
|
+
signing_key:
|
147
|
+
specification_version: 3
|
148
|
+
summary: Insert OmnitureRails3 summary.
|
149
|
+
test_files: []
|
150
|
+
|