Skip to content

Instantly share code, notes, and snippets.

@MattFaus
Created January 2, 2014 23:03
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MattFaus/8228870 to your computer and use it in GitHub Desktop.
Save MattFaus/8228870 to your computer and use it in GitHub Desktop.
A function to programmatically build and query funnel data via the MixPanel API.
class MixPanel(object):
def get_page_view_funnel(self, content_urls):
# Build up the events array. Each "event" is a step in the funnel
events = []
for cu in content_urls:
events.append({
"event": "Page View",
"selector": 'properties["Page View Page"] == "%s"' % (cu,),
})
return self.request(["arb_funnels"], {
"events": events,
# The time window to query over.
"from_date": start_dt.strftime("%Y-%m-%d"),
"to_date": end_dt.strftime("%Y-%m-%d"),
# The next two parameters control how the server aggregates the
# data before returning it to you, so you should very carefully
# select these to return only the information you need.
# This groups the data points based on their properties. We have
# 3 possible values for User Type: Logged In, Phantom (our name for
# "Logged Out"), and New (registered in the past month).
"on": 'properties["User Type"]',
# The time level at which
# This can be 'minute', 'hour', 'day', 'week', or 'month'.
# It determines the level of granularity of the data you get back.
"unit": 'month'
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment