Upgrade to Pro — share decks privately, control downloads, hide ads and more …

GA4 automation tips for analysts

GA4 automation tips for analysts

Gianluca Campo

March 09, 2024
Tweet

More Decks by Gianluca Campo

Other Decks in Marketing & SEO

Transcript

  1. Powered by Head of Analytics & SEO @ Nucleus https://www.linkedin.com/in/gianluca-campo/

    https://www.giancampo.com/ Proud to be a MeasureCamp organizer!
  2. Powered by Nucleus is a Silver Supporter! Nucleus is the

    only Italian consulting agency specializing exclusively in SEO and Analytics. Established in 2018 by founders Duccio Lunari and Alberto Todeschini, who bring two decades of experience in the digital and search market, the company quickly carved out a significant niche in the industry. It has secured collaborations with major national and international companies, including Corriere della Sera, Novartis, Danone, Tim, FC Inter, Bper, Mediaset, VeraLab, Mondadori, Prénatal, and many others. Thanks to its deep vertical expertise, Nucleus is continuously growing and now boasts a team of 25, including some of the most renowned professionals in their fields.
  3. Powered by Some premises 1. This is my first English

    talk <3 2. I’ve learned a lot by preparing this deck: Thank you! This deck is for analysts who 1. Crave for more knowledge about Google Analytics Data API 2. Need easy ways to get their data out of Google Analytics for free 3. Want some introduction to programming 4. Don’t necessarily care about Gen AI :) Introduction What we’re going to see 1. Google products 2. Google Sheets 3. KNIME 4. Python
  4. Powered by Google // GA4 Query Explorer: Notes - 1/3

    1. Choose account and property 2. Remember to tick “Show advanced options” 3. Time range a. YYYY-MM-DD b. yesterday, today c. or NdaysAgo d. You can add another time range in parallel 4. Metrics and dimensions a. Be careful about scopes! b. Custom definitions are included (look at this example) 5. Order type a. By metric, choose a metric and ascending or descending order with the arrow next to the it b. By dimension, better to explain with the examples in Google documentation https://ga-dev-tools.google/ga4/query-explorer/ 6. Metric aggregation a. Total, minimum or maximum b. Useful for overall views c. I guess useful when HLL++ kicks in as well (more on this here and here) 7. Dimension filters a. Filter type string has got these match types b. Filter type in list is a comma separated list of values c. Filters can be combined with andGroup, orGroup and notExpression d. For a complete list of filters see here 8. Metric filters a. Filter type numeric has got these operations available b. Filter type between has got the fields fromValue and toValue c. Filters can be combined with andGroup, orGroup and notExpression 9. Limit is the max number of rows to return 10. Offset is the index for the starting row
  5. Powered by Google // GA4 Query Explorer: Notes - 2/3

    10. Cohort group a. A cohort is a group of subjects who experienced a common event in a selected time period b. The only available dimension to define a cohort is firstSessionDate c. The dateRange field is exactly the same seen at point - 3/4 d. A cohortsRange is the extension of the dateRange (see here) with offset and granularity e. Remember to add Cohort as dimension in the dimensions field to make the request work https://ga-dev-tools.google/ga4/query-explorer/
  6. Powered by Google // GA4 Query Explorer: Notes - 3/3

    11. Keep empty rows a. This option gives the chance to get rows with metrics equal to 0 b. If unticked - as it is by default - the report will NOT show rows with metrics equal to 0 12. Make request a. You can simply make a request b. Or you can see the request JSON, available for easy copy-pasting c. The request JSON is good if you want to make the call yourself and need the POST request https://ga-dev-tools.google/ga4/query-explorer/ 13. The response can be a. An interactive table, with filters and sorting. The table is a bit hard to copy-paste since its pages are limited to 10 rows b. A JSON response, easy to copy-paste. The JSON response can be converted to a CSV with online tools such as https://data.page/json/csv but needs to be processed in a spreadsheet
  7. Powered by Google // GA4 Query Explorer: Use cases 1.

    Preparing the body for requests to Google Analytics Data API made with other client libraries, e.g. the Python client library 2. Rapidly retrieving data, by making very simple calls (for large responses remember I suggest to further process the JSON response) 3. Double checking the results obtained in other platforms, for instance Looker Studio https://ga-dev-tools.google/ga4/query-explorer/
  8. Powered by Google // Google APIs Explorer: Notes 1. More

    or less the same tool as the GA4 Query Explorer with the advanced options enabled 2. Deserves a mention since it helps understanding how to build the request JSON 3. You need to exactly remember how dimensions and metrics are named. In this case you can a. Use the Dimensions & Metrics Explorer b. Copy-paste the request JSON from GA4 Query Explorer 4. However, there’s at least also an additional important field available: returnPropertyQuota returnPropertyQuota returns: 1. tokensPerDay (up to 200K for standard GA4 props.) 2. tokensPerHour (up to 40K for standard GA4 props.) 3. concurrentRequests (up to 10 for standard GA4 props.) 4. tokensPerProjectPerHour (up to 14K for standard GA4 props.) 5. And others. https://developers.google.com/analytics/devguides/reporting/data/v1/rest/v1beta/properties/runReport
  9. Powered by Google // Google APIs Explorer: Use cases 1.

    The same use cases of GA4 Query Explorer 2. PLUS: it gives you an exact count of tokens consumed with each request or the total amount of tokens consumed in a day https://developers.google.com/analytics/devguides/reporting/data/v1/rest/v1beta/properties/runReport
  10. Powered by Google // Event Builder: Notes 1. It uses

    the Measurement Protocol for GA4 2. Choose the client gtag.js or firebase 3. Mandatory parameters: a. api_secret, available in the GA4 UI in the Data Stream details b. measurement_id, again in the Data Stream details c. client_id, I usually take it from my browser in the GA HTTP network requests 4. event_category and event_name a. correspond to an incomplete list of GA4 recommended events (see here) b. You can also add a custom event 5. Event details a. You are suggested with the event parameters related to your event_name choice b. If you’ve chosen a custom event here the details are custom as well c. Tick “Show advanced options” to customize the suggested fields or add User properties 6. Validate the request, and fix possible issues 7. When the event is valid you can a. Send it to GA4! b. Copy the payload c. Share a link to coworkers https://ga-dev-tools.google/ga4/event-builder/
  11. Powered by Google // Event Builder: Use cases 1. Generating

    the payload for calls with Measurement Protocol 2. Retrieving the most important information to test a MP request, for instance the host 3. Simulating what happens when you send events through MP 4. Creating synthetic data populating the GA4 UI with new information not available otherwise https://ga-dev-tools.google/ga4/event-builder/
  12. Powered by Google // Event Builder: Example - 1/4 Transactions

    from a MP setup were coming from Unassigned How to tie sessions to transactions tracked via Measurement Protocol for GA4 (giancampo.com)
  13. Powered by Google // Event Builder: Example - 2/4 I

    saw a thread in Measure Slack pointing towards Google documentation for the same exact issue I had, and I did what recommended How to tie sessions to transactions tracked via Measurement Protocol for GA4 (giancampo.com)
  14. Powered by Google // Event Builder: Example - 3/4 A

    couple of notes to populate those fields: 1. engagement_time_msec can be anything, so I decided to put a simple 1 in there (in the same Slack thread, Simo Ahava reported that this parameter is probably not needed at all) 2. session_id must be a real value so I took this information from a debugging session with Google Analytics Debugger (by David Vallejo) How to tie sessions to transactions tracked via Measurement Protocol for GA4 (giancampo.com)
  15. Powered by Google // Event Builder: Example - 4/4 I

    sent multiple transactions and they were correctly recorded in the Real Time report Finally, the sessionized transaction was collected as coming from Direct traffic How to tie sessions to transactions tracked via Measurement Protocol for GA4 (giancampo.com)
  16. Powered by GSheets // GA4 Magic Reports: Notes 1. This

    is by far the most reliable add-on for Google Sheets I’ve found 2. Kudos to Michele Pisani for his awesome work on this 3. Super user-friendly 4. Scheduling options available 5. Comparing date ranges 6. Easy documentation and support 7. I’ve found some glitches, but just a few (e.g. I don’t always find custom dimensions, but it’s easy to put them there and the query works like a charm) GA4 Magic Reports - Google Workspace Marketplace
  17. Powered by GSheets // GA4 Magic Reports: Use cases 1.

    Downloading data for fast reporting 2. Deep diving into analysis with full control over the output compared to the GA4 UI 3. Scheduling downloads to feed Looker Studio recurring reports GA4 Magic Reports - Google Workspace Marketplace
  18. Powered by GSheets // GA Reports Builder for Google Analytics

    GA4 Reports Builder for Google Analytics™ - Google Workspace Marketplace
  19. Powered by GSheets // GA Reports Builder: Notes 1. Not

    the best tool by Google 2. Terrible UI, IMHO 3. NO scheduling options 4. NO comparisons 5. NO documentation (hidden in some cells there’s a link to the old documentation) 6. NO working filters GA4 Reports Builder for Google Analytics™ - Google Workspace Marketplace
  20. Powered by GSheets // No reason why you should choose

    Google https://www.linkedin.com/posts/aleksandr-ignatenko_ga4-googlesp readsheets-activity-7170373426451341312-mvr8
  21. Powered by KNIME // Analytics Platform: Notes 1. Totally free

    and available for any OS 2. Installation of Google Connector Nodes is quite easy (download here) 3. You need 3 nodes to make a query to Google Analytics a. Google Authenticator b. Google Analytics Connector c. Google Analytics Query 4. Google Authenticator a. You can choose the auth type: Interactive (with a popup window) or API Key b. Scope should be set to Google Analytics but you can add multiple ones 5. Google Analytics Connector a. Just choose account and property and you’re done b. (You could even decide timeouts but I haven’t found it useful) KNIME Analytics Platform | KNIME 6. Google Analytics Query a. Choose metrics and dimensions (custom definitions available) b. A date range c. Dimension filters available, but no metric filters d. The advanced options include i. Case sensitivity ii. Output property quotas (as flow variables)! 7. Then you have thousands of nodes to process the output table
  22. Powered by KNIME // Analytics Platform: Use cases 1. Making

    calls to Google Analytics and retrieving data already sorted in a table 2. It’s an ETL platform so after you Extract data from Google Analytics, you can Transform and even Load them 3. You can further process datasets applying machine learning algorithms, visualizations, or whatever you want KNIME Analytics Platform | KNIME
  23. Powered by KNIME // Analytics Platform: Example - 1/2 How

    to easily read a GTM JSON export file? Google_Tag_Manager_JSON_to_Excel – KNIME Community Hub
  24. Powered by KNIME // Analytics Platform: Example - 2/2 I

    came up with a simple KNIME workflow doing the following: 1. The 1st node reads the JSON file 2. The 1st column of nodes will use JSON paths to grab a chunk from the original file 3. The 2nd column of nodes split chunks to rows 4. The final node writes and save an Excel file Google_Tag_Manager_JSON_to_Excel – KNIME Community Hub
  25. Powered by Python // Google Colab: Notes 1. Google Colab

    is probably the best way to start using Python a. No Python installation needed b. No need for package management or other complicated stuff c. No need for powerful machines, that’s up to Google 2. Most famous packages and ML algorithms already available 3. It still needs some knowledge of Python, but you can copy-paste anything from the web or use ChatGPT 4. It needs a service account to login to Google services a. You should create one in Google Cloud Console 5. Then you can download a JSON file to authenticate your Colab application 6. Shortcuts to Google Drive, automatic plotting, forms and so on Welcome To Colaboratory - Colaboratory (google.com)
  26. Powered by Python // Google Colab: Use cases 1. Doing

    more advanced analysis: All the features available in the APIs are just behind the corner 2. You can further process datasets applying machine learning algorithms, visualizations, or whatever you want 3. Creating web applications accessible and usable for colleagues or clients Welcome To Colaboratory - Colaboratory (google.com)
  27. Powered by Python // Google Colab: Examples - 1/1 1.

    Let’s see it in action: GA4 API Python quickstart.ipynb 2. Here is an example with PandasAI looking for anomalies: GA4 API Python quickstart w/ PandasAI.ipynb 3. But Python is not just for querying GA4 data: digital-analytics-python-scripts/AnalyticsFTW_GA4Ut mTagsClassifier_v0_1_0.ipynb at main · giancampo/digital-analytics-python-scripts · GitHub Welcome To Colaboratory - Colaboratory (google.com)