Integrate Google Analytics to the Website
Let's find out how to integrate Google Analytics into your website to capture user activity.
How we get started
If you don’t have a Google Analytics account, you can go to Google Analytics homepage and locate the “Start for free” button. Once we’ve signed up for Google Analytics, we’ll need to create an account, property, and tracking ID for our website. Placing the tracking ID into the config.yaml
file and triggering a fresh website deployment will complete the Google Analytics integration and enable us to analyze the data immediately.
How to set up Google Analytics
We can follow these steps to integrate Google Analytics, or GA, into our website:
-
First, we sign in to Google Analytics and click “Start measuring” to create an account.
-
Under “Account setup,” provide an appropriate name (for example, personal-website), and configure the “Account Data Sharing Settings.” The defaults should be fine. Click “Next.”
-
Under “Property setup,” provide an appropriate name (for example, personal-website-property).
-
Click on “Show advanced options” to create a Universal Analytics property. For the Website URL, we’ll provide the URL to our website. Click “Next.”
-
Under “About your business,” we can configure the settings to our liking. Click “Next” and accept the terms of service.
-
We can find the tracking ID by returning back to the Admin console and selecting the “Account” and “Property” that we created in the previous steps.
Note: We have to make sure we locate the Universal Analytics property that’s property name reads
UA-XXXXXXX-X
and not the GA4 property. -
Under “Property,” click on “Tracking Info” > “Tracking Code.” Copy the tracking ID, which takes the form of
UA-XXXXXXXXX-1
. -
Also, copy the “Global Site Tag” (
gtag.js
), which is a small script that enables GA tracking on our web page. -
Open
config/_default/params.toml
in the main directory and create agoogleAnalytics
parameter. We’ll insert our tracking code as the parameter value.
Get hands-on with 1400+ tech skills courses.