Klaviyo is a real-time service for understanding your customers by aggregating all your customer data, identifying important groups of customers and then taking action. http://www.klaviyo.com/
- Track customers and events directly from your backend.
- Track customers and events via JavaScript using a Rack middleware.
gem install klaviyo
To automatically insert the Klaviyo script in your Rails app, add this to your environment config file or create a new initializer for it:
require 'rack/klaviyo'
config.middleware.use "Klaviyo::Client::Middleware", "YOUR_KLAVIYO_API_TOKEN"
This will automatically insert the Klaviyo script at the bottom on your HTML page, right before the closing body
tag.
To record customer actions directly from your backend, in your application_controller
class add a method to initialize Klaviyo.
class ApplicationController < ActionController::Base
before_filter :initialize_klaviyo
def initialize_klaviyo
@klaviyo = Klaviyo::Client.new("YOUR_KLAVIYO_API_TOKEN")
end
end
Then in your controllers where you'd like to record an event:
@klaviyo.track('Did something important',
email: '[email protected]',
properties: { key: 'value' }
)