Search code examples
apigoogle-analyticsfacebook-marketing-api

Getting a user's marketing source from Google Analytics


I'm a backend developer who has no experience with Google Analytics, but I've a requirement to find a way to collect the Marketing Medium/Source for each user from Google Analytics and save it in my database, I've been searching and looking how to get it from an API request but I didn't find a way yet, could you guys help?


Solution

  • You can use the Google Python API to fetch the Google Analytics data. You can read more here.

    Medium and Source information can be found out by using the dimension ga:sourceMedium You can find more info about dimensions and metrics here

    Following which you can setup a daily script and fetches the data from your Google Analytics account and dumps data into csv which you can successively load into your database using libraries such as psycopg2.