Module: ReferralBox::ApplicationHelper

Defined in:
app/helpers/referral_box/application_helper.rb

Instance Method Summary collapse

Instance Method Details

#referral_box_javascript_tagObject

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
  }
  
  (: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 referral_box_referral_button(user, text = nil, options = {})
  text ||= "Share Referral Link"
  link_text = options[:icon] ? "#{options[:icon]} #{text}" : text
  
  link_to(
    link_text,
    referral_box_referral_link(user, options),
    options.merge(
      class: "referral-box-referral-link #{options[:class]}".strip,
      target: options[:target] || '_blank',
      rel: options[:rel] || 'noopener'
    )
  )
end

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, options = {})
  return unless user.respond_to?(:referral_code) && user.referral_code.present?
  
  base_url = options[:base_url] || root_url
  ref_param = options[: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)
  
  (:div, class: 'referral-box-user-stats') do
    concat((:div, "Points: #{user.points_balance}", class: 'points'))
    concat((:div, "Tier: #{user.current_tier || 'None'}", class: 'tier'))
    concat((:div, "Referrals: #{user.total_referrals rescue 0}", class: 'referrals'))
  end
end