Skip to content

Instantly share code, notes, and snippets.

@bowd
Created November 11, 2010 14:12
Show Gist options
  • Save bowd/672538 to your computer and use it in GitHub Desktop.
Save bowd/672538 to your computer and use it in GitHub Desktop.
def write(type, attributes, plan)
geo = resolve_geo(attributes[:remote_addr])
listener =
if attributes[:anonymous] == true
-1
else
( attributes[:user_id].to_i == 0 ? nil : attributes[:user_id].to_i )
end
event = {
:type => type,
:id => attributes[:id].to_i,
:created_at => DateTime.parse(attributes[:created_at].to_s),
:track => attributes[:track_id].to_i,
:listener => listener,
:owner => attributes[:owner_id].to_i,
:country => geo[:country_code],
:region => geo[:region],
:app => attributes[:app],
:referrer => attributes[:referrer],
}.reject { |k,v| v.nil? }
Stats::MongoStore.store(plan).write(event)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment