Created
April 12, 2012 16:48
-
-
Save jparbros/2369025 to your computer and use it in GitHub Desktop.
omniture_common_params refactor #3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class ApplicationController < ActionController::Base | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module Omniture | |
| class Base | |
| def initialize(options = {}) | |
| @campaign = options[:campaign] | |
| @options = options | |
| @controller_context = Omniture.controller_context | |
| omniture_common_params | |
| end | |
| def omniture_common_params | |
| @omniture_data_arr = [self] | |
| # Set the omniture LOGIN | |
| set_omniture_login | |
| # Set the omniture REGISTRATION | |
| set_omniture_registration | |
| set_omniture_cookie | |
| # Set the omniture PDP version | |
| set_omniture_pdp_version | |
| @omniture_data_arr.size > 1 ? omniture_data_arr : omniture_data_arr.first | |
| end | |
| def set_omniture_login | |
| if @options[:logged] || @controller_context[:session]['omn_fire_registration_success'] | |
| @omniture_data_arr.insert(0, Omniture.generate_params(:login_success, @options)) | |
| end | |
| end | |
| def set_omniture_registration | |
| if Account.current && @controller_context[:session]['omn_fire_registration_success'] | |
| @omniture_data_arr.insert(0, Omniture.generate_params(:registration_success, @options, { :account => Account.current })) | |
| @controller_context[:session]['omn_fire_registration_success'] += 1 | |
| @controller_context[:session]['omn_fire_registration_success'] = nil if @controller_context[:session]['omn_fire_registration_success'] >= 2 | |
| end | |
| end | |
| def set_omniture_pdp_version | |
| @omniture_data_arr.each { |o| o.set_pdp_version(pdp_version) if o.respond_to?(:set_pdp_version) } | |
| end | |
| def set_omniture_cookie | |
| visitor_id = cookies[:omniture] || request.session_options[:id] | |
| cookies[:mc_id] = { | |
| :value => visitor_id, | |
| :expires => 10.years.from_now | |
| } | |
| end | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module Omniture | |
| def self.set_controller_context(session, cookies, controller_name, action_name, request) | |
| @controller_context = { | |
| :session => session, | |
| :cookies => cookies, | |
| :controller_name => controller_name, | |
| :action_name => action_name, | |
| :request => request | |
| } | |
| end | |
| def self.controller_context | |
| @controller_context ||= {} | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class SomeController < ApplicationController | |
| helper_method :omniture_params | |
| protected | |
| def omniture_params | |
| Omniture.set_controller_context(session, cookies, controller_name, action_name, request) | |
| Omniture.generate_params(:unknown_page, params, {:controller => controller_name, :action => action_name }) | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment