{"id":16201005,"url":"https://github.com/lin-jun-xiang/pyga4","last_synced_at":"2025-03-19T05:31:01.934Z","repository":{"id":195490898,"uuid":"691960588","full_name":"Lin-jun-xiang/pyga4","owner":"Lin-jun-xiang","description":"📊Python Google Analytics 4 (GA4) Data Extraction and Analysis Toolkit","archived":false,"fork":false,"pushed_at":"2023-09-22T01:10:08.000Z","size":3001,"stargazers_count":4,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-04-23T23:14:35.677Z","etag":null,"topics":["bigquery","free","ga","ga4","google-analytics","google-analytics-python-api","python"],"latest_commit_sha":null,"homepage":"https://lin-jun-xiang.github.io/pyga4/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Lin-jun-xiang.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-09-15T08:56:53.000Z","updated_at":"2023-11-29T11:34:09.000Z","dependencies_parsed_at":"2024-10-10T09:35:18.702Z","dependency_job_id":"e5fe2954-895b-4480-8483-f407a0adaefa","html_url":"https://github.com/Lin-jun-xiang/pyga4","commit_stats":null,"previous_names":["lin-jun-xiang/pyga4"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Lin-jun-xiang%2Fpyga4","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Lin-jun-xiang%2Fpyga4/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Lin-jun-xiang%2Fpyga4/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Lin-jun-xiang%2Fpyga4/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Lin-jun-xiang","download_url":"https://codeload.github.com/Lin-jun-xiang/pyga4/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243971180,"owners_count":20376784,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bigquery","free","ga","ga4","google-analytics","google-analytics-python-api","python"],"created_at":"2024-10-10T09:35:12.370Z","updated_at":"2025-03-19T05:31:01.325Z","avatar_url":"https://github.com/Lin-jun-xiang.png","language":"Python","readme":"\u003cp align=\"center\"\u003e\n    \u003cimg src='https://github.com/Lin-jun-xiang/pyga4/blob/main/static/images/pyGA4_logo.PNG?raw=true' width='60%' /\u003e\n\u003c/p\u003e\n\n[English version](README.md) | [Chinese version README.md](README.zh-TW.md)\n\n[Documents](https://lin-jun-xiang.github.io/pyga4/) | [Pypi](https://pypi.org/project/pyga4/)\n\n## Overview\n\n- [Overview](#overview)\n- [Introduction](#introduction)\n- [How to Stream GA4 Data to Bigquery in Real-time?](#how-to-stream-ga4-data-to-bigquery-in-real-time)\n- [Features](#features)\n- [How to Use?](#how-to-use)\n  - [Download the Package](#download-the-package)\n  - [Connect to Your Bigquery](#connect-to-your-bigquery)\n  - [Connect to GA4 Tables](#connect-to-ga4-tables)\n  - [Evaluate Query Cost with dry run](#evaluate-query-cost-with-dry-run)\n  - [Analyze User Properties](#analyze-user-properties)\n  - [Analyze Device Properties](#analyze-device-properties)\n  - [Analyze Events](#analyze-events)\n\n---\n\n## Introduction\n\n* `pyGA4` is a Python toolkit designed for **extracting, processing, and analyzing** data from **Google Analytics 4 (GA4)**.\n* 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.\n\n## How to Stream GA4 Data to Bigquery in Real-time?\n\nFirst, we assume that everyone has already integrated GA4 data into their respective platform websites (there are many online tutorials).\n\nNext, we will use a free third-party service to stream data into Bigquery. For detailed instructions, please refer to the [official documentation](https://support.google.com/analytics/answer/9823238?hl=en#zippy=%2Cin-this-article).\n\nIf successful, you will see tables in Bigquery similar to the following (`analytics_xxxx`), [ref](https://analyticscanvas.com/knowledge-base/ga4-bigquery-export-tutorial-002-querying-event-params/):\n\n![https://analyticscanvas.com/knowledge-base/ga4-bigquery-export-tutorial-002-querying-event-params/](static/images/2023-09-21-15-04-30.png)\n\n## Features\n\n- **Query Cost Estimation**: Provides the Bigquery `dry run` feature to estimate query cost before execution.\n- **Data Extraction**: Easily connect to your GA4 property, retrieve data, and save it for analysis.\n- **Data Preprocessing**: Prepare and clean your GA4 data for analysis with built-in data preprocessing functions.\n- **Custom Queries**: Execute custom queries to filter and aggregate data based on your specific needs.\n- **Data Analysis**: Perform various types of analysis, including user behavior analysis, conversion tracking, and more.\n- **Data Visualization**: Create informative visualizations and reports to communicate your findings effectively.\n- **Simple Integration**: Seamlessly integrate `pyGA4` into your data pipeline or analytics workflow.\n\n## How to Use?\n\nFor more features, please refer to the [package documentation](https://lin-jun-xiang.github.io/pyga4/).\n\n### Download the Package\n\n```\npip install pyga4\n```\n\n### Connect to Your Bigquery \n```python\nfrom google.cloud import bigquery\n\nclient = bigquery.Client()\n# Or you can use:\n# client = bigquery.Client.from_service_account_json(\n#    './private/service-project-data-dev-01d11c742ba1.json'\n# )\n```\n\n### Connect to GA4 Tables\n```python\nfrom pyga4.model import Ga4Table\n\n# Use your project_id, dataset_name (analytics_xxxx)\nga4_table = Ga4Table(client, PROJECT_ID, DATASET_NAME)\n\n# Show the tables list in dataset, e.g., analytics_date1, analytics_date2\ntable_id_list = ga4_table all_tables_list\nprint(table_id_list)\n\n# Select the table you want to analyze\nga4_table.table_id = 'events_intraday_20200812'\n```\n\n### Evaluate Query Cost with dry run\n```python\n    # Query with dry run:\n    ga4_table.query_config.dry_run = True\n    query = f\"\"\"\n    SELECT event_timestamp FROM `\u003cproject_id\u003e.\u003cdataset_name\u003e.\u003cdata_table\u003e`\n    \"\"\"\n    results = ga4_table.query(query) # return None, but you can see the query usage!\n```\n\n### Analyze User Properties\n\n**Query User ID and Country List**\n\n```python\n# User attribute\nuser_id_list = ga4_table.user_id_list\nuser_country_list = ga4_table.geo_country_list\n```\n\n**Query User ID and Country Distribution**\n\n```python\nfrom pyga4.analytic import UserAnalytic\n\n# UserAnalytic\nuser_analytic = UserAnalytic(ga4_table)\ncountries_dist = user_analytic.countries_distribution\nuserid_dist = user_analytic.user_id_distribution\n```\n\n### Analyze Device Properties\n\n```python\n# DeviceAnalytic\ndevice_analytic = DeviceAnalytic(ga4_table)\nmobile_brand_dist = device_analytic.mobile_brand_distribution\n```\n\n### Analyze Events\n\n```python\n# EventAnalytic\nevent_analytic = EventAnalytic(ga4_table)\npage_loc_dist = event_analytic.pages_distribution\n```\n\n\u003ca href=\"#top\"\u003eBack to top\u003c/a\u003e\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flin-jun-xiang%2Fpyga4","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flin-jun-xiang%2Fpyga4","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flin-jun-xiang%2Fpyga4/lists"}