Skip to content

Commit

Permalink
Merge pull request #72 from matomo-org/wordpress
Browse files Browse the repository at this point in the history
Make plugin work with Matomo for WordPress
  • Loading branch information
tsteur authored Jul 15, 2021
2 parents 9988845 + 92f18f2 commit cebe9ac
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 10 deletions.
15 changes: 15 additions & 0 deletions Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
namespace Piwik\Plugins\VisitorGenerator;

use Piwik\SettingsPiwik;
use Piwik\SettingsServer;

include_once __DIR__ . '/vendor/autoload.php';

Expand All @@ -27,6 +28,20 @@ public function __construct($matomoUrl = null)
$this->setMatomoUrl($matomoUrl);
}

protected function makeMatomoTracker($idSite)
{
if (SettingsServer::isMatomoForWordPress()) {
$trackerFile = plugin_dir_path( MATOMO_ANALYTICS_FILE ) . "tests/phpunit/framework/test-local-tracker.php";
if (file_exists($trackerFile)) {
include_once $trackerFile;
return new \MatomoLocalTracker($idSite, $this->getMatomoUrl());
} else {
throw new \Exception('The visitor generator in Matomo for WordPress works only when the plugin is installed from Git and is only intended for development.');
}
}
return new \MatomoTracker($idSite, $this->getMatomoUrl());
}

/**
* @param $matomoUrl
*/
Expand Down
2 changes: 1 addition & 1 deletion Generator/VisitsFake.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function generate($time = false, $idSite = 1, $limit = 1000)
{
$date = date("Y-m-d", $time);

$tracker = new \MatomoTracker(1, $this->getMatomoUrl());
$tracker = $this->makeMatomoTracker($idSite);
$tracker->setDebugStringAppend('dp=1');
$tracker->enableBulkTracking();
$tokenAuth = Piwik::requestTemporarySystemAuthToken('VistorGenerator', 24);
Expand Down
19 changes: 14 additions & 5 deletions Menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,26 @@

use Piwik\Menu\MenuAdmin;
use Piwik\Piwik;
use Piwik\SettingsServer;

class Menu extends \Piwik\Plugin\Menu
{
public function configureAdminMenu(MenuAdmin $menu)
{
if (Piwik::hasUserSuperUserAccess()) {
$menu->addDevelopmentItem(
'VisitorGenerator_VisitorGenerator',
['module' => 'VisitorGenerator', 'action' => 'index'],
$order = 20
);
if (SettingsServer::isMatomoForWordPress()) {
$menu->addSystemItem(
'VisitorGenerator_VisitorGenerator',
['module' => 'VisitorGenerator', 'action' => 'index'],
$order = 20
);
} else {
$menu->addDevelopmentItem(
'VisitorGenerator_VisitorGenerator',
['module' => 'VisitorGenerator', 'action' => 'index'],
$order = 20
);
}
}
}
}
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,17 @@ VisitorGenerator makes a lot of requests to the Matomo tracking API to send the

## Using it in Matomo for WordPress

The developer menu item is not available in Matomo for WordPress. Visits have to be generated using the command line instead:
It only works in Matomo for WordPress if the plugin is installed through git as it's only intended for development.

In Matomo for WordPress you can find the UI in the Matomo Admin under "System".

You can also use the command line to generate the data:

```
cd wp-content/plugins/matomo/app
./console visitorgenerator:generate-visits --idsite=1
```

If you are getting an error about SSL errors then you can use the `--custom-matomo-url="..."` option to specify using HTTP. For example `--custom-matomo-url="http://my-domain/wp-content/plugins/matomo/app/"`.

### Legalnotice

This plugin is released under the GPLv3+ license.
Expand Down
1 change: 0 additions & 1 deletion templates/index.twig
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
title="{{ 'VisitorGenerator_ChoiceYes'|translate|e('html_attr') }}">
</div>

<input type="hidden" value="{{ token_auth }}" name="token_auth"/>
<input type="hidden" value="{{ nonce }}" name="form_nonce"/>

<p>
Expand Down

0 comments on commit cebe9ac

Please sign in to comment.