[Python] Google API Audience Export with Python help request. It literally does not exist on...

Discussão em 'Python' iniciado por Stack, Fevereiro 6, 2025.

  1. Stack

    Stack Membro Participativo

    I am writing to you out of desperation because you are my last hope. Basically I need to export GA4 data using the Google API(BigQuery is not an option) and in particular, I need to export the dimension userID(Which is traced by our team).

    Here, in this documentation I can see how to export most of the dimensions, but the code provided in this documentation provides these dimensions and metrics, while I need to export the ones here . I went to Google Analytics GitHub and there were no code samples with the audience whatsoever. I asked 6 LLMs for code samples and I got 6 different answers that all failed to do the API call. By the way, the API call with the sample code of the first documentation is executed perfectly. It's the Audience Export that I cannot do.

    So, here is one of the 6 code samples(the credentials are inserted already in the environment with the os library):

    property_id = 123
    audience_id = 456
    from google.analytics.data_v1beta.types import (
    DateRange,
    Dimension,
    Metric,
    RunReportRequest,AudienceDimension,
    AudienceDimensionValue,
    AudienceExport,
    AudienceExportMetadata,
    AudienceRow,
    )
    from google.analytics.data_v1beta.types import GetMetadataRequest

    client = BetaAnalyticsDataClient()
    # Create the request for Audience Export
    request = AudienceExport(
    name=f"properties/{property_id}/audienceExports/{audience_id}",
    dimensions=[{"dimension_name": "userId"}] # Correct format for requesting userId dimension
    )

    # Call the API
    response = client.get_audience_export(request)


    The sample code might have some syntax errors because I couldn't copy the whole original one from the work computer, but again, with the Core Reporting code, it worked perfectly. Would anyone here have an idea how should I write the Audience Export code in Python? Thank you!

    Continue reading...

Compartilhe esta Página