Skip to content

Instantly share code, notes, and snippets.

@xbora
Created November 20, 2012 02:39
Show Gist options
  • Save xbora/4115575 to your computer and use it in GitHub Desktop.
Save xbora/4115575 to your computer and use it in GitHub Desktop.
Mixpanel library in RubyMotion
class MP
class << self
def init_mixpanel
@mixpanel = Mixpanel.sharedInstance
self.identify(@mixpanel)
@mixpanel.people.set({"$last_login" => Time.now})
MP.update_person(@mixpanel)
end
def track(api, event, props)
api.track(event, properties: props)
end
def identify(api)
api.people.identify(PFUser.currentUser.objectId) if PFUser.currentUser
end
def update_person(api)
m = appDelegate.current_member
props = {}
unless m.nil?
props["$email"] = kill_nil(m["email"])
props["$first_name"] = kill_nil(first_name(m["name"]))
props["$last_name"] = kill_nil(last_name(m["name"]))
props["$username"] = kill_nil(m["username"])
props["stripe_id"] = kill_nil(m["stripe_id"])
props["cc_last_four"] = kill_nil(m["cc_last_four"])
props["credits"] = kill_nil(m["credits"])
props["fb_uid"] = kill_nil(m["fb_uid"])
props["hype_machine_username"] = kill_nil(m["hype_machine_username"])
props["rdio_moniker"] = kill_nil(m["rdio_moniker"])
props["soundcloud_username"] = kill_nil(m["soundcloud_username"])
props["spotify_username"] = kill_nil(m["spotify_username"])
props["last_fm_username"] = kill_nil(m["last_fm_username"])
props["location"] = m["location"].latitude.to_s + ", " + m["location"].longitude.to_s unless m["location"].nil?
props["user_id"] = PFUser.currentUser.objectId
props["member_id"] = m.objectId
props["recommendation_days_before"] = kill_nil(m["recommendation_days_before"])
props["$created"] = m.createdAt
api.people.set(props)
api.registerSuperProperties({"mp_name_tag" => kill_nil(m["name"])})
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment