Learn business growth with Google Analytics 4 Forums Google Analytics 4 How to Use a Custom Dimension with GA4 and JDBC

  • How to Use a Custom Dimension with GA4 and JDBC

    Posted by Jacob on 28 July 2022 at 3:36 pm

    Hey, I could really use some help here. I’m working with the JDBC driver for GA4 and attempting to query some custom dimensions. After checking the metadata API, it looks like one of the custom dimensions is labeled as ‘customUser:dimension1’.

    However, when I try to run a query— specifically ‘SELECT Date, conversions, dimensions FROM “GoogleAnalytics4″.”Engagement” where Dimensions=’customUser:dimension1’ and Date=’20230510’— I get an error.

    Here’s a snapshot of the error: [Error Image](https://i.stack.imgur.com/Jb80o.png)

    I’m kinda stuck figuring this out. Somehow, it seems to recognize the dimension ‘customUser:dimension1’ because the same error pops up even when I try querying something random like ‘customUser:random’.

    Here’s what I see with the random query: [Random Query Error Image](https://i.stack.imgur.com/QavkI.png)

    Does anyone know what might be the problem here?

    Benjamin replied 11 months, 2 weeks ago 3 Members · 2 Replies
  • 2 Replies
  • Lucas

    7 June 2023 at 1:18 am

    It’s likely you’re seeing an error because the syntax of your query is incorrect. In the Google Analytics 4 (GA4) SQL system, custom dimensions are not queried in the same way as regular dimensions. The ‘Dimensions’ in your query is likely being interpreted as a column name, resulting in an error because there’s no such column present in the “GoogleAnalytics4″.”Engagement” table.

    Instead of including ‘customUser:dimension1’ within the WHERE clause of the SQL statement, you should include it as one of the fields being selected, just like ‘Date’ and ‘conversions’. This is because ‘customUser:dimension1’ is a dimension, not a specific value within a column. Your query should look somewhat like this: ‘SELECT Date, conversions, customUser:dimension1 FROM “GoogleAnalytics4″.”Engagement” where Date=’20230510”. Performing the query in this manner should solve your problem, assuming ‘customUser:dimension1’ is a valid dimension within your GA4 dataset.

  • Benjamin

    5 July 2023 at 5:11 pm

    Based on the information you’ve described, the issue might be related to the way you’re querying your custom dimension. In Google Analytics 4, custom dimensions sometimes require a specific syntax and you may need to reference them in a different way than just 'customUser:dimension1'. Instead of applying the WHERE clause to Dimensions directly, you need to use the dimension name more specifically. For example, if the dimension is a custom User scoped dimension, you might need to use something like User_Dimensions.<Your_Custom_Dimension_Name>. Additionally, ensure that your data type format and date are correct. If these suggestions do not solve the problem, it would be beneficial to check Google’s documentation on querying custom dimensions in GA4, as they have detailed instructions and guides which can help resolve your issue.

Log in to reply.