Start learning with our library of video tutorials taught by experts. Get started

Google Analytics Tips
Illustration by Richard Downs

Google Analytics Tips

with Corey Koberg

Video: R Programming and Google Analytics

One of the most useful things we can do with our Analytics data is to Scientists utilize the incredibly powerful open source R programming language to This is by no means an R programming course. Now the next thing we'll need to do is install a connector between It's going to actually download that, install that, and Now we just find this by going to Google and And for metrics, we want to grab users.
Expand all | Collapse all
  1. 7m 18s
    1. R Programming and Google Analytics
      7m 18s
  2. 54s
    1. Welcome to the series
  3. 17m 8s
    1. How Google Analytics accounts, properties, and views are structured
      6m 36s
    2. User management: 2013 update
      6m 19s
    3. Best practices for user management
      4m 13s
  4. 20m 49s
    1. Installing Google Analytics on WordPress
      8m 28s
    2. Google Analytics debugging and troubleshooting: The basics
      6m 10s
    3. Google Analytics debugging and troubleshooting: With a tag management system (TMS)
      6m 11s
  5. 23m 58s
    1. Demographics
      6m 45s
    2. Interest categories
      5m 26s
    3. Enabling Audience reports and understanding where the data comes from
      11m 47s
  6. 26m 37s
    1. Intro and built-in segments
      14m 57s
    2. Custom segments via the Segment Builder
      11m 40s
  7. 12m 25s
    1. User Segments: A huge improvement
      6m 23s
    2. Advanced Topic: Sequenced Segments
      6m 2s
  8. 27m 8s
    1. Cohort analysis now built into Google Analytics
      8m 22s
    2. Permanent filters and removing internal traffic
      8m 19s
    3. Filters everyone should use to get clean data
      10m 27s
  9. 13m 25s
    1. Using an advanced filter to get accurate information on subdomains
      7m 20s
    2. When to use a segment vs. a filter
      6m 5s
  10. 18m 0s
    1. Finding my most valuable customers
      9m 54s
    2. Making Adwords work smarter and more profitably
      8m 6s
  11. 15m 20s
    1. What is Google’s Universal Analytics?
      7m 7s
    2. Upgrading from Classic to Universal Analytics
      8m 13s
  12. 7m 11s
    1. Test driving the API in 5 minutes
      7m 11s
  13. 14m 16s
    1. Migrating Custom Variables to Custom Dimensions
      14m 16s
  14. 4m 5s
    1. Creating a Custom Report in 30 seconds
      4m 5s
  15. 5m 41s
    1. Five Time zone tips to save your data
      5m 41s
  16. 9m 56s
    1. Importing data with Custom Data Import
      9m 56s
  17. 6m 29s
    1. Query string parameters
      6m 29s
  18. 17m 17s
    1. YouTube videos
      9m 3s
    2. Local visitor time zones
      8m 14s

Watch this entire course now—plus get access to every course in the library. Each course includes high-quality videos taught by expert instructors.

Become a member
please wait ...
Google Analytics Tips
4h 7m Intermediate Dec 04, 2013 Updated Aug 13, 2014

Viewers: in countries Watching now:

Get a new Google Analytics tip every other week from online marketing expert Corey Koberg. Most users unlock just a fraction of the power that Google Analytics offers, so in this course Corey exposes tips and tricks to unlock insights into one of the most sophisticated tools in the marketer or site owner's arsenal. He offers peeks into the latest power features, advice for deeply mining your digital data, and actions you can take to optimize your site for both traffic and conversions. Corey answers common questions about online marketing and web analytics, including installation, tag management, reporting, custom variables/dimensions, attribution modeling, segmentation, multichannel funnels, data accuracy, visualizations, Universal Analytics, and more. What's more, Corey welcomes your questions and will shape future videos based on member requests, so send them to us at

Marketing Analytics
Google Analytics
Corey Koberg

R Programming and Google Analytics

One of the most useful things we can do with our Analytics data is to import that data into other systems. Scientists utilize the incredibly powerful open source R programming language to do advanced statistical modeling and visualizations. So pulling our Analytics data into R allows us to take advantage of that power and enhance our analysis. This is by no means an R programming course. So, for now, I want to show you how to connect the two sources, so that your Google Analytics data can be pulled into the R environment. First thing we want to do is download and install that R environment.

Simply go to and follow these download links. Go to the US mirror here at Berkeley and download from this. 'Kay, we'll simply follow the prompts here and install this. Okay. Now this will give you the base environment that is technically all you need. People prefer a more robust editing environment, so we're going to download a free editor called RStudio as well. I highly recommend it and it's

Then we click on Download RStudio and you want the free version here, Desktop. Okay. Now, we've got the base R tools now. And we're going to go ahead and open up RStudio first. Now the next thing we'll need to do is install a connector between Google Analytics and R. There's several ways to do this, but RGA is a very simple library that has some built-in functions that pull in Google Analytics data very easily. So to do this, we're going to first install Devtools via this console by typing in install.packages("devtools").

Okay. That's installed successfully there. And then, we can actually launch that library devtools. And now, we're going to pull down RGA itself by typing install_github("rga","skardhamar"). It's going to actually download that, install that, and then we're going to launch that library just like we did similarly there. RGA, and we're all set.

Okay. Now that we're connected. Let's run a quick query and pull in some data. The easiest way to do this is by starting with the Query Explorer first. Now, if you're not familiar with the Google Analytics Query Explorer, you can see my other tips called GA API in 5 Minutes. But for now, we'll go ahead and pull that up and assume that you have a working knowledge of that. Now we just find this by going to Google and typing in query explorer and the first thing that pops up there. Okay. Remember, we've got our Account, Property, and View here. And what that's really going to identify here is this number, this its profile ID that we want to grab.

So, remember, this one right here is a number we're going to need to pull in. It's one of the things that Query Explorer can help us find. And let's just run a really simple query to pull in some basic GA data. So, let's say for dimensions here let's grab a date. And for metrics, we want to grab users. And we can do a filter. So let's just filter this to only people in, take a region, so let's say here the US. And then I'm going to grab our date range. So, the 23rd through, lets say, the 25th Okay.

So we did that here and we've got our dimension of date. We've got these three dates, the 23rd, the 24th, and the number of users for each of those. And what we want to try and do is make sure that when we replicate this on the R side that we pull in this data to match exactly what we've got here. So, switching back to the R Studio environment here, what I'm going to do is pull up a script that's going to do exactly that. So, I'ma load a script here. And the very top, we've got a place where we're going to keep the start date, just like we had before the 23rd, and the end date. It's going to call for that library. It's going to load this RGA library. The second thing it's going to do here is it's going to authenticate.

And remember, we need to basically tell Google Analytics, through this script, that it should allows us to access that data. So the script itself has to authenticate to Google somehow. So I'll show you how we'll do that. Once it's done that the next thing that we're going to do is open an instance for that and we're going to pull down exactly what we just had there. We're going to set that IDS to exactly what we had over there in the query explorer. We're going to set it to be batched as true and a couple other things here. Set the start date. Set the end date. The metrics are exactly what we had there, GA users, GA date.

And we're going to sort it by date and we're going to filter it here, the country equals US. And then we're going to write that to a CSV file. And that's pretty much it. So, what we're trying to do here is replicate what we've done in the Query Explorer and pull that into our R environment. Okay. So let's go ahead and run this. I'm going to do Ctrl + A, Ctrl+Shift+Enter. What it's going to do is it's going to launch this browser window and it's going to ask me if I want to authenticate this. Our Google Analytics would like to access my data. Do I want to accept that or not as my current user. So if I click that I want to accept this, it's going to give me this code string, here that I can then go back and paste into our studio, down here.

And it's going to authenticate. Now, once it's done that, it goes and it runs the query and it pulls back the data. What you want to do is make sure that the data that we've got here in R is going to match what we had in the Query Explorer. So we see here, we've got 23rd, 24th, 25th, 720, 696, 637. So we've done it. Now, it's also written out the CSV file. So we can go ahead and see what that looks like. And it's going to be a CSV that has exactly that data in it. So we've successfully pulled the data into R and then exported that out to a CSV.

And one thing I want to point out here is sometimes you'll have authentication issues, for some reason. It tries to go on before it authenticates. If that happens what you want to do is come up here and just highlight to the part where it goes to the authentication. And then when you do your Ctrl+Shift+Enter, it's only going to launch up to that part. And and that will make it such that it can authenticate first, and you won't skip past that in there. So sometimes when it asks you to. Enter in that string that you've got copied there.

It's already gone past that in the script. So, to get past that you simply highlight only up to the authentication part and then go from there. After you've authenticated, you're going to be authenticated and it won't ask you to do it again. You can just run the scripts as you want once you've authenticated it's, it's, you don't need to do it every single time. So, now we've seen how you can connect the data from Google with the mathematical horsepower of R. We've obviously just scratched the surface here. And, although, I would love to hear the different ways that you are using these two. So, please let me know in a feedback or via Twitter. Also, if you have any particular analysis challenges or examples you'd like to Google Analytics in R, please let me know that as well.

Find answers to the most frequently asked questions about Google Analytics Tips.

Expand all | Collapse all
please wait ...
Q: Why can't I earn a Certificate of Completion for this course?
A: We publish a new tutorial or tutorials for this course on a regular basis. We are unable to offer a Certificate of Completion because it is an ever-evolving course that is not designed to be completed. Check back often for new movies.
Share a link to this course

What are exercise files?

Exercise files are the same files the author uses in the course. Save time by downloading the author's files instead of setting up your own files, and learn by following along with the instructor.

Can I take this course without the exercise files?

Yes! If you decide you would like the exercise files later, you can upgrade to a premium account any time.

Become a member Download sample files See plans and pricing

Please wait... please wait ...
Upgrade to get access to exercise files.

Exercise files video

How to use exercise files.

Learn by watching, listening, and doing, Exercise files are the same files the author uses in the course, so you can download them and follow along Premium memberships include access to all exercise files in the library.

Exercise files

Exercise files video

How to use exercise files.

For additional information on downloading and using exercise files, watch our instructional video or read the instructions in the FAQ.

This course includes free exercise files, so you can practice while you watch the course. To access all the exercise files in our library, become a Premium Member.

Are you sure you want to mark all the videos in this course as unwatched?

This will not affect your course history, your reports, or your certificates of completion for this course.

Mark all as unwatched Cancel


You have completed Google Analytics Tips.

Return to your organization's learning portal to continue training, or close this page.

Become a member to add this course to a playlist

Join today and get unlimited access to the entire library of video courses—and create as many playlists as you like.

Get started

Already a member?

Become a member to like this course.

Join today and get unlimited access to the entire library of video courses.

Get started

Already a member?

Exercise files

Learn by watching, listening, and doing! Exercise files are the same files the author uses in the course, so you can download them and follow along. Exercise files are available with all Premium memberships. Learn more

Get started

Already a Premium member?

Exercise files video

How to use exercise files.

Ask a question

Thanks for contacting us.
You’ll hear from our Customer Service team within 24 hours.

Please enter the text shown below:

The classic layout automatically defaults to the latest Flash Player.

To choose a different player, hold the cursor over your name at the top right of any page and choose Site preferencesfrom the dropdown menu.

Continue to classic layout Stay on new layout
Exercise files

Access exercise files from a button right under the course name.

Mark videos as unwatched

Remove icons showing you already watched videos if you want to start over.

Control your viewing experience

Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.

Interactive transcripts

Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.

Are you sure you want to delete this note?


Your file was successfully uploaded.

Thanks for signing up.

We’ll send you a confirmation email shortly.

Sign up and receive emails about and our online training library:

Here’s our privacy policy with more details about how we handle your information.

Keep up with news, tips, and latest courses with emails from

Sign up and receive emails about and our online training library:

Here’s our privacy policy with more details about how we handle your information.

submit Lightbox submit clicked
Terms and conditions of use

We've updated our terms and conditions (now called terms of service).Go
Review and accept our updated terms of service.