Hi there, I am a new user (and long time PHP developer) and I’m just loving what I see so far. I’m thinking of using Piwik to manage potentially 1000’s of websites - actually they would be individual pages that are set up as a site that we need to track and report on individually!
I was wondering if there is a way to upload a .csv file of the urls, etc. ?
Or is there an API call that will create a website? If so, I could then write a simple program to insert each of our sites automatically. This would be needed after the initial load for new sites/pages as necessary.
Also, it would be great if I could use our own website id as the site id, to make coordinating our tasks much easier.
Unfortunately there is no example.
I have tried to use a php curl call to add a site to piwik, but I always get the message that the action does not exist in the named module.
I have tried:
Action ‘addSite’, module 'SitesManager’
Action SitesManager.‘addSite’, module ‘API’ (thats how its called in the piwik web interface)
This code works using file_get_contents rather than curl, but shows you the basics. You don’t actually need the URL as Piwik tracks with teh site-id (returned on the addSite call)
<?php
// this token is used to authenticate your API request.
// You can get the token on the API page inside your Piwik interface
$token_auth = 'gdgdgdghddggdhdghddfghdfgh';
$file = fopen("input.csv","r");
// csv name, url
while(! feof($file))
{
$row=fgetcsv($file);
print_r($row);
echo "<br>";
$url = "https://analytics-02.mydomain.com/";
$url .= "?module=API&method=SitesManager.addSite";
$url .= "&siteName=".urlencode($row[0]);
$url .= "&urls=".$row[1];
$url .= "&token_auth=$token_auth";
$fetched = file_get_contents($url);
print_r ($fetched);
echo "<br>";
}
fclose($file);
?>
I call it code blindness, you get so familiar with the code you don’t notice the obvious. All ways good to get an outsider to look, even if they are not technical, I have found just talking someone through a problem spurs a different thought process.
Hey there, thanks for the help with understanding how I can add new sites. Our main application essentially manages websites and we want to use Piwik to do the analytics for each of the managed sites.
Because of this, it would be really helpful if I could specify the site_id (instead of relying on the database auto-increment value) when calling the Piwik API to create a new site.
Does anyone know how I could do that?
If necessary, I could write a plugin (or override the existing code if that is possible) to be able to pass the id to the Piwik add website function.
It is quite easy to query the Piwik ID before hand, there are lots of SitesManager.getSites… methods . That is for instance how the Multi-Site Wordpress plugin handles it.
So once you have added a site you can always get it back, e.g. using SitesManager.getSitesIdFromSiteUrl
If you do it your way I think you would be fighting the system!