Ruby wrapper for the Klaviyo API
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

What is Klaviyo?

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.

What does this Gem do?

  • Track customers and events directly from your backend.
  • Track customers and events via JavaScript using a Rack middleware.

How to install?

gem install klaviyo

How to use it with a Rails application?

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 ="YOUR_KLAVIYO_API_TOKEN")

Then in your controllers where you'd like to record an event:

@klaviyo.track('Did something important',
  email: '',
  properties: { key: 'value' }