TUTORIAL: Python API for Google Analytics (GA4)

Поделиться
HTML-код
  • Опубликовано: 16 июн 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.
  • ХоббиХобби

Комментарии • 69

  • @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!!!!

  • @PeakBIAdmin
    @PeakBIAdmin Месяц назад

    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.

  • @spectatorDH
    @spectatorDH Год назад

    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 26 дней назад

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

  • @shubhamjagtap108
    @shubhamjagtap108 Год назад

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

  • @jorgeayala17
    @jorgeayala17 Год назад

    love this video. Thank you so much!

  • @KalTheBlackCat
    @KalTheBlackCat Год назад +1

    Keep up the good work 😀!

  • @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!🙃

  • @ProgrammingNewbie
    @ProgrammingNewbie Год назад +1

    Fing awesome mami! TY so much!

  • @emilianouribeescobar9712
    @emilianouribeescobar9712 11 месяцев назад

    i like your content

  • @isabelperalvafigueiredo4959
    @isabelperalvafigueiredo4959 10 месяцев назад

    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  7 месяцев назад

      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-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?

  • @deepdishseo
    @deepdishseo 3 месяца назад

    Spasibo! 🙏

  • @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  10 месяцев назад

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

  • @user-nm2ms5ow1c
    @user-nm2ms5ow1c 8 месяцев назад

    thanks

  • @prajwalsantosh
    @prajwalsantosh 6 месяцев назад

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

    • @probabilistically
      @probabilistically  6 месяцев назад

      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.)

  • @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  10 месяцев назад

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

  • @navalhatode5221
    @navalhatode5221 9 месяцев назад +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 7 месяцев назад

      I have the same problem, could you resolve it?

    • @probabilistically
      @probabilistically  7 месяцев назад

      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

  • @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

  • @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

  • @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.

  • @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.

  • @eduardodasilvaargenti2996
    @eduardodasilvaargenti2996 Год назад

    When I try to run format_report(request), I get an error "403 User does not have sufficient permissions for this property..."
    I followed all the steps shown in the video. Any ideas on what's missing?

    • @probabilistically
      @probabilistically  Год назад +1

      Make sure 1) the service account is added to the right property/account in GA Admin interface 2) you have the correct property code in python.

  • @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  6 месяцев назад

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

  • @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.

  • @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  6 месяцев назад

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

    • @KubaAlbion
      @KubaAlbion 3 дня назад

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

  • @sibin_s
    @sibin_s 9 месяцев назад

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

    • @probabilistically
      @probabilistically  7 месяцев назад +1

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

    • @sibin_s
      @sibin_s 7 месяцев назад

      Thanks! @@probabilistically

  • @subrinalazad3215
    @subrinalazad3215 Год назад +1

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

  • @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

  • @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  7 месяцев назад

      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: ruclips.net/video/N2bbJQroGB4/видео.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?