Introduction to Google Analytics 4 | Blog | Web & Roll

Introduction to Google Analytics 4

Google have recently released early access to their latest update to Google Analytics. If you log in and see the below, you are able to become an early adopter of Google Analytics 4.


What are the differences?

The main difference between Google Analytics 4 and previous versions is the event-driven data model. Google Analytics collects various metrics (pieces of data) such as sessions or pageViews. Sessions are recorded every time a user enters your site, and pageViews are recorded each time they enter a new page.

Over the years as the web has evolved, more websites are built as single page apps with frameworks like React. Although it’s possible to record a pageView in React using some code like this…

const history = createBrowserHistory();
history.listen(location => {
  ReactGA.set({ page: location.pathname });
  ReactGA.pageview(location.pathname);
});

… It’s not ideal and it would be much easier if we could record the data like pageViews and sessions like we did before when all websites loaded new content when you clicked to a new page.


In simple terms

If you are struggling to understand what I mean, imagine buying something online. You would normally add a product to your basket, checkout, then receive an order confirmation. Each step in that process could send lots of data, but for this post lets just consider:

  • Metrics – Such as pageViews or sessions each time you enter a new page
  • Events – It’s possible to record other events like addToCart

Google Analytics allows you to view this data in various reports. An app like React requires you to manually send this data because it’s essentially a single-page app so there are no new pages.


Making the switch

There are pro’s and con’s when considering migrating over to Google Analytics 4. A lot will depend on the framework your website uses, and the data you are interested in viewing.

From what we can see after reading the documentation and trying the new UI, we are excited for the future of Google Analytics and what is possible.

Written by Tom Barber
I'm a web developer & online marketing specialist who tends to spend most days experimenting & keeping up to date with HTML, CSS, JS, PHP & various other work-related jargon. I lead the development team & like to constantly push boundaries within the business. Unfortunately, I support LUFC.