Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added proxy feature for Matomo Tag Manager #79

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions config.php.example
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@
// This URL will never be revealed to visitors or search engines.
$MATOMO_URL = 'http://your-matomo-domain.example.org/matomo/';

$MATOMO_TRUSTED_URLS = [
// Edit the lines below, and replace http://your-matomo-domain.example.org/matomo/
// with your Matomo URL ending with a slash.
// Also add any other trusted_hosts[] - config you have in config/config.ini.php
// These URLs will never be revealed to visitors or search engines using the tag manager.
'http://your-matomo-domain.example.org/matomo/'
];

// Edit the line below and replace http://your-tracker-proxy.org/ with the URL to your tracker-proxy
// setup. This URL will be used in Matomo output that contains the Matomo URL, so your Matomo is effectively
// hidden.
Expand Down
3 changes: 3 additions & 0 deletions js/.htaccess
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
RewriteEngine On

RewriteRule ^(.*)\.js$ index.php
54 changes: 54 additions & 0 deletions js/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php
/**
* Matomo - free/libre analytics platform
* Matomo Proxy Hide URL
*
* @link https://matomo.org/faq/how-to/#faq_132
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/

$configFile = __DIR__ . '/../config.php';
if (file_exists($configFile)) {
include $configFile;
}

$calledJsFile = $_SERVER['REQUEST_URI'];

if (strpos($calledJsFile, 'js') === false) {
exit();
}

// -----
// Important: read the instructions in README.md or at:
// https://github.com/matomo-org/tracker-proxy#matomo-tracker-proxy
// -----
//// FALLBACK CONFIG IF config.php IS NOT USED

// Edit the line below, and replace http://your-matomo-domain.example.org/matomo/
// with your Matomo URL ending with a slash.
// This URL will never be revealed to visitors or search engines.
if (! isset($MATOMO_URL)) {
$MATOMO_URL = 'http://your-matomo-domain.example.org/matomo/';
}

if (! isset($MATOMO_URL)) {
$MATOMO_TRUSTED_URLS = [
// Edit the lines below, and replace http://your-matomo-domain.example.org/matomo/
// with your Matomo URL ending with a slash.
// Also add any other trusted_hosts[] - config you have in config/config.ini.php
// These URLs will never be revealed to visitors or search engines using the tag manager.
'http://your-matomo-domain.example.org/matomo/'
];
}

// Edit the line below and replace http://your-tracker-proxy.org/ with the URL to your tracker-proxy
// setup. This URL will be used in Matomo output that contains the Matomo URL, so your Matomo is effectively
// hidden.
if (! isset($PROXY_URL)) {
$PROXY_URL = 'http://your-tracker-proxy.org/';
}

$fileName = $MATOMO_URL . $calledJsFile;
$fileContent = file_get_contents($fileName);

echo str_replace($MATOMO_TRUSTED_URLS, $PROXY_URL, $fileContent);