Simple module to work with Google Analytics 4 API.
Features:
- Run real time report
- Run Google Analytics report
pip install install google-analytics-data
Requirements: Python 3.6+
- Create a Google Cloud Account
- Start using ga4
importosimportpandasaspdfromga4importGA4RealTimeReportos.environ['GOOGLE_APPLICATION_CREDENTIALS'] ='ga4_service_acct.json'property_id='307310528'lst_dimension= ['country', 'city', 'deviceCategory']
lst_metrics= ['activeUsers']
ga4_realtime=GA4RealTimeReport(property_id)
report=ga4_realtime.query_report(
dimensions=lst_dimension,
metrics=lst_metrics
)
df=pd.DataFrame(data=report['rows'], columns=report['headers'])
print(df)