Learn business growth with Google Analytics 4 Forums Google Analytics 4 Troubleshooting Duplicate Column Error in GA4 Property Filter with Google Analytics Data API in R

  • Troubleshooting Duplicate Column Error in GA4 Property Filter with Google Analytics Data API in R

    Posted by Olivia on 26 April 2022 at 9:25 am

    Hey there! So, I’m tinkering around with the GA Data API (for GA4 properties) using R, but I hit a bit of a snag. When I run the filter line (it’s the last one in the code below), I get this error:

    data has to be uniquely named, but there are duplicate columns in there.

    I thought I’d nailed the syntax because I used the one outlined here:

    Filter DSL for GA4 filters

    Have a look at the code below and tell me what’s throwing it off:

    ga_properties <- data.frame(brand = c("mybrand"),
                         property_id = c("123456789"))
    test_properties <- filter(ga_properties, brand == "mybrand")
    prop_ids <- test_properties$property_id
    
    date_range <- c('2022-06-01', '2022-06-30')  
    sel_dimensions <- c('customEvent:screen_name')
    sel_metrics <- c('eventCount','totalUsers')
    dimension_filter <- ga_data_filter(city=="Copenhagen" | city == "London")
    
    Raj replied 11 months ago 3 Members · 2 Replies
  • 2 Replies
  • Sebastian

    Member
    13 October 2022 at 7:06 pm

    The issue you’re facing seems to be related to the last line of your code where you’re attempting to filter data by city. According to the error you’re receiving, there appear to be duplicate column names in your data. In simple words, there’s an issue with your data set having two (or more) columns with the same name, which is making it hard for R to understand which one to use.

    Now, just focusing on the last line of your code where you seem to be getting the error, you’re making a call to ga_data_filter function with parameters for city to equal “Copenhagen” or “London”. When this line of code is executed properly, it should return a filter object which includes references to filters for the cities “Copenhagen” and “London” separately. It seems that there’s nothing wrong with this line as per the provided syntax.

    Just to make sure everything is working right, you might want to check if your installed version of the R package rlang is up-to-date. The requirement is for it to be version 1.02 or later.

  • Raj

    Member
    9 January 2023 at 8:12 pm

    You seem to have built your data frame correctly, but the problem appears when setting up the dimension filter. The “data” in “data has to be uniquely named” refers to the data input used in the dimension filter. You’ve specified ‘city’ twice in the filter which the function doesn’t like. Try altering the syntax, possibly by using a different function or encapsulating the two cities in a single command.

Log in to reply.