Module: SimplySuggest::ViewHelper

Defined in:
lib/simply_suggest/view_helper.rb

Instance Method Summary collapse

Instance Method Details

#get_tracking_code(options = {}) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/simply_suggest/view_helper.rb', line 20

def get_tracking_code options = {}
  user_id     = options.delete(:user_id)
  object_id   = options.delete(:object_id)
  object_type = options.delete(:object_type)
  event       = options.delete(:event)
  use_script  = options[:script] == nil ? true : options[:script]

  script = "
    window.track_recommendation = window.track_recommendation || [];
    window.track_recommendation.push({ event: \"setAccount\", value: \"#{SimplySuggest.config.public_key}\" });
    window.track_recommendation.push({ event: \"#{event}\", object: \"#{object_id}\", type: \"#{object_type}\", user: \"#{user_id}\" });
  ".html_safe

  return script unless use_script
   :script, script
end

#simply_suggest_scriptObject



10
11
12
13
14
15
16
17
18
# File 'lib/simply_suggest/view_helper.rb', line 10

def simply_suggest_script
   :script do
    "(function() {
      var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
      po.src = '//static.#{SimplySuggest.config.domain}/script/v1.js';
      var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
    })();".html_safe
  end
end

#track_click(source_id, destination, user_id, options = {}) ⇒ Object



37
38
39
# File 'lib/simply_suggest/view_helper.rb', line 37

def track_click source_id, destination, user_id, options = {}
  track_recommendation_click(source_id, destination.id, destination.class.to_s.downcase, user_id, options)
end

#track_recommendation_click(source_id, destination_id, user_id, klass, options = {}) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
# File 'lib/simply_suggest/view_helper.rb', line 41

def track_recommendation_click source_id, destination_id, user_id, klass, options = {}
  use_script = options[:script] == nil ? true : options[:script]

  script = "
    window.track_recommendation = window.track_recommendation || [];
    window.track_recommendation.push({ event: \"trackClick\", type: \"#{klass}\", source: \"#{source_id}\", destination: \"#{destination_id}\", user: \"#{user_id}\" });
  ".html_safe

  return script unless use_script
   :script, script
end