Giter VIP home page Giter VIP logo

brockman's Introduction

Brockman

A Python client for working with the FocusLab API.

Kent Brockman

Currently this client only implements trigger recording but eventually it will provide support for the full API.

Getting Started

First you need to create an instance of the FocusLabClient:

from brockman.client import FocusLabClient

client = FocusLabClient(api_key='da9dcaa0364541498d4ae6b4865cf395')

The only required parameter for the client is api_key. You can get your API key from your FocusLab Dashboard. Optionally you can also pass an endpoint parameter but you probably shouldn't do this unless you've been told to do so by somebody from FocusLab.

You're now ready to start making calls to the FocusLab API.

Trigger Recording

To record a trigger, all you need to do is call the record_trigger method on a client instance:

from brockman.client import FocusLabClient

client = FocusLabClient(api_key='da9dcaa0364541498d4ae6b4865cf395')

client.record_trigger(
    actor_id=user.id,
    action='viewed',
    obj='blog post',
    identities={'email': user.email, 'user_id': user.id},
    attributes={'plan': user.plan},
    variables={'tags': post.tags, 'title': post.title}
)

The parameters to record_trigger are described below:

actor_id : A required string that acts as a session token. If you are using this client in combination with the javascript tracking code, you can use the fl_actor_id cookie value as the user's actor_id. Otherwise any string that will be relatively consistent for a user can be used (e.g. a user id).

action : A required string that describes the event that the trigger is representing (e.g. viewed, downloaded, streamed, etc).

obj : A required string that describes the thing that the event being represented by the trigger is happening to (e.g. artist, blog post, product).

identities : An optional dictionary of identities for the user. Any identities provided will be returned when you download a group from FocusLab. Additionally they are used to connect together activity streams from the user. Dictionary values can be strings, integers, floats, or lists. Possible identities include email addresses, user ids, and facebook ids.

attributes : An optional dictionary of attributes for the user. Attributes are pieces of data about a user that you'd like to filter against, but should not be used for connecting activity streams. Dictionary values can be strings, integers, floats, or lists. Possible attributes include plan type, user level, or date joined.

variables : An optional dictionary of variables for the trigger. Variables are pieces of data about the event the trigger is representing. Dictionary values can be strings, integers, floats, or lists. Possible variables include genres, tags, categories, titles, product code, or author.

Django Integration

Brockman includes some optional pieces that make it a little easier to work within a Django environment.

Django Client

The Django Client is a version of the FocusLabClient class that automatically pulls configuration info in from Django's settings module.

To use the Django Client just set FL_API_KEY in your settings module and then use the brockman.django.client.DjangoFocusLabClient class instead of brockman.client.FocusLabClient.

Celery Task

Celery is a popular framework for handling delayed/async tasks. By using the task provided at brockman.django.celery.tasks.record_trigger instead of the client directly, you can record a trigger to FocusLab without introducing any extra latency or errors to your own application. Below is an example of using the record_trigger task.

from brockman.django.celery.tasks import record_trigger

record_trigger.delay(
    actor_id=user.id,
    action='viewed',
    obj='blog post',
    identities={'email': user.email, 'user_id': user.id},
    attributes={'plan': user.plan},
    variables={'tags': post.tags, 'title': post.title}
)

As you can see the method signature is the same as on the client.

Getting Help

If you have any questions or run into any problems please feel free to email us at [email protected] or to use the chat box at http://focuslab.io.

brockman's People

Contributors

seanoc avatar

Watchers

 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.