FredHutch / coopMetrics

Functions to easily pull metrics for the coop blog and wiki from github and google analytics
Other
1 stars 1 forks source link

coopMetrics

The coopMetrics package was developed as a thin wrapper around the gh and googleAnalyticsR packages to pull specific metrics. It's meant to work specifically with GitHub Pages blogs set up using Jekyll.

Installation

devtools::install_github(repo = "FredHutch/coopMetrics",
                         ref = "main")

Usage

This package works by pulling data from GitHub and Google Analytics. This package is a work in progress! The goal is to build out functions that make it easier to pull data on blogs hosted with GitHub and tracked with Google Analytics.

Pulling data

Use the function getBlogStatistics() to pull data from both Google Analytics and GitHub. User must specify the owner and repo for GitHub, web property name for GoogleAnalytics, the desired dateRange, and whether or not they would like to use cached data to speed up the function.

Here's an example where I pull data from the FredHutch/coop repository.

getBlogStatistics(owner = "FredHutch",
                  repo = "coop",
                  webPropertyName = "Coop",
                  dateRange = c("2020-01-01", "2020-06-30"),
                  useCache = FALSE)

Metrics

The following metrics are captured:

From Github:

From Google Analytics:

Columns with the prefix gh are pulled from GitHub and columns with the prefix ga are pulled from Google Analytics.

Caching

The user can create a data cache to speed up the data pull using the function createCache(). This function saves the data internally to the package as R/sysdata.rda. Currently the only data that is cached is the contributor data.

Example usage:

createCache(owner = "FredHutch",
            repo = "coop",
            dateRange = c("2019-01-01", "2021-03-31"),
            overwrite = TRUE)

A note on dateRange

More info:

Google Analytics API

GitHub API