Git Product home page Git Product logo

python-klaviyo's Introduction

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. http://www.klaviyo.com/

What does this package do?

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

How to install?

easy_install klaviyo

or

pip install klaviyo

API Examples

After installing the klaviyo package you can initiate it using your public token which is for track events or identifying profiles and/or your private api key to utilize the metrics and list apis.

import klaviyo

client = klaviyo.Klaviyo(public_token=PUBLIC_TOKEN, private_token=PRIVATE_TOKEN)

You can then easily use Klaviyo to track events or identify people. Note, track and identify requests take your public token.

# Track an event...
client.track('Filled out profile', email='[email protected]', properties={
    'Added social accounts' : False,
})

# you can also add profile properties
client.track(
  'Filled out profile', 
  email='[email protected]', 
  properties={
    'Added social accounts' : False,
  }, 
  customer_properties={
    '$first_name': 'Thomas',
    '$last_name': 'Jefferson'
  }
)

# ...or just add a property to someone
client.identify(email='[email protected]', properties={
    '$first_name': 'Thomas',
    '$last_name': 'Jefferson',
    'Plan' : 'Premium',
})

You can get metrics, a timeline of events and export analytics for a metric. See here for more https://www.klaviyo.com/docs/api/metrics

# return all metrics
client.metrics()

# you can paginate through using the page offset
client.metrics(page=1)


# return a timeline of all metrics
client.metric_timeline()

# add a since param to get data 
# you can paginate through using a Unix timestamp or a UUID obtained from the next attribute
client.metric_timeline(since=since)

# you can query a specific metric id by
client.metric_timeline(metric_id=metric_id)

# you can export metric data
client.metric_export(metric_id)

You can create, update, read, and delete lists. See here for more information https://www.klaviyo.com/docs/api/v2/lists

# to get all lists
client.lists()

# to add a new list
client.lists(
  list_name = 'YOUR_LIST_NAME'  ,
  method = 'POST'
)

# get list details
client.list(list_id)

# update list name
client.list(
  list_id, 
  list_name = 'NEW_LIST_NAME',
  method = 'POST'
)

# delete a list
client.list(
    list_id,
    method = 'DELETE'
)

Note in the list_subscription call, subscription_type is either subscribe or members. Please refer to the docs to see which method is correct https://www.klaviyo.com/docs/api/v2/lists#post-subscribe and https://www.klaviyo.com/docs/api/v2/lists#post-members

# subscribe members to a list and check if they're in a list
client.list_subscription('list_id', subscription_type, data=data, method="GET")

# you can unsubscribe customers from a list
client.unsubscribe_from_list('list_id', subscription_type, emails)

# get exclusion emails from a list - marker is used for paginating
client.list_exclusions('list_id', marker=None)

# get all members in a group or list
client.all_members('group_id')

How to use it with a Django application?

To automatically insert the Klaviyo script in your Django app, you need to make a few changes to your settings.py file. First, add the following setting:

KLAVIYO_API_TOKEN = 'YOUR_KLAVIYO_API_TOKEN'

then add the Klaviyo middleware at the top of the MIDDLEWARE_CLASSES:

MIDDLEWARE_CLASSES = [
    'klaviyo.middleware.KlaviyoSnippetMiddleware',
    # Other classes
]

This will automatically insert the Klaviyo script at the bottom on your HTML page, right before the closing body tag.

python-klaviyo's People

Contributors

bialecki avatar remstone7 avatar eric-silberstein avatar erikpotterov avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.