Skip to content

Instantly share code, notes, and snippets.

@smithjd
Last active October 7, 2022 22:27
Show Gist options
  • Save smithjd/c7fd10c5125342fb211a4b4a395680b0 to your computer and use it in GitHub Desktop.
Save smithjd/c7fd10c5125342fb211a4b4a395680b0 to your computer and use it in GitHub Desktop.
API and Web-based Google Analytics access to properties I own are different

I am trying to access Google Analytics data with googleAnalyticsR but I find that I can access one site but not the other. I'm the admin for both properties and they both look the same to me when I'm using Google's Analytics web interface.

<script async="" src="https://www.googletagmanager.com/gtag/js?id=G-RH1RGKF16D"></script>

<script async src="https://www.googletagmanager.com/gtag/js?id=G-VD0TCNF8BF"></script>

Both sites appear in the GA Web interface; Google is collecting data, etc., etc.

GA-web-interface-mirror

GA-web-interface-shambhala

Now I execute the following R code in Rstudio:

library(googleAnalyticsR)
library(tidyverse)
library(googlesheets4)

ga_auth(email = "my.admin.email.address@gmail.com")

account_list <- ga_account_list()

Here is the problem:

The second property shows up in the account_list data frame, but not the first.

And when I use the property number from the second property in the following code, I get good data:

df <- google_analytics("view-id-number", 
  date_range = c("2022-08-01", "2022-09-08"),
  metrics = c("pageviews",  "avgTimeOnPage" ),
  dimensions = c("pagePath"),
  anti_sample = TRUE)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment