Anita Owens

View Original

How to export your digital analytics data from R

Ok, so you've imported your data into R. Maybe you've done some on-the-fly calculations but now you want to save the export your hard-earned work from R. 

Data Import

Let's start by installing the packages and libraries you will be using.

See this content in the original post

Google Analytics API Authorization

Let's authorize Google Analytics and take a look at our accounts.

See this content in the original post

For a list of the API query names visit: https://ga-dev-tools.appspot.com/query-explorer/

Query Report

Let's pull our report. I'm going to pull the equivalent of the Default Channels Report. Since I want to compare sessions from quarter 1 of this year and quarter 1 of last year, I have 2 date ranges.

See this content in the original post
See this content in the original post
See this content in the original post
See this content in the original post

Export Data

We're going to save our data to an excel spreadsheet using the xlsx package.

See this content in the original post

Your new file will be saved to your present working directory.

A quick glance at our excel file shows all the data we have exported from R.

All done! You can also save your data as a csv file which is a good idea if you have a particularly large dataset.

See this content in the original post

All code can also be found on R pubs. Happy analyzing!