Amalytics: A tiny analytics powered by HarperDB
And named after me!!
Amalytics is a tiny analytics service built using Flask for the application and HarperDB for storing data. This post explains how to use the application, the design approach, metrics calculated, and the future scope.
You can go ahead and try out the application. The demo is currently running on Google Cloud Platform with free credits.
- Sign Up
- Add a new website
The the following script to just before the closing
The script grabs the
windows.innerWidthand sends it back to the analytics endpoint.
Visit your website(the one you added)
- Check the stats on Amalytics
If you're not comfortable creating a new account, use the following credentials to check out the stats.
username: amalshaji password: amalshaji
Tools & Technologies Used
- Flask - For building the application
- HarperDB - Storing data
- Docker - Containerize Flask application
- Traefik - Easy deployment and automatic SSL certificates
- GCP - Virtual Machine to serve the application demo
The application is divided into multiple packages(
sites), each of which defines the following files.
- forms.py: Contains all the forms generated using Flask-WTF
- routes.py: Contains all the routing and core functionalities
- models.py: Models for each package that defines operations on HarperDB
- utils.py: Helper functions
Following is an example of a Model:
from db import db, schema from harperdb.exceptions import HarperDBError class Click: def create(payload): return db.insert(schema, "clicks", [payload]) def get_click_data(website: str): try: data = db.search_by_value(schema, "clicks", "domain", website) except HarperDBError: data = None return data
This helps simplify the database operations. For example, one can create a new
Click entry by passing the payload dictionary to
Device: The device used to access the page. The device(either
Desktop is parsed from the
Browser: The browser used to access the page.
Referrer: The referrer, i.e, which page/website referrer the URL.
Page Visited: The pages visited within the website that you're tracking
Country: Country from which the user viewed the page/website
Clicks: Clicks, aka Views, is the number of unique views on each website page. A user is unique if the
hash(page URL + IP + User-Agent) is unique for
x hours. Redis is used to store this unique value. If the value is not present, a view is counted, else discarded.
I've always wanted to build something like Amalytics. The hashnode-harperdb hackathon gave enough juice to complete the application. Currently, I'm looking for bugs and fixing them as I go. If you really like the application, give it a try(use
amalshaji for username and password). I plan to keep the server alive until the end of the hackathon. Feedbacks and PRs are always welcome.