Learning Outcomes
- describe the motiviation for collecting analytics for a web application
- describe the options available for collecting analytics
- implement Google Analytics for a web application
Resources
Lab
Video walk through of this lab.
This lab is a continuation of the previous email lab which we augment by adding Google Analytics to the application enabling page and event tracking.
Create a Google Analytics Account and Property
Login into your Google account if you have not already done so.
Go to Google Analytics. Click on the “Start measuring” or “Set up for free” or whatever the button says.
Create an account name. Agree to data sharing, or not, as you see fit. Click on the “Next” button.
Under “Property Setup | Property details”, enter whatever you want for “Property name”.
Choose your reporting time zone and currency.
Click on “Show advanced options”.
Enable “Create a Universal Analytics property”
For “Website URL”, choose “https://email-sms.4949NN.xyz”.
Select “Create a Universal Analytics property only”.
Click on the “Next” button.
Select whatever you want for “Industry category”, “Business size”, and intended use.
Click on the “Create” button.
Agree to the terms and conditions.
Opt in or out of email communications as you see fit.
You should be taken to a page that shows your Tracking ID and code.
Modify the Frontend to do Page Tracking
In the frontend terminal, add the history
and react-ga
modules to the project:
In frontend/src/application.js
, switch from using BrowserRouter
:
to Router
:
Import the modules into the application in frontend/src/application.js
:
Just before the definiton of the Application
class, initialize ReactGA, set up the history object, and the history event listener:
Finally, add the history
event listener to the Router
component:
Rebuild the frontend with yarn build
. Do a hard refresh of the application in the browser. Flip between the home, “About”, and “Email” pages of the app in the browser. You should see the results in the Realtime Overview of the Google Analytics dashboard.
Modify the Frontend to do Event Tracking
Import ReactGA into frontend/src/emailform.js
:
In the sendEmail
event handler, record an email send event:
Rebuild the frontend with yarn build
. Do a hard refresh of the application in the browser. Send an email. You should see the results in the Realtime Events of the Google Analytics dashboard.
Assignment
- Implement event tracking for the SMS as well.
- Implement CI/CD for the project and deploy to Google Cloud Run at
https://email-sms.4949NN.xyz
.