Installing Plausible for Website Analytics

Traducciones al Español
Estamos traduciendo nuestros guías y tutoriales al Español. Es posible que usted esté viendo una traducción generada automáticamente. Estamos trabajando con traductores profesionales para verificar las traducciones de nuestro sitio web. Este proyecto es un trabajo en curso.
Create a Linode account to try this guide with a $ credit.
This credit will be applied to any valid services used during your first  days.

Plausible is a free and open source website analytics tool that does not rely on external services. Plausible allows you to track visitors, demographic data, device data, and much more. Plausible has a graphical interface that provides charts and maps that provide insight into the performance of your website server. Setting Plausible up on Akamai Connected Cloud and integrating it within your application is straightforward.

Before You Begin

  1. If you have not already done so, create a Linode account and Compute Instance. See our Getting Started with Linode.

  2. You need to generate an API Token.

  3. Deploy a Docker Marketplace App. This includes creating your limited sudo user, your SSH public key, the previously generated API token, the domain you’d like to use and an email address, the preferred image, region, plan, and root password. There are additional options for opening ports to allow email, however this is only needed if you’ll be allowing others to register for this Plausible instance. Once ready click on Create Linode. The process will take about 5-10 minutes to complete.

  4. You need a domain name configured in the DNS Manager. Create A/AAAA records pointing to the server hosting Docker.

Note
This guide is written for a non-root user. Commands that require elevated privileges are prefixed with sudo. If you’re not familiar with the sudo command, see the Users and Groups guide.

Cloning the Plausible Repository

  1. After you created your Compute Instance, you can login via SSH via your local terminal. Once you login, update and upgrade your server.

    sudo apt update && sudo apt upgrade -y
  2. Now that your system is up to date, clone the repository from Plausible containing the Docker compose file and the configuration files.

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

Adding Required Configurations

  1. There is a file called plausible-conf.env within the hosting folder. This contains the environmental variables for the Docker compose file. The most important variables to configure are the SECRET_KEY_BASE and the BASE_URL variables. You can generate a security key with the command below. ​

    openssl rand -base64 64 | tr -d '\n' ; echo
  2. Use a tool such as nano or vim to edit the plausible-conf.env file. Add your domain to the BASE_URL variable. For now, use the HTTP protocol rather than HTTPS. In a later section, you will change this after generating the proper SSL certification.

  3. Once you’ve added the URL and key, save the file.

  4. Next, use nano or vim to open the docker-compose.yml file. Change any database passwords for security. ​

Deploying the Container

  1. Using the command below, deploy the container. ​

    sudo docker-compose up -d
    
  2. With the container running, navigate to port 8000 on your domain name to ensure that your new Plausible website is up and running. For instance, if you had the domain example.com, you’d enter the following: ​

    http://example.com:8000
    

​ If you see the Plausible website you, Plausible was deployed successfully.

Reverse Proxy and Certificate

Now, you need to set up NGINX server software and configure it to run your Plausible website.

  1. Install NGINX with the command below. ​

    sudo apt update
    sudo apt install nginx
    
  2. Allow the ports 80 and 443 in NGINX. ​

    sudo ufw allow "Nginx Full"
    
  3. Create a configuration profile in the /etc/nginx/sites-available/ directory. You can call this anything. The command below uses nano, but feel free to use your preferred editor. ​

    sudo nano /etc/nginx/sites-available/plausible.conf
    
  4. Copy and paste the following configuration text into your empty configuration file. Be sure to change the example.com domain to the domain you wish to use. In this case do not include http or https. ​

    File: /etc/nginx/sites-available/plausible.conf
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    
    server {
        listen       80;
        listen       [::]:80;
        server_name  example.com;
        access_log  /var/log/nginx/plausible.access.log;
        error_log   /var/log/nginx/plausible.error.log;
        location / {
          proxy_pass http://localhost:8000;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      }
    }

    Save the file and exit the editor. This configuration is for HTTP only. In the next step, when we acquire our SSL certificate, Certbot will implement HTTPS automatically.

  5. The next command links this new configuration in sites-available to sites-enabled. ​

    sudo ln -s /etc/nginx/sites-available/plausible.conf /etc/nginx/sites-enabled/
    
  6. We can use a NGINX command to verify that the configuration is correct. After it says the test was successful, reload the NGINX service.

    sudo nginx -t
    sudo systemctl reload nginx
    

Now that the service is reloaded, visit your website without the port to ensure the new configuration is working. ​

Adding a TLS (SSL) Certification with Certbot

​ Adding an SSL certificate to any website is an important step for both security and user confidence. Generating a TLS certificate for our NGINX proxy is straightforward.

  1. First, install Certbot. ​

    sudo apt install certbot python3-certbot-nginx
    
  2. With the application installed, run Certbot with the domain name you have chosen. After running this command, there will be additional prompts.

    sudo certbot --nginx -d your.domain.here
    

    You’ll need to enter your email, accept Certbot’s terms of service, decide if you’d like to share your email, and then select if you’d like all HTTP traffic redirected to HTTPS. This is optional, but redirecting is generally a good idea.

    If successful, you’ll see a “congratulations” message with some additional information. At this point, you should go back into your plausible-conf.env from earlier and change your BASE_URL so this reflects the domain being served over HTTPS. ​

Accessing Plausible and Additional Configuration

​ You’re done! You can now create your account, add your website, and retrieve the code snippet you will include on your website. When adding the code to your website, make sure it’s in a location that is visible on every page. This can be done with a plugin in WordPress or with the code injection on Ghost. The inclusion process will be slightly different for every platform and service. ​ There are many more configuration options and changes you can make. For example, such as adding a variable to disable registration. Additionally, setting up email servers and notification was not covered in this article. For more options and advanced configuration, please check out Plausible’s official documentation.

This page was originally published on


Your Feedback Is Important

Let us know if this guide was helpful to you.


Join the conversation.
Read other comments or post your own below. Comments must be respectful, constructive, and relevant to the topic of the guide. Do not post external links or advertisements. Before posting, consider if your comment would be better addressed by contacting our Support team or asking on our Community Site.
The Disqus commenting system for Linode Docs requires the acceptance of Functional Cookies, which allow us to analyze site usage so we can measure and improve performance. To view and create comments for this article, please update your Cookie Preferences on this website and refresh this web page. Please note: You must have JavaScript enabled in your browser.