pyga4’s documentation!

class pyga4.model.bigquery.BaseTable(client, project_id: str, dataset_name: str)[source]

Bases: Client

Connect to the data set from bigquery

property all_tables_list: list

Return all tables id from data set

property table_id: str
to_dataframe()[source]
class pyga4.model.bigquery.Client(client, project_id: str)[source]

Bases: object

Instance the bigquery client and define its attributes

Parameters

query_config:

if dry_run=True, the query will not response results, but return the bytes usage which indicate cost.

Examples

`python Client().query_config.dry_run = True `

query_config = <google.cloud.bigquery.job.query.QueryJobConfig object>
class pyga4.model.bigquery.Ga4Table(client, project_id: str, dataset_name: str)[source]

Bases: BaseTable

property device_category_list: list

Return all device_category from data table ex: mobile, desktop

property device_language_list: list

Return all device_language from data table

property device_mobile_brand_name_list: list

Return all device_mobile_brand_name from data table ex: Apple

property device_mobile_model_name_list: list

Return all device_mobile_model_name from data table ex: iPhone

property device_operating_system_list: list

Return all device_operating_system from data table ex: iOS

property device_web_info_browser_list: list

Return all device_web_info_browser from data table

property event_date_list: list

Return all event_date from data table

property event_name_list: list

Return all event_name from data table

property event_timestamp_list: list

Return all event_timestamp from data table

property geo_city_list: list

Return all user city from data table

property geo_country_list: list

Return all user countries from data table

property geo_metro_list: list

Return all user metro from data table

property geo_region_list: list

Return all user region from data table

property geo_sub_continent_list: list

Return all user sub_continent from data table

property page_location_list: list

Return all event of page location from data table

query(query: str) list[source]

Custom query from data table

property user_id_list: list

Return all user_id from data table

pyga4.model.bigquery.calculate_bytes_processed(func)[source]
class pyga4.analytic.analytic.BaseAnalytic(table: Ga4Table)[source]

Bases: object

static attribute_distribution(table: Ga4Table, attribute_name: str) Counter[source]
class pyga4.analytic.analytic.DeviceAnalytic(table: Ga4Table)[source]

Bases: BaseAnalytic

The features of technology

property browser_distribution: Counter
property category_distribution: Counter
property mobile_brand_distribution: Counter
property mobile_model_distribution: Counter
property os_distribution: Counter
class pyga4.analytic.analytic.EventAnalytic(table: Ga4Table)[source]

Bases: BaseAnalytic

The features of event

static conversion_rate(engagement_events: Any, target_events: Any) float[source]

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.

property pages_distribution: Counter

Return most common pages for all users

static track_user_loc()[source]

Return most common pages for an user

class pyga4.analytic.analytic.UserAnalytic(table: Ga4Table)[source]

Bases: BaseAnalytic

The features of user

property countries_distribution: Counter
property user_id_distribution: Counter
class pyga4.analytic.data_transform.Transformer[source]

Bases: object

Transform the data of GA4

static timestamp_to_datetime(ga4_timestamp: str | Iterable) str | list[source]