Our analytics for the Overtures website is within Matomo. This is convenient as it is all archived within the platform and can be set up to send out emailed reports at regular intervals. Integrating our GitHub Repo Metrics into Matomo makes the dashboard/platform an all-in-one resource.
I gave it a go but only go as far as rendering the JSON response from Github on the Matomo dashboard. I've outlined general steps below:
[ ] Have secret keys, repos and profile information securely inputted and stored in the system settings within matomo (edit SystemSettings.php to generate use ./console generate:settings. This is the code I used below. I can also share the API.php code as well, however, I've been struggling to get it working after trying to figure out how to render the data (500 error):
<?php
/**
* Matomo - free/libre analytics platform
*
* @link https://matomo.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/
namespace Piwik\Plugins\GitHubInsights;
use Piwik\Settings\Setting;
use Piwik\Settings\FieldConfig;
use Piwik\Validators\NotEmpty;
/**
* Defines Settings for GitHubInsights.
*
* Usage like this:
* $settings = new SystemSettings();
* $settings->metric->getValue();
* $settings->description->getValue();
*/
class SystemSettings extends \Piwik\Settings\Plugin\SystemSettings
{
/** @var Setting */
public $githubProfile; // GitHub profile setting declaration
/** @var Setting */
public $trackedRepos; // Tracked repositories setting declaration
/** @var Setting */
public $apiKey; // API key setting declaration
protected function init()
{
// GitHub Profile initialization
$this->githubProfile = $this->createGitHubProfileSetting();
// GitHub Repos initialization
$this->trackedRepos = $this->createRepoSetting();
// API key setting initialization
$this->apiKey = $this->createAPISetting();
}
private function createGitHubProfileSetting()
{
return $this->makeSetting('githubProfile', $default = '', FieldConfig::TYPE_STRING, function (FieldConfig $field) {
$field->title = 'GitHub Profile';
$field->uiControl = FieldConfig::UI_CONTROL_TEXT;
$field->description = 'Enter the GitHub profile you want to track';
$field->validators[] = new NotEmpty();
});
}
private function createRepoSetting()
{
return $this->makeSetting('trackedRepos', $default = '', FieldConfig::TYPE_ARRAY, function (FieldConfig $field) {
$field->title = 'Tracked Repositories';
$field->uiControl = FieldConfig::UI_CONTROL_TEXTAREA;
$field->description = 'Enter the names of the GitHub repositories you want to track, one per line.';
});
}
private function createAPISetting()
{
return $this->makeSetting('apiKey', $default = null, FieldConfig::TYPE_STRING, function (FieldConfig $field) {
$field->title = 'API Key';
$field->uiControl = FieldConfig::UI_CONTROL_TEXT;
$field->description = 'Enter your GitHub API key here [ADD DETAILED DESCRIPTION]';
$field->validators[] = new NotEmpty();
});
}
public function getTrackedRepositories()
{
$value = $this->trackedRepos->getValue();
if (!is_string($value)) {
return []; // Return an empty array if the value is not a string
}
return explode("\n", str_replace("\r", "", $value));
}
}
GitHub Metrics Matomo Plugin
Our analytics for the Overtures website is within Matomo. This is convenient as it is all archived within the platform and can be set up to send out emailed reports at regular intervals. Integrating our GitHub Repo Metrics into Matomo makes the dashboard/platform an all-in-one resource.
I gave it a go but only go as far as rendering the JSON response from Github on the Matomo dashboard. I've outlined general steps below:
[ ] Set up dev environment
[ ] Create a new plugin (I believe visualizationplugin gives a more accurate template) using the
./console generate:visualizationplugin
[ ] Fetch GitHub API traffic endpoint within the API.php file
./console generate:api
Essentially[ ] Render the information within a widget
./console generate:widget
to start the traffic data can be presented in a table :| Repository | Timestamp | Unique Clones | Clones |
./console generate:settings
. This is the code I used below. I can also share the API.php code as well, however, I've been struggling to get it working after trying to figure out how to render the data (500 error):