• Stars
    star
    145
  • Rank 245,327 (Top 5 %)
  • Language
    PHP
  • License
    GNU General Publi...
  • Created over 9 years ago
  • Updated 7 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

HTTP proxy for Matomo's tracker API. This script allows to track websites with Matomo without revealing to your visitors the secret Matomo server URL.

Matomo Tracker Proxy

Build Status

This script allows to track websites with Matomo without revealing the Matomo server URL.

This is useful for users who track multiple websites on the same Matomo server, but don't want to show the Matomo server URL in the source code of all tracked websites.

Requirements

To run this properly you will need:

  • latest version of Matomo installed on a server (or Matomo Cloud)
  • one or several website(s) to track with this Matomo, for example http://trackedsite.com
  • the website to track must run on a server with PHP 5.3 or higher
  • PHP must have either the CURL extension enabled or allow_url_fopen=On

Installation

1. Create a user in Matomo

In your Matomo server:

  • login as Super user
  • create a user, set the login for example: "UserTrackingAPI"
  • assign this user write or admin permission on all websites you wish to track (otherwise the visitor IP address and other things won't be tracked correctly)
  • log in as this newly created user and create an auth token

2. Install the proxy

You need to install the proxy on the server where your websites are hosted. You can do it both ways:

  • download the files manually
  • or install the whole repository with git
âš¡ Important note about where to install the proxy
To ensure the highest data accuracy possible, and that your Matomo cookies are set correctly, please install the proxy in your main website domain name and web server. This proxy should be ideally installed on your webserver directly under trackedsite.com. If you installed the proxy in a sub-domain under analytics.trackedsite.com then this would cause data to be less accurate. (Why? because if the sub-domain analytics.trackedsite.com was to resolve to a CNAME that does not match trackedsite.com OR if it was to resolve to A/AAAA addresses that do not match the first half of the A/AAAA addresses running trackedsite.com, then the cookies set by the Matomo Tracker Proxy in the response would only have a lifetime of maximum 7 days on Safari >= 16.4.)

Manual download of matomo.php

With git

  • clone the repository: git clone https://github.com/matomo-org/tracker-proxy.git matomo into your website root directory (for example at http://trackedsite.com/matomo/matomo.php)
  • copy the configuration template: cp config.php.example config.php
  • change the configuration in the newly created config.php:
    • $MATOMO_URL should contain the URL to your Matomo server
    • $PROXY_URL should contain the URL to the tracker-proxy server
    • $TOKEN_AUTH should contain the token_auth

By using git you will later be able to update by simply running git pull.

Be aware that with this method, matomo.php and other files are in a matomo/ subdirectory. Keep that in mind when applying the instructions for the next step.

3. Use the proxy in the Javascript tracker

The proxy file (http://trackedsite.com/matomo.php) will be called by the Matomo Javascript tracker instead of calling directly the (secret) Matomo server (http://your-matomo-domain.example.org/matomo/).

To achieve this, change the Matomo Javascript Code that is in the footer of your pages:

  • go to Matomo > Settings > Websites > Show Javascript Tracking Code.

  • copy the Javascript snippet and change the last lines to the following:

    [...]
    (function() {
        var u="//trackedsite.com/";
        _paq.push(["setTrackerUrl", u+"matomo.php"]);
        _paq.push(["setSiteId", "tracked-site-id-here"]);
        var d=document, g=d.createElement("script"), s=d.getElementsByTagName("script")[0];
        g.type="text/javascript"; g.async=true; g.defer=true; g.src=u+"matomo.php"; s.parentNode.insertBefore(g,s);
    })();
    </script>
    <!-- End Matomo Code -->

    What has changed in this code snippet compared to the normal Matomo code?

    • any reference(s) to the secret Matomo URL are now replaced by your website URL (the proxy).
    • matomo.js becomes matomo.php (or matomo/matomo.php if you used the git method): matomo.php is the proxy script
    • make sure to replace tracked-site-id-here with your idsite
    • if the <noscript> is present in your tracking code, you can remove it (it contains the secret Matomo URL which you want to hide)
  • paste the modified Matomo Javascript code in the pages you wish to track.

This modified Javascript code will then track visits/pages/conversions by calling trackedsite.com/matomo.php, which will then automatically call your (hidden) Matomo Server URL.

At this stage, example.com should be tracked by your Matomo without showing the Matomo server URL. Repeat the step 3. for each website you wish to track in Matomo.

4. (optional) Use the proxy with Matomo's Opt Out form

The tracker-proxy also supports proxying the matomo opt out form. To use this, change the URL used in the opt out iframe to use the tracker proxy's matomo-proxy.php file.

Note: you can get the opt out iframe from inside the Administration > Privacy > Users opt-out page in your Matomo instance.

Configuration

Timeout

By default, the matomo.php proxy will wait 5 seconds for the Matomo server to return the response. You may change this timeout by editing the $timeout value in config.php.

User-Agent

By default, the matomo.php proxy will contact your Matomo server with the User-Agent of the client requesting matomo.php. You may force the proxy script to use a particular User-Agent by editing the $user_agent value in config.php.

Contributing

If you have found a bug, you are welcome to submit a pull request.

Running the tests

Before running the tests, create a config.php file w/ the following contents in the root repository directory:

<?php
$MATOMO_URL = 'http://localhost/tests/server/';
$TOKEN_AUTH = 'xyz';
$timeout = 5;

The tests need a webserver to be pointed to the root of this repository. The simplest way is to just use Vagrant:

$ vagrant up
$ vagrant ssh
$ cd /vagrant/tests
$ composer install

Running the tests with CURL wrapper

  • Set allow_url_fopen = Off in your webserver php.ini
  • Check in phpinfo() that allow_url_fopen = Off
  • Run: vendor/bin/phpunit

Running the tests with Fopen wrapper

  • Set allow_url_fopen = On in your webserver php.ini
  • Check in phpinfo() that allow_url_fopen = On
  • Run: vendor/bin/phpunit

Be advised that the tests require at least PHP 5.4 to run, but the proxy itself can run with PHP 5.3.

More Repositories

1

matomo

Liberating Web Analytics. Star us on Github? +1. Matomo is the leading open alternative to Google Analytics that gives you full control over your data. Matomo lets you easily collect data from websites & apps and visualise this data and extract insights. Privacy is built-in. We love Pull Requests!
PHP
18,186
star
2

device-detector

The Universal Device Detection library will parse any User Agent and detect the browser, operating system, device used (desktop, tablet, mobile, tv, cars, console, etc.), brand and model.
PHP
2,665
star
3

docker

Official Docker project for Matomo Analytics
Shell
783
star
4

referrer-spam-list

Community-contributed list of referrer spammers. Comment +1 in any issue or Pull request and the spammer will be added to the list!
652
star
5

matomo-nginx

Nginx configuration for running Matomo
399
star
6

matomo-sdk-android

SDK for Android to measure your apps with Matomo. Works on Android phones, tablets, Fire TV sticks, and more!
Java
383
star
7

matomo-sdk-ios

Matomo iOS, tvOS and macOS SDK: a Matomo tracker written in Swift
Swift
381
star
8

matomo-log-analytics

Import any kind of server logs in Matomo for powerful log analytics. Universal log file parsing and reporting.
Python
208
star
9

matomo-php-tracker

PHP Client for Matomo Analytics Tracking API
PHP
188
star
10

tag-manager

Free Open Source Matomo Tag Manager - A simple way to manage and maintain all of your (third-party) tags on your website.
PHP
139
star
11

matomo-nodejs-tracker

A Node.js wrapper for the Matomo (Piwik) tracking HTTP API
JavaScript
116
star
12

matomo-for-wordpress

Get a fully functioning Matomo Analytics for your WordPress. Star us on Github? +1. Matomo is the leading open alternative to Google Analytics that gives you full control over your data. Privacy is built-in. 100% data ownership, no one else can see your data. We love Pull Requests!
PHP
108
star
13

piwik-python-api

Piwik API for Python
Python
99
star
14

matomo-mobile-2

Matomo Mobile 2 App - The official Git repository! Liberating Web Analytics on the go!
JavaScript
99
star
15

plugin-QueuedTracking

Scale your large traffic Matomo service by queuing tracking requests (in Redis or MySQL) for better performance.
PHP
81
star
16

piwik-dotnet-tracker

C# API client SDK for the Piwik Tracking API
C#
73
star
17

matomo-java-tracker

Official Java implementation of the Matomo Tracking HTTP API.
Java
69
star
18

searchengine-and-social-list

List of Search engines URLs, keywords and Social network URLs definitions used by Matomo Analytics
62
star
19

github-sync

Synchronize labels and milestones accross GitHub repositories
PHP
56
star
20

developer-documentation

Matomo Developer Website
PHP
54
star
21

component-ini

Read and write INI configurations.
PHP
49
star
22

github-issues-mirror

Provides a read-only mirror for your GitHub issues
PHP
41
star
23

plugin-LoginLdap

LDAP authentication and synchronization for Matomo.
PHP
37
star
24

piwik-dotnet-api

Official C# implementation of the Matomo Analytics API
C#
36
star
25

component-cache

PHP caching library based on Doctrine cache
PHP
34
star
26

matomo-dev-environment

Matomo Development Environment (Vagrant)
Puppet
33
star
27

github-changelog-generator

Queries the GitHub issues API to format a changelog
JavaScript
30
star
28

matomo-package

Matomo release script (official package), and debian/ubuntu package (allows sysadmins to deploy Matomo within seconds using "apt-get install piwik -V")
Makefile
28
star
29

plugin-MarketingCampaignsReporting

PHP
24
star
30

plugin-SecurityInfo

Provides security information about your PHP environment and offers suggestions based on PhpSecInfo from the PHP Security Consortium.
PHP
24
star
31

matomo-icons

Source files for the icons in Matomo
Python
22
star
32

plugin-GoogleAnalyticsImporter

Google Analytics to Matomo importer
PHP
22
star
33

component-network

Network component: manipulate IP addresses (ipv4, ipv6) in PHP used in the Matomo project
PHP
20
star
34

plugin-VisitorGenerator

Plugin to create fake visits, websites, users and goals to populate Matomo reports
PHP
19
star
35

travis-scripts

Scripts used to manage and automate travis CI builds for Matomo and plugins.
PHP
16
star
36

plugin-TreemapVisualization

Matomo plugin that lets you view reports as treemaps.
JavaScript
15
star
37

plugin-CustomDimensions

Custom Dimensions lets you track any custom data in Matomo
PHP
13
star
38

puppet-piwik

Piwik Puppet Module
Puppet
13
star
39

plugin-CustomAlerts

Alerts are a great way to get notified of changes on your website in Matomo.
PHP
13
star
40

plugin-Bandwidth

Monitor Bandwidth for each page, download, and measure overall traffic in bytes
PHP
13
star
41

component-decompress

Decompress files
PHP
12
star
42

matomo-map-generator

Python script that generates all svg maps used in the Matomo map widget
Python
12
star
43

plugin-EnvironmentVariables

Allows you to specify Matomo config in environment variables instead of the config file.
PHP
10
star
44

plugin-TrackingSpamPrevention

PHP
10
star
45

plugin-TasksTimetable

List all maintenance tasks that are scheduled to run. Displays the task names and next execution time in a table.
PHP
6
star
46

plugin-LogViewer

View your Matomo logs within Matomo
PHP
5
star
47

plugin-CustomVariables

This plugins allows you to configure and track Custom Variables in your Matomo Analytics.
PHP
5
star
48

plugin-Migration

Migrate a Matomo Measurable (website, app, roll-up, ...) from one Matomo instance to another Matomo
PHP
5
star
49

plugin-LoginHttpAuth

PLUGIN IS NOT ACTIVELY MAINTAINED - We're looking for a new maintainer to fork this plugin. see https://github.com/matomo-org/plugin-LoginHttpAuth/issues/26 --- Plugin to let you connect to Matomo using HTTP Auth protocol instead of the standard Login mechanism
PHP
5
star
50

plugin-Provider

Reports the Internet Service Provider of your visitors as part of your Matomo Analytics
PHP
4
star
51

plugin-AnonymousPiwikUsageMeasurement

Help making Matomo better by sending anonymized usage data to the creators the project, and/or to your own Matomo instance and/or to any other Matomo instance
PHP
4
star
52

matomo-wordpress-plugin-examples

Examples on how to enrich the Matomo Analytics for WordPress plugin.
PHP
3
star
53

looker-studio-connector

The officially supported Matomo Connector for Looker Studio enables you to explore your Matomo data in Looker Studio at no cost. You can connect to both Matomo Cloud instances or On-Premise instances using just a Matomo Auth Token.
TypeScript
3
star
54

plugin-DeviceDetectorCache

Makes tracking in Matomo Analytics faster by detecting many devices, operating systems, bots, and browsers from a cache.
PHP
3
star
55

plugin-PiwikDebugger

Debug and troubleshoot a Matomo server or a plugin with this useful plugin toolkit
PHP
3
star
56

matomo-marketplace-for-wordpress

Keep plugins from the Matomo Marketplace up to date in your WordPress with the convenience of a click. Get notified on new updates.
PHP
3
star
57

plugin-ClassicFontTheme

Less
2
star
58

cloudflare-app-manual

Piwik Analytics app for Cloudflare. Adds the tracking code when user already has a running Piwik.
JavaScript
2
star
59

github-action-plugin-translations

Github action for automatic translation update for plugins using transifex
Shell
2
star
60

piwik-python-tracker

Official Python implementation of the Piwik Tracking HTTP API.
2
star
61

plugin-IE11ReleaseChannel

Adds a new release channel that is still compatibile with Internet Explorer 11.
PHP
1
star
62

test-examples

PHP
1
star
63

google-tag-manager-matomo-template

Official Matomo Tracking Tag for Matomo Cloud & Google Tag Manager
Smarty
1
star
64

.github

1
star
65

code-search

Code search in Matomo and all Matomo plugins registered in the Marketplace
HTML
1
star
66

github-action-tests

tests package for github action
Shell
1
star
67

plugin-MatomoCustomRelease

PHP
1
star