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

Support for GA4 version of user deletion request (working patch inside) #432

Open
zjuul opened this issue Oct 11, 2023 · 1 comment
Open
Assignees

Comments

@zjuul
Copy link
Contributor

zjuul commented Oct 11, 2023

Tried to do a bulk user deletion, but found out the API for GA4 works a tiny bit differently, and googleAnalyticsR does not work.

The below patch will make it work by adding an new allowed propertyType parameter to ga_clientid_deletion - and also handles the API response correctly.

It works on my local machine:

deletions <- ga_clientid_deletion(
  client_ids,
  ga4_propertyid,
  idType = "CLIENT_ID",
  propertyType = "ga4"
)

Got stuck updating the documentation, so this is a code-only patch.
If you can include this functionality to the package, that would be awesome. Hope my code helps.

git diff output below:

diff --git a/R/client_id.R b/R/client_id.R
index 7a53375..e3c7144 100644
--- a/R/client_id.R
+++ b/R/client_id.R
@@ -73,7 +73,7 @@ ga_clientid_hash <- function(webPropertyId, clientId){
 ga_clientid_deletion <- function(userId,
                              propertyId,
                              idType = c("CLIENT_ID", "USER_ID", "APP_INSTANCE_ID"),
-                             propertyType= c("ga", "firebase")){
+                             propertyType= c("ga", "firebase", "ga4")){
   idType       <- match.arg(idType)
   propertyType <- match.arg(propertyType)
   
@@ -97,7 +97,7 @@ ga_clientid_deletion <- function(userId,
 ga_user_deletion_one <- function(userId,
                                  propertyId,
                                  idType = c("CLIENT_ID", "USER_ID", "APP_INSTANCE_ID"),
-                                 propertyType= c("ga", "firebase")){
+                                 propertyType= c("ga", "firebase", "ga4")){
   
   idType       <- match.arg(idType)
   propertyType <- match.arg(propertyType)
@@ -119,7 +119,9 @@ ga_user_deletion_one <- function(userId,
     body <- c(body, list(webPropertyId = propertyId))
   } else if(propertyType == "firebase"){
     body <- c(body, list(firebaseProjectId = propertyId))    
-  } 
+  } else if( propertyType == "ga4"){
+    body <- c(body, list(propertyId = propertyId))
+  }
   
   the_url <- "https://www.googleapis.com/analytics/v3/userDeletion/userDeletionRequests:upsert"
   
@@ -147,10 +149,14 @@ parse_user_deletion <- function(x){
   }
   
   if(!is.null(x$webPropertyId)){
+    # ga
     property <- x$webPropertyId
-  } else {
+  } else if(!is.null(x$firebaseProjectId)) {
     # firebase
     property <- x$firebaseProjectId
+  } else {
+    # ga4
+    property <- x$propertyId
   }
   
   data.frame(

@MarkEdmondson1234
Copy link
Collaborator

Up for a pull request?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants