Report of how many logins each month in a year


(Jens Andersson) #1

Hi i have a wordpress site where i extract username as a custom variable now i am able to see how many times each customer logins and i can select month year ans so on but i would like to take this data and make this into a report of how much they access the site each month for a period of a year so i can send it to the users.
is this possible


(Naser Aslam) #2

Hi Jens, Yes this is possible and i have already done it. You nee to use matomo api for it. If you don’t know about it please read the documentation. Some sample code given below.

$url="http://localhost/matomo/matomo/index.php?module=API&method=Live.getLastVisitsDetails&format=json&idSite=1&period=day&date=today&expanded=1&translateColumnNames=1&language=en&token_auth=your-auth-token-here&filter_limit=1000";
$Web_data = json_decode(file_get_contents($url), true);
//print_r($Web_data);
for ($i=0; $i <sizeof($Web_data) ; $i++) {
  if(array_key_exists("customVariables",$Web_data[$i]) AND (sizeof($Web_data[$i]["customVariables"])>0) AND ($Web_data[$i]["customVariables"]["1"]["customVariableValue1"]!="visitor"))
  {
    $name=$Web_data[$i]["customVariables"]["1"]["customVariableValue1"]!=""?$Web_data[$i]["customVariables"]["1"]["customVariableValue1"]:"unknow";
    $v_id=$Web_data[$i]["visitorId"];
    $actions=$Web_data[$i]["actions"];
    $time=$Web_data[$i]["serverDatePretty"]." ".$Web_data[$i]["serverTimePretty"];
    $device_type=$Web_data[$i]["deviceType"];
    $OS=$Web_data[$i]["operatingSystem"];
    $browser_name=$Web_data[$i]["browserName"];
    $country=$Web_data[$i]["country"];

    echo "
    <tr>
    <td><a target='_blank' href='http://localhost/testing/show_record.php?id=".$v_id."&v_name=".$name."&t_actions=".$actions."'>$name</a></td>
    <td>$actions</td>
    <td>$time</td>
    <td>$device_type</td>
    <td>$OS</td>
    <td>$browser_name</td>
    <td>$country</td>
  </tr>
  ";
  }
}