Skip to content

Instantly share code, notes, and snippets.

@izakp
Created Apr 23, 2014
Embed
What would you like to do?
session_ids = self.query_database[:events_master].where(:name => 'script.loaded', :source => 'tracker', :timestamp => period.range)
.exclude(:remote_ip => BLACKLIST_IPS).exclude(:pageview_id => self.embedded_pageview_ids(period)).distinct(:session_id)
.select_map(:session_id)
total_sessions = 0
session_ids.each do |session_id|
query = self.query_database[:events_master].where(:name => 'script.loaded', :source => 'tracker', :timestamp => period.range, :session_id => session_id)
events = query.order(:timestamp).all
sessions = 1
last_timestamp = events.shift[:timestamp]
events.each do |event|
if event[:timestamp] > last_timestamp + SESSION_EXPIRY
sessions += 1
end
last_timestamp = event[:timestamp]
end
total_sessions += sessions
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment