Use Matomo Website Analytics on OCI with MDS

Matomo is a Google Analytics alternative for tracking metrics on your websites. If you follow my blog, you know how easy it is to deploy popular Open Source web solutions like WordPress, Joomla!, Drupal, Moodle, and Magento on Oracle Cloud Infrastructure (OCI).

All these solutions are using MySQL Database Service to store their data.

I’ve recently added a new stack to deploy Matomo. Of course, this can be a standalone installation to collect all your analytics from self-hosted websites, but today I’ll describe how to use it with an existing stack we’ve already deployed on OCI.

For this example, I deployed WordPress using the following stack: oci-wordpress-mds.

The first step is to deploy Matomo on OCI.

In the second screen of the Stack’s wizard, we specify that we want to use an existing infrastructure. This way we won’t need to recreate our VCN, subnets, security lists, Internet Gateway, etc. — we want share what we’ve already deployed for WordPress:

OCI panel
OCI panel where you can toggle whether or not to use existing infrastructure

As you can see for the majority of the input fields, we need to provide the OCID. These can be found on the OCI’s dashboard. For example the OCID for the MySQL Database can be found here:

OCI dashboard
OCI dashboard with callouts highlighting the Copy OCID command

We do this for every resources we want to reuse.

Then we create an apply job for the stack and when done we can get the public IP and other necessary information in the output section:

Outputs page
The Outputs page in OCI, where you can find IP address, username, and other information

We can then enter the public IP in a browser and finish the installation:

Matamo dashboard
Matamo dashboard with a halfway-finished progress bar

It’s important to use the right connector/adapter: MYSQLI.

Then we follow the wizard and enter the required information.

When done, we can add our WordPress in Matomo to start tracking it. The first step is the retrieve its name (in our case, its public IP as I don’t use DNS):

WordPress public IP
WordPress public IP is available to be copied from the OCI dashboard

Once added in Matomo, we can retrieve the javascript code used to track our website:

JS tracking code
JS tracking code

We copy that code and we go into the admin dashboard of our WordPress site to modify the theme and add the previous code in the header file:

WordPress theme editor dashboard
WordPress theme editor dashboard
JS Code
JS code pasted into WordPress editor

And this is all we needed to be able to get analytics of our website we deployed on OCI.

Matomo dashboard
Matomo dashboard