Javascript client for Tracking API

This is default recommended client. Learn more at:

Using the Javascript client works well for most users where pasting a Javascript code in the page footer is not an issue.

Tracking API Clients

Sometimes you cannot use JavaScript to track data with Matomo. Whether you develop iOS apps, Android apps, Titanium apps, or apps written in PHP, Java, C#, C++, Python, etc. you can use a native client to track the data in Matomo.

Learn more in Tracking API Clients and SDKs

Tracking API Reference

If you are not using Javascript, PHP, Java, Python, C#, C++, Python or Objective -C (for which clients are available), you can still directly call the Tracking Web API over HTTPS.

The Tracking Web API Reference documents the various parameters and features of the Tracking API.

Use case: Tracking data using the php client

We will now look at some of these methods to record data in Matomo. In the following, replace {$IDSITE} with your Matomo website ID, and replace with your Matomo URL.

Image Tracker code

The Image Tracker code can be used when Javascript is not allowed.

Some websites like MySpace or eBay will not allow users to add Javascript to their profile but accept HTML. In this case, you can still track visits with Matomo using the Image Tracker.
Note: the code doesn’t use Javascript so Matomo will not be able to track some user information such as search keywords, referrers, screen resolutions, browser plugins and page titles. The image tracker code also does not create first party tracking cookies which results in some information being lost.

<!-- Matomo Image Tracker -->
<img src="{$IDSITE}&amp;rec=1" style="border:0" alt="" />
<!-- End Matomo -->

The following parameters can also be passed to the image URL:

  • rec – (required) The parameter &rec=1 is required to force the request to be recorded
  • idsite – (required) Defines the Website ID being tracked
  • action_name – Defines the custom Page Title for this page view
  • urlref – The Referrer URL: must be set to the referrer URL used before landing on the page containing the Image tracker. For example, in PHP this value is accessible via
  • idgoal – The request will trigger the given Goal
  • revenue – Used with idgoal, defines the custom revenue for this conversion
  • bots – Set &bots=1 to track all requests to the tracking image, including from bots and robots
  • and more! – There are many more parameters you can set beyond the main ones above. See the Tracking API documentation page.

Matomo Tracking API (Advanced users)

It is also possible to call the Matomo Tracking API using your favorite programming language.

Follow these instructions to get started with the PHP Tracking Web API client:

  • Click here to download the file PiwikTracker.php (You may need to right click this link and select Save Page As)
  • Upload the PiwikTracker.php file in the same path as your project files
  • Copy the following code, then paste it onto every page you want to track.

    // -- Matomo Tracking API init -- 
    require_once "/path/to/PiwikTracker.php";
    PiwikTracker::$URL = '';
  • Choose a Tracking method, then paste the code onto every page you want to track.

    • Method 1: Advanced Image Tracker
      The client is used to generate the tracking URL that is wrapped inside a HTML code.
      Paste this code before the code in your pages.

      // Example 1: Tracks a pageview for Website id = {$IDSITE}
      echo '<img src="'. str_replace("&","&amp;", Piwik_getUrlTrackPageView( $idSite = {$IDSITE}, $customTitle = 'This title will appear in the report Actions > Page titles')) . '" alt="" />';
      // Example 2: Triggers a Goal conversion for Website id = {$IDSITE} and Goal id = 2
      // $customRevenue is optional and is set to the amount generated by the current transaction (in online shops for example)
      echo '<img src="'. str_replace("&","&amp;", Piwik_getUrlTrackGoal( $idSite = {$IDSITE}, $idGoal = 2, $customRevenue = 39)) . '" alt="" />';

      The Advanced Image Tracker method is similar to using the standard Javascript Tracking code. However, some user settings are not detected (resolution, local time, plugins and cookie support).

    • Method 2: HTTP Request
      You can also query the Matomo Tracker API remotely via HTTP. This is useful for environment where you can’t execute HTML nor Javascript.
      Paste this code anywhere in your code where you wish to track a user interaction.

      $piwikTracker = new PiwikTracker( $idSite = {$IDSITE} );
      // Specify an API token with at least Write permission, so the Visitor IP address can be recorded 
      // Learn more about token_auth:
      // You can manually set the visitor details (resolution, time, plugins, etc.) 
      // See all other ->set* functions available in the PiwikTracker.php file
      $piwikTracker->setResolution(1600, 1400);
      // Sends Tracker request via http
      $piwikTracker->doTrackPageView('Document title of current page view');
      // You can also track Goal conversions
      $piwikTracker->doTrackGoal($idGoal = 1, $revenue = 42);

      Read more about the Matomo Tracking HTTP API or the PHP Client.

More information

See also these related FAQ entries