Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating google analytics metrics getter #73

Merged
merged 13 commits into from
Mar 5, 2024
Merged

Conversation

cansavvy
Copy link
Collaborator

@cansavvy cansavvy commented Feb 26, 2024

Purpose/implementation Section

What changes are being implemented in this Pull Request?

Fixing up some things for usability and DRYness purposes.

The google analytics all_ga_metrics() is being deprecated changed so it can take property ids instead of just taking all properties from an account.

In order to do this, we needed to make a new function get_ga_property_info() that will allow a display name (and other info) for a property to be retrieved.

@cansavvy
Copy link
Collaborator Author

cansavvy commented Feb 26, 2024

I also ran styler::style_dir("R") so a lot of the changes have to do with that.

I can separate out these changes if it makes it to hard to review, but I tried to highlight the actual changes.

@@ -127,6 +127,41 @@ get_ga_properties <- function(account_id, token = NULL) {
return(results$properties)
}

#' Get all property information for a particular property id
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@howardbaek This is a new function

Copy link
Contributor

@howardbaik howardbaik Mar 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't working for me. As documented, I made sure to check the box See and download your Google Analytics data. on the OAuth screen:

Screenshot 2024-03-01 at 11 36 49 AM

When I run the example, I get

> property_info <- get_ga_property_info(property_id = "422558989")
Using user-supplied cached tokens stored using authorize("google")


Error in request_ga(token = token, url = paste0("https://analyticsadmin.googleapis.com/v1alpha/properties/",  : 
  API request failed:{
  "error": {
    "code": 403,
    "message": "The caller does not have permission",
    "status": "PERMISSION_DENIED"
  }
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@howardbaek Did you login with ITCR Gmail or your own personal gmail? If you logged in with your own gmail, you don't have access to this property id so it wouldn't work.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I should make that more clear in the example

#' }
get_all_ga_metrics <- function(account_id = NULL, token = NULL, dataformat = "dataframe") {
get_multiple_ga_metrics <- function(account_id = NULL, property_ids = NULL, token = NULL, dataformat = "dataframe",
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And this function got reworked. Can you take a look and see what you think of the changes and if you have recommendations? @howardbaek

Copy link
Contributor

@howardbaik howardbaik Mar 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above:

> some_properties <- get_multiple_ga_metrics(property_ids = c("422671031", "422558989"))
Using user-supplied cached tokens stored using authorize("google")

Error in request_ga(token = token, url = paste0("https://analyticsadmin.googleapis.com/v1alpha/properties/",  : 
  API request failed:{
  "error": {
    "code": 403,
    "message": "The caller does not have permission",
    "status": "PERMISSION_DENIED"
  }
}

Copy link
Contributor

@howardbaik howardbaik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we may have to address the Google scopes as the functions here are denying permission.

@cansavvy
Copy link
Collaborator Author

cansavvy commented Mar 5, 2024

We tested this in a pair programming session and found out it was because Howard was trying to access a property id with the hutchgmail account that it does not have access to. Tried to fix the docs appropriately.

@cansavvy cansavvy merged commit 4f0ffa6 into main Mar 5, 2024
4 of 5 checks passed
@cansavvy cansavvy deleted the cansavvy/ga-updates branch March 5, 2024 19:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants