Ubuntu builds statistics website Umami statistics

Umami is a simple, fast, privacy-focused alternative to Google Analytics

Official GitHub address:https://github.com/umami-software/umami
officialMirror address: https://docker.umami.dev/umami-software/umami:postgresql-latest

based on Develop and support Or Postgresql and other database storage methods, you can control the data in your own hands. And UMAMI also provides very detailedThe visual interface, UI experience and statistical accuracy are very good. UMAMI can also prevent being blocked by ad blocking plug-ins, etc., and the statistical accuracy is high.

Official documentation: A detailed getting started guide can be found athttps://umami.is/docs/turn up

Self-built statistics website Umami Statistics-1

Function:
  • : Umami can track and analyze website visits, page views, user behavior and other indicators to help you understand how users interact with your website.
  • Event Tracking: It supports tracking of specific events, such as button clicks, form submissions, video playback, etc., so that you can understand the specific actions of users on your website.
  • User insights: With Umami, you can get information about your users, such as visit frequency, the ratio of new users to returning users, etc., so as to gain a deeper understanding of your user base.
  • Source Analysis: Umami can track the sources of users visiting your website, including search engines, social media, direct visits, etc., to help you evaluate the effectiveness of your marketing channels.
  • Custom reports: Based on your needs, Umami allows you to create customized reports and charts for better analysis and visualization of data.
  • A/B testing support: Umami can help you conduct A/B testing to compare different versions of pages or features to optimize the user experience of your website.
  • Data export: You can export data to CSV or other formats for integration and further analysis with other tools or analytics platforms.
Features:
  • Easy to use: Umami has a user-friendly interface and easy setup, making it relatively easy to use even for non-technical people.
  • Open source and free: As an open source project, Umami is free to use, and you can customize and extend it according to your needs.
  • Data Privacy: Umami takes user data privacy seriously and does not collect sensitive information or use it for advertising purposes.
  • Lightweight: Its design is relatively simple and will not have a significant impact on the performance of the website. It is suitable for small and medium-sized websites and projects.
  • Flexible customization: Since it is open source, you can redevelop and customize Umami according to your needs to meet specific analysis requirements.
  • Real-time data: Umami provides real-time data monitoring and feedback, allowing you to understand website dynamics and user behavior in a timely manner.

Require:

  • A server with Node.js version 12 or higher
  •  Umami supports MySQL and Postgresql databases.

Install Node.js on Ubuntu and update npm to the latest version

Install Node.js

NodeSource will continue to maintain the following architectures and may add others in the future.

  • amd64(64-bit)
  • armhf(ARM 32-bit hard float, ARMv7 and above:arm-linux-gnueabihf
  • arm64(ARM 64-bit, ARMv8 and above:aarch64-linux-gnu

Node project website:https://github.com/nodesource/distributions

Self-built statistics umami statistics-1

Update the system

sudo apt update && sudo apt upgrade

Install Dependencies

sudo apt install wget curl nano ufw software-properties-common dirmngr apt-transport-https gnupg2 ca-certificates lsb-release debian-archive-keyring unzip -y

Node.js v18.x

Install the latest npm package provided by NodeSource

Node.js currently has three versions: Node.js 18.x, Node.js 20.x, and Node.js 21.x

The following is the installation of Node.js 18.x, which can be done in one line of code. &&\ means that the following code will be executed after the previous command is executed correctly.

curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash - &&\ sudo apt-get install -y nodejs

Install as root

curl -fsSL https://deb.nodesource.com/setup_18.x | bash - &&\ apt-get install -y nodejs

After the installation is complete, check whether the version is installed successfully.

node -v

If you want to install other versions, just replace setup_20.x in the above command with the version you want to install.

Note: After installing Node.js 20.x or Node.js 21.x in Ubuntu 22.4, umami will be blank and inaccessible after opening. This will cause a 404 error!

Solution to the blank screen after Umami is installed

This is also a huge pit. After compiling with Node.js 20.x and Node.js 21.x, an error will occur. When you open the browser, a blank screen will appear, not without content. After pressing F12, you will find that all js files are inaccessible. This problem will occur when compiling with Node.js 20.x and Node.js 21.x. After installing Node.js 18.x, everything compiles normally and there is no problem opening it.

Note: Please use Node.js 18.x to compile, please use Node.js 18.x to compile, please use Node.js 18.x to compile, important things to say three times. Don't dig a hole for yourself!

The following content about Node.js is for reference only. In actual applications, please ignore the following Node-related content.

----------------------------------------------------------------------------------------

Node official website download address:https://nodejs.org/en/download/

There is another method, directly inInstall Node using apt

Note: If you use apt to install, you may install a lower version of node, which will result in an error during the subsequent installation:

error @clickhouse/client@0.2.10: The engine "node" is incompatible with this module. Expected version ">=16". Got "12.22.9"
error Found incompatible module.
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.

This error means that your current Node.js version does not meet the requirements of the @clickhouse/client module. The @clickhouse/client module requires Node.js version to be at least 16. Your current Node.js version is 12.22.9.

To resolve this issue, you may consider upgrading your Node.js version to one that meets the requirements.

 

sudo apt update sudo apt install nodejs # Does not come with npm, need to install it yourselfsudo apt install npm # Use n Node version management tool to upgrade to the latest versionsudo npm install n -g # Download the latest stable versionsudo n stable # Download the latest versionsudo n lastest # View the downloaded versionsudo n ls # Switch Node versionsudo n 18.21.1 # Upgrade npm sudo npm install npm -g

Uninstall nodejs Ubuntu and Debian packages

apt-get purge nodejs &&\ rm -rf /etc/apt/sources.list.d/nodesource.list &&\ rm -rf /etc/apt/keyrings/nodesource.gpg #Uninstall npm npm uninstall npm -g

If you cannot install npm during the installation process, you can use nvm to install it

Install Node.js and npm using nvm: Node Version Manager (nvm) makes it easier to manage Node.js versions and npm. You can install nvm and use it to install Node.js and npm by following these steps:

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash #Or use wget to install wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash #Install Node.js and npm. npm is included in Node. Installing Node will automatically install npm nvm install node #Use the newly installed Node nvm use node

 

Use nvm to install multiple versions of node

#View the currently installed node nvm ls #Install the 20x version of node, the highest version of 20x will be installed by default, for example 20.12 nvm install 20 #Use the 20x version nvm use 20 #Permanently use the 20x version nvm alias default 20

End of reference!!

--------------------------------------------------------------------------------------------------

Note: If none of the above methods work, you can try using yarn instead of npm. Yarn is a fast, reliable, and secure package manager that is often used as a replacement for npm. You can install yarn by following the steps below:

Install Yarn

Use yarn instead of npm: Because the project uses Yarn for compilation, we need to install Yarn.

npm install -g yarn

Install through Yarn official installation script: Yarn officially provides an installation script, you can install it with the following command:

curl -o- -L https://yarnpkg.com/install.sh | bash # or use wget to install wget -qO- https://yarnpkg.com/install.sh | bash

Create a new MySQL database

Here we use MySQL and create a new empty database in the database

Use phpmyadmin to create an empty database for Umami on the server.

Self-built statistics website Umami Statistics-1

Or create it directly on the server:

mysql -u root -p umami < sql/schema.mysql.sql

Install Umami

Download and install Umami

Custom downloads are placed in the /home/umami directory, or you can place them in other directories.

cd /home/ #git pull umami git clone https://github.com/umami-software/umami.git #enter the umami directory cd umami #install yarn install

Self-built statistics website Umami Statistics-1Wait patiently. After the installation is complete, you need to configure the .env file.

Configure .env file

Create a new file named .env in the umami folder.

Use the touch command to create a new .env file, or directly use the vim command to create a new .env file

vi .env

Note that after the .env file is created, it cannot be viewed in the directory. .env is a hidden file and can be edited directly using vi.

Edit the .env file and enter the following configuration and save it:

DATABASE_URL=mysql://umamiuser:umamipass@127.0.0.1:3306/umami_db APP_SECRET=bu4orqfdlG+Dh3Otau4oWSBbI9kGWSkGfYc/WiH/ DISABLE_TELEMETRY=1 TRACKER_SCRIPT_NAME=custom

DATABASE_URL
DATABASE_URL=mysql://umamiuser:umamipass@127.0.0.1:3306/umami_db
Explanation: This is Umami's database connection URL, pointing to a MySQL database umami_db, the database user is umamiuser, the password is umamipass, and the database server runs at 127.0.0.1:3306.
Ensure effectiveness:
Confirm that the database has been created correctly and the database user and password are configured correctly.
Make sure that the MySQL database allows connections through the 127.0.0.1 address.
Make sure the Umami service can access the MySQL database.

APP_SECRET
APP_SECRET=bu4orqfdlG+Dh3Otau4oWSBbI9kGWSkGfYc/WiH/
Explanation: This is an application key used for encryption and signing. Umami uses it to ensure the security of JWT (JSON Web Tokens) and other sensitive information.
Ensure effectiveness:
Keep this key safe and do not make it public or disclose it.
More complex keys can be generated, for example using openssl rand -base64 32 to generate a new key.

DISABLE_TELEMETRY
DISABLE_TELEMETRY=1
Explanation: Disabling telemetry means no statistics or usage data will be sent to Umami's servers.
Ensure Validity: This configuration is valid and has telemetry disabled, suitable for stricter privacy requirements.

TRACKER_SCRIPT_NAME
TRACKER_SCRIPT_NAME=custom
Explanation: This setting specifies the name of the Umami tracking script. The default name is umami.js, but you can change it to custom.js or any other name.
Ensure validity: If you wish to use a custom name, make sure you reference the correct JavaScript tracking script in your web page code.
Other possible configuration items
Depending on the Umami version you use and your requirements, you may also need the following configuration:

NEXT_PUBLIC_BASE_URL
Used to specify the base URL of your Umami instance. For example, if your Umami is installed on https://umami.example.com can be configured as:

NEXT_PUBLIC_BASE_URL=https://umami.example.com

DISABLE_AUTH
If you wish to disable Umami's authentication feature, you can set:

DISABLE_AUTH=true
Warning: Disabling authentication will allow anyone to access the admin panel and is recommended only for development environments.

UMAMI_VERSION
If you want to use a specific version of Umami, you can specify it:

UMAMI_VERSION=v1.35.0

PORT
Configure the port that Umami listens on (if the default port does not apply):

PORT=3000

SMTP configuration (for email notifications)
If you need to enable email notification or other mail functions, you can set up SMTP configuration, for example:

SMTP_HOST=smtp.example.com
SMTP_PORT=587
SMTP_USER=user@example.com
SMTP_PASSWORD=yourpassword

UMAMI_LOG_LEVEL

Configure the log level, which can be set as needed:

UMAMI_LOG_LEVEL=info
Configuration file example:
Combine all these configuration items into a .env file:

DATABASE_URL=mysql://umamiuser:umamipass@localhost:3306/umami_db APP_SECRET=bu4orqfdlG+Dh3Otau4oWSBbI9kGWSkGfYc/WiH/ DISABLE_TELEMETRY=1 TRACKER_SCRIPT_NAME=custom NEXT_PUBLIC_BASE_URL=https://umami.example.com DISABLE_AUTH=true PORT=3000

These configuration items should be valid, make sure you have verified the MySQL database connection, and add other related configurations (such as SMTP or authentication settings) as needed.

Example of linking two databases

postgresql://username:mypassword@localhost:5432/mydb mysql://username:mypassword@localhost:3306/mydb

Installing the Update

Run the following command to update Prisma related dependencies:

yarn add --dev prisma@latest yarn add @prisma/client@latest

 

Compile Umami

yarn build

Just wait for him to finish executing.

If you encounter an error that you cannot connect to the database

$ node scripts/check-db.js
✓ DATABASE_URL is defined.
✗ Unable to connect to the database.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
ERROR: "check-db" exited with 1.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Change localhost to 127.0.0.1

DATABASE_URL=mysql://username:password@127.0.0.1:3306/database name APP_SECRET=bu4orqfdlG+Dh3Otau4oWSBbI9kGWSkGfYc/WiH/ DISABLE_TELEMETRY=1 TRACKER_SCRIPT_NAME=custom

Error P3018 encountered during installation

Error: P3018

A migration failed to apply. New migrations cannot be applied before the error is recovered from. Read more about how to resolve migration issues in a production database: https://pris.ly/d/migrate-resolve

Migration name: 05_add_visit_id

Database error code: 1305

Database error:
FUNCTION t_umami_hk.BIN_TO_UUID does not exist

Please check the query number 2 from the migration file.

✗ Command failed: prisma migrate deploy
Error: P3018

A migration failed to apply. New migrations cannot be applied before the error is recovered from. Read more about how to resolve migration issues in a production database: https://pris.ly/d/migrate-resolve

Migration name: 05_add_visit_id

Database error code: 1305

Database error:
FUNCTION t_umami_hk.BIN_TO_UUID does not exist

Please check the query number 2 from the migration file.

 

error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
ERROR: "check-db" exited with 1.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

MariaDB does not yet implement BIN_TO_UUID, which is a built-in function in MySQL. Using MariaDB database installation will report error p3018

After umami was updated to version 2.11, UUID support was introduced. MySQL needs to generate a random UUID in the migration script, but if you are using MariaDB, MariaDB does not support this feature. You need to modify the database manually.

Solution to p3018 error

Execute the following command and then reinstall to solve the problem.

npx prisma migrate resolve --applied "05_add_visit_id" #Re-run the installation command yarn build

Uninstall Umami

If some irreversible operations occur during the installation process, you can uninstall Umami and reinstall it, just delete the Umami installation directory.

rm -rf /home/umami reboot

Port 3000 is occupied

If port 3000 is occupied, the startup will fail and you need to shut down nghttpx which occupies port 3000.

nghttpx occupies port 3000. If there is no service to run on nghttpx, just shut down nghttpx.

systemctl stop nghttpx systemctl disable nghttpx reboot

Install PM2 Manager

PM2 manager is a daemon program that opens Umami through PM2

npm install pm2 -g sudo yarn global add pm2 cd /home/umami pm2 start npm --name umami -- start pm2 startup pm2 save

Error 1143 encountered when installing PM2 using npm

node:internal/modules/cjs/loader:1143
const err = new Error(message);
^

Error: Cannot find module 'semver'
Require stack:
- /usr/share/nodejs/npm/lib/utils/unsupported.js
- /usr/share/nodejs/npm/lib/cli.js
- /usr/share/nodejs/npm/bin/npm-cli.js
at Module._resolveFilename (node:internal/modules/cjs/loader:1143:15)
at Module._load (node:internal/modules/cjs/loader:984:27)
at Module.require (node:internal/modules/cjs/loader:1231:19)
at require (node:internal/modules/helpers:179:18)
at Object. (/usr/share/nodejs/npm/lib/utils/unsupported.js:2:16)
at Module._compile (node:internal/modules/cjs/loader:1369:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1427:10)
at Module.load (node:internal/modules/cjs/loader:1206:32)
at Module._load (node:internal/modules/cjs/loader:1022:12)
at Module.require (node:internal/modules/cjs/loader:1231:19) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'/usr/share/nodejs/npm/lib/utils/unsupported.js',
'/usr/share/nodejs/npm/lib/cli.js',
'/usr/share/nodejs/npm/bin/npm-cli.js'
]
}

Node.js v20.12.2

Solution:

This error occurs when the server is not restarted after npm is installed, and the variables do not take effect. Restarting the server can solve the problem.

Huge pit

After installation, use yarn start command to open Umami. If port 3000 is occupied, a port occupation error will be displayed.

root@localhost:~# yarn start
yarn run v1.22.22
error Couldn't find a package.json file in "/root"
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
root@localhost:~# cd /home/umami
root@localhost:/home/umami# yarn start
yarn run v1.22.22
$ next start
⨯ Failed to start server
Error: listen EADDRINUSE: address already in use :::3000
at Server.setupListenHandle [as _listen2] (node:net:1897:16)
at listenInCluster (node:net:1945:12)
at Server.listen (node:net:2037:7)
at /home/umami/node_modules/next/dist/server/lib/start-server.js:279:16
at new Promise ()
at startServer (/home/umami/node_modules/next/dist/server/lib/start-server.js:190:11)
at nextStart (/home/umami/node_modules/next/dist/cli/next-start.js:50:40)
at /home/umami/node_modules/next/dist/bin/next:155:54
at async main (/home/umami/node_modules/next/dist/bin/next:155:5) {
code: 'EADDRINUSE',
errno: -98,
syscall: 'listen',
address: '::',
port: 3000
}
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Use the command to see who is occupying port 3000

root@localhost:~# sudo lsof -i :3000
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
nghttpx 919 root 5u IPv4 34021 0t0 TCP localhost:3000 (LISTEN)
nghttpx 958 root 5u IPv4 34021 0t0 TCP localhost:3000 (LISTEN)

nghttpx occupies port 3000. If there is no service to run on nghttpx, just shut down nghttpx.

systemctl stop nghttpx systemctl disable nghttpx reboot

Stop the service, then disable it from starting on boot, then restart the system.

Attention: A huge pit is coming.

use yarn start Command to start Umami. At this time, the port is not occupied and the startup starts normally. Then:

root@localhost:/home/umami# yarn start
yarn run v1.22.22
$ next start
▲ Next.js 14.1.4
- Local: http://localhost:3000

⚠ "next start" does not work with "output: standalone" configuration. Use "node .next/standalone/server.js" instead.
✓ Ready in 2s

During the startup process, a warning was thrown, which roughly means

"Next start" is not applicable to the "Output: Standalone" configuration. Please use "node.next/standalone/server.js" Is this warning an error? Do I need to solve it? I checked online and found that it is a problem with next.js. Final result: Ignore this warning. If you can access the IP address + port in the browser normally, you need to proceed to the next step. Note that the server firewall must open port 3000. Otherwise, access will be denied.

Test whether the installation is successful

After the installation is complete, you need to access it through the IP address + port to see if the page can be opened. The page will open slowly for the first time, so just wait a while.

Self-built statistics website Umami Statistics-1

If no error is displayed, the installation is successful. Test whether the local http://127.0.0.1:3000 can be opened normally.

curl http://127.0.0.1:3000

Check to see if there is any data output.

Self-built statistics website Umami Statistics-1Check the current status of port 3000. If port 3000 is still occupied, umami should not be started.

lsof -i:3000

Open Umami in your browser using your server IP + port

Ubuntu builds statistics website Umami statistics-1

Log in using the system default username and password

  • Username: admin
  • Password: umami

Ubuntu builds statistics website Umami statistics-1

The page is very simple and elegant, go and set up yourAfter adding the website, you can get the code and start statistics!

Remember to change your password in your personal profile and make it more complex!

Ubuntu builds statistics website Umami statistics-1

PM2 uninstall

# Disable PM2 startup pm2 unstartup # Kill the daemon pm2 kill # Uninstall npm remove pm2 -g # Delete all saved configurations and logs rm -rf ~/.pm2

Finally, after the deletion is complete, go to /usr/local/lib/node_modules/ and check if there is a pm2 folder. If so, just delete it.

OpenLiteSpeed as a reverse proxy server

Create a new virtual host in OpenLiteSpeed, and then enter this host to create a newExternal Applications , select Network Server for Type, enterTongji , the address is 127.0.0.1:3000, you can write public network IP:3000

Ubuntu builds statistics website Umami statistics-1

Ubuntu builds statistics website Umami statistics-2

Ubuntu builds statistics website Umami statistics-3

Then create a resource set, select Proxy as the type, and set the URI to /

Ubuntu builds statistics website Umami statistics-1

Ubuntu builds statistics website Umami statistics-2

Ubuntu builds statistics website Umami statistics-3

 

Note: Select the previously created tongji for the network server and fill in the maximum for other settings.

Rewrite rules. Because the domain names of the front-end and back-end are different, pseudo-static rules should be used to pass the domain name to the back-end. Otherwise, the back-end will refuse the connection and the front-end will directly return a 403 or 500 error.

Ubuntu builds statistics website Umami statistics-1

RewriteRule ^/(.*)$ http://tongji/$1 [P,E=Proxy-Host:xxx.com]
Note that tongji is the name of the external application in the second step, xxx.com isThe domain name of .
If you have installed the CyberPanel panel, the rewrite rules will prompt Disabled by CyberPanel. You need to fill in the rewrite rules in the website corresponding to the CyberPanel panel.
Finally, restart OpenLiteSpeed and you can access it normally.

Configure Chinese

After we log in to the backend, the default may be English. The panel comes with simplified Chinese. Open Settings–>Profile–>Language and select Chinese.

Upgrade and update umami

There is an update for umami. Pause pm2 and execute the following code to update before running:

pm2 stop umami #Enter the umami file directorycd /home/umami git pull yarn install yarn build

I encountered this during the upgrade of umami. prisma migrate deploy Error: P3009

This error is caused by the introduction of UUID support after umami was updated to version 2.11. MySQL needs to generate a random UUID in the migration script, but if you are using MariaDB, MariaDB does not support this feature. You need to modify the database manually.

The following is the mysql execution statement.

-- AlterTable ALTER TABLE website_event ADD COLUMN visit_id VARCHAR(36) NULL; -- Update with UUIDv4 UPDATE website_event we JOIN ( SELECT DISTINCT s.session_id, s.visit_time, LOWER(CONCAT( HEX(SUBSTR(MD5(RAND()), 1, 4)), '-', HEX(SUBSTR(MD5(RAND()), 1, 2)), '-4', SUBSTR(HEX(SUBSTR(MD5(RAND()), 1, 2)), 2, 3), '-', CONCAT(HEX(FLOOR(ASCII(SUBSTR(MD5(RAND())), 1, 1)) / 64)+8),SUBSTR(HEX(SUBSTR(MD5(RAND()), 1, 2)), 2, 3)), '-', HEX(SUBSTR(MD5(RAND()), 1, 6)) )) AS uuid FROM ( SELECT DISTINCT session_id, DATE_FORMAT(created_at, '%Y-%m-%d %H:00:00') visit_time FROM website_event ) s ) a ON we.session_id = a.session_id AND DATE_FORMAT(we.created_at, '%Y-%m-%d %H:00:00') = a.visit_time SET we.visit_id = a.uuid WHERE we.visit_id IS NULL; -- ModifyColumn ALTER TABLE website_event MODIFY visit_id VARCHAR(36) NOT NULL; -- CreateIndex CREATE INDEX website_event_visit_id_idx ON website_event(visit_id); -- CreateIndex CREATE INDEX website_event_website_id_visit_id_created_at_idx ON website_event(website_id, visit_id, created_at);

Then resolve the migrations in the Umami folder:

# Enter the umami file directory cd /home/umami npx prisma migrate resolve --applied "05_add_visit_id"

After executing the update command, don't forget to start PM2

#Enter the umami file directorycd /home/umami git pull yarn install yarn build pm2 start npm --name umami -- start

 

At this point, the umami setup is officially over. The rest of the configuration is very simple, we just need to follow the instructions on the umami panel. If you have any questions, please leave a message in the comment area.

Reference articles:https://www.howtoforge.com/how-to-install-umami-analytics-on-debian-12/

5/5 - (1 vote)

Leave a Reply

Your email address will not be published. Required fields are marked *