Skip to content

acidlabs/spree_mixpanel

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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: '[email protected]:marcosteixeira/spree_mixpanel.git', branch: '2-1-stable'

Bundle your dependencies and run the installation generator:

bundle
bundle exec rails g spree_mixpanel:install

Sidekiq (Optional)

In order to upload data to mixpanel in background you can use Sidekiq gem.

Run your redis server

redis-server

Execute Sidekiq

bundle exec sidekiq

Usage

Add your Mixpanel credentials to config/initializers/mixpanel.rb:

Spree::Mixpanel::Config.configure do |config|
  config.connection_token = "YOUR TOKEN"
end

Storing user profiles

@user.mixpanel_track_user

By 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
end

Sending orders to mixpanel

@order.mixpanel_track_order

By 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
end

Tracking order revenue

@order.mixpanel_track_charges

By 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
end

You can override mixpanel_total.

Order.class_eval do
  def mixpanel_total
    100 # personalized total
  end
end

In 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
end

Testing

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 spec

When 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

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Ruby 97.8%
  • CSS 1.2%
  • JavaScript 1.0%