Welcome to the Ultimate Guide to Matomo Tracker
Matomo Tracker is a powerful tool for web analytics, providing a variety of APIs to help you monitor and analyze your website traffic. In this guide, we will introduce Matomo Tracker and explore its various APIs with useful code snippets.
Getting Started
To get started with Matomo Tracker, you first need to install the Matomo PHP client library. You can do this via Composer:
composer require matomo/matomo-php-tracker
Basic Tracking
Once you have installed the library, you can start by creating a basic tracking request:
require_once '/path/to/matomo-php-tracker/MatomoTracker.php';
$matomoTracker = new MatomoTracker($siteId = 1, $matomoUrl = 'https://your-matomo-domain.com/matomo.php');
$matomoTracker->doTrackPageView('Page Title');
Tracking Events
Tracking events is crucial for understanding how users interact with your website. Here’s how you can track a custom event:
$matomoTracker->doTrackEvent($category = 'Videos', $action = 'Play', $name = 'Video Title', $value = 42);
Tracking Goals
Goals help you measure specific objectives. Here’s how to track a goal:
$matomoTracker->doTrackGoal($goalId = 1, $revenue = 30.5);
Tracking Ecommerce
If you run an online store, tracking ecommerce interactions is vital. Here’s an example of ecommerce tracking:
$matomoTracker->addEcommerceItem($sku = '1234', $name = 'Product Name', $category = 'Category', $price = 50.75, $quantity = 1);
$matomoTracker->doTrackEcommerceOrder($orderId = 'ORD12345', $grandTotal = 202.25, $subTotal = 180.00, $tax = 12.25, $shipping = 10.00, $discount = 0.00);
App Example
Below is an example of a simple PHP application that integrates various Matomo Tracker APIs for comprehensive analytics:
require_once '/path/to/matomo-php-tracker/MatomoTracker.php';
$matomoTracker = new MatomoTracker($siteId = 1, $matomoUrl = 'https://your-matomo-domain.com/matomo.php');
// Track a page view
$matomoTracker->doTrackPageView('Homepage');
// Track an event
$matomoTracker->doTrackEvent('Videos', 'Play', 'Homepage Video', 1);
// Track a goal
$matomoTracker->doTrackGoal(1, 20.00);
// Track an ecommerce order
$matomoTracker->addEcommerceItem('1234', 'Product Name', 'Category', 50.75, 1);
$matomoTracker->doTrackEcommerceOrder('ORD12345', 202.25, 180.00, 12.25, 10.00, 0.00);
By leveraging these APIs, you can gain comprehensive insights into your web traffic and user interactions, empowering you to make data-driven decisions for your business.
Hash: be1ddff5af987fff94b3bc797223f06a7558dbf19982cf691a812ff6e54b9c2b