---
# System prepended metadata

title: Matomo Research

---

# Matomo Research

1. 環境要求
    - **支援問題: Matomo不支援MS SQL Server**
    - PHP 7.x 以上
    - MySQL 5.7 以上 or MariaDB
    - Webserver such as Apache, Nginx, IIS, LiteSpeed...
    - can be run on any operating system such as Linux (Ubuntu, RedHat, CentOS, Raspberry Pi OS, etc.), Windows, macOS Server or FreeBSD.
    - in MySQL, USER should have the permission to SELECT, INSERT, UPDATE, DELETE, CREATE, INDEX, DROP, ALTER, CREATE TEMPORARY TABLES, LOCK TABLES, FILE.

2. 硬體環境要求
    
    a. Tracking 100,000 page views per month or less
    - One server is sufficient to host both the database and app server
    - App server minimum recommended configuration: 2 CPU, 2 GB RAM, 50GB SSD disk.

    b. Tracking 1 million page views per month or less
    - One server can be sufficient to host both the database and app server
    - App server minimum recommended configuration: 4 CPU, 8 GB RAM, 250GB SSD disk.

3. 手機APP端
    - CUSTOM DIMENSIONS
        - 對於網站或APP上的使用者或觸發事件，指派任何自訂資料(如頁面評價、事件觸及率、搜尋指標...)，並將其製作成使用者、對話性、頁面瀏覽程度的視覺化報告
        - assign any custom data to your visitors or actions (like pages, events, site search, …) and then visualize the reports of how many visits, conversions, pageviews, etc.
    - Event Tracking
        - 追蹤使用者在每個事件(頁面)所停留的時間，或是使用者在頁面上的動作，例如:
        - Compliance Interactions – 有多少人調整了marketing cookies的進階設定?
        - Page Interactions – 有多少人去點擊 tabbed content 或 image lightbox?
        - Document Downloads – 有多少人下載了網站上的PDF檔案?
        - Ecommerce Interactions – 有多少人將產品加入購物車中，卻一直沒有進入結帳的步驟?
        - Form Events – 建立的表單存在任何問題嗎?使用者是否曾填完表單但卻不送出呢?
        - Lead Generation – 有多少人完成了 newsletter 中的 opt-in form?
        - Non-Page Links – 有多少人曾經點擊網站上的mail連結或電話連結呢
        - Screen Interactions – 使用者平均滾動滾輪多久才能抵達頁面的底部呢
        - Social Media buttons Interactions - 網站與社群媒體的交互連結
    - Content Tracking
        - 評價頁面上內容區塊的表現
        - e.g. ad, banner, 內容intro
        - 可以使用在任何內容區塊
    - Ecommerce
        - Ecommerce orders
        - Total revenue
        - Average order value
        - Ecommerce revenue per visit
        - Ecommerce conversion rate
        - Purchased products
        - Abandoned carts metrics: Visits with abandoned carts, revenue left in carts

4. Comparision with desktop
    
    - SDKs 不能支援部分 Desktop 端的功能:Search Engine Keywords, Form Analytics, Heatmaps & Session Recordings, Media Analytics, Multi Channel Attribution, WooCommerce Analytics
    - “Acquisition” 不會顯示資料 (Websites, Search Engines, Social, Campaigns).
    - (Android SDK) “Acquisition channels” 會顯示安裝資訊, 可了解APP是如何被安裝上去的
    - Outlinks 模組由自動追蹤改為手動追蹤
    - (Android SDK) Downloads report會顯示App version code & APK checksum
    - SDKs 不能支援內容追蹤 (content impressions & content interactions) 


5. Mobile App & Desktop software statistics reports
    - APPs 的使用者數量 (per day, week, month, …)
    - 使用者使用APP的時間長短
    - 追蹤 icons, 按鈕或任何元件的觸及狀況 
    - 紀錄裝置的資訊與作業環境
    - 紀錄任何與APP相關的 Custom Variables 
    - how often is the app opened?
    - When and how long is the app opened?
    - 新用戶、常用用戶、全體用戶所記錄的錯誤訊息與錯誤報告



REF:
https://github.com/matomo-org/matomo-sdk-android
https://matomo.org/features/
https://matomo.org/faq/general/what-features-of-matomo-analytics-are-supported-when-tracking-mobile-app-analytics-using-android-or-ios-sdk/
https://matomo.org/blog/2012/04/how-to-use-piwik-to-track-mobile-apps-activity-clicks-phones-errors-etc/


# SDK use case 

**SDKs可以使用Dashboard**
但基礎功能相較於desktop少


若是開發Android base的程式，可以先透過tracker挖掘資料，再利用Java用戶端將資料傳送至Matomo Server。

- Android Tracker: github.com/matomo-org/matomo-sdk-android
- Java Client: github.com/matomo-org/matomo-java-tracker

## Android

### Create a Request

Each PiwikRequest represents an action the user has taken that you want tracked by your Piwik server. Create a PiwikRequest through

```
PiwikRequest request = new PiwikRequest(siteId, actionUrl);
```
The following parameters are also enabled by default:

```
required = true;
visitorId = random 16 character hex string;
randomValue = random 20 character hex string;
apiVersion = 1;
responseAsImage = false;
```
Overwrite these properties as desired.

Note that if you want to be able to track campaigns using Referrers > Campaigns, you must add the correct URL parameters to your actionUrl. For example,

```
URL actionUrl = new URL("http://example.org/landing.html?pk_campaign=Email-Nov2011&pk_kwd=LearnMore");
```
See Tracking Campaigns for more information.

All HTTP query parameters denoted on the Matomo Tracking HTTP API can be set using the appropriate getters and setters. See **PiwikRequest.java** for the mappings of the parameters to their corresponding Java getters/setters.

Some parameters are dependent on the state of other parameters: **EcommerceEnabled** must be called before the following parameters are set: EcommerceId and EcommerceRevenue.

**EcommerceId** and **EcommerceRevenue** must be set before the following parameters are set: *EcommerceDiscount, EcommerceItem, EcommerceLastOrderTimestamp, EcommerceShippingCost, EcommerceSubtotal, and EcommerceTax*.

**AuthToken** must be set before the following parameters are set: *VisitorCity, VisitorCountry, VisitorIp, VisitorLatitude, VisitorLongitude, and VisitorRegion.*


### Sending Requests
Create a PiwikTracker through

```
PiwikTracker tracker = new PiwikTracker(hostUrl);
```
where hostUrl is the url endpoint of the Piwik server. Usually in the format http://your-piwik-domain.tld/piwik.php.

To send a single request, call

```
HttpResponse response = tracker.sendRequest(request);
```
If you have multiple requests to wish to track, it may be more efficient to send them in a single HTTP call. To do this, send a bulk request. Place your requests in an **Iterable** data structure and call

```
HttpResponse response = tracker.sendBulkRequest(requests);
```
If some of the parameters that you've specified in the bulk request requre AuthToken to be set, this can also be set in the bulk request through

```
HttpResponse response = tracker.sendBulkRequest(requests, authToken);
```

## iOS

If you are building iOS apps, Apple tvOs or macOS apps, you can use the Swift PiwikTracker client (or the older Objective-C PiwikTracker) to send tracking data to your Matomo server.
- IOS Tracker: github.com/matomo-org/matomo-sdk-ios

### Matomo Instance (iOS)

The Matomo iOS SDK doesn't provide a instance of the PiwikTracker. In order to be able to track data you have to create an instance first.

```
let matomoTracker = MatomoTracker(siteId: "23", baseURL: URL(string: "https://demo2.matomo.org/piwik.php")!)
```
The `siteId` is the ID that you can get if you add a website within the Matomo web interface. The `baseURL` it the URL to your Matomo web instance and has to include the "piwik.php" or "matomo.php" string.

You can either pass around this instance, or add an extension to the `MatomoTracker` class and add a shared instance property.

```
extension MatomoTracker {
    static let shared: MatomoTracker = MatomoTracker(siteId: "1", baseURL: URL(string: "https://example.com/piwik.php")!)
}
```
The `siteId` is the ID that you can get if you add a website within the Matomo web interface. The baseURL is the URL to your Matomo web instance and has to include the "piwik.php" or "matomo.php" string.

You can use multiple instances within one application.

### These features aren't implemented yet
Tracking of more things
 - Social Interactions
 - Goals and Conversions
 - Outlinks
 - Downloads

Customizing the tracker
- use different dispatchers (Alamofire)



