Learn business growth with Google Analytics 4 Forums Google Analytics 4 Unavailable custom event data in GA4 using Google Analytics Data API v4

  • Unavailable custom event data in GA4 using Google Analytics Data API v4

    Posted by Ethan on 22 May 2022 at 10:58 pm

    Hey everyone! So we’re trying to set up our website with GA4 to collect data using Google Analytics Data API v4. We were able to set up custom events which show up smoothly on Google Analytics UI under Engagement/Events. However, when we access https://analyticsdata.googleapis.com/v1beta/, it seems like some are playing hide and seek.

    Just to give you clearer picture, we used this code to fetch a list of all dimensions and metrics:

    from google.analytics.data_v1beta import BetaAnalyticsDataClient
    from google.analytics.data_v1beta.types import GetMetadataRequest
    
    property_id = "PROPERTY_ID"
    client = BetaAnalyticsDataClient()
    request = GetMetadataRequest(name=f"properties/{property_id}/metadata")
    print(client.get_metadata(request=request))
    

    It’s quite perplexing that some events aren’t visible through the code above. Has anyone else encountered a similar situation?

    Thanks a bunch!

    PS: I discovered that only events marked as conversion (Configure/Events) turn up in the metadata. Interesting, isn’t it?

    PPS: Based on this, the link https://analyticsdata.googleapis.com/v1beta/properties/GA4_PROPERTY_ID/metadata gives back only metrics and dimensions. I’m guessing that we might require something a bit different to retrieve all events? Thoughts?

    Aaron replied 10 months, 3 weeks ago 3 Members · 2 Replies
  • 2 Replies
  • Ethan

    Member
    4 November 2022 at 12:09 pm

    Yes, you’re on the right track with your observation and assumption. It’s important to note that event names are not part of the metadata that is returned by the endpoint you’re using. As such, only dimensions, metrics and the metadata related to them will be returned by the GetMetadataRequest.

    To fetch all events, you’ll need to use a different endpoint and method. Google Analytics Data API provides a method run_report() which you can use to fetch all event names (it’s important to note that this could be a huge number). Set ‘eventName’ in the list of ‘dimensions’ in the request parameters and execute the request.

    Furthermore, it’s accurate that only events marked as ‘conversion’ show up as metrics in the metadata, since GA4 differentiates these from normal ‘events’ for their expected high importance. Other events don’t automatically become metrics and won’t show up. However, you can create custom metrics based on these events in GA4 interface.

    Keep in mind that due to the flexible nature of event-based tracking, the Metadata API does not provide an exhaustive list of all possible event names, parameters, or event-scoped custom dimensions or metrics.

  • Aaron

    Administrator
    3 April 2023 at 4:39 pm

    The person is trying to gather data from their website by using Google Analytics Data API v4. They successfully created custom events, which are special user interactions with a website that can be tracked independently from a web page or a screen load. However, they’re encountering a problem where some of the events are not reflecting when accessing a particular link. They also found out that only events that have been labelled as ‘conversions’, which represent a completed activity on a website, are visible. They’re asking for help to solve this issue and wondering if they need to implement something else to see all of the website’s events.

Log in to reply.