Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
Lin-jun-xiang committed Sep 15, 2023
0 parents commit cf76caa
Show file tree
Hide file tree
Showing 15 changed files with 1,288 additions and 0 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/translate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# .github/workflows/translate.yml
name: Translate Readme

on:
push:
branches: ['test']

jobs:
translate:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 3

- name: Auto Translate
uses: Lin-jun-xiang/action-translate-readme@v2 # Based on the tag
with:
token: ${{ secrets.Action_Bot }} # Based on step2 name
g4f_provider: g4f.Provider.DeepAi # You can change this provider
165 changes: 165 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
config.py
test.py
private/

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
Pipfile.lock
Pipfile

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/#use-with-ide
.pdm.toml

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 JunXiang

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<p align="center">
<img src='./static/images/pyGA4_logo.PNG' width='60%' />
</p>

[English version](README.md) | [Chinese version README.md](README.zh-TW.md)

## Introduction

* `pyGA4` is 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.

## Features

- **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 `pyGA4` into your data pipeline or analytics workflow.
20 changes: 20 additions & 0 deletions README.zh-TW.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
--------------------------------
<p align="center">
<img src='./static/images/pyGA4_logo.PNG' width='60%' />
</p>

[English version](README.md) | [Chinese version README.md](README.zh-TW.md)

## 簡介

* `pyGA4` 是一個 Python 工具箱,設計用於從 **Google Analytics 4 (GA4)** 提取、處理和分析資料。
* 無論您是數位行銷專業人士、數據分析師或有興趣從 GA4 資料中獲得洞見的任何人,這個套件簡化了處理 GA4 資料的流程。

## 功能

- **資料提取**: 輕鬆連接到您的 GA4 網站,擷取資料並儲存以進行分析。
- **資料預處理**: 使用內建的資料預處理函數準備和清理 GA4 資料,以便進行分析。
- **自訂查詢**: 根據您的特定需求執行自定查詢以篩選和彙總資料。
- **資料分析**: 執行各種類型的分析,包括使用者行為分析、轉換追蹤等。
- **資料視覺化**: 創建資訊豐富的視覺化和報告,以有效地傳達您的發現。
- **簡單整合**: 無縫地將 `pyGA4` 集成到您的資料管道或分析工作流程中。
1 change: 1 addition & 0 deletions ga4/analytic/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from ga4.analytic.data_transform import Transformer
84 changes: 84 additions & 0 deletions ga4/analytic/analytic.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
from collections import Counter
from typing import Any

from ga4.model.bigquery import Ga4Table


class User:
"""The features of user"""
@staticmethod
def most_common_countries(table: Ga4Table, n: int = 3) -> list:
pass


class Technology:
"""The features of technology"""
@staticmethod
def most_common_os(table: Ga4Table, n: int = 3) -> list:
pass

@staticmethod
def most_common_browser(table: Ga4Table, n: int = 3) -> list:
pass


class Page:
"""The features of page"""

@staticmethod
def most_common_pages(table: Ga4Table, n: int = 3) -> list:
"""Return most common pages for all users"""
all_pages_loc = table.page_location_list
counts = Counter(all_pages_loc)
top_n = counts.most_common(n)

return top_n

@staticmethod
def track_user_loc():
"""Return most common pages for an user"""
pass

@staticmethod
def conversion_rate(engagement_events: Any, target_events: Any) -> float:
"""Calculate the conversion rate
If your "target" is to measure how many people `place an order`(purchased),
so your `ad clicks` would be the "engagement" because the orders resulting
from the ad are your "conversions."
If your "target" is to measure how many people `clicking the ad`,
then your ad clicks would become the "conversions,"
and `ad impressions` would become the "engagement."
Parameters
----------
action_events:
The engagement events that users perform.
target_events:
The target events that represent successful conversions.
Returns
-------
float
The calculated conversion rate as a percentage.
Examples
--------
If `action_events` contains 1000 page views and `target_events` contains 200 purchases,
the conversion rate would be calculated as:
>>> conversion_rate([...,1000], [...,200])
20.0
If you have multiple engagement events and target events, you can calculate the combined
conversion rate as well:
>>> conversion_rate([1000, 500], [200, 100])
18.18
Note that the input lists should contain counts or frequencies of events.
"""
return len(target_events) / len(engagement_events) * 100.0
Loading

0 comments on commit cf76caa

Please sign in to comment.