API Reference

class manhattan.visitor.Visitor(id, log, site_id='', buffer_writes=True)[source]

A handle to perform operations on the given visitor session.

AVERAGE = 'A'
CURRENCY = 'C'
NUMERIC = 'N'
PER = 'I'
PERCENTAGE = 'P'
RATE = 'R'
SUM = 'S'
flush()[source]

Write buffered records to log.

goal(name, value=None, value_type=None, value_format=None)[source]

Log a goal hit for this visitor.

Parameters:
  • name (str) – Name of the goal.
  • value (int or float) – Value of this goal.
  • value_type (RATE, AVERAGE or SUM) – Type of goal value aggregation to perform.
  • value_format (NUMERIC, CURRENCY, or PERCENTAGE) – Display format for this goal value.
page(request)[source]

Log a page view for this visitor.

Parameters:request (webob.Request instance) – A request object corresponding to the page to log.
pixel()[source]

Log a pixel view for this visitor.

split(test_name, populations=None)[source]

Perform a split test for this visitor. The resulting population is calculated deterministically based on the test name and the visitor id, so the same visitor id and the same test name will always be assigned to the same population.

Parameters:
  • test_name (str) – Name of the test.
  • populations

    Population specified. Can be any of the following:

    None – 50/50 split performed between True or False. list – Select evenly between entries in the list. dict – A weighted split between keys in the dict. The weight of each population is specified by the value, as a float.
Returns:

The population selected for the visitor.

timestamp()[source]

Override this to generate event timestamps in a different way. Defaults to the POSIX epoch.

write(*records)[source]
class manhattan.client.Client(connect='tcp://127.0.0.1:5555', wait=3000)[source]
exception manhattan.client.ServerError[source]
exception manhattan.client.TimeoutError[source]
manhattan.client.main()[source]
class manhattan.middleware.ManhattanMiddleware(app, log, secret, cookie_name='manhattan', pixel_path='/vpixel.gif', host_map=None, buffer_writes=True)[source]
count_page(req)[source]
get_visitor_id(req)[source]
handle_pixel(visitor, fresh)[source]
inject_pixel(resp)[source]
class manhattan.backend.Backend(sqlalchemy_url, rollups=None, complex_goals=None, flush_every=500, cache_size=2000)[source]
all_tests()[source]
count(goal=None, variant=None, rollup_key='all', bucket_id=0, site_id=None)[source]
flush()[source]
get_pointer()[source]
goal_value(goal, variant=None, rollup_key='all', bucket_id=0, site_id=None)[source]
handle(rec, ptr)[source]
handle_nonbot(rec, history)[source]
iter_rollups(timestamp, history)[source]
record_complex_goals(history, new_name, timestamp, site_id)[source]
record_conversion(history, vid, name, timestamp, site_id, value=None, value_type='', value_format='')[source]
record_impression(history, vid, name, selected, timestamp, site_id)[source]
reset_counters()[source]
results(test_name, goals, site_id=None)[source]