I have set-up a one-click Piwik autologin for the statistics of a hosting service. The problem is that many users have more than one site, so I would like to be able to force which one to display in Piwik.
For example if a user has a “website1” and a “website2”, and he clicks on the “statistics” link of “website2”, he will get the “website1” stats for now. I would like to force “website2”.
Is there an easy way to do this, if possible by passing the website name or url (and not the idSite)?
Thanks for your answer, but it would be much more useful for me to be able to specify the website in the URL, even if it involve to use the idSite parameter (from the piwik db)…
function redirectToCoreHomeIndex()
{
$defaultReport = Piwik_UsersManager_API::getInstance()->getUserPreference(Piwik::getCurrentUserLogin(), Piwik_UsersManager_API::PREFERENCE_DEFAULT_REPORT);
$module = 'CoreHome';
$action = 'index';
//Added by smaon, 31 march 2011
$idSite = Piwik_Common::getRequestVar('idSite', -1, 'string');
// User preference: default report to load is the All Websites dashboard
if($defaultReport == 'MultiSites'
&& Piwik_PluginsManager::getInstance()->isPluginActivated('MultiSites'))
{
$module = 'MultiSites';
}
if($defaultReport == Piwik::getLoginPluginName())
{
$module = Piwik::getLoginPluginName();
}
if($idSite == -1) //Added by smaon, there is certainly a way to do this nicer
parent::redirectToIndex($module, $action);
else
parent::redirectToIndex($module, $action, $idSite);
}
Now I can call the Piwik auto-login with idSite specify in the url. I think this could be useful for more people.