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

dimension for customEvent is not working #12466

Open
temuycro opened this issue Mar 15, 2024 · 9 comments
Open

dimension for customEvent is not working #12466

temuycro opened this issue Mar 15, 2024 · 9 comments
Assignees
Labels
type: question Request for information or clarification. Not an issue.

Comments

@temuycro
Copy link

Hello.

Whenever I want to get any Event-Scoped Custom Dimension, the API doesn't recognizes the function.
I followed the syntax as showin in the official documentation, but I still get this error:

ValueError: Protocol message Dimension has no "customEvent" field.

My goal is to get the eventCount (number of events) from a custom event I created AND currently measuring and making reports on Looker Studio and Explorations directly on the Google Analytics 4 interface.

Does anybody has the same problem?

These are the libraries I'm loading

# Load the libraries

from google.oauth2 import service_account
from google.analytics.data_v1beta import BetaAnalyticsDataClient
from google.analytics.data_v1beta.types import RunReportRequest, FilterExpression, Filter
import pandas as pd

And this is the request code:

# Path to service account key file.
key_path = 'credencial_ga4.json'

# Initialize client
credentials = service_account.Credentials.from_service_account_file(
    key_path, scopes=["https://www.googleapis.com/auth/analytics.readonly"]
)
client = BetaAnalyticsDataClient(credentials=credentials)

# Create a report request with a filter.
request = RunReportRequest(
    property=f"properties/XXXXXXXXX",
    dimensions=[{"customEvent": "click"}],
    metrics=[{"name": "eventCount"}],
    date_ranges=[{"start_date": "2020-01-01", "end_date": "today"}],
    dimension_filter=FilterExpression(
        filter=Filter(
            field_name="hostName",
            string_filter=Filter.StringFilter(value="subdomain.domain.com", match_type=Filter.StringFilter.MatchType.EXACT)
        )
    )
)

# Make the request.
response = client.run_report(request)
@temuycro temuycro changed the title customEvent:{event_name} is not dimension for customEvent is not working Mar 15, 2024
@parthea parthea self-assigned this Mar 27, 2024
@parthea parthea added the type: question Request for information or clarification. Not an issue. label Mar 28, 2024
@parthea
Copy link
Contributor

parthea commented Mar 28, 2024

Hi @temuycro,

dimensions should be of type Dimension. Something like [{"name": "value"}] is expected, as an example.

dimensions=[{"name":"customEvent:click"}], could be used in your example

Try the following

request = RunReportRequest(
    property=f"properties/XXXXXXXXX",
    dimensions=[{"name":"customEvent:click"}],
    metrics=[{"name": "eventCount"}],
    date_ranges=[{"start_date": "2020-01-01", "end_date": "today"}],
    dimension_filter=FilterExpression(
        filter=Filter(
            field_name="hostName",
            string_filter=Filter.StringFilter(value="subdomain.domain.com", match_type=Filter.StringFilter.MatchType.EXACT)
        )
    )
)

Please also see https://developers.google.com/analytics/devguides/reporting/data/v1/advanced#event-scoped_custom_dimensions for more examples.

@temuycro
Copy link
Author

temuycro commented Apr 3, 2024

Hi @parthea,

Nope, it didn't work :(

InvalidArgument: 400 Did you mean customEvent:list? Field customEvent:click is not a valid dimension. For a list of valid dimensions and metrics, see https://developers.google.com/analytics/devguides/reporting/data/v1/api-schema

@parthea parthea assigned ikuleshov and unassigned parthea Apr 3, 2024
@ikuleshov
Copy link
Collaborator

temuycro@,

I suggest you try using the API Explorer to call the getMetadata method of the Data API and make sure this dimension is available. Chances are, "click" is not among the custom event parameters available for your property. For further questions, please contact the Google Analytics API Support team, as this question does not seem to be specific to the client library implementation.

@temuycro
Copy link
Author

temuycro commented Apr 4, 2024

@ikuleshov hi! Thank you!

Is there a way to do this using Python?

@parthea
Copy link
Contributor

parthea commented Apr 4, 2024

@temuycro,

The client library was able to send the request to the API however the response from the API was
InvalidArgument: 400 Did you mean customEvent:list? Field customEvent:click is not a valid dimension.

As mentioned in #12466 (comment), please use the Try it method on this page to confirm that click is among the custom event parameters available for your property. This is also mentioned in setup 1 here. Please let us know the result after querying the property.

@temuycro
Copy link
Author

temuycro commented Apr 4, 2024

@parthea hello.

I tried using this endpoint GET https://analyticsdata.googleapis.com/v1beta/properties/GA4_PROPERTY_ID/metadata (changing my GA4_PROPERTY_ID with mine. But I don't know how to get the data, since my credentials is a .json file.

Sorry, I'm not a developer. I'm currently using Postman.

Would you guide me through this? Also, at least a little bit of code on Python, like the one I used in the first comment?

@parthea
Copy link
Contributor

parthea commented Apr 4, 2024

@temuycro
Copy link
Author

temuycro commented Apr 4, 2024

@parthea Done! Sorry I didn't understand when you mentioned Try it because my documentation is in Spanish lol.

You were right: the customEvent:click is not available. Do you know why is that?

@parthea
Copy link
Contributor

parthea commented Apr 4, 2024

@temuycro , This is an API specific question rather than a client library question as mentioned in #12466 (comment). You'll get better quality answers from the API team. Please fill out this form to obtain technical support for the API: https://developers.google.com/analytics/devguides/support

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: question Request for information or clarification. Not an issue.
Projects
None yet
Development

No branches or pull requests

3 participants