R code to produce web analytics summaries for BC Stats ShinyApps in production.
This repository contains code only. Data and outputs live on secure LAN storage and are accessed via safepaths.
- R: 4.0.0+ (recommended: match your team’s standard)
- Network access: VPN connection required to access LAN storage
- Access/credentials:
- Google Analytics (GA4) API access may require credentials (API keys / OAuth)
- Shiny metrics rely on
rsconnectaccess where applicable
Secrets must never be committed. Use a local-only configuration file for credentials.
- Store credentials locally in
~/.Renviron(see.Renviron.example) - Ensure the file is listed in
.gitignore - Raw API pulls are saved locally (e.g., as
.RData) to avoid repeatedly calling APIs during development
SAFEPATHS_NETWORK_PATH
GA_PROPERTY_ID
GA_SERVICE_EMAIL
GA_SERVICE_KEY
SHINY_ACC_NAME
SHINY_TOKEN
SHINY_SECRET
GA_DATE_START
GA_DATE_END
- Google Analytics (GA4) API
- Shiny
rsconnect::showMetrics()API
All data is stored in a hierarchical network folder structure accessed through safepaths.
{LAN_FOLDER}/0. Misc/Data Science Tooling/web-hosting-and-dashboards/shinyapps_webtraffic_monitoring/
├── data/
│ └── # Raw API pulls / raw exports
└── outputs/
├── tables/ # Output tables (CSV / Excel)
└── visuals/ # Output charts / figures
Install required packages:
install.packages(c(
"googleAnalyticsR",
"tidyverse",
"lubridate",
"zoo",
"janitor",
"slider",
"rsconnect",
"safepaths",
"glue"
))
remotes::install_github("bcgov/safepaths")Follow the safepaths documentation: https://github.com/bcgov/safepaths
You will need the project’s specific LAN path key from the maintainers.
- Connect to VPN.
- Configure
safepaths(one-time setup). - Set up local credentials (GA4 / rsconnect) using the local config approach above.
- Run the pipeline scripts:
- Download raw data (GA4 / rsconnect)
- Save cached raw data (e.g.,
.RData) - Build processed datasets
- Produce tables and visuals in
outputs/
Typical outputs include:
-
Tables (CSV / Excel)
- weekly/monthly active users (or sessions, depending on availability)
- rolling averages
- recent week/month snapshots
- geography breakdowns
- device/OS/browser breakdowns
- download event counts
- concurrent use
-
Visuals
- trend charts
- app-to-app comparison charts
- concurrency plots (time series + distributions)
- This GitHub repository stores only code. All data resides on secure LAN storage accessed via
safepaths. - The analysis uses data containing no Personal Information (PI) or other sensitive information.
- The analytic code is developed openly to promote transparency and reproducibility.
See CONTRIBUTING.
This project follows the Contributor Code of Conduct.
For access questions or the safepaths configuration key, contact:
- Zhijia Ju: https://github.com/Anakin2009
- Or open an issue in this repository
Copyright 2026 Province of British Columbia
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.