Package: ga-extractor
Google Analytics ExtractorA CLI tool for extracting Google Analytics data using Google Reporting API. Can be also used to transform data to various formats suitable for migration to other analytics platforms.SetupYou will need Google Cloud API access for run the CLI:Navigate toCloud Resource Managerand clickCreate Projectalternatively create project withgcloud projects create $PROJECT_IDNavigate toReporting APIand clickEnableCreate credentials:Go tocredentials pageClickCreate credentials, selectService accountGive it a name and make note of service account email. ClickCreate and ContinueOpenService account pageSelect previously created service account, OpenKeystabClickAdd KeyandCreate New Key. Choose JSON format and download it. (store thissecurely)Give SA permissions to GA -guideemail: SA email from earlierrole:ViewerAlternatively seehttps://martinheinz.dev/blog/62.To install and run:pipinstallga-extractor
ga-extractor--helpRunningga-extractor--help# Usage: ga-extractor [OPTIONS] COMMAND [ARGS]...# ...# Create config file:ga-extractorsetup\--sa-key-path="analytics-api-24102021-4edf0b7270c0.json"\--table-id="123456789"\--metrics="ga:sessions"\--dimensions="ga:browser"\--start-date="2022-03-15"\--end-date="2022-03-19"cat~/.config/ga-extractor/config.yaml# Optionally, check configga-extractorauth# Test authentication# Successfully authenticated with user: ...ga-extractorsetup--help# For options and flagsValue for--table-idcan be found in GA web console - Click onAdminsection,View Settingsand seeView IDfieldAll configurations and generated extracts/reports are stored in~/.config/ga-extrator/...You can also use metrics and dimensions presets using--presetwithFULLorBASIC, if you're not sure which data to extractExtractga-extractorextract# Report written to /home/some-user/.config/ga-extractor/report.jsonextractperform raw extraction of dimensions and metrics using the provided configsMigrateYou can directly extract and transform data to various formats. Available options are:JSON (Default option; Default API output)CSVSQL (compatible withUmamiAnalytics PostgreSQL backend)ga-extractormigrate--format=CSV# Report written to /home/user/.config/ga-extractor/02c2db1a-1ff0-47af-bad3-9c8bc51c1d13_extract.csvhead/home/user/.config/ga-extractor/02c2db1a-1ff0-47af-bad3-9c8bc51c1d13_extract.csv# path,browser,os,device,screen,language,country,referral_path,count,date# /,Chrome,Android,mobile,1370x1370,zh-cn,China,(direct),1,2022-03-18# /,Chrome,Android,mobile,340x620,en-gb,United Kingdom,t.co/,1,2022-03-18ga-extractormigrate--format=UMAMI# Report written to /home/user/.config/ga-extractor/cee9e1d0-3b87-4052-a295-1b7224c5ba78_extract.sql# IMPORTANT: Verify the data and check test database before inserting into production instance# To insert into DB (This should be run against clean database):catcee9e1d0-3b87-4052-a295-1b7224c5ba78_extract.sql|psql-Upostgres-asome-dbYou can verify the data is correct in Umami web console and GA web console:Umami extractGA PageviewsNote: Some data in GA and Umami web console might be little off, because GA displays many metrics based on sessions (e.g. Sessions by device), but data is extracted/migrated based on page views. You can however confirm that percentage breakdown of browser or OS usage does match.DevelopmentSetupRequirements:Poetry (+ virtual environment)poetryinstall
python-mga_extractor--helpTestingpytestBuilding Packagepoetryinstall
ga-extractor--help# Usage: ga-extractor [OPTIONS] COMMAND [ARGS]...# ...