A native Rubymotion wrapper around the Mixpanel API
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
app
lib
spec
.gitignore
.travis.yml
Gemfile
Gemfile.lock
LICENSE.md
README.md
Rakefile
motion_panel.gemspec

README.md

MotionPanel Build Status

A native RubyMotion wrapper around the Mixpanel API.

For updates, find me here or follow me on twitter

##Installation MotionPanel requires the AFMotion library, please ensure it is installed correctly.

Gemfile

gem 'motion_panel'

Rakefile

require 'motion_panel'

then run bundle install and you should be good to go.

##Tracking an event Before you start tracking events, you must initialize it with your project token.

Mixpanel.shared_instance_with_token(YOUR_MIXPANEL_TOKEN)

From then on, you can simple access the client without the token:

Mixpanel.shared_instance

You can then use the shared instance to track events:

Mixpanel.shared_instance.track('Example event', 'attribute' => 'Value', 'second_attribute' => 'Second value')

If you wish to include a custom user distinct_id to the event, you can include a 'distinct_id' value in the options.

The following attributes will be included by default for every call:

  • app_version
  • ios_version
  • orientation
  • resolution
  • retina?

Tracking people

A person in Mixpanel is defined by a distinct_id. You have the option to pass this as part of the options hash in every people method. A universally unique vendor string will be used if this key is omitted.

###Set To track a user

Mixpanel.shared_instance.people.set('$first_name' => 'Tom',
                                    '$last_name' => 'Broomfield',
                                    'occupation' => 'Developer')

Remember, if you want to use your own unique identifier for the user profile, remember to include it in a hash.

Mixpanel.shared_instance.people.set('distinct_id' => 21,
                                    '$first_name' => 'Tom',
                                    '$last_name' => 'Broomfield',
                                    'occupation' => 'Developer')

Please be aware that the properties with the '$' prefix are special Mixpanel attributes. Refer to the Mixpanel documentation for more information.

###Set Once You can also use the set_once method. This will work in the same way to the set method, except it will not overwrite existing property values. This is useful for properties like "First login date".

Mixpanel.shared_instance.people.set_once('First login' => '19/04/2015')

###Add The add method will increment numerical values. A great example of this is tracking sign in count.

Mixpanel.shared_instance.people.add('Log in count' => 1)

###Append The append method will allow you to add a key value pair to the Mixpanel array object.

Mixpanel.shared_instance.people.append('Roles' => 'Admin')

If the array does not exist, it will be created. Each attribute can be added to the same list multiple times.

###Union Similar to the add method, this will accept an array of properties for a key and ensure they are added the to list. Unlike the add method, each property will only appear in the list once.

Mixpanel.shared_instance.people.union('Roles' => ['Admin', 'User'])

###Delete Deletes the entire profile from Mixpanel.

Mixpanel.shared_instance.people.delete!

##Config Configuration can be changed through the Mixpanel.config object.

Mixpanel.config.disable_on_simulator # Blocks all calls if device is a simulator. Default: false
Mixpanel.config.disable_in_development # Blocks all calls if app is in development environment. Default: false
Mixpanel.config.disable_in_test # Blocks all calls if app is in the test environment. Default: true

##TODO

  • Better exceptions.
  • Unset method on people.

Feel free to shoot through a PR or open an issue.

Thankyou to the incredible people at Mixpanel and RubyMotion for the great services they provide to developers.