Skip to content

Commit

Permalink
docs: added php syntax highlighting in readme and updated contributors
Browse files Browse the repository at this point in the history
  • Loading branch information
thelfensdrfer committed Jun 23, 2023
1 parent 1604eae commit 5b8d535
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 39 deletions.
1 change: 1 addition & 0 deletions Contributors.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@
* https://github.com/simonschaufi
* https://github.com/stayallive
* https://github.com/aschempp
* https://github.com/jnngr
102 changes: 63 additions & 39 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,19 @@ This library can be installed via composer: `composer require visualappeal/matom

### Create an instance of matomo

require(__DIR__ . '/vendor/autoload.php');
```php
require(__DIR__ . '/vendor/autoload.php');

use VisualAppeal\Matomo;
use VisualAppeal\Matomo;

$matomo = new Matomo('http://stats.example.org', 'my_access_token', 'siteId');
$matomo = new Matomo('http://stats.example.org', 'my_access_token', 'siteId');
```

There are some basic parameters (period, date, range) which you can define at the beginning. They do not change until you reset them with

$matomo->reset();
```php
$matomo->reset();
```

So you can execute multiple requests without specifying the parameters again.

Expand All @@ -38,48 +42,62 @@ The ID of your website, single number, list separated through comma `"1,4,7"`, o

The period you request the statistics for

Matomo::PERIOD_DAY
Matomo::PERIOD_WEEK
Matomo::PERIOD_MONTH
Matomo::PERIOD_YEAR
Matomo::PERIOD_RANGE
```php
Matomo::PERIOD_DAY
Matomo::PERIOD_WEEK
Matomo::PERIOD_MONTH
Matomo::PERIOD_YEAR
Matomo::PERIOD_RANGE
```

If you set the period to `Matomo::PERIOD_RANGE` you can specify the range via

$matomo->setRange('2012-01-14', '2012-04-30'); //All data from the first to the last date
$matomo->setRange('2012-01-14', Matomo::DATE_YESTERDAY); //All data from the first date until yesterday
$matomo->setRange('2012-01-14'); //All data from the first date until now
```php
$matomo->setRange('2012-01-14', '2012-04-30'); //All data from the first to the last date
$matomo->setRange('2012-01-14', Matomo::DATE_YESTERDAY); //All data from the first date until yesterday
$matomo->setRange('2012-01-14'); //All data from the first date until now
```

If you set it to something other than `Matomo::PERIOD_RANGE` you can specify the date via:

$matomo->setPeriod(x);
$matomo->setDate('2012-03-03');
```php
$matomo->setPeriod(x);
$matomo->setDate('2012-03-03');

Case x of PERIOD_DAY the report is created for the third of march, 2012
Case x of PERIOD_WEEK the report is created for the first week of march, 2012
Case x of PERIOD_MONTH the report is created for march, 2012
Case x of PERIOD_YEAR the report is created for 2012
Case x of PERIOD_DAY the report is created for the third of march, 2012
Case x of PERIOD_WEEK the report is created for the first week of march, 2012
Case x of PERIOD_MONTH the report is created for march, 2012
Case x of PERIOD_YEAR the report is created for 2012
```

### date

Set the date via

$matomo->setDate('YYYY-mm-dd');
```php
$matomo->setDate('YYYY-mm-dd');
```

Or use the constants

$matomo->setDate(Matomo::DATE_TODAY);
$matomo->setDate(Matomo::DATE_YESTERDAY);
```php
$matomo->setDate(Matomo::DATE_TODAY);
$matomo->setDate(Matomo::DATE_YESTERDAY);
```

Report for the last seven weeks including the current week

$matomo->setPeriod(Matomo::PERIOD_WEEK);
$matomo->setDate('last7');
```php
$matomo->setPeriod(Matomo::PERIOD_WEEK);
$matomo->setDate('last7');
```

Report for the last 2 years without the current year

$matomo->setPeriod(Matomo::PERIOD_YEAR);
$matomo->setDate('previous2');
```
$matomo->setPeriod(Matomo::PERIOD_YEAR);
$matomo->setDate('previous2');
```

### segment, idSubtable, expanded

Expand All @@ -89,32 +107,38 @@ For some functions you can specify `segment`, `idSubtable` and `expanded`. Pleas

Specify a output format via

$matomo->setFormat(Matomo::FORMAT_JSON);
```php
$matomo->setFormat(Matomo::FORMAT_JSON);
```

JSON is converted with `json_decode` before returning the request.

All available formats

Matomo::FORMAT_XML
Matomo::FORMAT_JSON
Matomo::FORMAT_CSV
Matomo::FORMAT_TSV
Matomo::FORMAT_HTML
Matomo::FORMAT_RSS
Matomo::FORMAT_PHP
```php
Matomo::FORMAT_XML
Matomo::FORMAT_JSON
Matomo::FORMAT_CSV
Matomo::FORMAT_TSV
Matomo::FORMAT_HTML
Matomo::FORMAT_RSS
Matomo::FORMAT_PHP
```


## Example

Get all the unique visitors from yesterday:

require(__DIR__ . '/vendor/autoload.php');
```php
require(__DIR__ . '/vendor/autoload.php');

use VisualAppeal\Matomo;
use VisualAppeal\Matomo;

$matomo = new Matomo('http://stats.example.org', 'my_access_token', 1, Matomo::FORMAT_JSON);
$matomo = new Matomo('http://stats.example.org', 'my_access_token', 1, Matomo::FORMAT_JSON);

$matomo->setPeriod(Matomo::PERIOD_DAY);
$matomo->setDate(Matomo::DATE_YESTERDAY);
$matomo->setPeriod(Matomo::PERIOD_DAY);
$matomo->setDate(Matomo::DATE_YESTERDAY);

echo 'Unique visitors yesterday: ' . $matomo->getUniqueVisitors();
echo 'Unique visitors yesterday: ' . $matomo->getUniqueVisitors();
```

0 comments on commit 5b8d535

Please sign in to comment.