SpreeMixpanel (master is not implemented yet. See 2-1-stable or 2-2-stable branches)
Spree integration with Mixpanel
Installation
Add spree_mixpanel to your Gemfile:
gem 'spree_mixpanel', git: 'git@github.com:marcosteixeira/spree_mixpanel.git', branch: '2-1-stable'Bundle your dependencies and run the installation generator:
bundle
bundle exec rails g spree_mixpanel:installSidekiq (Optional)
In order to upload data to mixpanel in background you can use Sidekiq gem.
Run your redis server
redis-serverExecute Sidekiq
bundle exec sidekiqUsage
Add your Mixpanel credentials to config/initializers/mixpanel.rb:
Spree::Mixpanel::Config.configure do |config|
config.connection_token = "YOUR TOKEN"
endStoring user profiles
@user.mixpanel_track_userBy default, we send first_name, last_name, and email from user. You can override user mixpanel_personal_fields and return personalized fields.
User.class_eval do
def mixpanel_personal_fields
{
'My Field' => 'FIELD',
'Total sales' => self.total_sales # personalized method in your user model
}
end
endSending orders to mixpanel
@order.mixpanel_track_orderBy default, we send number, total, state, email and payment_state from order. You can override order mixpanel_personal_fields and return personalized fields.
Order.class_eval do
def mixpanel_personal_fields
{
'My Field' => 'FIELD',
'Personal amount' => self.personal_amount
}
end
endTracking order revenue
@order.mixpanel_track_chargesBy default paid orders revenue are automatically sent to mixpanel.
You can change this behaviour changing push_order_charges configuration.
# config/initializers/mixpanel.rb
Spree::Mixpanel::Config.configure do |config|
config.push_order_charges = false # true by default
endYou can override mixpanel_total.
Order.class_eval do
def mixpanel_total
100 # personalized total
end
endIn order to send personalized fields you can override mixpanel_charge_fields
Order.class_eval do
def mixpanel_charge_fields
{'User name' => user_name } # personalized field
end
endTesting
Be sure to bundle your dependencies and then create a dummy test app for the specs to run against.
bundle
bundle exec rake test_app
bundle exec rspec specWhen testing your applications integration with this extension you may use it's factories. Simply add this require statement to your spec_helper:
require 'spree_mixpanel/factories'Copyright (c) 2014, released under the New BSD License