Use a different hostname for tracker


I’ve setup a Piwik installation which has two hostnames. One is for accessing UI (, the other will be used for tracker ( For the tracker hostname, I’ve setup a vhost which only contains piwik.php and piwik.js. This works as expected.

Now I want to make it easier when getting the tracking code from the UI. As today when you’re using the UI hostname (, you will see the UI hostname in the tracking code. I want to be able to see the tracker hostname ( in the tracking code instead.

I’ve tried to manually update the piwikUrl in the piwik_option table. But it is reverted to whenever I access the UI. Another solution would be to update /plugins/Morpheus/templates/javascriptCode.tpl manually.

Any thoughts on what would be the best approach?

(Matthieu Aubry) #2

Yes, it’s possible to do this. you need to create a Custom Piwik plugin Introduction: Develop - Matomo Analytics (formerly Piwik Analytics) - Developer Docs - v3

In the plugin you need to listen to event ‘Piwik.getJavascriptCode’ Events - Matomo Analytics (formerly Piwik Analytics) - Developer Docs - v3

This lets you modify the Piwik Tracker URL displayed in UI in your plugin.

can be done in your custom plugin with a function like:

public function manipulateJavascriptTrackingCode(&$codeReplace, $parameters)
        $codeReplace['piwikUrl'] = $MY_URL;
        $codeReplace['httpsPiwikUrl'] = $MY_URL;


Thanks Matt!

Worked like a charm. I noticed though that the ImageTrackerCode wasn’t updated with this. So I tried to update it by listening to ‘SitesManager.getImageTrackingCode’ [ ].

Then I created following function:

public function manipulateImageTrackingCode(&$piwikUrl, &$urlParams)
$piwikHost = $MY_URL;

But it won’t update the domain name. Not sure where I’m doing wrong. Any suggestions?


Answer to my own question. The function should look like this:

public function manipulateImageTrackingCode(&$piwikUrl, &$urlParams)
$piwikUrl = $MY_URL;