Any way to use piwik tracking without side id in the code (e.g. automatically add a website)

Hi all,
I’m new to this and I quite like piwik but it lacks a feature I consider very useful when you have loads of domains to track.
Every time you add a domain (website) you have to put a siteID in the tracking code. If you have …say 300 domains to track it is not an easy task.
Does anyone know if the tracking code can be enhanced in order to call the API in order to add a website to the DB with data from the calling URL and use the siteID afterwards?

I found something similar for an older version but I am really not sure how it can be implemented now.

Below the original idea taken with copy paste - credit goes to the initial author:

The first of my release is a hook for piwik tracking, this code works as of version 1.8.4. What it does is that it inspects the referring URL to see if a site for it already exists in the database. For example, the referring URL is, it will strip out to check in the Piwik database. If the site exists, it uses the existing site id for it, otherwise it will create a new site and returns the new id to you.

Edit your piwik.php and remove this line from it:

require_once PIWIK_INCLUDE_PATH .’/core/API/Request.php’;
Then add the following changes, don’t forget to add your API token:

// Put this into your piwik.php

function getId($url) {

$parts = parse_url(strtolower($url));
$name = $parts[‘host’];
$url = “$parts[scheme]://$parts[host]”;

$request = new Piwik_API_Request(“
$result = $request->process();
$ids = unserialize($result);

if (count($ids) === 1) {
return $ids[0][‘idsite’];
} else if (count($ids) < 1) {
$request = new Piwik_API_Request(“
$result = $request->process();
return unserialize($result);

// … later in the file, after all the other require_once …

require_once PIWIK_INCLUDE_PATH .’/core/API/Request.php’;
require_once PIWIK_INCLUDE_PATH .’/core/Loader.php’;

// … then before the tracking code, the last if block …

$_GET[‘idsite’] = getId($_GET[‘url’]);
This should theoretically work with the existing tracking code that you put on your website. If you notice that last line in the snippet, it resets the idsite variable, which means it will override whatever was there. I also set the default time zone to “America/Los_Angeles”, change that to the timezone that you want. I personally have this saved as track.php and change my tracking code by replacing all occurrences of piwik.php to track.php, but this is not necessary if you are to replace the existing piwik.php file.

You can use SitesManager.addSite API method to create new website, this method returns siteID
You can then use method SitesManager.getJavascriptTag to return tracking code for this siteID