Module: ReferralBox::ApplicationHelper
- Defined in:
- app/helpers/referral_box/application_helper.rb
Instance Method Summary collapse
-
#referral_box_javascript_tag ⇒ Object
Include ReferralBox JavaScript and configuration.
-
#referral_box_referral_button(user, text = nil, options = {}) ⇒ Object
Generate a referral link button with styling.
-
#referral_box_referral_link(user, options = {}) ⇒ Object
Generate a referral link with enhanced tracking.
-
#referral_box_user_stats(user) ⇒ Object
Display user’s referral stats.
Instance Method Details
#referral_box_javascript_tag ⇒ Object
Include ReferralBox JavaScript and configuration
6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'app/helpers/referral_box/application_helper.rb', line 6 def referral_box_javascript_tag return unless ReferralBox.configuration.enable_device_tracking config = { enabled: ReferralBox.configuration.enable_device_tracking, collect_geo: ReferralBox.configuration.collect_geo_location, api_endpoint: referral_box_track_referral_path } content_tag(:script, "window.ReferralBoxConfig = #{config.to_json};", type: 'application/javascript') + javascript_include_tag('referral_box', 'data-turbolinks-track': 'reload') end |
#referral_box_referral_button(user, text = nil, options = {}) ⇒ Object
Generate a referral link button with styling
30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'app/helpers/referral_box/application_helper.rb', line 30 def (user, text = nil, = {}) text ||= "Share Referral Link" link_text = [:icon] ? "#{options[:icon]} #{text}" : text link_to( link_text, referral_box_referral_link(user, ), .merge( class: "referral-box-referral-link #{options[:class]}".strip, target: [:target] || '_blank', rel: [:rel] || 'noopener' ) ) end |
#referral_box_referral_link(user, options = {}) ⇒ Object
Generate a referral link with enhanced tracking
20 21 22 23 24 25 26 27 |
# File 'app/helpers/referral_box/application_helper.rb', line 20 def referral_box_referral_link(user, = {}) return unless user.respond_to?(:referral_code) && user.referral_code.present? base_url = [:base_url] || root_url ref_param = [:ref_param] || 'ref' "#{base_url}#{base_url.include?('?') ? '&' : '?'}#{ref_param}=#{user.referral_code}" end |
#referral_box_user_stats(user) ⇒ Object
Display user’s referral stats
46 47 48 49 50 51 52 53 54 |
# File 'app/helpers/referral_box/application_helper.rb', line 46 def referral_box_user_stats(user) return unless user.respond_to?(:points_balance) content_tag(:div, class: 'referral-box-user-stats') do concat(content_tag(:div, "Points: #{user.points_balance}", class: 'points')) concat(content_tag(:div, "Tier: #{user.current_tier || 'None'}", class: 'tier')) concat(content_tag(:div, "Referrals: #{user.total_referrals rescue 0}", class: 'referrals')) end end |