Metabase, free analytics to skyrocket your Facebook Messenger chatbot marketing

Share on facebook
Facebook
Share on google
Google+
Share on twitter
Twitter
Share on linkedin
LinkedIn

What is Metabase, and how it can help your Facebook Messenger chatbot marketing efforts?

Metabase is an open-source analytics tool (think of Google Analytics) that can connect to almost any database you own. With it, you can create charts and graphs that provide lovely insight on your Facebook Messenger chatbot marketing efforts. You can create a chart to see how many new users you have each day, or how many users come back to your bot. It can answer any question you have about your data. The best thing? You can install it on your server and keep your data private and secure.

Tutorial: Installing Metabase on an AWS EC2 server

Warning

This tutorial requires good DevOps skills, an AWS account, and a little bit of patience and perseverance.

Let’s start by logging in to your AWS account and creating a new EC2 server instance to hold the Metabase software.

First, go to the EC2 dashboard and create a new instance. We’ll select an Ubuntu 20.04 LTS AMI for the image.

For the instance type, select t2.micro (we select this one because if you don’t have other EC2 instance, and you are using a new AWS account, you get this instance for free for 12 months).

Let’s go with the defaults for the instance details.

Add 20GB SSD for storage. We need to have a little bit of space for the software we want to install later.

Create a new security group and give SSH, HTTP, and HTTPS access.

Create a new key pair or use an existing one to connect via SSH to your instance.

Click “Launch instance”. Go to the EC2 dashboard and wait for the instance state to be “Running”.

From the EC2 dashboard, select Elastic IPs from the left menu. We want to give our instance a static IP. Allocate a new IP address and associate it to the Metabase instance.

Now we need to create a domain or subdomain to point to Metabase. We will use a subdomain for this example. Go to Route 53, and under your primary domain, add a subdomain metabase.yourdomain.com that points to the IP address that we associated with the Metabase instance.

Go to the EC2 dashboard, select the instance, and click connect. Follow the steps in the SSH client.

Once connected to your EC2 instance, we need to install a couple of tools before we can install and configure Metabase.

First, we need to install docker.

sudo apt update
sudo apt upgrade
sudo apt install docker.io
sudo systemctl enable --now docker 

Test that docker works

 sudo docker run hello-world 

After docker gets installed, let’s use it to mount and serve the latest image of Metabase.

docker run -d -p 3000:3000 \
  -e "MB_DB_TYPE=mysql" \
  -e "MB_DB_DBNAME=metabase" \
  -e "MB_DB_PORT=3306" \
  -e "MB_DB_USER=<username>" \
  -e "MB_DB_PASS=<password>" \
  -e "MB_DB_HOST=my-database-host" \
  --restart=unless-stopped \
  --name metabase metabase/metabase 

Now with Metabase running in a docker container, we need to protect the data by adding an SSL (HTTPS) certificate to our server. For this, we will use a free certificate provider named Let’s Encrypt.

Install nginx (or apache, but we use nginx for this tutorial)

sudo apt install nginx

Check that nginx is running by typing your Metabase public IP in the browser.

sudo vi /etc/nginx/sites-available/your_domain 
upstream metabase {
  server 127.0.0.1:3000;
}
server {
    listen 80;
    server_name yourdomain.com;

    location / {
      proxy_pass     http://metabase;
      proxy_redirect   off;
      proxy_set_header  Host $host;
      proxy_set_header  X-Real-IP $remote_addr;
      proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header  X-Forwarded-Host $server_name;

    }
} 

Save your edits.

sudo ln -s /etc/nginx/sites-available/your_domain /etc/nginx/sites-enabled/
sudo systemctl restart nginx
 

Install Let’s Encrypt client, certbot

sudo apt install certbot python3-certbot-nginx
sudo certbot --nginx -d metabase.yourdomain.com 

Follow the instructions. It’s better to allow HTTP to HTTPS redirection for improved security.

Let’s Encrypt certificates are only valid for 90 days (while commercial certificates can be valid for up to 2-3 years), meaning you need to renew the certificates before they expire. Hopefully, we can do this in an automated way by setting up a cron job to renew the certificates before they expire. The cerbot package that we installed already does this for us and checks if the certificates are still valid. Run the following command to make sure the cron job is active.

sudo systemctl status certbot.timer  

Run the renew command in dry mode to test that renewing finishes without any errors.

sudo certbot renew --dry-run 

All the set up finished, go to https://metabase.yourdomain.com to see Metabase running correctly. 

Subscribe to our newsletter to learn more about Metabase and how you can make it useful. 

More to explore

Leave a Reply

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