Posts Tagged ‘ga.js’

Google Universal Analytics GA3 – Two Code Versions

Wednesday, January 4th, 2023

Google Analytics has been around since 2005 when Google acquired a web analytics company called Urchin.

Urchin Code (circa 2005)

  • Based on “Urchin on Demand” codebase
  • August 2006 – implemented “asynchronous tracking” code between <head>tags

Google Analytics (GA2)

  • April 2011 – Implemented new dashboards, reports, etc.
  • September 2011 – Launched Real-Time analytics

Google Universal Analytics (GA3) – Version A

  • October 2012 – New features including cross-platform tracking, flexible tracking data collection from multiple devices, and the introduction of custom dimensions and metrics
  • Used the ga.js library
Google Analytics GA3 – Circa 2017 (gtag.js library)
  • ga.js library includes:
    • The basic tracking functions for a default setup of Google Analytics
    • Uses multiple functions to send data
    • The _setAccount function associates the tracking code with your specific Google Analytics account by setting the account number (which is provided to you when you create your account)
    • The _trackPageview function tracks a pageview on your website (i.e. “hits”).
  • ga.js is designed to support Google Analytics (i.e. no other Google products)

Google Analytics 360

  • March 2016 – primarily targeted for enterprise customers; included tag manager, optimize, data studio, etc.

Google Universal Analytics (GA3) -version B

  • October 2017 – Implemented “Global Site Tag” data collection method (gTag.js) to unify the tagging system
  • gtag.js code is similar to ga.js code but has a slightly different syntax. Here is an example of the tracking code for Google Analytics using gtag.js:
  • gtag.js code includes the same basic tracking functions as the ga.js library, but the syntax is slightly different:
    • A single ‘gtag' function is used to send data to Google Analytics and other Google Products, and the config' command is used to set the account number for your Google Analytics account
  • ga.js is designed to support multiple Google marketing products (i.e. Google Analytics, Google Ads, Google Tag Manager,, and Google Optimize)
  • Scheduled to stop collecting data on July 1, 2023

Google Analytics 4 (GA4)

  • October 2020 – Released GA4
  • Integrated with Google’s ‘BigQuery”; Tracks “events” instead of “sessions”
  • The gtag.js similar to the code found in UA (GA3) 2017 version except:
    • It includes the basic tracking functions for a default setup
    • The ‘gtag‘ function is used to send data to GA4
    • The ‘config‘ command is used to set the measurement ID for your GA4 property
    • The measurement ID is a unique identifier that is provided to you when you create a GA4 property
  • In addition gtag.js, you will also need to implement event tracking in order to capture user interactions with your website. Here is an example of how you might track a button click event in GA4:
  • As of January 2023, GA4 is still work-in progress

“gtag.js” used in Google Universal Analytics and Google Analytics G4

gtag.js is a JavaScript library that is used to send data to Google Analytics and other Google marketing and analytics products. There are two main versions of gtag.js:

  • one that is used for Universal Analytics (the previous version of Google Analytics)
  • one that is used for Google Analytics 4 (GA4)

“gtag.js” used in Google Universal Analytics (G3, 2017)

The version of gtag.js that is used for Universal Analytics is designed to support the traditional pageview-based tracking model of Universal Analytics.

It includes functions that allow you to track pageviews, set custom dimensions and metrics, and configure other aspects of your Universal Analytics tracking.

Here is an example of the gtag.js code for Universal Analytics:

“gtag.js” used in Google Analytics (G4, 2020)

The version of gtag.js that is used for GA4 is designed to support the event-driven tracking model of GA4.

It includes functions that allow you to track specific events (such as button clicks or pageviews) and send them to GA4 for analysis.

Here is an example of the gtag.js code for GA4:

Key Takeaways

As of now, Google Universal Analytics (UA or G3) is going away on July , 2023 so it is imperative that you start collecting web traffic data for now with GA4.

It is unclear if Google will retain historical data under UA so it might be a good idea to export data you want to keep.

  • GA4 should be implemented even if is is not prime-time ready
  • Installing GA4 should not impact GA3 (UA) data collection
  • If you are still using GA3 (FY2012) version without issues, do not upgrade to GA3 (2017) which uses gTag.js library before installing GA4. There are un-documented reporting discrepancies between ga.js and gtag.js