How to Setup and Integrate Umami to Your Next.js Site
Tags: webdev, nextjs, javascript, tutorial
Published: 2022-02-20 05:55:13

## Disclaimer

> In this article, I will focus on how to self-host and set up Umami, then integrate it into the Next.js-based project.

## Introduction

Often, when someone or organization wants to set up the web analytics tool, they usually use [Google Analytics](https://analytics.withgoogle.com/). But as some people know that we cannot collect real data because when there’s a person visit a website and he or she set an adblocker in their browser, the analytic tool cannot work properly. And of course, there’s also a privacy issue with this tool.

Alright so are there any alternatives? Yes, I’ll recommend [Umami](https://umami.is/docs/about). Why? According to its official docs, Umami is open source and can be the privacy-focused alternative to Google Analytics.

![Umami Web](https://umami.is/about-screenshot.png)

Okay, so let’s jump to the main point. How to set up and self-host Umami? In this article, I’ll explain how to set up Umami with Vercel and Supabase.

## Preparing The Account

First, of course, make sure you already have a [Github](https://github.com/join) account. If you don’t have it yet, please make it first because it will be needed to deploy our self-host Umami. 

After you have a Github account, make sure you also registered at [Vercel](https://vercel.com/signup) and [Supabase](https://supabase.com/).

## Setup Supabase

Now, you can log in to [Supabase](https://supabase.com/) and go to the main dashboard and click “New Project”. Use the organization and project’s name based on your preferences and needs.


![New Project](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l9nt4fhzvcwl8vi220o8.png)

Fill in the form fields based on your personal preferences. Also, select the closest region to your domicile in the region form field.


![NewProjectForm](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yaqc6mupm8jbg7j8vjcr.png)

After you click the “Create New Project” button, go to the SQL Editor section.


![Supabase SQL Editor](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0bz6iuw8dldov55dv1i2.png)

Then, you can copy the SQL Schema query from [Umami’s Github Repository](https://github.com/mikecao/umami/blob/master/sql/schema.postgresql.sql). After that, you can run the query.


![Supabase Query](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tvpbz8ack0gpvd274v7y.png)

## Deploy on Vercel

You can easily deploy Umami to Vercel just by open [Umami’s Docs (Running on Vercel section)](https://umami.is/docs/running-on-vercel) and clicking the “Deploy” Button. Then, you can select Github and fill in the repository name and after that, you can just follow the default steps.

If you have reached the step like the image below, head back for a while to Supabase.


![Deploy Vercel](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6f42lu9gpqrzufuaege9.png)

In Supabase, go to the Settings menu and then click the “Database” section. Go to the “Connection String” segment. Select “URI” and copy & paste it to DATABASE_URL on your Vercel settings. Don’t forget to change “YOUR_PASSWORD” into your own Supabase database password.


![Connection String](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/218qfkelkvksn2we94pm.png)


![Configure Project Vercel](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6rquvx2g1wcr963a68m3.png)

For the HASH_SALT field, you can use [Password Generator](https://passwordsgenerator.net/) to generate some random string and copy & paste it. After that, you can deploy it to Vercel.

If you want to change the domain after the deploy process, you can go to the project settings and select the Domain menu, then click the “Edit” button.


![Vercel Change Domain](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3qs3w6t786wqs90qmf7u.png)

## Configuring Your Umami

Now you can open the deployed Umami on your browser. The default username is `admin` and the password is `umami`. You can change it later if you want. You can go to the Settings menu and go to the profile section to change your current password.


![Umami Change Password](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qh0mmgv1vez4d131i644.png)

## Adding Umami to Your Website

In the Settings menu, go to the Website section and click “Add Website” Button. You can add your website name and link there and enable the “Share URL” if you want.

After the website is added, you can copy the “Tracking Code”. You can paste it into your project soon.


![Add Umami to Your Site](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kk14xtn5wg1nld327z58.png)

Now for the final step, go to your web project folder. In my case, I use Next.js and I paste the code in the `_document.tsx` file.


![Next JS Integrate](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l6yyeu9g78ae0w3mbdk6.png)

And yeah, congratulations! You just need to push the newest commit of your project and you can watch the statistics of your own site at Umami. The statistics will appear on your Umami dashboard within 24 hours.

## Closing

You can follow these same steps on your other projects. Hope it helps. Let me know if you have some feedback or something to discuss in the comment section.

Reference: [How to Setup Umami with Vercel and Supabase (by Jacob Bouchard)](https://dev.to/jakobbouchard/setting-up-umami-with-vercel-and-supabase-3a73)