Tracking virtual subdomains

Hi,
I’ll try to explain what I need.
I have one domain that support * as subdomains. So, this site, based on subscription will show users links like this:
user1.domain.com
user2.domain.com
Actually user1 and user2 is not an subdomain created on domain.com. Because domain.com can take any subdomain I use requested link, check the database for user1 and if exists leave it as it is to browse the site. If there is no such user I force a redirect to www.domain.com

Now the problem comes with tracking. I need to show each user stats for their site.
user1 need to see the trafic on user1.domain.com.

Piwik is able to track every virtual subdomain ? Maybe a variable in the javascript or use piwik_idsite with the id of the users from database, I don’t know.
Waiting all the help I can get.

Thank you,

Just add each user’s subdomain separately; each gets a separate site id.

Those are virtual subdomains, generated on the fly based on user subscription on other page. And I could end up having thousand of users (subdomains).

What are you missing from the API and/or plugin architecture? You can already create and manage users & sites programmatically.

After testing and looking closer in the database structure I figure it out that every site had to have an entry in piwik_site. This is the first place where the framework looks when using an API request.
I add entry in the database based on user id but I don’t know a way to create those entries in the site table.
Maybe I can bypass siteid validation when I get the data from database on API call.

You can create a table (or add a column to an existing one) to map users to site ids.

Thank you for your sugestions. But I’m really new to piwik, can you guide me into the right direction with this ?

Finnaly, is working.
If anyone is interested here is what I did.
I had to create a new function for API called getSiteFromName in SitesManager. I call this with subdomain I get from URL.
If return is true, call SitesManager.getJavascriptTag to show javascript tracking code.
Else, I call SitesManager.addSite and after that I call SitesManager.getJavascriptTag with the return from previous call as idSite.

All the best for all,

You might consider adding an index to the site name column if lookups start taking too long.