Class: Gricer::ActiveRecord::Session

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
Gricer::ActiveModel::Session, Gricer::ActiveModel::Statistics, LimitStrings
Defined in:
app/models/gricer/active_record/session.rb

Overview

ActiveRecord Model for Session Statistics

Instance Attribute Summary collapse

Class Method Summary collapse

Methods included from LimitStrings

included

Methods included from Gricer::ActiveModel::Statistics

included, #model_type

Methods included from Gricer::ActiveModel::Session

#duration, included, #ip_address=

Instance Attribute Details

#agentGricer::Agent

The current value of the associated agent.

Returns:

  • (Gricer::Agent)

    the current value of agent



101
102
103
# File 'app/models/gricer/active_record/session.rb', line 101

def agent
  @agent
end

#cityString

The current value of the city from which the session was requested.

You need to configure a GeoIP in the Config instance.

Returns:

  • (String)

    the current value of city



101
102
103
# File 'app/models/gricer/active_record/session.rb', line 101

def city
  @city
end

#countryString

The current value of the country from which the session was requested.

You need to configure a GeoIP in the Config instance.

Returns:

  • (String)

    the current value of country



101
102
103
# File 'app/models/gricer/active_record/session.rb', line 101

def country
  @country
end

#domainString

The current value of the domain (only major info) from which the session was requested.

Returns:

  • (String)

    the current value of domain



101
102
103
# File 'app/models/gricer/active_record/session.rb', line 101

def domain
  @domain
end

#flash_major_versionString

The current value of the major version of flash installed on the requesting agent.

This feature needs the usage of TrackHelper#gricer_track_tag.

Returns:

  • (String)

    the current value of flash_major_version



101
102
103
# File 'app/models/gricer/active_record/session.rb', line 101

def flash_major_version
  @flash_major_version
end

#flash_versionString

The current value of the version of flash installed on the requesting agent.

This feature needs the usage of TrackHelper#gricer_track_tag.

Returns:

  • (String)

    the current value of flash_version



101
102
103
# File 'app/models/gricer/active_record/session.rb', line 101

def flash_version
  @flash_version
end

#ip_address_hashString

The current value of the ip address in an anonyminized hash

Returns:

  • (String)

    the current value of ip_address_hash



101
102
103
# File 'app/models/gricer/active_record/session.rb', line 101

def ip_address_hash
  @ip_address_hash
end

#javaBoolean

The current value of the java capability of the requesting agent.

This feature needs the usage of TrackHelper#gricer_track_tag.

Returns:

  • (Boolean)

    the current value of java



101
102
103
# File 'app/models/gricer/active_record/session.rb', line 101

def java
  @java
end

#javascriptBoolean

The current value of the javascript capability of the requesting agent.

This feature needs the usage of TrackHelper#gricer_track_tag.

Returns:

  • (Boolean)

    the current value of javascript



101
102
103
# File 'app/models/gricer/active_record/session.rb', line 101

def javascript
  @javascript
end

#latitudeFloat

The current value of the latitude of the city/region from which the session was requested.

You need to configure a GeoIP in the Config instance.

Returns:

  • (Float)

    the current value of latitude



101
102
103
# File 'app/models/gricer/active_record/session.rb', line 101

def latitude
  @latitude
end

#longitudeFloat

The current value of the longitude of the city/region from which the session was requested.

You need to configure a GeoIP in the Config instance.

Returns:

  • (Float)

    the current value of longitude



101
102
103
# File 'app/models/gricer/active_record/session.rb', line 101

def longitude
  @longitude
end

#postal_codeString

The current value of the region from which the session was requested.

You need to configure a GeoIP in the Config instance.

Returns:

  • (String)

    the current value of postal_code



101
102
103
# File 'app/models/gricer/active_record/session.rb', line 101

def postal_code
  @postal_code
end

#previous_sessionGricer::Session

The current value of the associated previous session.

Returns:

  • (Gricer::Session)

    the current value of previous_session



101
102
103
# File 'app/models/gricer/active_record/session.rb', line 101

def previous_session
  @previous_session
end

#regionString

The current value of the region from which the session was requested.

You need to configure a GeoIP in the Config instance.

Returns:

  • (String)

    the current value of region



101
102
103
# File 'app/models/gricer/active_record/session.rb', line 101

def region
  @region
end

#requested_localeString

The current value of the locale requested

Returns:

  • (String)

    the current value of requested_locale



101
102
103
# File 'app/models/gricer/active_record/session.rb', line 101

def requested_locale
  @requested_locale
end

#requested_locale_majorString

The current value of the locale requested (major locale only)

Returns:

  • (String)

    the current value of requested_locale_major



101
102
103
# File 'app/models/gricer/active_record/session.rb', line 101

def requested_locale_major
  @requested_locale_major
end

#requested_locale_minorString

The current value of the locale requested (major locale only)

Returns:

  • (String)

    the current value of requested_locale_minor



101
102
103
# File 'app/models/gricer/active_record/session.rb', line 101

def requested_locale_minor
  @requested_locale_minor
end

#screen_depthInteger

The current value of the depth in bits of the screen the requesting agent’s window is on.

This feature needs the usage of TrackHelper#gricer_track_tag.

Returns:

  • (Integer)

    the current value of screen_depth



101
102
103
# File 'app/models/gricer/active_record/session.rb', line 101

def screen_depth
  @screen_depth
end

#screen_heightInteger

The current value of the height in pixels of the screen the requesting agent’s window is on.

This feature needs the usage of TrackHelper#gricer_track_tag.

Returns:

  • (Integer)

    the current value of screen_height



101
102
103
# File 'app/models/gricer/active_record/session.rb', line 101

def screen_height
  @screen_height
end

#screen_widthInteger

The current value of the width in pixels of the screen the requesting agent’s window is on.

This feature needs the usage of TrackHelper#gricer_track_tag.

Returns:

  • (Integer)

    the current value of screen_width



101
102
103
# File 'app/models/gricer/active_record/session.rb', line 101

def screen_width
  @screen_width
end

#silverlight_major_versionString

The current value of the major version of silverlight installed on the requesting agent.

This feature needs the usage of TrackHelper#gricer_track_tag.

Returns:

  • (String)

    the current value of silverlight_major_version



101
102
103
# File 'app/models/gricer/active_record/session.rb', line 101

def silverlight_major_version
  @silverlight_major_version
end

#silverlight_versionString

The current value of the version of silverlight installed on the requesting agent.

This feature needs the usage of TrackHelper#gricer_track_tag.

Returns:

  • (String)

    the current value of silverlight_version



101
102
103
# File 'app/models/gricer/active_record/session.rb', line 101

def silverlight_version
  @silverlight_version
end

Class Method Details

.avg_durationFloat

Get the average duration of sessions in seconds.

Returns:

  • (Float)


131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'app/models/gricer/active_record/session.rb', line 131

def self.avg_duration
  if (c = self.count) > 0
    #logger.debug ActiveRecord::Base.connection.class

    if ::ActiveRecord::Base.connection.class.to_s == 'ActiveRecord::ConnectionAdapters::PostgreSQLAdapter'
      self.sum("date_part('epoch', \"#{self.table_name}\".\"updated_at\") - date_part('epoch', \"#{self.table_name}\".\"created_at\")").to_f / c.to_f    
    else
      self.sum("strftime('%s', \"#{self.table_name}\".\"updated_at\") - strftime('%s', \"#{self.table_name}\".\"created_at\")") / c.to_f
    end
  else
    0
  end
end

.browsersActiveRecord::Relation

Filter out anything that is not a Browser or MobileBrowser

Returns:

  • (ActiveRecord::Relation)


119
120
121
122
# File 'app/models/gricer/active_record/session.rb', line 119

def self.browsers
  self.includes("agent")
  .where("\"#{Agent.table_name}\".\"agent_class_id\" IN (?)", [0x1000, 0x2000])
end

.first_by_id(id) ⇒ Object



124
125
126
# File 'app/models/gricer/active_record/session.rb', line 124

def self.first_by_id(id)
  where(id: id).first
end

.new_visitsActiveRecord::Relation

Filter out only new visits (which does not have a previous_session)

Returns:

  • (ActiveRecord::Relation)


113
114
115
# File 'app/models/gricer/active_record/session.rb', line 113

def self.new_visits
  where("\"#{self.table_name}\".\"previous_session_id\" IS NULL")
end