class Reparty::Report::Mixpanel

Attributes

api_key[R]
api_secret[R]
fields[R]
report[R]

Public Class Methods

new(*args, &block) click to toggle source
Calls superclass method Reparty::Report::new
# File lib/reparty/report/mixpanel.rb, line 8
def initialize(*args, &block)
  super(args.shift, args.shift)

  @api_key = args.shift
  @api_secret = args.shift

  @report = args.shift
  @fields = []
  case @report
    when :funnel
      @funnel_id = args.shift
    when :engage
      @fields = args.shift if args.present?
  end

  @color = "#7548a2"
end

Public Instance Methods

client() click to toggle source
# File lib/reparty/report/mixpanel.rb, line 26
def client
  @client ||= ::Mixpanel::Client.new({api_key: api_key, api_secret: api_secret})
end
engage_data() click to toggle source
# File lib/reparty/report/mixpanel.rb, line 45
def engage_data
  @engage_data ||= client.request(
      "engage",
      {
          where: "properties[\"$last_seen\"] > \"#{1.day.ago.strftime("%Y-%m-%dT%H:%M:%S")}\""
      }
  )["results"]
end
funnel_data() click to toggle source
# File lib/reparty/report/mixpanel.rb, line 30
def funnel_data
  from_date = (DateTime.now-(interval*7)).strftime("%Y-%m-%d")
  to_date = (DateTime.now-1).strftime("%Y-%m-%d")

  @funnel_data ||= Hash[client.request(
      "funnels",
      {
          funnel_id: @funnel_id,
          interval: interval,
          from_date: from_date,
          to_date: to_date
      }
  )["data"].sort.reverse]
end