Module: SimplySuggest::ViewHelper
- Defined in:
- lib/simply_suggest/view_helper.rb
Instance Method Summary collapse
- #get_tracking_code(options = {}) ⇒ Object
- #simply_suggest_script ⇒ Object
- #track_click(source_id, destination, user_id, options = {}) ⇒ Object
- #track_recommendation_click(source_id, destination_id, user_id, klass, options = {}) ⇒ Object
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 = {} user_id = .delete(:user_id) object_id = .delete(:object_id) object_type = .delete(:object_type) event = .delete(:event) use_script = [:script] == nil ? true : [: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 content_tag :script, script end |
#simply_suggest_script ⇒ Object
10 11 12 13 14 15 16 17 18 |
# File 'lib/simply_suggest/view_helper.rb', line 10 def simply_suggest_script content_tag :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, = {} track_recommendation_click(source_id, destination.id, destination.class.to_s.downcase, user_id, ) 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, = {} use_script = [:script] == nil ? true : [: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 content_tag :script, script end |