How to Install Plausible Analytics on macOS

Plausible Analytics is a simple and lightweight web analytics tool that offers privacy-friendly metrics to website owners. It is an open-source software that can be easily installed on a server, including macOS.

In this tutorial, we'll go through the step-by-step process of installing Plausible Analytics on a macOS system.

Prerequisites

Before starting the installation process, ensure that you have the following prerequisites.

Step 1: Install Dependencies

Plausible Analytics relies on some external packages, and we need to ensure they are installed on our macOS system. These packages include:

We will use Homebrew – a package manager for macOS, to install these packages.

Open the Terminal app on your macOS system, and run the following command to install Homebrew.

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Once installed, you can run the following command to install the required packages.

brew install git node nginx yarn

Step 2: Clone Plausible Analytics Repository

To install Plausible Analytics on your system, we need to clone the repository from GitHub.

Open Terminal, and run the following command to clone the Plausible Analytics repository.

git clone https://github.com/plausible/plausible.git

Step 3: Install Dependencies

After cloning the repository, navigate to the plausible directory and run the following commands to install the dependencies.

cd plausible
yarn install

Step 4: Configure Plausible Analytics

Plausible Analytics uses a configuration file to set up the server settings. In the plausible directory, duplicate the .env.template file and name it .env. You can use the following command to create a copy of the .env file.

cp .env.template .env

Then, use your preferred text editor to open the .env file and set the values for the following variables:

By default, the port number is set to 8000.

Step 5: Start the Plausible Server

After configuring Plausible Analytics, you can start the server using the following command.

yarn dev

If the server starts without issues, you should see a message similar to the following:

Plausible Analytics running at http://localhost:8000/

Step 6: Set up Nginx Server Block

To expose your Plausible server to the internet, we need to set up an Nginx config file.

Run the following command to create a file named plausible in the /usr/local/etc/nginx/servers/ directory.

sudo touch /usr/local/etc/nginx/servers/plausible
sudo nano /usr/local/etc/nginx/servers/plausible

In the file, paste the following Nginx configuration:

server {
    listen 80;
    # replace example.com with your domain name
    server_name example.com;
  
    location / {
        proxy_pass http://localhost:8000;
        # forward headers for analytics
        proxy_set_header Referer $http_referer;
        proxy_set_header Upgrade-Insecure-Requests $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
    }
}

After pasting the config, save and exit the file.

To enable the Nginx config, run the following commands.

sudo mkdir /usr/local/etc/nginx/sites-enabled/
sudo ln -s /usr/local/etc/nginx/servers/plausible /usr/local/etc/nginx/sites-enabled/

Finally, verify that the Nginx config is valid by running this command.

sudo nginx -t

If there are no errors, you can restart Nginx.

sudo brew services restart nginx

Step 7: Verify Plausible Analytics

Now that you have set up Plausible Analytics, you can verify if it is working correctly by accessing the Plausible analytics dashboard on your website by visiting http://yourdomain.com.

If everything is set up correctly, you should see the Plausible dashboard.

Conclusion

Installing Plausible Analytics on macOS is a straightforward process that allows website owners to access privacy-friendly analytics data. By following the steps in this tutorial, you can install Plausible Analytics on your macOS system and start monitoring your website's traffic while ensuring the privacy of your users.

If you want to self-host in an easy, hands free way, need an external IP address, or simply want your data in your own hands, give IPv6.rs a try!

Alternatively, for the best virtual desktop, try Shells!