Setup Google Universal Analytics
Table of Contents
- Introduction
- Setup Universal Analytics
- Setup Property
- Add Basic Information
- Setup Tracking Code
- Add Tracking Code to Web Page
- Verify the Tracking Code
- Conclusion
Introduction
This page shows an example of how to set up Universal Analytics for learning purposes. Please be aware that Google Universal Analytics will no longer process new data beginning July 1, 2023. You'll need to switch to a Google Analytics 4 Property.
Setup Universal Analytics
If you're new to Google Analytics, you'll need to set up an account. Once you have a Google Analytics account, you can create a property as the screen shows below.
Again, this blog is for learning purposes only, so we choose the Universal Analytics property, but most likely you'll need to use the GA4 property.
Setup Property

Add Basic Information

Setup Tracking Code
At this point, you should be getting the Google Tracking code snippet. You'll need to add this to your website so the site can start tracking activity.

Add Tracking Code to Web Page
As described in the Setup Tracking Code section, you'll need to copy the Google Tracking Code to any page on your site that needs tracking.
The following is sample code showing how to add a Google Tag Manager script to Next.js.
import Script from 'next/script'
export default function Nextra({ Component, pageProps }) {
return (
<>
<Script
strategy="afterInteractive"
src='https://www.googletagmanager.com/gtag/js?id=UA-{Your Property ID}' />
<Script
strategy="afterInteractive"
dangerouslySetInnerHTML={{
__html: `
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-{Your Property ID}');
`,
}}
/>
</>
)
}
Verify the Tracking Code
After adding the above tracking code to your site, go back to Google Analytics and check if there are any records.
The above code sends a pageview to Google Analytics.
gtag('config', '{your tracking ID}');
Conclusion
In this blog, we walked through the simple steps to set up Google Universal Analytics on your website. While Universal Analytics is being sunset in favor of GA4, understanding the setup process remains useful for migration planning and maintaining legacy tracking configurations.