README.md

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: - gh_numCommits: Number of commits - gh_numPostTotal: Running total of number of posts - gh_numNewPosts: Number of new posts that month - gh_totalContributor: Running total number of contributors - gh_numNewContributor: Number of new contributors that month - gh_handles: If a new contributor was added shows their handle. If no new contributors shows NA.

From Google Analytics: - ga_users: Number of users - ga_newUsers: Number of new users - ga_sessions: Number of sessions - ga_pageviews: Number of pageviews - ga_mostViewed: The top three posts (by views)

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



FredHutch/coopMetrics documentation built on June 7, 2021, 7:45 a.m.