1. Go to this page and download the library: Download pixelopen/magento-plausible library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
pixelopen / magento-plausible example snippets
/* Vendor/MyModule/Controller/Example/Index.php */
declare(strict_types=1);
namespace Vendor\MyModule\Controller\Example;
use Magento\Framework\App\Action\HttpGetActionInterface;
use PixelOpen\Plausible\Session\Goals;
class Index implements HttpGetActionInterface
{
protected Goals $goals;
protected ResultFactory $resultFactory;
public function __construct(
Goals $goals,
ResultFactory $resultFactory
) {
$this->goals = $goals;
$this->resultFactory = $resultFactory;
}
public function execute(): ResultFactory
{
$result = $this->resultFactory->create(ResultFactory::TYPE_LAYOUT);
$this->goals->add('my_page_view_action')->send();
return $result;
}
}