GA4 Data API vs Universal Analytics API

Google Analytics 4 (GA4) Data API is a new, exciting, and revolutionary version of Google Analytics Data APIs. Google Analytics 4 Data API allows you to access and track events across platforms in one property, making it easier to view your user data and insights from your websites and mobile applications.

GA4, however, came as a surprise to many who used to depend on the previous Universal Analytics. There are many differences between Google Analytics 4 and Universal Analytics (UA) that changed how you can query your data with the APIs.

And because there is confusion about GA4 Data API, we find it crucial to take a deeper look into the specifics of this new API. Today, we will focus on the differences, similarities, advantages, and disadvantages of the new GA4 Data API compared with the previous UA Reporting API.

So let’s dive right in!

What is Google Analytics 4 Data API?

The new Google Analytics Data API is a set of protocols and tools that allows you to access and extract your Google Analytics 4 reporting data. Currently, the API still provides some features in Alpha and Beta stages, so you may find some capabilities are limited.

Also, the API offers no support to the previous Google Analytics versions at this phase, so it is worth noting before building your next production projects.

Read more: Google Ads API vs Google AdWords API: An In-Depth Analysis and Review

Why is GA4 Data API better than the previous UA APIs?

Offers improved cross-platform analytics

Formerly, Google Analytics 4 was branded as Google Analytics App + Web, and as the name implies, you can now monitor your data from both your applications and websites within a single property. In contrast, UA Reporting API did not offer this functionality in a single property.

Consistent data structures

Data structures for both the requests and results make data extraction simple. For example, the results for metrics and dimensions are now of the same data type, as opposed to the data structure in the previous UA reporting API.

Improved filter syntax

The new Data API has significantly changed how we use the filter for metrics and dimensions to offer greater convenience and functionality. With the new syntax, the new parameters like andGroup, orGroup, and notExpression make it easier to chain multiple filters together, which you had to make several requests in the Reporting API to get the same results.

Easy integration with other business applications

Since your Google Analytics 4 data can be accessed programmatically over the API, it allows seamless integration with your favorite business applications. You can use them with other APIs for you to automate complex reporting tasks and perform powerful customizations according to your needs.

Google Analytics 4 Data API vs Universal Analytics Property API: The Key Differences and Similarities

The main differences between the GA4 Data API and the UA Reporting API comes from the following variants:

Queries

Unlike the Universal Analytics API, GA4 Data API queries do not have parameters with View ID or Property ID. Rather, you simply pass the numeric GA4 property ID over the request URL.

Thus, it differs totally from the Reporting APIs, which requires the views (profile) for reporting identification.

For example:

https://analyticsdata.googleapis.com/v1beta/properties/xxxxxxx:runReport 

Where xxxxxxx is your GA4 property ID. If you were transitioning from UA, your GA4 property is your UA property without the “UA-” prefix.

Core reporting methods

While the Universal Analytics API uses just a single method for the core reporting functionality, there are more methods with the Data API that increases convenience and functionality.

That is, the Reporting API has only getBatch, whereas the GA4 API has four: runReport, runPivotReport, batchRunReports, and batchRunPivotReports.

Syntax for metrics and dimensions

Visible changes in the API schemas for the custom dimensions and metrics are also apparent between the GA4 API and the previous APIs.

The names of the dimensions and metrics, for instance, are not prefixed with ga: like in Universal Analytics API. GA4 Data API uses a new syntax for the dimensions and metrics.

The date ranges, clauses, and orderBys

The date ranges between the two APIs did not change much, except for the number of the date ranges, on a single request. With the new GA4 Data API, you can request up to four date ranges over two in the Reporting API. 

  • What is similar between the two is the date format input as well as the values.

Like the dimensionsFilterclauses and metricsFilterClauses, the new dimensionFilter and metricFilter clauses do the same thing respectively, but you should rewrite them accordingly in the new API.

Last, the ordering structure in Data API has a different structure for the orderBys field, but with a similar functionality as with the Reporting API.

  • With Data API’s OrderBys specification, you can sort results according to dimensions, metrics, and pivot, but you need to add the direction ordering.
//UA Property API

"orderBys": [
        {
          "fieldName": "ga:sessions",
          "sortOrder": "DESCENDING"
        }
      ]

//Data API

  "orderBys": [
    {
      "metric": {
        "metricName": "sessions"
      },
      "desc": true
    }
  ]

Results for the API requests

Your request results that are returned also come with more changes in their structure. Probably, any changes were made primarily improves consistency and convenience.

So let’s look at the summary of the changes:

Structure of results for dimensions and metrics values 

One difference between GA4 API and UA Property API is the results’ structure for the dimensions and metrics values. GA4 Data API has a consistent structure where both the values for dimensions and metrics are both objects. The UA Property API had metrics as an object with array values, while the values for dimensions were just arrays.

//UA Property API

"rows": [
        {
          "dimensions": [
            "Canada"
          ],
          "metrics": [
            {
              "values": [
                "3467"
              ]
            }
          ]
        }

//Data API

  "rows": [
    {
      "dimensionValues": [
        {
          "value": "Canada"
        }
      ],
      "metricValues": [
        {
          "value": "3467"
        }
      ]

Metrics aggregations

Another difference is what has not been included by default in the query results for the metric aggregations. That is, the new API will calculate metric aggregations only if you specify. 

  • The results of this data metrics will be the same, just as you would get with the UA Property API.
//Specifying Data Metrics in Data API

"metricAggregations": [
    "TOTAL",
    "MAXIMUM",
    "MINIMUM"
  ]

Pivot functionality

While you could get the pivot functionality in the batchGet method, the new API supports it through the runPivotReport and batchRunPivotReports. This change has also affected the way we implement them. Now, each row response represents a single cell within a table over the previous UA Property API, where the row response is represented as a complete table line.

Read more: GA4 Set-Up: Checklist for a Perfect Google Analytics 4

Final Thoughts

Google Analytics Data API allows you to access your user’s event data from your websites and applications. This is a new API, and as with anything new, it often comes with considerable merits and demerits, which we have discussed in this post. 

There are also major improvements for this new API that have added more functionality, thus making it much better than the previous UA property API. More so, the API’s future promises even more.

The API is still young, though, and many other features are not yet well-developed or rather missing. Besides causing usage inconveniences, the API also requires more effort, dedication, and perseverance to learn and understand how these differences affect how you fetch your data.

However, the unique experience of this API can be a wonderful challenge for those who love to dabble and discover the immense possibilities of new technologies.

Get All Your Marketing Data in One Place

Dataslayer automatically pulls all your marketing data from over 40 data sources to your favorite destinations, be it Google Data Studio, Google Sheets, Google BigQuery, or BI tools (Qlik, Tableau, Power BI) with API.