Class: MetrixApp

Inherits:
Object
  • Object
show all
Defined in:
lib/metrixapp.rb

Instance Method Summary collapse

Constructor Details

#initialize(account_code) ⇒ MetrixApp

Creates a new MetrixApp instance used to send data to your account. You MUST pass your account code

Usage:

m = MetrixApp.new 'abc123'


13
14
15
16
17
# File 'lib/metrixapp.rb', line 13

def initialize()
  raise ArgumentError.new 'You MUST specify your account code' unless .match /[A-Za-z0-9]{32}/
  @account_code = 
  @http = Net::HTTP::Persistent.new
end

Instance Method Details

#log(event_name, data = {}) ⇒ Object

Send your data to MetrixApp. Any optional data is stored as JSON and avaiable by logging into your account and dowloading your data as CSV.

The following options are available:

:event_name

The event name, eg Signup. MANDATORY argument

:data

Any extra data you wish to store for further analysis.

Usage:

m = MetrixApp.new 'abc123'
m.log 'Singup'
m.log 'Login', :user => '[email protected]'
m.log 'Upgrade', ['[email protected]', 'Premium']


33
34
35
36
37
38
# File 'lib/metrixapp.rb', line 33

def log(event_name, data={})
  event_name = event_name.to_s
  raise ArgumentError.new 'You MUST give your event a name' unless event_name.match /.+/
  
  @http.request URI.parse("http://www.metrixapp.com/log?name=#{CGI::escape(event_name)}&data=#{CGI::escape(data.to_json)}&account_code=#{@account_code}")
end