Class: Trackguard::PageViewRecorder

Inherits:
ApplicationService show all
Defined in:
app/services/trackguard/page_view_recorder.rb

Constant Summary collapse

BOT_REGEX =
/
  Googlebot|Bingbot|Slurp|DuckDuckBot|Baidu|YandexBot|
  facebookexternalhit|Twitterbot|LinkedInBot|
  curl|wget|python-requests|python-urllib|
  Go-http-client|libwww|Java|Ruby|
  bot|crawl|spider
/ix

Instance Method Summary collapse

Methods inherited from ApplicationService

call

Constructor Details

#initialize(path:, ip:, user_agent:, referer:, session_id:, trace_id:, source: nil, initial: false, http_method: nil) ⇒ PageViewRecorder

Returns a new instance of PageViewRecorder.



11
12
13
14
15
16
17
18
19
20
21
22
# File 'app/services/trackguard/page_view_recorder.rb', line 11

def initialize(path:, ip:, user_agent:, referer:, session_id:, trace_id:, source: nil, initial: false,
               http_method: nil)
  @path        = path.to_s
  @ip          = ip
  @user_agent  = user_agent.to_s
  @referer     = referer
  @session_id  = session_id
  @trace_id    = trace_id
  @source      = source.presence
  @initial     = initial
  @http_method = http_method
end

Instance Method Details

#callObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/services/trackguard/page_view_recorder.rb', line 24

def call
  return if BOT_REGEX.match?(@user_agent)
  return if BlockedUserAgent.blocked?(@user_agent)
  return if @path.blank? || @path.start_with?("/admin")

  TrackPageViewJob.perform_later(
    path: @path,
    ip: @ip,
    user_agent: @user_agent,
    referer: @referer,
    session_id: @session_id,
    trace_id: @trace_id,
    source: @source,
    initial: @initial,
    http_method: @http_method
  )
end