Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
^pkgdown$
^.lintr$
.vscode$
^\.github$
terraform/
DEVELOPER.md
^README\.Rmd$
^CODE_OF_CONDUCT\.md$

1 change: 1 addition & 0 deletions .github/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.html
50 changes: 50 additions & 0 deletions .github/workflows/pkgdown.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
branches: [main, master]
pull_request:
release:
types: [published]
workflow_dispatch:

name: pkgdown.yaml

permissions: read-all

jobs:
pkgdown:
runs-on: ubuntu-latest
# Only restrict concurrency for non-PR jobs
concurrency:
group: pkgdown-${{ github.event_name != 'pull_request' || github.run_id }}
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
GARGLE_ENCRYPTION_KEY: ${{ secrets.GARGLE_ENCRYPTION_KEY }}
permissions:
contents: write
steps:
- uses: actions/checkout@v4

- uses: r-lib/actions/setup-pandoc@v2

- uses: r-lib/actions/setup-r@v2
with:
use-public-rspm: true

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::pkgdown, local::.
needs: website

- name: Build site
run: pkgdown::build_site_github_pages(new_process = FALSE, install = TRUE)
shell: Rscript {0}

- name: Deploy to GitHub pages 🚀
if: github.event_name != 'pull_request'
uses: JamesIves/github-pages-deploy-action@v4.5.0
with:
clean: false
branch: gh-pages
folder: docs
2 changes: 2 additions & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,6 @@ Suggests:
testthat (>= 3.0.0),
zoo
VignetteBuilder: quarto
URL: https://nih-cfde.github.io/programets/
BugReports: https://github.com/nih-cfde/programets/issues
Config/testthat/edition: 3
3 changes: 2 additions & 1 deletion _pkgdown.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
url: ~
url: https://seandavi.github.io/programets/
template:
bootstrap: 5
bslib:
bootswatch: materia
pkgdown-nav-height: 100px

39 changes: 18 additions & 21 deletions vignettes/googleanalytics.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,21 @@ The package provides functions to authenticate with your Google account, retriev

# Getting started with `googleAnalyticsR`


```{r}
## setup
#| label: setup
library(googleAnalyticsR)
library(programets)
```

```{r eval=FALSE}
## authenticate
```{r}
#| eval: false
#| label: authenticate
ga_auth(email = "seandavi@gmail.com")
```

```{r echo=FALSE}
```{r}
#| echo: false
#| label: service_account
json_file <- gargle::secret_decrypt_json(
path = system.file(
"secret",
Expand All @@ -49,25 +51,21 @@ ga_auth(email = "seandavi@gmail.com")
```

```{r}
## get your accounts
#| label: get-accounts
account_list <- ga_account_list("ga4")

## account_list will have a column called "viewId"
account_list$viewId
## account_list will have a column called "propertyId"
account_list$propertyId

## View account_list and pick the one that you want to use
## In this case, we will use Bioconductor
ga_id <- 388188354

```

The resulting `res` object will contain the data for the specified date range, metrics, and dimensions. You can view the first few rows of the data using the `head()` function.




```{r}
library(googleAnalyticsR)
#| label: get-data
library(lubridate)

start_date <- Sys.Date() - 365
Expand All @@ -85,28 +83,27 @@ daily_user_country_data <- ga_data(

```{r}
#| label: moving-average

library(ggplot2)
library(zoo)
library(dplyr)

# Group by user type and country, then calculate rolling average
moving_avg_data <- daily_user_country_data %>%
arrange(date) %>%
group_by(newVsReturning, country) %>%
moving_avg_data <- daily_user_country_data |>
arrange(date) |>
group_by(newVsReturning, country) |>
mutate(
activeUsers_7day_avg = rollmean(activeUsers, k = 7, fill = NA, align = "right"),
sessions_7day_avg = rollmean(sessions, k = 7, fill = NA, align = "right")
) %>%
) |>
ungroup()

# Let's see the results
head(moving_avg_data)

# Plot the moving average for active users
moving_avg_data %>%
group_by(date, newVsReturning) %>%
summarise(activeUsers_7day_avg = sum(activeUsers_7day_avg, na.rm = TRUE)) %>%
moving_avg_data |>
group_by(date, newVsReturning) |>
summarise(activeUsers_7day_avg = sum(activeUsers_7day_avg, na.rm = TRUE)) |>
ggplot(aes(x = date, y = activeUsers_7day_avg, color = newVsReturning)) +
geom_line() +
labs(
Expand Down