Technical Documentation

技術文書

Matomoに関する技術文書

開発者向け Matomo Tracking API サンプル (PHP SDK)

 

お好きなプログラミング言語を使ってMatomo Tracking APIを呼び出すことができます。

例として、以下の手順で PHP Tracking Web API クライアントを使用します。

  • MatomoTracker.phpをダウンロードするには、ここをクリックしてください。(このリンクを右クリックしてSave Page As)
  • プロジェクトファイルと同じパスにMatomoTracker.phpファイルをアップロードします。
  • 以下のコードをコピーし、追跡したいすべてのページに貼り付けます。以下では、{$IDSITE}をあなたのマトモウェブサイトIDに置き換え、https://matomo.example.org/ をあなたのマトモURLに置き換えてください。
    <?php 
    // -- Matomo Tracking API init -- 
    require_once "/path/to/MatomoTracker.php";
    MatomoTracker::$URL = 'https://matomo.example.org/';
    ?>
    
  • トラッキング方法を選択し、トラッキングしたいすべてのページにコードを貼り付けます。
    • 方法1:高度なイメージトラッカー
      クライアントは、HTMLコード内にラップされたトラッキングURLを生成するために使用されます。
      このコードをページ内のコードの前に貼り付ける。

      <?php 
      // Example 1: Tracks a pageview for Website id = {$IDSITE}
      echo '<img src="'. str_replace("&","&amp;", Matomo_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;", Matomo_getUrlTrackGoal( $idSite = {$IDSITE}, $idGoal = 2, $customRevenue = 39)) . '" alt="" />';
      ?>
      

      Advanced Image Trackerの方法は、標準のJavascript Trackingコードを使用する方法と似ています。ただし、一部のユーザー設定は検出されません(解像度、ローカル時間、プラグイン、クッキーのサポート)。

    • 方法2:HTTPリクエスト
      また、Matomo (Piwik) Tracker APIにHTTP経由でリモートから問い合わせることもできます。これはHTMLやJavascriptを実行できない環境で便利です。
      このコードを、ユーザーとのインタラクションを追跡したいコードの任意の場所に貼り付けてください。

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

      Matomo トラッキング HTTP APIまたはPHPクライアントについての詳細はこちらをご覧ください

 

 

オンラインデモを体験

面倒なアカウント登録や
サーバーへのインストールは一切不要です。
実際の解析データを反映した管理画面で、
Matomoの快適な操作感を
今すぐ体験できます。

matomo画面
※Matomo Cloudは
Matomo開発元である
InnoCraft社が
提供するサービスです。
matomo画面

法人向け導入運用サポート

導入から運用まで 完全支援

Matomoユーザー会では、法人・団体向けにMatomoの導入から運用までの技術支援を行っています。
必要なサービスだけを組み合わせてご利用いただけます。

導入・運用支援

初期構築をお任せ

要件の整理から環境構築、導入直後の調整まで、必要な作業をまとめてお任せいただけます。

  • 要件整理・ヒアリング
  • 環境構築・インストール
  • パフォーマンス調整

matomo保守

導入後も安心の保守

操作や設定のご相談から、バージョンアップや性能改善までを継続的に支援します。

  • お問い合わせ対応
  • バージョンアップ対応
  • 性能・障害の調査対応

サーバ保守

サーバ稼働もお任せ

Matomoが動作するサーバを監視し、障害時も含めて計測を止めない状態を維持します。

  • 死活・リソース監視
  • 障害の一次・二次対応
  • 24時間365日の対応

オプション

必要な分だけ依頼

ご契約の有無にかかわらず、必要な作業だけを単発でご依頼いただけます。

  • トレーニング・設定代行
  • マニュアル・運用設計
  • データ移行
法人導入のご相談はお気軽にお問い合わせください。

要件整理・見積もり・PoC環境提供まで無償で対応いたします。