Skip to content

Matomo on the Ametnes Platform#

This tutorial series covers provisioning an Ametnes Matomo analytics service and integrating it with Keycloak-protected applications so every page view is tracked against the authenticated user's identity.

Topic Page
Track page views from Keycloak-protected applications Keycloak Integration

Prerequisites#

  • An Ametnes Platform account.
  • A configured Data Service Location.

Provision Matomo on Ametnes Platform#

  1. Sign in to the Ametnes Platform console.
  2. Click New Resource.
  3. Enter:
  4. Name: a unique name for your Matomo service.
  5. Resource Kind: matomo.
  6. Tier: choose a preset tier size that matches your expected traffic and archiving load.
  7. Storage: choose capacity for Matomo's bundled database.
  8. Select your Data Service Location.
  9. Click Create.
  10. Save the generated connection details: URL, username, and password.

Deploying data services at scale is easier with the Ametnes Cloud Terraform provider.

Create an API token

In your Ametnes Cloud account:

  1. Navigate to Users.
  2. Click Edit on your user.
  3. Click Get User Token and a user token will be generated for you.
  4. Keep the generated token in a secure place, as it will not be shown again.

Install Terraform

Follow the instructions here to install Terraform on your computer.

Create your project

Add these files to an empty folder on your workstation.

Set up the variables

variables.tf
variable "token" {
  type = string
  description = "The Ametnes Cloud API token to use. Create one in the Ametnes Cloud console for your registered email."
}

variable "username" {
  type = string
  description = "Your Ametnes Cloud registered email address."
}

variable "project" {
  type = string
  description = "The project you'd like to create your resources in."
  default = "Default"
}

Add your API key secrets

secrets.auto.tfvars
username = "Your.Email@domain.com"
token = "YourApiToken"

Define your resources

main.tf
terraform {
  required_providers {
    ametnes = {
      source  = "ametnes.com/cloud/ametnes"
    }
  }
}

# Init and create the provider.
provider "ametnes" {
  token    = var.token
  username = var.username
}

# Read the location.
data "ametnes_location" "location" {
  name = "Your Data Service Location"
  code = "DSL1"
}

# Read the project that will host all your resources.
data "ametnes_project" "project" {
  name = var.project
}

# Create a Matomo service resource.
resource "ametnes_service" "matomo" {
  name        = "MatomoService"
  project     = data.ametnes_project.project.id
  location    = data.ametnes_location.location.id
  kind        = "matomo:5.9"
  description = "Matomo data service"
  capacity {
    storage = 10
  }
  config = {
    architecture     = "Starter"
    "admin.email"    = var.username
    "admin.password" = "YourStrongPassword"
  }
}

output "service_connections" {
  value = ametnes_service.matomo.connections
}

The architecture config option selects the preset tier size (Starter, Small, Basic, Medium, Large, XLarge, 2XLarge, 3XLarge, or 4XLarge) and capacity.storage sizes Matomo's bundled database. You do not need to attach a separate Network Access resource: it is created for you automatically.

Deploy your Terraform resources

  1. Run terraform init.
  2. Run terraform plan to see the resources that will be created.
  3. Run terraform apply -auto-approve.
  4. Once Terraform finishes, the service_connections output contains the connection details for your Matomo service.

Note

Matomo is deployed inside your private environment and is only accessible within your internal network.

Tip

Matomo ships with a bundled MariaDB database for its application state. If you want to perform detailed data analytics on your data, you can connect directly to your database — this is the use case for the direct database connection. Treat the admin credentials like any production admin account and rotate them if they were shown only once during creation.

Connect to the Matomo database#

Matomo bundles a MariaDB database for its application data. To connect to it directly:

  1. Open your Matomo resource in the Ametnes Platform console.
  2. Under Connections, find the mariadb connection and note its host and port.
  3. Connect with the mysql client:
mysql -h <matomo_host_name> -P <matomo_port> -u root -p<matomo_password> --connect-timeout=60 --protocol=TCP --verbose

Replace <matomo_host_name> and <matomo_port> with the values from Connections, and <matomo_password> with the admin password saved during creation.

Open Matomo#

  1. Open the Matomo URL in a browser (from your resource details in the console, or from the service_connections output if you used Terraform).
  2. Sign in with the username and password saved during creation.

Validation checklist#

  • Matomo resource status is online in Ametnes Platform.
  • You can sign in to the Matomo UI using the saved URL and credentials.
  • You can connect to the bundled MariaDB using the mysql client.