TUTORIAL: Python API for Google Analytics (GA4)

Поділитися
Вставка
  • Опубліковано 12 лип 2024
  • Get your Google Analytics (GA4) data in python through Google Analytics Data API v1 beta.
    Create API keys, authorize your app in Google Analytics, create a request and format the response, visualize the data in python or export the data to CSV or Excel. Complementary report code included.
    Quickstart Guide:
    developers.google.com/analyti...
    Python code in GitHub repository:
    github.com/tanyazyabkina/GA4_...
    Google Developers Guide:
    googleapis.dev/python/analyti...
    Metrics and Dimensions:
    developers.google.com/analyti...
    Chapters:
    0:00 GA4 to python overview
    0:53 API keys using Quickstart
    2:51 API keys manually
    6:27 Authorize in GA4
    8:57 Python setup
    10:09 Google analytics data request and response
    12:46 Export response in Excel/CSV
    13:19 Monthly web traffic chart
    13:45 Python GA4 report
    15:33 Validate GA4 in python against Data Studio
    My website: zyabkina.com
    If you want to contact me, the best way is to ping me on LinkedIn using Connect-Add a note (three dots in the mobile app) and mention that you watched my video.
  • Навчання та стиль

КОМЕНТАРІ • 67

  • @NSLABTUTORIAIS
    @NSLABTUTORIAIS Рік тому +2

    Many, many thanks. I searched a lot for some API tutorial with Python to connect to GA4 that worked. Congratulations, yours is very clear, simple and functional.

  • @colinsorensen2366
    @colinsorensen2366 Рік тому +4

    You are a LIFESAVER. My least favorite part of analytics is setting up new APIs, but this worked brilliantly, and your code is much cleaner than the quickstart code. Thank YOU!!!!

  • @tieduprightnowprcls
    @tieduprightnowprcls Рік тому

    Thankyou for the video, Tanya!
    I just a need a working code to get started with, and what you have provided in the video is more than enough.

  • @lowgn9251
    @lowgn9251 Місяць тому

    Great !! Everything is so simple with your explanations ! Thanks a lot

  • @shubhamjagtap108
    @shubhamjagtap108 Рік тому

    Great. Thank you for sharing, much appreciated. It solved my problem.

  • @zonezero3290
    @zonezero3290 Рік тому +1

    Absolutely a good video for beginners, even though the quality of the video itself only got 480p, still pretty nice! thx!

    • @probabilistically
      @probabilistically  Рік тому +1

      Thanks for pointing out the resolution. After 15 mins of checking all the versions and settings, I am still confused why this happened and how come I never noticed. Clearly, I am not a good video editor!🙃

  • @jorgeayala17
    @jorgeayala17 Рік тому

    love this video. Thank you so much!

  • @PeakBIAdmin
    @PeakBIAdmin 2 місяці тому

    Mam you are a lifesaver. I went through so many tutorials but none was as clear and detailed as yours. Thank you for posting this.

  • @KalTheBlackCat
    @KalTheBlackCat Рік тому +1

    Keep up the good work 😀!

  • @ProgrammingNewbie
    @ProgrammingNewbie Рік тому +1

    Fing awesome mami! TY so much!

  • @deepdishseo
    @deepdishseo 4 місяці тому

    Spasibo! 🙏

  • @emilianouribeescobar9712
    @emilianouribeescobar9712 Рік тому

    i like your content

  • @isabelperalvafigueiredo4959
    @isabelperalvafigueiredo4959 11 місяців тому

    Thank you sooo much for the detailed explanation! I have a question: do you know/have a way to query custom dimensions too? I'm struggling with this right now.

    • @probabilistically
      @probabilistically  8 місяців тому

      I have not done it using the API, but Google has a way to pull custom dimensions:
      developers.google.com/analytics/devguides/reporting/data/v1/api-schema#custom_dimensions

  • @user-nm2ms5ow1c
    @user-nm2ms5ow1c 9 місяців тому

    thanks

  • @jnibur
    @jnibur Рік тому

    Very nice video. Question for you. By doing this, could you extract the same day data by hour ? Or do you still need to wait until next next to see today's data?

    • @probabilistically
      @probabilistically  11 місяців тому

      There is a realtime report: developers.google.com/analytics/devguides/reporting/data/v1/realtime-basics

  • @user-hn2gu2jj6v
    @user-hn2gu2jj6v Рік тому

    Hi I have a question. So I have experienced missing data (downloaded the output in CSV) when I added more dimensions to RunReportRequest function. Is there any possible solutions to solve this?

  • @prajwalsantosh
    @prajwalsantosh 7 місяців тому

    Great Video! Do you have any idea on how to pull custom segment level data as well?

    • @probabilistically
      @probabilistically  7 місяців тому

      developers.google.com/analytics/devguides/reporting/data/v1/exploration-api-schema
      I believe that's the dimension called 'segment': A segment is a subset of your Analytics data. For example, of your entire set of users, one segment might be users from a particular country or city. To learn more, see Segment builder. The segment dimension returns the name assigned to the segment in the request with a 1-based prefix (i.e. if the first segment is named 'Paid Traffic' in the request, then this segment will be '1. Paid Traffic' in the response). If segments names are not specified in the request, segments are named by 1-based names (i.e. '1. Segment', '2. Segment', etc.)

  • @navalhatode5221
    @navalhatode5221 10 місяців тому +2

    Thank you for the video. Really help to code . I have question: As GA4 api only retrieve the data of 10,000 rows. How can we retrieve all the data (10,000 + rows)?

    • @josemiguelvilchesfierro3258
      @josemiguelvilchesfierro3258 8 місяців тому

      I have the same problem, could you resolve it?

    • @probabilistically
      @probabilistically  8 місяців тому

      There are limit and offset options for the number of rows that allow the request to return more than 10K records. Here is a guide that explains how they work:
      developers.google.com/analytics/devguides/reporting/data/v1/basics#navigate_long_reports

  • @sukhkaur27
    @sukhkaur27 Рік тому

    Great video! I tried this on my local environment and it worked amazingly well, however, how can I automate this to run everyday on cloud using Azure Function App or similar? Would really appreciate some help. Thank you!

    • @probabilistically
      @probabilistically  11 місяців тому

      I believe, it should be possible. I am not an Azure expert, though.

  • @jeancarlossedanoporta5351
    @jeancarlossedanoporta5351 Рік тому

    Very good video. Congratulations
    Query: How much is the cost of the API service in GCP?

    • @probabilistically
      @probabilistically  Рік тому

      There is no cost if you stay within Standard Property limits, which are quite generous. Here is more detail on specific quotas: developers.google.com/analytics/devguides/reporting/data/v1/quotas

  • @angelomartinez113
    @angelomartinez113 Рік тому

    Do you know if the access token and refresh token are the same from UA to GA4?

    • @probabilistically
      @probabilistically  Рік тому +1

      If you authorize both UA and GA4 APIs for the project, you should be able to use the same tokens for both.

  • @juanitamiles4328
    @juanitamiles4328 Рік тому

    Hi can we also extract GA4 data only with API. In this tutorial you have used python but I just want to extract with API only

    • @probabilistically
      @probabilistically  Рік тому +1

      I believe so: developers.google.com/analytics/devguides/reporting/data/v1/rest/v1beta/properties/runReport

  • @jose.antoniogonzalezbustos3259

    Hi! I have a question. Why is the metric "Average Engagement Time" not on the list of metrics for the API, i can see it in "Aquisition->User Aquisition" in the table but its not on the list. Does anyone know how to get it?

    • @probabilistically
      @probabilistically  Рік тому

      There are two metrics that you can use here: userEngagementDuration and averageSessionDuration. Not that the first will give you the total and second the average.

  • @pratyush801
    @pratyush801 7 місяців тому

    hi !
    thanks for this amazing tutorial.
    I am getting a SSL Handshake error when trying to run format_report function .
    Any idea how it can be resolved ?

    • @probabilistically
      @probabilistically  7 місяців тому

      I am not sure. I would check property ID and correct credentials location.

    • @KubaAlbion
      @KubaAlbion 29 днів тому

      I have same problem, did you manage to fix it?

  • @angelomartinez113
    @angelomartinez113 Рік тому

    I love your videos. Thanks for share your knowledge. Maybe you are able to help me with a doubt I have an implementation in UA with severals advertisers_id with view_id so I need to migrate all the advertisers to GA4. But I don't have property_id. Are there a way to get the property_id to all my advertisers? What are the steps that I will follow is I only have several advertisers_id?

    • @probabilistically
      @probabilistically  Рік тому +1

      Describe what you mean "migrate all the advertisers to GA4"? Is this a python task or a UA to GA4 migration task?

    • @angelomartinez113
      @angelomartinez113 Рік тому

      @@probabilistically Is a python task, I have a several Google accounts with refresh and access token and I need to migrate all of them to GA4 but I got the 403 User does not have sufficient permissions for this property. Could you give an advice?

    • @probabilistically
      @probabilistically  Рік тому

      @@angelomartinez113 Refresh and access tokens - are you authorizing an app or a service account? If you have a service account, then the "email" (looks like an email, but is not an actual email) needs to be added as a user to the GA4 properties - which are different than the UA properties.

  • @subrinalazad3215
    @subrinalazad3215 Рік тому +1

    Thank for the fot video !!
    I am stuck with this: client = BetaAnalyticsDataClient()
    Getting JSONDecodeError & DefaultCredentialsError &

  • @naganathkousik7233
    @naganathkousik7233 2 місяці тому

    Hey , I have a doubt , is there is any way that I can ask view access in google analytics with the help of python or js script
    If yes can you pls tell me the approach?
    Thanks in advance

    • @probabilistically
      @probabilistically  2 місяці тому

      Check out the Analytics Management API. This API allows adding new users into accounts. developers.google.com/analytics/devguides/config/mgmt/v3/mgmtReference

  • @ManuelTorres-ci2so
    @ManuelTorres-ci2so Рік тому

    Is it possible to access the conversion data from the library or rest api?

    • @probabilistically
      @probabilistically  Рік тому +1

      There is a metric called isConversionEvent (boolean), and it marks conversion events that you set up in GA4 Admin -> Events. The same field is availabe in Looker Studio, so if you want to expore it first, I would recommend trying it there.

    • @probabilistically
      @probabilistically  Рік тому +1

      More here: developers.google.com/analytics/devguides/reporting/data/v1/api-schema

  • @sibin_s
    @sibin_s 10 місяців тому

    Is there an Id (like userid) to call as dimension to fetch all visitor data ??

    • @probabilistically
      @probabilistically  8 місяців тому +1

      The API is good for summaries not all data. Look into BigQuery export for detailed raw data export.

    • @sibin_s
      @sibin_s 8 місяців тому

      Thanks! @@probabilistically

  • @cristiandiaz3551
    @cristiandiaz3551 9 місяців тому

    DefaultCredentialsError: Fil was not found.
    Output is truncated. View as a scrollable element or open in a text editor. Adjust cell output settings
    What is the correct way to write the Credentials , cuz i get an error in that file , some one can help me ? just an example of how i have to put the credecials

    • @probabilistically
      @probabilistically  7 місяців тому

      The JSON credentials file downloaded from Google Cloud is all you need. Make sure your file location is referenced correctly.

  • @prasenjitroychowdhury1777
    @prasenjitroychowdhury1777 8 місяців тому

    Hi ma'am, thanks for sharing this video on YT, could you please share a NEW video using the same GA4, Analytic Data API, using .React JS and report can show into the desired URL /admin website?

    • @probabilistically
      @probabilistically  8 місяців тому

      Unfortunately, am in analytics, so I don't know React JS. Excellent suggestion for someone else, though. @jiejenn, maybe?

  • @lavycube3521
    @lavycube3521 Рік тому

    I don't understand, you searched for the active users, right? But active users where? How do I search the amount of people in a certain field?

    • @probabilistically
      @probabilistically  Рік тому

      Active users are the count distinct of users/pseudousers from pageview event records. If you limit pageviews to a certain area of the site, you will get users for that area. If you break users up by page, then the sum should be larger than the total for the site because some users go to more than one page.

  • @juanitamiles4328
    @juanitamiles4328 Рік тому

    Hi,
    Can we also extract the GA3 data with same method

    • @probabilistically
      @probabilistically  Рік тому

      Yes, you absolutely can. Here is the guide: ua-cam.com/video/N2bbJQroGB4/v-deo.html

    • @juanitamiles4328
      @juanitamiles4328 Рік тому

      Hi @@probabilistically Thanks, seriously your GA4 extract video helped me alot ❤

    • @juanitamiles4328
      @juanitamiles4328 Рік тому

      more questions:-
      1) I want to fetch below Dimension/Metrics but not able to see these on API Documentation. Can you help me how I can fetch these
      - Goal Completions
      - Ad Distribution Network
      - Event Category/Action/Label
      2) Can GA3 and GA4 data be stitched together? if yes than how we can do?

    • @probabilistically
      @probabilistically  Рік тому

      @@juanitamiles4328 Glad it helped!

    • @juanitamiles4328
      @juanitamiles4328 Рік тому

      @@probabilistically
      do you have answer of my below questions ?
      1) I want to fetch below Dimension/Metrics but not able to see these on API Documentation. Can you help me how I can fetch these
      - Goal Completions
      - Ad Distribution Network
      - Event Category/Action/Label
      2) Can GA3 and GA4 data be stitched together? if yes than how we can do?