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.
devtools::install_github(repo = "FredHutch/coopMetrics",
ref = "main")
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.
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)
The following metrics are captured:
From Github:
gh_numCommits
: Number of commitsgh_numPostTotal
: Running total of number of postsgh_numNewPosts
: Number of new posts that monthgh_totalContributor
: Running total number of contributorsgh_numNewContributor
: Number of new contributors that monthgh_handles
: If a new contributor was added shows their handle. If no new contributors shows NA.From Google Analytics:
ga_users
: Number of usersga_newUsers
: Number of new usersga_sessions
: Number of sessionsga_pageviews
: Number of pageviewsga_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.
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)
dateRange
Google Analytics requires an account.
The googleAnalyticsR::ga_auth
function is utilized to authenticate. It will prompt you to supply your credentials through an interactive pop out.
See documentation about GoogleAnalyticsR
here
See documentation about the Google Analytics API here