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) ⇒ PageViewRecorder

Returns a new instance of PageViewRecorder.



11
12
13
14
15
16
17
18
19
20
# 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)
  @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
end

Instance Method Details

#callObject



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

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
  )
end