Thanh Nguyen
WordPress & Matomo Freelancer

Migrating a measurable element from a Matomo instance to another

Detailed procedure for changing Matomo server and migrating the statistics of a measurable element
Table of contents

Why migrate a measurable element?

You may need to migrate the data of a measurable item from a source Matomo instance to a target Matomo instance in the following situations:

  • Your Matomo instance includes websites of different customers and you wish to move the web analytics data of a specific customer to an instance dedicated to this customer;
  • You have several Matomo instances under management and you wish to merge them into one main Matomo instance to facilitate maintenance;
  • You delegate or take over the maintenance of a site and the management of Matomo statistics is also part of the elements to be transferred.

In this article, we are going to see how to make a migration between two instances of Matomo On-Premise.

Requirements

To migrate a site from one Matomo to another, you need to fulfill these requirements.

Source

All these pre-requisites are mandatory:

  • Install the Migration extension;
  • Have command line access to the source Matomo instance;
  • List the installed extensions.

Target

The following requirements are mandatory:

  • Gather the information to connect to the Matomo instance database;
  • Ensure that the MySQL port is open (default: 3306);
  • Ensure that both source and target Matomo version are iso;
  • Ensure that all extensions installed on the source Matomo instance are also present on the target Matomo instance. (The presence of the Migration extension is not required on the target instance.)

Migration of a measurable element

The migration tool will create a new website element in the target Matomo, using the next available site ID (idSite). It will then copy all the data from the source website to this newly created target website.

Command line

Before launching a migration, it is of course recommended to update the database of the target instance. The migration command is migration:measureable. You then need to specify the necessary parameters:

Go to the directory where Matomo is installed.

/usr/bin/php console migration:measurable --source-idsite=IDSITE --target-db-host=TARGET_MYSQL_HOST --target-db-username=TARGET_MYSQL_USERNAME --target-db-password=TARGET_MYSQL_PASSWORD --target-db-name=TARGET_MYSQL_DBNAME --target-db-prefix=matomo_
  • /usr/bin/php console: Instruction for calling the migration command;
  • migration:measurable: Command to migrate a measurable element;
  • –source-idsite: The numerical identifier of the measurable element to be migrated;
  • –target-db-host: The host of the target database;
  • –target-db-username: The user with access to the target database;
  • –target-db-password: The password of the user with access to the target database.

Command options

  • –target-db-prefix=matomo_: If necessary, specify the target database table prefix;
  • –target-db-port=3306: Specify the target database port (default: “3306”);
  • –skip-logs: Skip log migration;
  • –skip-archives: Skip migration of archives;
  • –dry-run: Enable debug mode ;

If you encounter any problems during the migration, you can refer to the official documentation, which covers, in particular, the creation of an SSH tunnel between the two servers and user privileges.

Don’t forget to update the tracking code on the website so that it corresponds to the new Matomo domain and the new idSite.

I’m Thanh Nguyen, I build fancy and ergonomic websites since 1998 and Zidane’s double in the World Cup final.

Leave a Reply

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

Related posts

Rechercher sur le site