[go: nahoru, domu]

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

How to use GA4 "Audience Export Dimensions" #12802

Open
1 task done
AkshatSoni26 opened this issue Jun 15, 2024 · 0 comments
Open
1 task done

How to use GA4 "Audience Export Dimensions" #12802

AkshatSoni26 opened this issue Jun 15, 2024 · 0 comments
Labels
triage me I really want to be triaged. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.

Comments

@AkshatSoni26
Copy link

Determine this is the right repository

  • I determined this is the correct repository in which to report this feature request.

Summary of the feature request

How to use GA4 Audience Export Dimensions. So take a data for a particular user by giving userId.

Desired code experience

file: main.py

from google.analytics.data_v1beta import BetaAnalyticsDataClient
from google.analytics.data_v1beta.types import (
    DateRange,
    Dimension,
    Metric,
    RunReportRequest,
    AudienceDimension,
    AudienceExport
)
import pandas as pd


def sample_run_report(property_id=GA4_PROPERTY_ID):
    property_id = GA4_PROPERTY_ID

    client = BetaAnalyticsDataClient()

    request = RunReportRequest(
        property=f"properties/{property_id}",
        dimensions=[Dimension(name='city'), Dimension(name='country'), AudienceDimension(name="userId")],
        metrics=[Metric(name="activeUsers"), Metric(name='userKeyEventRate'), Metric(name='screenPageViews')],
        date_ranges=[DateRange(start_date="2020-03-31", end_date="today")],
    )
    
    response = client.run_report(request)

    data = {'city': [], 'country': [], 'activeUsers': [], 'userKeyEventRate': [], 'screenPageViews':[]}

    for row in response.rows:
        data['city'].append(row.dimension_values[0].value)
        data['country'].append(row.dimension_values[1].value)
        data['activeUsers'].append(row.metric_values[0].value)
        data['userKeyEventRate'].append(row.metric_values[1].value)
        data['screenPageViews'].append(row.metric_values[2].value)


    df = pd.DataFrame(data=data)

    print(df.head(30))

Expected results

got the user data.

API client name and version

google-analytics-data

@AkshatSoni26 AkshatSoni26 added triage me I really want to be triaged. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design. labels Jun 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
triage me I really want to be triaged. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.
Projects
None yet
Development

No branches or pull requests

1 participant