Module: Analytic::Trackable

Included in:
DashboardController
Defined in:
app/controllers/concerns/analytic/trackable.rb

Instance Method Summary collapse

Instance Method Details

#analytic_enqueue_track_job!Object

Parameters:

  • params (Hash)


21
22
23
24
25
26
27
28
29
30
31
32
# File 'app/controllers/concerns/analytic/trackable.rb', line 21

def analytic_enqueue_track_job!
  Analytic::TrackJob.perform_later(
    session_id: analytic_session_id,
    visitor_id: analytic_visitor_id,
    ip: analytic_ip,
    host: analytic_host,
    path: analytic_path,
    referrer: analytic_referrer,
    user_agent: request.user_agent,
    params: analytic_params
  )
end

#analytic_hostString

Returns:

  • (String)


55
56
57
# File 'app/controllers/concerns/analytic/trackable.rb', line 55

def analytic_host
  request.host
end

#analytic_ipIPAddr

Returns:

  • (IPAddr)


45
46
47
48
49
50
51
52
# File 'app/controllers/concerns/analytic/trackable.rb', line 45

def analytic_ip
  ip_addr = IPAddr.new(request.remote_ip)

  return ip_addr.mask(Analytic.config.ip_v4_mask) if Analytic.config.ip_v4_mask? && ip_addr.ipv4?
  return ip_addr.mask(Analytic.config.ip_v6_mask) if Analytic.config.ip_v6_mask? && ip_addr.ipv6?

  ip_addr
end

#analytic_paramsHash

Returns:

  • (Hash)


75
76
77
# File 'app/controllers/concerns/analytic/trackable.rb', line 75

def analytic_params
  params.slice(*Analytic.config.params)
end

#analytic_pathString

Returns:

  • (String)


60
61
62
# File 'app/controllers/concerns/analytic/trackable.rb', line 60

def analytic_path
  request.path
end

#analytic_referrerString

Returns:

  • (String)


65
66
67
# File 'app/controllers/concerns/analytic/trackable.rb', line 65

def analytic_referrer
  request.referer
end

#analytic_session_idString

Returns:

  • (String)


35
36
37
# File 'app/controllers/concerns/analytic/trackable.rb', line 35

def analytic_session_id
  session[:analytic_session_id] ||= SecureRandom.uuid
end

#analytic_track!Object

Parameters:

  • params (Hash)


6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'app/controllers/concerns/analytic/trackable.rb', line 6

def analytic_track!
  Analytic::Event.create!(
    timestamp: Time.current,
    session_id: analytic_session_id,
    visitor_id: analytic_visitor_id,
    ip: analytic_ip,
    host: analytic_host,
    path: analytic_path,
    referrer: analytic_referrer,
    user_agent: request.user_agent,
    params: analytic_params
  )
end

#analytic_user_agentString

Returns:

  • (String)


70
71
72
# File 'app/controllers/concerns/analytic/trackable.rb', line 70

def analytic_user_agent
  request.user_agent
end

#analytic_visitor_idString

Returns:

  • (String)


40
41
42
# File 'app/controllers/concerns/analytic/trackable.rb', line 40

def analytic_visitor_id
  cookies.permanent[:analytic_visitor_id] ||= SecureRandom.uuid
end