Module: Kenshoo
- Defined in:
- lib/kenshoo.rb
Constant Summary collapse
- KENSHOO_PARAMS =
{ 'AF' => 'tracking', 'AW' => 'clickref', 'CJ' => 'sid', 'LS' => 'u1', 'PJ' => 'sid', 'GN' => 'mid', 'SAS' => 'afftrack', 'TD' => 'Epi' }
Class Method Summary collapse
- .included(base) ⇒ Object
-
.link_with_tracking_id(instance, session) ⇒ Object
returns nil if there is no outlink or affiliate code.
- .wrap_link_with_tracking_id(link, network_code, session) ⇒ Object
Class Method Details
.included(base) ⇒ Object
4 5 6 |
# File 'lib/kenshoo.rb', line 4 def self.included(base) base.before_filter :set_kenshoo_tracking_id end |
.link_with_tracking_id(instance, session) ⇒ Object
returns nil if there is no outlink or affiliate code
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/kenshoo.rb', line 20 def self.link_with_tracking_id(instance, session) link = instance.try(:link) return nil unless [Coupon, Store].include?(instance.class) && !link.blank? network_code = begin instance.is_a?(Coupon) ? instance.store.affiliate_network.code : instance.affiliate_network.code rescue nil end wrap_link_with_tracking_id(link, network_code, session) end |
.wrap_link_with_tracking_id(link, network_code, session) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/kenshoo.rb', line 32 def self.wrap_link_with_tracking_id(link, network_code, session) outlink = link = link.strip begin tracking_param = KENSHOO_PARAMS[network_code] if !session['sid'].blank? && !tracking_param.blank? uri = URI(link) if uri.query uri.query << "&#{tracking_param}=#{session['sid']}" else uri.query = "#{tracking_param}=#{session['sid']}" end outlink = uri.to_s end rescue => e = "[Kenshoo] Error when appending tracking id to link##{link} with network_code##{network_code}" if defined?(HoptoadNotifier) == "constant" HoptoadNotifier.notify(:error_class => e.class.name, :error_message => "#{e.} | #{}") end puts end return outlink end |