GithubHelp home page GithubHelp logo

buffer-1's Introduction

The Buffer R package

The buffer package is an internal R package whose purpose is to abstract common operations like reading and writing data from Buffer's data warehouses.

Getting Started

To download the buffer package, you'll need to install the devtools package.

install.packages("devtools")

Then, use the install_github() function to install the buffer package.

devtools::install_github("bufferapp/buffer")

Querying BigQuery

To query Redshift, you'll first need to make sure that you have your environment variables set in your .Renviron. Your .Renviron file might look something like this.

CHARTMOGUL_API_TOKEN=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
CHARTMOGUL_API_SECRET=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
MIXPANEL_TOKEN=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
MIXPANEL_KEY=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
MIXPANEL_SECRET=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

To set an environment variable, use the Sys.setenv() function.

Sys.setenv(MIXPANEL_KEY = "examplekeythatyoulluse"

Once these are set, you can connect to BigQuery with the bq_connect() function. It may prompt you to authenticate with your Google account.

# create connection
con <- bq_connect()

You'll then be able to run SQL queries from R, like so:

# define query
sql <- "select * from dbt_buffer.buffer_users limit 10"

# run query
users <- bq_query(con, sql)

Et voila!

Getting data from ChartMogul

The get_mrr_metrics function grabs data from ChartMogul's metrics API. You will need to add your ChartMogul API token and secret to your .Renviron file to use this function.

# add API credentials
Sys.setenv(CHARTMOGUL_API_TOKEN = token)
Sys.setenv(CHARTMOGUL_API_SECRET = secret)

There are several useful metrics we can collect from this API. We can retrieve all key MRR metrics by setting metric = "all". These include MRR, ARR, average revenue per account (ARPA), number of customers, LTV, the MRR churn rate, and the customer churn rate for each date. Here is an example.

# get key metrics
all <- get_mrr_metrics(metric = "all", start_date = "2019-01-01", end_date = "2019-06-01", interval = "day")

The MRR metrics include all of the MRR movements (new, reactivation, expansion, contraction, and churn).

# get mrr metrics
mrr <- get_mrr_metrics(metric = "mrr", start_date = "2019-01-01", end_date = "2019-06-01", interval = "day")

Get Customer MRR Events

The get_customer_mrr_events function returns a dataframe of activities for a given customer. It only returns the events of a single customer, and the ChartMogul UUID must be used.

# get mrr events
activities <- get_customer_mrr_events("cus_b8eb4d54-687a-11e9-a881-17e8291a772a")

Plotting with buffplot()

The buffplot() function is a wrapper around the ggplot() function that does a couple things. It sets the plot's theme to buffer_theme and makes the default color palette colorblind-friendly.

data(mtcars)

# plot
buffplot(mtcars, aes(x = wt, y = mpg, color = as.factor(gear))) + 
    geom_point() + 
    labs(x = "Weight", y = "MPG", color = "Gear")

buffer-1's People

Contributors

jwinternheimer 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.