Data Science

Digging into Data With #rStats [Includes Video]

digging-into-r

Image created by Yasmine Sedky (‏@yazsedky).

R is an open-source language and environment for statistical computing and graphics which has been described as: “The single most important tool for computational statistics.”

In other words, when you want to mine data, R helps you do it and allows you to present your findings in an attractive visual.

What’s so great about R?

  • It’s very well supported with a huge community, which means it’s constantly growing and evolving.
  • 6,000 libraries of pre-developed packages for a wide variety of applications.
  • The data frame is analogous to an Excel Spreadsheet or MySQL table.
  • No software licensing costs.
  • Reproducible analysis!

However, until recently, R didn’t have an interface to the Google Analytics API. Google being Google, they promptly fixed that problem by introducing the RGoogleAnalytics library. Now you can use R to analyze your Google Analytics data to do things like:

  • Custom reports with up to 7 dimensions and 10 metrics.
  • Batch data extraction.
  • Create larger queries with tens of thousands of records.
  • Predict product revenue.
  • Calculate the long-term value of marketing campaigns.

Let’s look at that last item: Calculating the long-term value of your marketing campaigns.

As you know, with Google Analytics it’s relatively easy to look at a given advertising campaign and see how many sessions and transactions it generated. GA shows you your sessions, revenue and transactions for each campaign, but doesn’t account for all of the people who may have discovered your business for the very first time as a result of one of those campaigns.

Those first-timers can result in a lot of revenue over the next several months. Wouldn’t it be nice to track the lifetime value of that marketing campaign? Yes!

The “R”ough Guide for Tracking Long-Term Value of Marketing Campaigns

Complete the one-time setup by creating a project on the Google Dev console, activating the Google Analytics API for your project, and copying your project’s client ID and client secret to your R script.

With R in your toolkit, you can now create a graph to visualize the cumulative transactions over time, adding incremental or daily transactions from users of a particular campaign to see the full value of that campaign.

Your query for new customers acquired from a specific campaign might look like this:

Query.list <- Init (start.date = “2015-01-01”,
End.date = “2015-02-01”,
Dimensions = “ga:date”,
Metrics = “ga:transactions,ga:transactionRevenue”,
Segment = “users: :sequence: :
^ga:userType==New Visitor;
dateOfSession<>2015-01-01_2015-01-07;
ga:campaign==Campaign A;
->>perSession::ga:transactions>0″,
sort = “ga:date”,
table.id = tableId)

Here, the segment we’re targeting is new visitors from a specific campaign. This should allow us to include all sessions for users who match these conditions. The “sequence” narrows the list down even further to those who visited during a specified time frame and made a purchase at some point.

From there, you can compare multiple campaigns to find out which result in more transactions over time. You may find that one campaign worked better for driving short-term revenue, and another campaign – which may have had a slower start – actually earns you more revenue over the course of a few months. Very valuable information!

Perhaps most importantly, you can then use R to make an attractive graph of this information to present to your non-techy clients. They’ll be very impressed.

Google Analytics Data Mining with R (includes 3 Real Applications):

Additional Resources


Let’s Get SaaSsy – I’m offering a limited number of SaaS consulting engagements.

Previous Post Next Post

You Might Also Like

No Comments

Leave a Reply