AppsScriptPulse

Request Google Analytics data for Google Sheets using natural language with the PaLM API and Google Apps Script

This video shows how to use the Palm API with Google Apps Script to extract data from Google Analytics 4 accounts. This can be useful for a variety of purposes, such as creating custom reports, automating data analysis, and building new data-driven applications.

Following on from the last post in Pulse where we looked at using Google PaLM API and MakerSuite in Google Apps Script, here’s another example from GDE Linda Lawton. As the video in the post shows Linda has been able to engineer prompts that allow you to use natural language to extract reports from Google Analytics. This shows the emergent capabilities of LLMs as well as some clever prompt engineering. The source post contains more detail, but here is an example:

var text = "The current date is '"+ date + "'. Create a JSON object which contains five parameter's dimension, metrics, start_date, end_date and property_id. The dimension and metric parameter's will be comma separated strings they can be empty if there is no valid text for it. The value of the dimension parameter should be a comma separated string of these dimensions names 'country, eventName, city, audienceName' and the value of the metric parameter should be a comma separated string of these metric names 'activeUsers, eventCount, screenPageViews', the property_id field will also be a string it will be a large number, start date and end date must be in the following format YYYY-MM-DD, which can be found in the given this text '" + prompt + "'. If no start date is found use set it to seven days ago and if no end date is found set it to today."

A couple of highlights worth noting:

  • Context – The current date is included programmatically to give the LLM a reference point
  • Reinforcement – ‘start date and end date must be in the following format YYYY-MM-DD’
  • Exceptions – ‘If no start date is found use set it to seven days ago and if no end date is found set it to today’

Source: GA4 + Palm API with Google App script

Webtrends: Add-on for Spreadsheet – Analytics Traps

The Webtrends add-on offers the functionality of the Webtrends API combined with the power of data manipulation in Google spreadsheets.

You can use the tool by installing it from the G Suite Marketplace : https://gsuite.google.com/marketplace/app/webtrends/227205745742?hl=en

With this add-on you can:

  • Get data from multiple reports at the same time;
  • Create custom calculations from the data obtained in the report;
  • Create dashboards with embedded data visualizations;
  • Schedule the automatic execution of reports so that the data is always updated;
  • Easily control who can see this data and views by leveraging Google Spreadsheet’s sharing and privacy features.

The add-on was created with Google Apps Script, in my blog dedicated to the subject there are detailed guidelines for using this add-on.

Source: Webtrends: Add-on for Spreadsheet – Analytics Traps

GA360 Unsampled Spreadsheet Add-on – Analytics Traps

The non-sampled reports in Google Analytics allow to obtain data based on 100% of the sessions even in those conditions where the platform applies the samplingUnsampled reports are currently only available to Google Analytics 360 users.

The request for non-sampled reports in Google Analytics does not provide an immediate response, in fact it can take from several minutes to more than an hour to obtain a downloadable report.

With the Add-on for Spreadsheet ‘GA360 Unsampled‘ it is possible to query the Unsampled Reports API to directly obtain the data without worrying about verifying the actual generation of the results, as they are conveniently retrieved automatically and saved in sheets dedicated to the Spreadsheet used.

Source: GA360 Unsampled Spreadsheet Add-on – Analytics Traps

How to build a Google Analytics Dashboard with Apps Script and Google Sites – Sheets to Apps

Using Google Analytics and looking for a new way to aggregate, store, and efficiently organize the data from your website in a Google Sheet? In this episode of Sheets to Apps, we show you how to combine the Google Analytics add-on with Apps Script, resulting in the automation of cohesive data summaries that are compatible with Google Sites.

In this latest episode Alexandrina Garcia-Verdin demonstrates how the Google Analytics Add-on can be combined with macros to automate regular reporting. The video description has links to all the resources you need to set this up.

Whilst ‘Sheets to Apps’ videos are targeted at low/no coders as an Apps Script Developer I always find it useful to have a look at the code to see how it is done, as more often than not there will be a technique or method I’ve not come across. In the case of this example my new discovery was the .autoFill() and after browsing the documentation, .autoFillToNeighbor() methods in SpreadsheetApp. These methods allow you to replicate the auto-fill functionality users have in Google Sheets.

Another discovery was the various .setOption() calls when building the charts. I’ve used .setOption() in projects in the past and the issue I’ve had is navigating the long list of options you can use for various chart types. Using the macro recorder seems like a great way to capture all the options you want to add to your script project.