{"id":8754,"library":"universal-analytics-python3","title":"Universal Analytics Python 3 Client","description":"This library provides a Python 3 interface to Google Analytics, supporting the Universal Analytics Measurement Protocol, with an interface loosely modeled after Google's analytics.js. It's a fork of `universal-analytics-python` with added support for Python 3, batch requests, and both synchronous and asynchronous API calls. The current version is 1.1.1, released on April 28, 2021. However, please note that Universal Analytics (UA) has ceased processing new data as of July 1, 2023, and all UA services and APIs, including the ones this library interacts with, will be fully shut down on July 1, 2024.","status":"abandoned","version":"1.1.1","language":"en","source_language":"en","source_url":"https://github.com/dmvass/universal-analytics-python3","tags":["google analytics","universal analytics","measurement protocol","analytics","deprecated"],"install":[{"cmd":"pip install universal-analytics-python3","lang":"bash","label":"Install with pip"}],"dependencies":[],"imports":[{"note":"The top-level package for imports is `universal_analytics`, not `universal_analytics_python3`.","wrong":"from universal_analytics_python3 import Tracker","symbol":"Tracker","correct":"from universal_analytics import Tracker"},{"symbol":"HTTPRequest","correct":"from universal_analytics import HTTPRequest"},{"symbol":"HTTPBatchRequest","correct":"from universal_analytics import HTTPBatchRequest"},{"symbol":"AsyncHTTPRequest","correct":"from universal_analytics import AsyncHTTPRequest"},{"symbol":"AsyncHTTPBatchRequest","correct":"from universal_analytics import AsyncHTTPBatchRequest"}],"quickstart":{"code":"import asyncio\nfrom universal_analytics import Tracker, AsyncHTTPRequest\n\n# NOTE: Universal Analytics has been deprecated by Google.\n# This code will NOT send new data to Google Analytics after July 1, 2023,\n# and the Universal Analytics API will be completely shut down on July 1, 2024.\n# Please migrate to Google Analytics 4 (GA4) and use the appropriate GA4 client library.\n# This example is for demonstration purposes only for the 'universal-analytics-python3' library.\n\nGA_TRACKING_ID = 'UA-XXXXX-Y' # Replace with your Universal Analytics Tracking ID\nCLIENT_ID = 'unique-user-id-123'\n\nasync def main():\n    print(\"Attempting to send Universal Analytics hit (note: UA is deprecated).\")\n    async with AsyncHTTPRequest() as http:\n        tracker = Tracker(GA_TRACKING_ID, http, client_id=CLIENT_ID)\n        await tracker.send('pageview', path='/home', title='Homepage')\n        print(f\"Sent pageview hit for client {CLIENT_ID} to {GA_TRACKING_ID}\")\n\nif __name__ == '__main__':\n    # Only run if a tracking ID is somewhat plausible\n    if GA_TRACKING_ID.startswith('UA-'):\n        asyncio.run(main())\n    else:\n        print(\"Invalid GA_TRACKING_ID format. Please set a valid 'UA-XXXXX-Y' for demonstration.\")","lang":"python","description":"A simple asynchronous example demonstrating how to initialize a Tracker and send a pageview hit. This example includes an important disclaimer regarding the deprecation and upcoming shutdown of Universal Analytics. Users should be aware that this library is no longer functional for new data collection."},"warnings":[{"fix":"Migrate to Google Analytics 4 (GA4) and use Google's official GA4 Data API client libraries (e.g., `google-analytics-data`). This library is no longer a viable solution for analytics tracking.","message":"Google's Universal Analytics (UA) has been deprecated. It ceased processing new data on July 1, 2023, and all UA services and APIs, including the ones this library relies on, will be completely shut down on July 1, 2024. This library is effectively abandoned for practical use cases involving current data.","severity":"breaking","affected_versions":"All versions"},{"fix":"Ensure you are using `async with AsyncHTTPRequest()` or explicitly call `await http_request_instance.aclose()` if not using a context manager. Upgrading to 1.1.1 or newer is recommended for this fix.","message":"For asynchronous usage with `httpx` (used by `AsyncHTTPRequest`), version 1.1.1 changed the client closing behavior to use `aclose()` instead of `close()` to align with `httpx` best practices. Older code calling `close()` on `AsyncHTTPRequest` instances will likely fail or lead to resource leaks.","severity":"breaking","affected_versions":"<1.1.1"},{"fix":"When retrieving 'Users' data, query for the exact desired time period (e.g., monthly users directly) rather than summing up finer-grained data (e.g., daily users). This is a limitation of Universal Analytics' data model.","message":"Attempts to sum 'Users' metric data across different time granularities (e.g., aggregating daily user counts to monthly) in Universal Analytics reports (and thus via this API) will lead to inflated and incorrect results due to the non-additive nature of the 'Users' metric.","severity":"gotcha","affected_versions":"All versions (inherent to UA Measurement Protocol)"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Change your import statements from `from universal_analytics_python3 import ...` to `from universal_analytics import ...`","cause":"Incorrect import path. The top-level package for import is `universal_analytics`, not the PyPI package name.","error":"ModuleNotFoundError: No module named 'universal_analytics_python3'"},{"fix":"If manually closing, change `http_request_instance.close()` to `await http_request_instance.aclose()`. The recommended approach is to use `async with AsyncHTTPRequest() as http:` which handles closing automatically.","cause":"In versions 1.1.1 and later, `AsyncHTTPRequest.close()` was renamed to `aclose()` and must be awaited, or the client should be used within an `async with` block. This warning indicates the asynchronous close method was not correctly called.","error":"RuntimeWarning: coroutine 'AsyncHTTPRequest.close' was never awaited"},{"fix":"Ensure the Google Analytics Tracking ID ('UA-XXXXX-Y') is correct and that the `Tracker` is properly instantiated before calling `send()`. For web contexts, verify `cookieDomain` settings or try with `cookieDomain='auto'` for testing.","cause":"This error, originating from the underlying Universal Analytics JavaScript library or Measurement Protocol, indicates that the tracker was not correctly initialized or attempts were made to send data before a valid tracker was established, often related to an invalid tracking ID or `cookieDomain` setting.","error":"Command ignored. Unknown target: undefined."}]}