Google Analytics is one of the best free ways to monitor the traffic that is coming into your website or web app. I am currently building a site called Buncha Tools and I want to add Google Analytics to monitor the traffic/visitors for my web app.
By the end of this article you will successfully have Google Analytics working in your Angular App.
- I am using the 4th version of Google Analytics (GA4) and Angular 9.
- I am assuming at this point that you already have your web property created, but if you don't please read Google's Documentation.
1. Setup a data stream for your Web Property
First navigate to your Google Analytics web property and go to the admin tab, and click "Data Streams".
Next click "Web" and fill in your URL and a Stream name:
At this point you will be in the "Web stream details" view. On this screen you will be able to see your Stream URL, Stream Name, Stream ID, Measurement ID and Status. The most important information on this page is the Measurement ID and the Tagging Instructions section. The Measurement ID is unique to our web property and allows Google Analytics to know that the analytics being sent to them are from our website.
4. Confirm Google Analytics is Working
The next step is to confirm that Analytics data is actually being sent to Google. Serve your app locally and open to the homepage of your app (it will be running on localhost but the Analytics data will still send to google).
While you have your app open in one tab of your browser, open up your Google Analytics and navigate to the home tab. As long as you have your app still open in your browser you should see a page view showing up in your Google Analytics.
This page view is certain to be you because at this point your Google Analytics code has not been updated for you production site. Alternatively you can also click the "Real Time" tab and as long as you have your app open, you should see 1 real time visitor (yourself).
You now have Google Analytics connected to your Angular app, the next step is to publish and begin monitoring your traffic through the Google Analytics dashboard.
Thanks for reading through the entire tutorial, I hope this helped you!