English version | Chinese version README.md
Overview
Introduction
pyGA4is a Python toolkit designed for extracting, processing, and analyzing data from Google Analytics 4 (GA4).- Whether you're a digital marketing professional, a data analyst, or anyone interested in gaining insights from GA4 data, this package simplifies the process of working with your GA4 data.
How to Stream GA4 Data to Bigquery in Real-time?
First, we assume that everyone has already integrated GA4 data into their respective platform websites (there are many online tutorials).
Next, we will use a free third-party service to stream data into Bigquery. For detailed instructions, please refer to the official documentation.
If successful, you will see tables in Bigquery similar to the following (analytics_xxxx), ref:
Features
- Query Cost Estimation: Provides the Bigquery
dry runfeature to estimate query cost before execution. - Data Extraction: Easily connect to your GA4 property, retrieve data, and save it for analysis.
- Data Preprocessing: Prepare and clean your GA4 data for analysis with built-in data preprocessing functions.
- Custom Queries: Execute custom queries to filter and aggregate data based on your specific needs.
- Data Analysis: Perform various types of analysis, including user behavior analysis, conversion tracking, and more.
- Data Visualization: Create informative visualizations and reports to communicate your findings effectively.
- Simple Integration: Seamlessly integrate
pyGA4into your data pipeline or analytics workflow.
How to Use?
For more features, please refer to the package documentation.
Download the Package
pip install pyga4
Connect to Your Bigquery
from google.cloud import bigquery
client = bigquery.Client()
# Or you can use:
# client = bigquery.Client.from_service_account_json(
# './private/service-project-data-dev-01d11c742ba1.json'
# )
Connect to GA4 Tables
from pyga4.model import Ga4Table
# Use your project_id, dataset_name (analytics_xxxx)
ga4_table = Ga4Table(client, PROJECT_ID, DATASET_NAME)
# Show the tables list in dataset, e.g., analytics_date1, analytics_date2
table_id_list = ga4_table all_tables_list
print(table_id_list)
# Select the table you want to analyze
ga4_table.table_id = 'events_intraday_20200812'
Evaluate Query Cost with dry run
# Query with dry run:
ga4_table.query_config.dry_run = True
query = f"""
SELECT event_timestamp FROM `<project_id>.<dataset_name>.<data_table>`
"""
results = ga4_table.query(query) # return None, but you can see the query usage!
Analyze User Properties
Query User ID and Country List
# User attribute
user_id_list = ga4_table.user_id_list
user_country_list = ga4_table.geo_country_list
Query User ID and Country Distribution
from pyga4.analytic import UserAnalytic
# UserAnalytic
user_analytic = UserAnalytic(ga4_table)
countries_dist = user_analytic.countries_distribution
userid_dist = user_analytic.user_id_distribution
Analyze Device Properties
# DeviceAnalytic
device_analytic = DeviceAnalytic(ga4_table)
mobile_brand_dist = device_analytic.mobile_brand_distribution
Analyze Events
# EventAnalytic
event_analytic = EventAnalytic(ga4_table)
page_loc_dist = event_analytic.pages_distribution
Metadata
Release files for pyga4 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pyga4-0.2.0.tar.gz | 7.5 kB | Without provenance | Details for pyga4-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pyga4-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for pyga4-0.2.0-py3-none-any.whl |
Total release size: 16.2 kB
Release files / pyga4-0.2.0.tar.gz
| Download URL | pyga4-0.2.0.tar.gz |
|---|---|
| Size | 7.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ee3bb44dffc88f55f8ad6d1531a8b3750dd2bf5260623e00d9dc64824cc53d6d
|
|
BLAKE2b-256 checksum How to use checksums |
559eadc66405ac6a8f445a813cdcdbb88ae6ec000d31dcade2d0dbfebb32bc7f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.5.1 CPython/3.8.6 Windows/10
|
Release files / pyga4-0.2.0-py3-none-any.whl
| Download URL | pyga4-0.2.0-py3-none-any.whl |
|---|---|
| Size | 8.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f771aecc78c76602b70edb6439dc38d55da1dc2dc0011d861d149db2747b7f44
|
|
BLAKE2b-256 checksum How to use checksums |
581f5b03fd5cfa54b76c86a943cba9e2080f3ab17c9ea0a4d234de03167da5d0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.5.1 CPython/3.8.6 Windows/10
|
Security for pyga4 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.