{"id":30524059,"url":"https://github.com/intake/intake-google-analytics","last_synced_at":"2025-08-26T20:52:38.454Z","repository":{"id":46820029,"uuid":"408542359","full_name":"intake/intake-google-analytics","owner":"intake","description":"Intake driver for Google Analytics queries","archived":false,"fork":false,"pushed_at":"2021-10-28T16:15:51.000Z","size":57,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-05-08T20:04:07.170Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/intake.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}},"created_at":"2021-09-20T17:41:52.000Z","updated_at":"2022-05-19T20:57:32.000Z","dependencies_parsed_at":"2022-09-23T04:51:44.455Z","dependency_job_id":null,"html_url":"https://github.com/intake/intake-google-analytics","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/intake/intake-google-analytics","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/intake%2Fintake-google-analytics","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/intake%2Fintake-google-analytics/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/intake%2Fintake-google-analytics/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/intake%2Fintake-google-analytics/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/intake","download_url":"https://codeload.github.com/intake/intake-google-analytics/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/intake%2Fintake-google-analytics/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":272254590,"owners_count":24901072,"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","status":"online","status_checked_at":"2025-08-26T02:00:07.904Z","response_time":60,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":[],"created_at":"2025-08-26T20:52:37.939Z","updated_at":"2025-08-26T20:52:38.443Z","avatar_url":"https://github.com/intake.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Intake Google Analytics driver\n\n[Intake](intake.readthedocs.io) driver for [Google Analytics Queries](https://developers.google.com/analytics/devguides/reporting/core/v4/quickstart/service-py)\n\n## Install\n\n```\nconda install -c defusco -c conda-forge intake-google-analytics\n```\n\n## Sample query\n\nAll queries require\n* the `view_id` for your Google Analytics account\n* a start date and end date\n* at least one [metric](https://ga-dev-tools.web.app/dimensions-metrics-explorer/) to compute\n* Service account credentials JSON file\n\nThe easiest way to get the `view_id` is to use the\n[Analytics Explorer](https://ga-dev-tools.web.app/account-explorer/).\n\nTo authenticate to the Core Reporting API v4 you will need a [service account]() and JSON credentials file.\nFollow the steps [here](https://developers.google.com/analytics/devguides/reporting/core/v4/quickstart/service-py#1_enable_the_api) to prepare your account and download the credentials. Typically, this\nfile is called `client_secrets.json`.\n\nTo compute the total number of visitors between 5 days ago and yesterday the following query\nis constructed.\n\n```python\nimport intake\n\nds = intake.open_google_analytics_query(\n    view_id='\u003cview_id\u003e',\n    start_date='5DaysAgo',\n    end_date='yesterday',\n    metrics=['ga:users'],\n    credentials_path='client_secrets.json'\n)\n\ndf = ds.read()\nprint(df)\n```\n\nThe output is\n\n```\n   ga:users\n0     301012\n```\n\n## Date ranges\n\nThis driver accepts a number of formats for both `start_date` and `end_date`\n\n* Specific string values: `'yesterday'`, `'today'`, `'\u003cN\u003eDaysAgo'`\n* Datetime-parsable strings in format `'YYYY-MM-DD'`\n* `pd.TimeStamp`, `datetime.date`, or `datetime.datetime` objects\n\nThese data types can be mixed. Here's a few examples\n\nGA strings only:\n\n```python\nds = intake.open_google_analytics_query(\n    view_id='\u003cview_id\u003e',\n    start_date='30DaysAgo',\n    end_date='yesterday',\n    metrics=['ga:users'],\n    credentials_path='client_secrets.json'\n)\n```\n\n\nDatetime objects and GA strings:\n\n```python\nimport pandas as pd\n\nds = intake.open_google_analytics_query(\n    view_id='\u003cview_id\u003e',\n    start_date=pd.to_datetime('March 19, 2020'),\n    end_date='30DaysAgo',\n    metrics=['ga:users'],\n    credentials_path='client_secrets.json'\n)\n```\n\nDatetime objects with differencing:\n\n```python\nimport pandas as pd\nimport datetime as dt\n\nds = intake.open_google_analytics_query(\n    view_id='\u003cview_id\u003e',\n    start_date=dt.datetime.now() - pd.DateOffset(months=6),\n    end_date=pd.to_datetime('today') - dt.timedelta(days=1),\n    metrics=['ga:users'],\n    credentials_path='client_secrets.json'\n)\n```\n\n\n## Metrics, Dimensions, and Filters\n\nThe easiest way to learn how to build queries and gather the required information is to use the\n[Query Explorer](https://ga-dev-tools.web.app/query-explorer/). Refer to the\n[UA Dimensions and Metrics explorer](https://ga-dev-tools.web.app/dimensions-metrics-explorer/)\nfor documentation on all available fields.\n\n\n### Metric expressions\n\nMetrics are specified as a list of strings or dictionaries and required for all queries.\nThe output DataFrame will have columns that match the metric expressions.\nWhen using the dictionary format the `'expression'` key is required and the `'alias'` key is\noptional to change the column name in the DataFrame.\nGA [metric expressions](https://developers.google.com/analytics/devguides/reporting/core/v4/basics#expressions)\nare supported for both string and dictionary inputs. Here's an example\nof the supported types of `metrics`.\n\n```python\nds = intake.open_google_analytics_query(\n    view_id='\u003cview_id\u003e',\n    start_date='5DaysAgo',\n    end_date='yesterday',\n    metrics=[\n        'ga:users',                      # simple string value\n        'ga:goal1completions/ga:users',  # metric expression as string\n        {'expression': 'ga:sessions'},   # the expression key is required for dicts\n        {\n            'expression': 'ga:sessionDuration/ga:sessions', # expression\n            'alias': 'time-per-session'                     # rename the column\n        }\n    ],\n    credentials_path='client_secrets.json'\n)\n```\n\n### Dimensions\n\nIn addition to metrics an optional list of fields can be provided as dimensions.\nSee the [UA Dimensions and Metrics Explorer](https://ga-dev-tools.web.app/dimensions-metrics-explorer/)\nfor the full list of available dimensions. Dimensions are provided as a list of strings.\nUnlike metrics dimensions do not support aliasing.\n\n```python\nds = intake.open_google_analytics_query(\n    view_id='\u003cview_id\u003e',\n    start_date='5DaysAgo',\n    end_date='yesterday',\n    metrics=[\n        'ga:users',\n        {\n            'expression': 'ga:sessionDuration/ga:sessions', \n            'alias': 'time-per-session'\n        }\n    ],\n    dimensions = ['ga:userType', 'ga:browser']\n    credentials_path='client_secrets.json'\n)\n```\n\n### Filtering\n\nFilters can be applied on metrics or dimensions. See the \n[filters documentation](https://developers.google.com/analytics/devguides/reporting/core/v3/reference#filters) \nfor more details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fintake%2Fintake-google-analytics","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fintake%2Fintake-google-analytics","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fintake%2Fintake-google-analytics/lists"}