· python programming

Google Analytics Reporting API for PostgreSQL

Python
Projects >> Google Analytics Reporting API for PostgreSQL


This is a Python script I developed for programmatically accessing report data in Google Analytics and inserting into PostgreSQL.

Google Analytics Reporting API V4 is used in this code. A detailed reference of the API can be accessed here.

In this example, a GA summary report is generated (using the JSON below) and inserted into a PostgreSQL staging table with the same name. These dimensions/metrics can be modified using the Dimensions & Metrics Explorer as a guide.

{
	"Dimensions": [
		{
			"name": "ga:date"
		},
		{
			"name": "ga:country"
		}
	],
	"Metrics": [
		{
			"expression": "ga:sessions"
		},
		{
			"expression": "ga:percentNewSessions"
		},
		{
			"expression": "ga:newUsers"
		},
		{
			"expression": "ga:bounceRate"
		},
		{
			"expression": "ga:transactions"
		},
		{
			"expression": "ga:transactionRevenue"
		},
		{
			"expression": "ga:transactionsPerSession"
		}
	],
	"dimensionFilterClauses": [
		{
			"filters": ["none"]
		}
	],
	"Segment": []
}


View my code on GitHub


About Me

I'm a data leader working to advance data-driven cultures by wrangling disparate data sources and empowering end users to uncover key insights that tell a bigger story. LEARN MORE >>



comments powered by Disqus