See ss/ folder for screenshots
A Web Analytics Tool to track user behavior,
popularity and traffic on a website.
It analyses a website (Subject) by placing a special
tracking script on the Subject and sending
non-identifiable data from the user's device and
collecting and persisting the user data in a database.
Finally, this data is presented on a Dashboard.
- I wished there existed a web analytics tool that does
not collect private user data. - I wanted to know the inner workings of a web analytics tool.
- I also wanted to sharpen my technical skills and
create a computer science side project.
- Collected 4 types of user data - number of visits,
time on page, device width and traffic source. - Used visibilityChange event and fetch API to send
analytics data. - Created a Node and Express server for the backend.
- Used MongoDB for the database.
- Used NextJS to create the Subject and Dashboard
websites. - Used Bootstrap and custom CSS for the Dashboard.
- Used Local time on Client and UTC on server and DB.
Used UTC to fetch and collect analytics data. - Used MongoDB's Aggregation Pipeline to Group Data
and make development easier. - Used Environment Variables to store APIs.
- Here is the Tracking Code.
- Here is the data collected from the Subject Website.
- Here is the data fetched and requested by the Dashboard.
- Here are the Server API endpoint calculations.
- Here is the Database Schema design.
- I did not use Beacon API, due to data collection
problems on iOS devices (till v12) and other problems.
Rather I used the Fetch API. - I added 10 sec delay before running tracking script
to filter out bots and mistakenly opened page. - I did not use IP address to track users, because
IP addresses change regularly and this is their private
data and I did not want to collect private user data.
- Add additional metrics to be tracked like top 5
most visited websites. - Try using Web Workers to asynchronously send user
data. - Try using AI to track and analyse user behavior
without sacrificing user privacy.
There are 3 parts of this Web Analytics project:
-
Subject Website: Website required to be analysed.
A tracking code is placed on each of its pages.
(Created with NextJS) -
Application Server: For collecting, analysing and
serving user data collected from the Subject website.
This is also used to save user data into a MongoDB
database. (Created with NodeJS, ExpressJS) -
Dashboard UI: A webpage to show charts based on
different metrics and analytics data collected from
the Subject Website. (Created with NextJS)
-
A tracking script is placed on the Subject website
and is downloaded to the user's device when the user
visits it. -
The user visits the Subject website and triggers
some particular events by, such as 'visiting the
website', 'minimising the window and reopening it',
'clicking a certain button', etc. -
Then this script sends user data to the Application
server where it is saved into a database. -
Server performs some Aggregation operations such as
Match, Group, and Project to fetch analytics data based
on different metrics from the DB and create it according
to the Dashboard's requirements. -
Data is, then, fetched from this database and
presented on a dashboard.
The script sends the user data - when the page is
hidden or closed.
When the page is visible or opened, this data is reset.
Hence, no personal data is collected.
However, we can measure the total number of visits and
total time spent on a page on the Subject website.
Note: These are NOT number of UNIQUE visitors and
time spent on page by those UNIQUE visitors.
Articles that helped me create this project:
- Build web analytics project from scratch
- Analytics Blog on CTRL
- How to build your own Web Analytics and avoid the Cookie Banner
- Web Fetch API on MDN
- Date API on MDN
- Get Client's timezone in Javascript
ReactJS, NextJS, NodeJS, ExpressJS, MongoDB,
MongooseJS, Chart.JS, React-Chartjs-2, HTML, CSS, JS