Module: Glib::Analytics::Funnel

Extended by:
ActiveSupport::Concern
Defined in:
app/controllers/concerns/glib/analytics/funnel.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#glib_analytics_feature_refererObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'app/controllers/concerns/glib/analytics/funnel.rb', line 33

def glib_analytics_feature_referer
  group = request.headers['GApp-Analytics-Referer-Group']
  action = request.headers['GApp-Analytics-Referer-Action']
  segment = request.headers['GApp-Analytics-Referer-Segment']
  placement = request.headers['GApp-Analytics-Referer-Placement']
  referrer_url = request.headers['referer'] # Notice that the HTTP header uses one "r"
  if group.nil? && action.nil? && !referrer_url.nil?
    current_host = request.host
    # The Referer header is attacker-controlled and may not be a valid URI
    # (scanners send junk like "() { ignored; }; cat /etc/passwd"). Treat an
    # unparseable referer as "no referer" rather than letting URI::InvalidURIError
    # bubble up mid-render, where the 500 rescue then double-renders.
    referrer_host =
      begin
        URI.parse(referrer_url).host
      rescue URI::InvalidURIError
        nil
      end

    # Replace the subdomain portion with regex so it will only match the non-subdomain part.
    # This will allow cross-subdomain referral, but it will not work if the host is a bare domain,
    # which is something that we should avoid doing anyway.
    regex = '^([^\.]*)\.'
    if current_host == referrer_host || !/#{current_host.sub(/#{regex}/, regex)}/.match(referrer_host).nil?
      referrer_url = referrer_url.delete_suffix('/')

      begin
        route = Rails.application.routes.recognize_path(referrer_url)
        group = route[:controller]
        action = route[:action]
      rescue ActionController::RoutingError
        # Do nothing. This may happen when the referrer is from the same domain,
        # but not from the same Rails app.
      end
    end
  end

  if group && action
    return { group: group, action: action, segment: segment, placement: placement }
  end

  nil
end

#glib_analytics_feature_segmentObject



28
29
30
31
# File 'app/controllers/concerns/glib/analytics/funnel.rb', line 28

def glib_analytics_feature_segment
  # To be overridden
  nil
end

#glib_analytics_included?Boolean

# Expose protected method

public  # Override
def policy_scope(*args)
  super
end

end

Returns:

  • (Boolean)


24
25
26
# File 'app/controllers/concerns/glib/analytics/funnel.rb', line 24

def glib_analytics_included?
  true
end