{"id":2031,"date":"2024-09-28T13:28:59","date_gmt":"2024-09-28T05:28:59","guid":{"rendered":"https:\/\/www.ruianding.com\/blog\/?p=2031"},"modified":"2024-09-29T13:26:43","modified_gmt":"2024-09-29T05:26:43","slug":"setting-up-matomo-for-web-traffic-analysis-on-my-personal-website","status":"publish","type":"post","link":"https:\/\/www.ruianding.com\/blog\/setting-up-matomo-for-web-traffic-analysis-on-my-personal-website\/","title":{"rendered":"Setting Up Matomo for Web Traffic Analysis on My Personal Website"},"content":{"rendered":"\n<p>As I continue to refine my personal website, I&#8217;ve become increasingly curious about whether my site is getting any traffic and if it&#8217;s helpful to others. To gain insight, I decided to add a tracking component to monitor website visits. After evaluating several options, I chose <strong><a href=\"https:\/\/matomo.org\/\">Matomo<\/a><\/strong> as my web analytics tool to track activity on both my homepage, <a href=\"http:\/\/www.ruianding.com\">www.ruianding.com<\/a>, and my WordPress blog, <a href=\"http:\/\/www.ruianding.com\/blog\">www.ruianding.com\/blog<\/a>.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-text-color has-cyan-bluish-gray-color has-alpha-channel-opacity has-cyan-bluish-gray-background-color has-background is-style-wide\"\/>\n\n\n\n<p>Here\u2019s a detailed breakdown of how I configured Matomo.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">1. Preparing the Server Environment<\/h2>\n\n\n\n<p>First, make sure the server environment has the necessary components (I already had these installed, so I skipped this step):<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Apache Web Server<\/li>\n\n\n\n<li>PHP (version 7.4 or higher)<\/li>\n\n\n\n<li>MySQL or MariaDB database<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">2. Download and Install Matomo<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">2.1 Download Matomo<\/h3>\n\n\n\n<p>Download the latest version of Matomo using the following command:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">cd \/tmp\nwget https:\/\/builds.matomo.org\/matomo.zip<\/pre>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1140\" height=\"370\" src=\"https:\/\/www.ruianding.com\/blog\/wp-content\/uploads\/2024\/09\/image-32.png\" alt=\"\" class=\"wp-image-2033\" style=\"width:558px;height:auto\"\/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">2.2 Extract and Move Matomo Files<\/h3>\n\n\n\n<p>Unzip the Matomo archive and move the files to the web directory <code>\/var\/www\/matomo<\/code>:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo unzip matomo.zip\nsudo mv matomo \/var\/www\/matomo<\/pre>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1130\" height=\"146\" src=\"https:\/\/www.ruianding.com\/blog\/wp-content\/uploads\/2024\/09\/image-33.png\" alt=\"\" class=\"wp-image-2035\" style=\"width:576px;height:auto\"\/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">2.3 Set Permissions<\/h3>\n\n\n\n<p>Set the appropriate ownership and permissions for the Matomo directory:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo chown -R www-data:www-data \/var\/www\/matomo\nsudo find \/var\/www\/matomo -type d -exec chmod 755 {} \\;\nsudo find \/var\/www\/matomo -type f -exec chmod 644 {} \\;<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">3. Configure Apache Virtual Host<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">3.1 Create a Virtual Host for Matomo<\/h3>\n\n\n\n<p>Create a new virtual host configuration file for Matomo:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo vi \/etc\/apache2\/sites-available\/matomo.conf<\/pre>\n\n\n\n<p>Add the following configuration:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"apache\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;VirtualHost *:80>\n    ServerName matomo.ruianding.com\n    DocumentRoot \/var\/www\/matomo\n    &lt;Directory \/var\/www\/matomo>\n        Options Indexes FollowSymLinks\n        AllowOverride All\n        Require all granted\n    &lt;\/Directory>\n    ErrorLog ${APACHE_LOG_DIR}\/matomo_app_error.log\n    CustomLog ${APACHE_LOG_DIR}\/matomo_app_access.log combined\n&lt;\/VirtualHost><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">3.2 Enable the Virtual Host and Mod_Rewrite<\/h3>\n\n\n\n<p>Enable the site and the <code>mod_rewrite<\/code> module:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo a2ensite matomo.conf\nsudo a2enmod rewrite<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">3.3 Restart Apache<\/h3>\n\n\n\n<p>Restart Apache to apply the changes:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo systemctl restart apache2<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">3.4 Update Local Hosts File for Testing<\/h3>\n\n\n\n<p>As I&#8217;d like testing locally first, I updated the <code>\/etc\/hosts<\/code> file to point to my server&#8217;s IP:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo vi \/etc\/hosts<\/pre>\n\n\n\n<p>Add the following line:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">server_ip matomo.ruianding.com<\/pre>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"814\" height=\"316\" src=\"https:\/\/www.ruianding.com\/blog\/wp-content\/uploads\/2024\/09\/image-34.png\" alt=\"\" class=\"wp-image-2037\" style=\"width:466px;height:auto\"\/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">3.5 Handling Matomo Access Issue Due to Proxy<\/h3>\n\n\n\n<p>Initially, I couldn\u2019t access Matomo, but I discovered this was due to a proxy interfering with my local host settings. <\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"636\" height=\"449\" src=\"https:\/\/www.ruianding.com\/blog\/wp-content\/uploads\/2024\/09\/image-35.png\" alt=\"\" class=\"wp-image-2038\" style=\"width:398px;height:auto\"\/><\/figure>\n\n\n\n<p>Disconnecting the proxy allowed the site to load correctly, teaching me that the proxy overrides DNS resolution for the browser, unlike the <code>ping<\/code> command, which works independently of the proxy settings.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"2604\" height=\"958\" src=\"https:\/\/www.ruianding.com\/blog\/wp-content\/uploads\/2024\/09\/image-37.png\" alt=\"\" class=\"wp-image-2040\" style=\"width:624px;height:auto\"\/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">4. Create a Database and User for Matomo<\/h2>\n\n\n\n<p>Log into MySQL and create a database and user for Matomo:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo mysql -u root -p<\/pre>\n\n\n\n<p>In the MySQL console:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">CREATE DATABASE matomo_db DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;\nCREATE USER 'matomo_user'@'localhost' IDENTIFIED BY 'password';\nGRANT ALL PRIVILEGES ON matomo_db.* TO 'matomo_user'@'localhost';\nFLUSH PRIVILEGES;\nEXIT;<\/pre>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1134\" height=\"432\" src=\"https:\/\/www.ruianding.com\/blog\/wp-content\/uploads\/2024\/09\/image-38.png\" alt=\"\" class=\"wp-image-2041\" style=\"width:440px;height:auto\"\/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">5. Complete the Matomo Web Installer<\/h2>\n\n\n\n<p>Once your server is ready, access the Matomo installation wizard by visiting <code>http:\/\/matomo.ruianding.com<\/code> in my browser. I followed these steps:<\/p>\n\n\n\n<p><strong>1. System Check:<\/strong> Matomo will verify if your system meets the requirements.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1508\" height=\"1370\" src=\"https:\/\/www.ruianding.com\/blog\/wp-content\/uploads\/2024\/09\/image-39.png\" alt=\"\" class=\"wp-image-2042\" style=\"width:450px;height:auto\"\/><\/figure>\n\n\n\n<p><strong>2. Database Setup:<\/strong> Enter the MySQL credentials.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1550\" height=\"1470\" src=\"https:\/\/www.ruianding.com\/blog\/wp-content\/uploads\/2024\/09\/image-40.png\" alt=\"\" class=\"wp-image-2043\" style=\"width:517px;height:auto\"\/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"2274\" height=\"620\" src=\"https:\/\/www.ruianding.com\/blog\/wp-content\/uploads\/2024\/09\/image-41.png\" alt=\"\" class=\"wp-image-2044\" style=\"width:752px;height:auto\"\/><\/figure>\n\n\n\n<p><strong>3. Create an Admin User:<\/strong> Set up a superuser for the Matomo dashboard.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"2314\" height=\"1182\" src=\"https:\/\/www.ruianding.com\/blog\/wp-content\/uploads\/2024\/09\/image-42.png\" alt=\"\" class=\"wp-image-2045\" style=\"width:759px;height:auto\"\/><\/figure>\n\n\n\n<p><strong>4. Configure My First Website:<\/strong> Add the website details for tracking.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"2294\" height=\"1258\" src=\"https:\/\/www.ruianding.com\/blog\/wp-content\/uploads\/2024\/09\/image-43.png\" alt=\"\" class=\"wp-image-2046\" style=\"width:758px;height:auto\"\/><\/figure>\n\n\n\n<p><strong>5.Tracking Code:<\/strong> Skip this if you\u2019re using log import for tracking, which I am.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">6. Use Matomo\u2019s Log Import Tool<\/h2>\n\n\n\n<p>Since I chose to track visits by importing Apache logs, I needed to set up the log import tool.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">6.1 Install Python and Dependencies<\/h3>\n\n\n\n<p>Matomo\u2019s log import tool is written in Python. Install Python 3 and the necessary libraries:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo apt install python3 python3-requests python3-geoip2 -y<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">6.2 Install the GeoIP Database (Optional)<\/h3>\n\n\n\n<p>To enable visitor location tracking, Matomo requires the GeoIP database. You can download the GeoLite2 City database after registering at <a href=\"https:\/\/www.maxmind.com\">MaxMind<\/a>. Follow the instructions to download and configure the database. I found this was not strictly necessary, as Matomo comes with built-in support for DBIP\/GeoIP.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">6.3 <strong>Set Up Apache Log Format<\/strong><\/h3>\n\n\n\n<p>Ensure that Apache logs are correctly formatted for Matomo to process:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"apache\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">LogFormat \"%h %l %u %t \\\"%r\\\" %>s %O \\\"%{Referer}i\\\" \\\"%{User-Agent}i\\\"\" matomo_log<\/pre>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1140\" height=\"742\" src=\"https:\/\/www.ruianding.com\/blog\/wp-content\/uploads\/2024\/09\/image-45.png\" alt=\"\" class=\"wp-image-2048\" style=\"width:429px;height:auto\"\/><\/figure>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"raw\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">%h: The IP address of the remote host (the user accessing your website).\n%l: The remote logname, which is often unused and will typically appear as a dash -.\n%u: The authenticated user (if applicable). If no authentication is used, this will also appear as a dash -.\n%r: The full request line, which includes the HTTP method (e.g., GET or POST), the requested resource (e.g., URL path), and the protocol (e.g., HTTP\/1.1).\n%>s: The HTTP status code, indicating the result of the request (e.g., 200 for success, 404 for not found).\n%O: The size of the response, in bytes.\n%{Referer}i: The referring URL, showing where the user came from before landing on your site (if available).\n%{User-Agent}i: The user agent, which provides information about the browser or device the visitor is using.\n<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">6.4 <strong>Use a Custom Log Format<\/strong><\/h3>\n\n\n\n<p>In the Apache virtual host configuration, we can specify a custom log format for Matomo. This format ensures that all the necessary details for Matomo&#8217;s log import tool are captured.<\/p>\n\n\n\n<p>First, open the virtual host configuration file and add the custom log configuration:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo vi \/etc\/apache2\/sites-available\/ruianding.com.conf<\/pre>\n\n\n\n<p>Next, add the following line inside the <code>&lt;VirtualHost&gt;<\/code> block to log requests in the <code>matomo_access.log<\/code> file using the custom <code>matomo_log<\/code> format:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"apache\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">CustomLog ${APACHE_LOG_DIR}\/matomo_access.log matomo_log<\/pre>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1140\" height=\"742\" src=\"https:\/\/www.ruianding.com\/blog\/wp-content\/uploads\/2024\/09\/image-46.png\" alt=\"\" class=\"wp-image-2050\" style=\"width:477px;height:auto\"\/><\/figure>\n\n\n\n<p>This will ensure that all log entries for your website are recorded in <code>\/var\/log\/apache2\/matomo_access.log<\/code> for later import into Matomo.<\/p>\n\n\n\n<p>Restart Apache to apply changes.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">7. Import Apache Logs<\/h2>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"2146\" height=\"1472\" src=\"https:\/\/www.ruianding.com\/blog\/wp-content\/uploads\/2024\/09\/image-44.png\" alt=\"\" class=\"wp-image-2047\" style=\"width:586px;height:auto\"\/><\/figure>\n\n\n\n<p>Use the <code>import_logs.py<\/code> tool to import Apache logs into Matomo:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo python3 \/var\/www\/matomo\/misc\/log-analytics\/import_logs.py \\\n--url=http:\/\/matomo.ruianding.com \\\n--idsite=1 \\\n--recorders=4 \\\n--enable-http-errors \\\n--enable-http-redirects \\\n--enable-static \\\n--enable-bots \\\n\/var\/log\/apache2\/matomo_access.log<\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>&#8211;url: <\/strong>This is the URL of your Matomo instance, such as http:\/\/matomo.yourdomain.com. In this case, I\u2019m using http:\/\/matomo.ruianding.com as my Matomo installation URL.<\/li>\n\n\n\n<li><strong>&#8211;idsite=1: <\/strong>This is the site ID assigned to your website by Matomo. The ID 1 typically corresponds to the first website you set up in Matomo.<\/li>\n\n\n\n<li>&#8211;<strong>-recorders=4:<\/strong> This sets the number of concurrent processes for importing logs. Adjust this value based on your server\u2019s performance. More recorders can speed up the import process but may require more system resources.<\/li>\n\n\n\n<li><strong>&#8211;enable-http-errors: <\/strong>Includes requests that resulted in HTTP error codes (e.g., 404, 500). This helps track pages that return errors.<\/li>\n\n\n\n<li><strong>&#8211;enable-http-redirects: <\/strong>Includes requests that resulted in HTTP redirects (e.g., 301, 302). This can be useful for tracking traffic flows and URL changes.<\/li>\n\n\n\n<li><strong>&#8211;enable-static: <\/strong>Includes requests for static resources such as CSS, JavaScript, and images. Depending on your needs, you may choose to exclude these to focus on dynamic page visits.<\/li>\n\n\n\n<li><strong>&#8211;enable-bots:<\/strong> Includes requests from bots and crawlers. By enabling this option, you can track how search engines and other bots are interacting with your site.<\/li>\n\n\n\n<li><strong>\/var\/log\/apache2\/matomo_access.log:<\/strong> This is the path to the Apache access log file that you want to import into Matomo.<\/li>\n<\/ul>\n\n\n\n<p><br>After completing the manual import, you can verify the results by checking the Matomo dashboard, the following graph shows that the import was successful:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"2584\" height=\"1254\" src=\"https:\/\/www.ruianding.com\/blog\/wp-content\/uploads\/2024\/09\/image-47.png\" alt=\"\" class=\"wp-image-2054\"\/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">8. Schedule Log Import<\/h2>\n\n\n\n<p>To keep the logs up to date, I set up a cron job to import logs every 6 hours:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo crontab -e<\/pre>\n\n\n\n<p>Add the following line:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">0 *\/6 * * * \/usr\/bin\/python3 \/var\/www\/matomo\/misc\/log-analytics\/import_logs.py --url=http:\/\/matomo.ruianding.com --idsite=1 --recorders=4 --enable-http-errors --enable-http-redirects --enable-static --enable-bots \/var\/log\/apache2\/matomo_access.log >> \/var\/log\/matomo_import.log 2>&amp;1<\/pre>\n\n\n\n<hr class=\"wp-block-separator has-text-color has-cyan-bluish-gray-color has-alpha-channel-opacity has-cyan-bluish-gray-background-color has-background is-style-wide\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Troubleshooting Apache Logs Not Recording Blog Visits<\/h2>\n\n\n\n<p>Initially, I found that logs for the <code>\/blog<\/code> directory were not being recorded in the Matomo log file. After checking with <code>apachectl -S<\/code>, I discovered separate HTTP and HTTPS configurations. <\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1428\" height=\"644\" src=\"https:\/\/www.ruianding.com\/blog\/wp-content\/uploads\/2024\/09\/image-48.png\" alt=\"\" class=\"wp-image-2056\" style=\"width:630px;height:auto\"\/><\/figure>\n\n\n\n<p>The missing <code>CustomLog<\/code> entry in the HTTPS configuration was causing the issue. After updating the HTTPS virtual host, the problem was resolved, and the logs were recorded correctly.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1162\" height=\"1022\" src=\"https:\/\/www.ruianding.com\/blog\/wp-content\/uploads\/2024\/09\/image-49.png\" alt=\"\" class=\"wp-image-2057\" style=\"width:517px;height:auto\"\/><\/figure>\n\n\n\n<p>After completing the setup, I\u2019m ready to analyze my site traffic and gain insights from Matomo \ud83c\udf89!<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>As I continue to refine my personal website, I&#8217;ve become increasingly curious about whether my site is getting any traffic and if it&#8217;s helpful to others. To gain insight, I decided to add a tracking component to monitor website visits. After evaluating several options, I chose Matomo as my web analytics tool to track activity [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_themeisle_gutenberg_block_has_review":false,"footnotes":""},"categories":[10],"tags":[61],"class_list":["post-2031","post","type-post","status-publish","format-standard","hentry","category-tutorial","tag-matomo"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.0 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Setting Up Matomo for Web Traffic Analysis on My Personal Website - \u6781\u7b80IT\uff5cSimpleIT<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.ruianding.com\/blog\/setting-up-matomo-for-web-traffic-analysis-on-my-personal-website\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Setting Up Matomo for Web Traffic Analysis on My Personal Website - \u6781\u7b80IT\uff5cSimpleIT\" \/>\n<meta property=\"og:description\" content=\"As I continue to refine my personal website, I&#8217;ve become increasingly curious about whether my site is getting any traffic and if it&#8217;s helpful to others. To gain insight, I decided to add a tracking component to monitor website visits. After evaluating several options, I chose Matomo as my web analytics tool to track activity [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.ruianding.com\/blog\/setting-up-matomo-for-web-traffic-analysis-on-my-personal-website\/\" \/>\n<meta property=\"og:site_name\" content=\"\u6781\u7b80IT\uff5cSimpleIT\" \/>\n<meta property=\"article:published_time\" content=\"2024-09-28T05:28:59+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-09-29T05:26:43+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.ruianding.com\/blog\/wp-content\/uploads\/2024\/09\/image-32.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1140\" \/>\n\t<meta property=\"og:image:height\" content=\"370\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Ruian Ding\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Ruian Ding\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.ruianding.com\/blog\/setting-up-matomo-for-web-traffic-analysis-on-my-personal-website\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.ruianding.com\/blog\/setting-up-matomo-for-web-traffic-analysis-on-my-personal-website\/\"},\"author\":{\"name\":\"Ruian Ding\",\"@id\":\"https:\/\/www.ruianding.com\/blog\/#\/schema\/person\/440d88575b7dc819a4cefc8c4199db3b\"},\"headline\":\"Setting Up Matomo for Web Traffic Analysis on My Personal Website\",\"datePublished\":\"2024-09-28T05:28:59+00:00\",\"dateModified\":\"2024-09-29T05:26:43+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.ruianding.com\/blog\/setting-up-matomo-for-web-traffic-analysis-on-my-personal-website\/\"},\"wordCount\":947,\"publisher\":{\"@id\":\"https:\/\/www.ruianding.com\/blog\/#\/schema\/person\/440d88575b7dc819a4cefc8c4199db3b\"},\"image\":{\"@id\":\"https:\/\/www.ruianding.com\/blog\/setting-up-matomo-for-web-traffic-analysis-on-my-personal-website\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.ruianding.com\/blog\/wp-content\/uploads\/2024\/09\/image-32.png\",\"keywords\":[\"Matomo\"],\"articleSection\":[\"Tutorial\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.ruianding.com\/blog\/setting-up-matomo-for-web-traffic-analysis-on-my-personal-website\/\",\"url\":\"https:\/\/www.ruianding.com\/blog\/setting-up-matomo-for-web-traffic-analysis-on-my-personal-website\/\",\"name\":\"Setting Up Matomo for Web Traffic Analysis on My Personal Website - \u6781\u7b80IT\uff5cSimpleIT\",\"isPartOf\":{\"@id\":\"https:\/\/www.ruianding.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.ruianding.com\/blog\/setting-up-matomo-for-web-traffic-analysis-on-my-personal-website\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.ruianding.com\/blog\/setting-up-matomo-for-web-traffic-analysis-on-my-personal-website\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.ruianding.com\/blog\/wp-content\/uploads\/2024\/09\/image-32.png\",\"datePublished\":\"2024-09-28T05:28:59+00:00\",\"dateModified\":\"2024-09-29T05:26:43+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/www.ruianding.com\/blog\/setting-up-matomo-for-web-traffic-analysis-on-my-personal-website\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.ruianding.com\/blog\/setting-up-matomo-for-web-traffic-analysis-on-my-personal-website\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.ruianding.com\/blog\/setting-up-matomo-for-web-traffic-analysis-on-my-personal-website\/#primaryimage\",\"url\":\"https:\/\/www.ruianding.com\/blog\/wp-content\/uploads\/2024\/09\/image-32.png\",\"contentUrl\":\"https:\/\/www.ruianding.com\/blog\/wp-content\/uploads\/2024\/09\/image-32.png\",\"width\":1140,\"height\":370},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.ruianding.com\/blog\/setting-up-matomo-for-web-traffic-analysis-on-my-personal-website\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.ruianding.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Setting Up Matomo for Web Traffic Analysis on My Personal Website\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.ruianding.com\/blog\/#website\",\"url\":\"https:\/\/www.ruianding.com\/blog\/\",\"name\":\"Ruian's Tech Troubleshooting Toolbox\",\"description\":\"Debug the World.\",\"publisher\":{\"@id\":\"https:\/\/www.ruianding.com\/blog\/#\/schema\/person\/440d88575b7dc819a4cefc8c4199db3b\"},\"alternateName\":\"\u4e01\u777f\u5b89\u7684\u6280\u672f\u5206\u4eab\u535a\u5ba2\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.ruianding.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/www.ruianding.com\/blog\/#\/schema\/person\/440d88575b7dc819a4cefc8c4199db3b\",\"name\":\"Ruian Ding\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.ruianding.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/www.ruianding.com\/blog\/wp-content\/uploads\/2023\/05\/logo.png\",\"contentUrl\":\"https:\/\/www.ruianding.com\/blog\/wp-content\/uploads\/2023\/05\/logo.png\",\"width\":284,\"height\":284,\"caption\":\"Ruian Ding\"},\"logo\":{\"@id\":\"https:\/\/www.ruianding.com\/blog\/#\/schema\/person\/image\/\"},\"description\":\"I am currently a Support Specialist at NIO, focusing on cloud-related issues for NIO Power. Previously, at Microsoft Entra ID, I specialized in identity and access management (IAM), including device registration, Windows Hello for Business (WHfB), multi-factor authentication (MFA), and single sign-on (SSO). In addition to my core expertise, I have a strong foundation in Active Directory, Servers, Cloud Computing, Network Administration, and Front-end Web Development. This diverse technical skill set enables me to effectively handle a wide range of challenges in a fast-paced IT environment.\",\"sameAs\":[\"https:\/\/www.ruianding.com\"],\"url\":\"https:\/\/www.ruianding.com\/blog\/author\/ruiand\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Setting Up Matomo for Web Traffic Analysis on My Personal Website - \u6781\u7b80IT\uff5cSimpleIT","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.ruianding.com\/blog\/setting-up-matomo-for-web-traffic-analysis-on-my-personal-website\/","og_locale":"en_US","og_type":"article","og_title":"Setting Up Matomo for Web Traffic Analysis on My Personal Website - \u6781\u7b80IT\uff5cSimpleIT","og_description":"As I continue to refine my personal website, I&#8217;ve become increasingly curious about whether my site is getting any traffic and if it&#8217;s helpful to others. To gain insight, I decided to add a tracking component to monitor website visits. After evaluating several options, I chose Matomo as my web analytics tool to track activity [&hellip;]","og_url":"https:\/\/www.ruianding.com\/blog\/setting-up-matomo-for-web-traffic-analysis-on-my-personal-website\/","og_site_name":"\u6781\u7b80IT\uff5cSimpleIT","article_published_time":"2024-09-28T05:28:59+00:00","article_modified_time":"2024-09-29T05:26:43+00:00","og_image":[{"width":1140,"height":370,"url":"https:\/\/www.ruianding.com\/blog\/wp-content\/uploads\/2024\/09\/image-32.png","type":"image\/png"}],"author":"Ruian Ding","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Ruian Ding","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.ruianding.com\/blog\/setting-up-matomo-for-web-traffic-analysis-on-my-personal-website\/#article","isPartOf":{"@id":"https:\/\/www.ruianding.com\/blog\/setting-up-matomo-for-web-traffic-analysis-on-my-personal-website\/"},"author":{"name":"Ruian Ding","@id":"https:\/\/www.ruianding.com\/blog\/#\/schema\/person\/440d88575b7dc819a4cefc8c4199db3b"},"headline":"Setting Up Matomo for Web Traffic Analysis on My Personal Website","datePublished":"2024-09-28T05:28:59+00:00","dateModified":"2024-09-29T05:26:43+00:00","mainEntityOfPage":{"@id":"https:\/\/www.ruianding.com\/blog\/setting-up-matomo-for-web-traffic-analysis-on-my-personal-website\/"},"wordCount":947,"publisher":{"@id":"https:\/\/www.ruianding.com\/blog\/#\/schema\/person\/440d88575b7dc819a4cefc8c4199db3b"},"image":{"@id":"https:\/\/www.ruianding.com\/blog\/setting-up-matomo-for-web-traffic-analysis-on-my-personal-website\/#primaryimage"},"thumbnailUrl":"https:\/\/www.ruianding.com\/blog\/wp-content\/uploads\/2024\/09\/image-32.png","keywords":["Matomo"],"articleSection":["Tutorial"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.ruianding.com\/blog\/setting-up-matomo-for-web-traffic-analysis-on-my-personal-website\/","url":"https:\/\/www.ruianding.com\/blog\/setting-up-matomo-for-web-traffic-analysis-on-my-personal-website\/","name":"Setting Up Matomo for Web Traffic Analysis on My Personal Website - \u6781\u7b80IT\uff5cSimpleIT","isPartOf":{"@id":"https:\/\/www.ruianding.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.ruianding.com\/blog\/setting-up-matomo-for-web-traffic-analysis-on-my-personal-website\/#primaryimage"},"image":{"@id":"https:\/\/www.ruianding.com\/blog\/setting-up-matomo-for-web-traffic-analysis-on-my-personal-website\/#primaryimage"},"thumbnailUrl":"https:\/\/www.ruianding.com\/blog\/wp-content\/uploads\/2024\/09\/image-32.png","datePublished":"2024-09-28T05:28:59+00:00","dateModified":"2024-09-29T05:26:43+00:00","breadcrumb":{"@id":"https:\/\/www.ruianding.com\/blog\/setting-up-matomo-for-web-traffic-analysis-on-my-personal-website\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.ruianding.com\/blog\/setting-up-matomo-for-web-traffic-analysis-on-my-personal-website\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.ruianding.com\/blog\/setting-up-matomo-for-web-traffic-analysis-on-my-personal-website\/#primaryimage","url":"https:\/\/www.ruianding.com\/blog\/wp-content\/uploads\/2024\/09\/image-32.png","contentUrl":"https:\/\/www.ruianding.com\/blog\/wp-content\/uploads\/2024\/09\/image-32.png","width":1140,"height":370},{"@type":"BreadcrumbList","@id":"https:\/\/www.ruianding.com\/blog\/setting-up-matomo-for-web-traffic-analysis-on-my-personal-website\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.ruianding.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Setting Up Matomo for Web Traffic Analysis on My Personal Website"}]},{"@type":"WebSite","@id":"https:\/\/www.ruianding.com\/blog\/#website","url":"https:\/\/www.ruianding.com\/blog\/","name":"Ruian's Tech Troubleshooting Toolbox","description":"Debug the World.","publisher":{"@id":"https:\/\/www.ruianding.com\/blog\/#\/schema\/person\/440d88575b7dc819a4cefc8c4199db3b"},"alternateName":"\u4e01\u777f\u5b89\u7684\u6280\u672f\u5206\u4eab\u535a\u5ba2","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.ruianding.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/www.ruianding.com\/blog\/#\/schema\/person\/440d88575b7dc819a4cefc8c4199db3b","name":"Ruian Ding","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.ruianding.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/www.ruianding.com\/blog\/wp-content\/uploads\/2023\/05\/logo.png","contentUrl":"https:\/\/www.ruianding.com\/blog\/wp-content\/uploads\/2023\/05\/logo.png","width":284,"height":284,"caption":"Ruian Ding"},"logo":{"@id":"https:\/\/www.ruianding.com\/blog\/#\/schema\/person\/image\/"},"description":"I am currently a Support Specialist at NIO, focusing on cloud-related issues for NIO Power. Previously, at Microsoft Entra ID, I specialized in identity and access management (IAM), including device registration, Windows Hello for Business (WHfB), multi-factor authentication (MFA), and single sign-on (SSO). In addition to my core expertise, I have a strong foundation in Active Directory, Servers, Cloud Computing, Network Administration, and Front-end Web Development. This diverse technical skill set enables me to effectively handle a wide range of challenges in a fast-paced IT environment.","sameAs":["https:\/\/www.ruianding.com"],"url":"https:\/\/www.ruianding.com\/blog\/author\/ruiand\/"}]}},"_links":{"self":[{"href":"https:\/\/www.ruianding.com\/blog\/wp-json\/wp\/v2\/posts\/2031","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.ruianding.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ruianding.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ruianding.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ruianding.com\/blog\/wp-json\/wp\/v2\/comments?post=2031"}],"version-history":[{"count":13,"href":"https:\/\/www.ruianding.com\/blog\/wp-json\/wp\/v2\/posts\/2031\/revisions"}],"predecessor-version":[{"id":2076,"href":"https:\/\/www.ruianding.com\/blog\/wp-json\/wp\/v2\/posts\/2031\/revisions\/2076"}],"wp:attachment":[{"href":"https:\/\/www.ruianding.com\/blog\/wp-json\/wp\/v2\/media?parent=2031"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ruianding.com\/blog\/wp-json\/wp\/v2\/categories?post=2031"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ruianding.com\/blog\/wp-json\/wp\/v2\/tags?post=2031"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}