Events driven analytics service powered by Mongo Atlas
Tags: atlashackathon, mongodb
Published: 2022-01-09 09:24:41

---
title: Events driven analytics service powered by Mongo Atlas
cover_image: https://res.cloudinary.com/practicaldev/image/fetch/s--cd682kBw--/c_imagga_scale,f_auto,fl_progressive,h_900,q_auto,w_1600/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1tah8m0zqe11xt7zknl5.png
published: true
description: My submission to the MongoDB Atlas Hackathon on DEV!
tags: atlashackathon, mongodb
---

[Instructions]: # (To submit to the MongoDB Atlas Hackathon on DEV, please fill out all sections.)

![mongo image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3zm9sj3y26giapwm3y2t.png)


### Overview of My Submission
[Note]: # (Please make sure the project links to the appropriate GitHub repository, and includes the [Apache-2 permissive license](https://www.apache.org/licenses/LICENSE-2.0)  and README.)

When utilising MongoDB Atlas charting tools one can with little code create an events driven analytics service. It's a magical feature where we can get charts with data straight from the DB.  

By creating your own service we can keep as much or as little of our users data as we want in-house without worrying about sharing sensitive information with third party products or services. It is also possible to extend the service endlessly to fit all types of applications, or with further request relay mechanisms. For instance relaying events to Facebook conversion API.

And since we are just making post requests over http our clients can be very thing, without pulling in any external SDKs or big npm packages.

There are two parts to my submission:
1. The backend - which collects all the events and stores them into mongodb atlas
2. The example app - The app mimics a regular landing page with a couple of CTA buttons and navigation.

### The Backend

The backend consists of a Nest.js server running graphql where the events get's stored into mongodb. It's nothing fancy it's just a create function for the events. 

One thing of note is that there is no resolver / query where one can get the events out from the server. So it's completely blocked from the outside world. Events goes in but events cannot be queried. 

Except in mongodb charts where we grant a service account read rights to make the charts. So there's no need to do any data aggregation on the server, mongodb atlas handles that for you, and with a little bit of getting used to even non-coding people in the organisation can make charts at their will. 

### The example app

This part of the submission is just a simple landing website with two pages written in react. 

![example app](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0jicbkz59ehsgja83xd7.png)

**On the first page** (home), there are a few elements which are common to all websites where the user takes some type of action and where we want to track the analytics. 

I've added sending tracking events on the CTA buttons, and the navigation. 

And the events are called:
- CTA1 clicked!
- CTA2 clicked!
- CTA3 clicked!
- Navigation: home
- Navigation: analytics
- Navigation: logo

These are the events that then makes up the charts on the analytics page.

![analytics page](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3mobvdt1dj1003p5ym57.png)

**On the second page** (analytics), there is an `Analytics` page where I display the use of the events by using MongoDB Atlas charting functionality. The charts are created in the mongodb atlas cloud website and then embedded into the page using iframes provided by the charting tools.

This is really cool because to make new charts does not require any coding, and can me made on the fly, or in personal dashboards, or as in this case embedded into any website. One can aggregate the data right on the dataset, while none of the events are query-able from the server.   


### Submission Category: 

[Note]: # (E-Commerce Creation, Prime Time, Action Star, Automation Innovation, or Choose Your Own Adventure)

Own Adventure (I think 🤔)


### Link to Code

[Note]: # (Our markdown editor supports pretty embeds. Try this syntax: `{% github link_to_your_repo %}` to share a GitHub repository)

{% github https://github.com/ugglr/dev-mongodb-hackathon %}


### Additional Resources / Info

[Note:] # (Be sure to link to any open source projects that are using your workflow!)

I wrote the service using Nest.js for the backend, and react for the frontend. 
{% github https://github.com/nestjs/nest %}
{% github https://github.com/facebook/react %}

Some other open source packages that I used:
- mongoose
- Graphql
- apollo server & client 

The deployment is powered by heroku and netlify. 

Hope you like what I've built!