forked from randland/omniture_client
/
omniture_rails.rb
58 lines (47 loc) · 1.44 KB
/
omniture_rails.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
module OmnitureClient
module ActionControllerMethods
def self.included(base)
base.extend(ClassMethods)
end
module ClassMethods
def reports_to_omniture(options = {})
include InstanceMethods
before_filter :set_reporter, options
before_filter :assign_flash_vars, options
attr_accessor :reporter
end
end
module InstanceMethods
def omniture_flash
flash[:omniture] ||= {}
end
def omniture_url
ssl = :ssl if request.ssl? && OmnitureClient::ssl_url
reporter.url(ssl)
end
def omniture_js
ssl = :ssl if request.ssl? && OmnitureClient::ssl_url
reporter.js(ssl)
end
def omniture_raw
reporter.raw
end
private
def set_reporter
@reporter ||= begin
"#{controller_path.classify}Reporter".constantize.new(self)
#rescue NameError
# BasicReporter.new(self)
end
end
def assign_flash_vars
reporter.class.clear_meta_vars unless omniture_flash.empty?
omniture_flash.each do |name, value|
reporter.add_var(name, value)
end
end
end
end
end
ActionController::Base.send(:include, OmnitureClient::ActionControllerMethods) if defined?(ActionController::Base)
OmnitureClient::config(YAML::load(File.open('config/omniture.yml'))[Rails.env]) if File.exists?('config/omniture.yml')