Tracking virtual subdomains

(bitstream) #1

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:
Actually user1 and user2 is not an subdomain created on Because 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

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

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,

(vipsoft) #2

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

(bitstream) #3

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).

(vipsoft) #4

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

(bitstream) #5

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.

(vipsoft) #6

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

(bitstream) #7

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

(bitstream) #8

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,

(vipsoft) #9

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