Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop'
Browse files Browse the repository at this point in the history
# Conflicts:
#	CHANGELOG.md
#	composer.json
  • Loading branch information
magentix committed Jun 10, 2024
2 parents 0a2062a + 81676a2 commit 71cd260
Show file tree
Hide file tree
Showing 20 changed files with 229 additions and 21 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
review:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Setup PHP, with composer and extensions
uses: shivammathur/setup-php@v2 #https://github.com/shivammathur/setup-php
Expand All @@ -20,7 +20,7 @@ jobs:

- name: Cache Composer packages
id: composer-cache
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: vendor
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 100.3.0

- New goals for product and category pages
- Allow to always send a goal on a full cached page
- "Login" goal is now sent with ajax login

## 100.2.2

- Magento 2.4.7 CSP compatibility
Expand Down
10 changes: 7 additions & 3 deletions Helper/Config.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Copyright (C) 2023 Pixel Développement
* Copyright (C) 2024 Pixel Développement
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand Down Expand Up @@ -42,14 +42,18 @@ class Config extends AbstractHelper

public const PLAUSIBLE_GOAL_ORDER = 'order';

public const PLAUSIBLE_GOAL_PRODUCT = 'product';

public const PLAUSIBLE_GOAL_CATEGORY = 'category';

/**
* Retrieve Instance URL
*/
public function getInstanceUrl(): string
{
$url = $this->scopeConfig->getValue(self::PLAUSIBLE_TRACKING_INSTANCE_URL, ScopeInterface::SCOPE_STORE);

if (! $url) {
if (!$url) {
$url = self::PLAUSIBLE_SAAS_INSTANCE_URL;
}

Expand Down Expand Up @@ -109,7 +113,7 @@ public function getAdminStatsSharedLink(?int $websiteId = null): string
$websiteId
);

if (! str_starts_with($link, $this->getInstanceUrl() . '/share')) {
if (!str_starts_with($link, $this->getInstanceUrl() . '/share')) {
return '';
}

Expand Down
36 changes: 36 additions & 0 deletions Plugin/GoalCategory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php
/**
* Copyright (C) 2024 Pixel Développement
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);

namespace PixelOpen\Plausible\Plugin;

use Magento\Catalog\Controller\Category\View;
use Magento\Framework\Controller\ResultInterface;
use PixelOpen\Plausible\Helper\Config;
use PixelOpen\Plausible\Session\Goals;

class GoalCategory
{
protected Goals $goals;

public function __construct(
Goals $goals
) {
$this->goals = $goals;
}

/**
* Add goal when customer visits a category
*/
public function afterExecute(View $subject, ResultInterface $result): ResultInterface
{
$this->goals->add(Config::PLAUSIBLE_GOAL_CATEGORY);

return $result;
}
}
36 changes: 36 additions & 0 deletions Plugin/GoalLoginAjax.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php
/**
* Copyright (C) 2024 Pixel Développement
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);

namespace PixelOpen\Plausible\Plugin;

use Magento\Customer\Controller\Ajax\Login;
use Magento\Framework\Controller\ResultInterface;
use PixelOpen\Plausible\Helper\Config;
use PixelOpen\Plausible\Session\Goals;

class GoalLoginAjax
{
protected Goals $goals;

public function __construct(
Goals $goals
) {
$this->goals = $goals;
}

/**
* Add goal after customer was connected
*/
public function afterExecute(Login $subject, ResultInterface $result): ResultInterface
{
$this->goals->add(Config::PLAUSIBLE_GOAL_LOGIN);

return $result;
}
}
10 changes: 5 additions & 5 deletions Plugin/GoalOrder.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Copyright (C) 2023 Pixel Développement
* Copyright (C) 2024 Pixel Développement
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand Down Expand Up @@ -45,15 +45,15 @@ public function __construct(
*/
public function beforeExecute(Success $subject)
{
if (! $this->successValidator->isValid()) {
if (!$this->successValidator->isValid()) {
return null;
}

$order = $subject->getOnepage()
->getCheckout()
->getLastRealOrder();

if (! $order) {
if (!$order) {
return null;
}

Expand All @@ -79,14 +79,14 @@ public function afterExecute(Success $subject, ResultInterface $result): ResultI
*/
public function getRevenue(OrderInterface $order): array
{
if (! $this->config->isRevenueTrackingEnabled()) {
if (!$this->config->isRevenueTrackingEnabled()) {
return [];
}

return [
'revenue' => [
'currency' => $order->getOrderCurrencyCode(),
'amount' => (float) $order->getGrandTotal(),
'amount' => (float)$order->getGrandTotal(),
],
];
}
Expand Down
36 changes: 36 additions & 0 deletions Plugin/GoalProduct.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php
/**
* Copyright (C) 2024 Pixel Développement
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);

namespace PixelOpen\Plausible\Plugin;

use Magento\Catalog\Controller\Product\View;
use Magento\Framework\Controller\ResultInterface;
use PixelOpen\Plausible\Helper\Config;
use PixelOpen\Plausible\Session\Goals;

class GoalProduct
{
protected Goals $goals;

public function __construct(
Goals $goals
) {
$this->goals = $goals;
}

/**
* Add goal when customer visits a product page
*/
public function afterExecute(View $subject, ResultInterface $result): ResultInterface
{
$this->goals->add(Config::PLAUSIBLE_GOAL_PRODUCT);

return $result;
}
}
18 changes: 16 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ The module includes goal events when enabled in module configuration.
| Goal Cart | Plausible goal name when customer goes to the cart. Leave empty to ignore. |
| Goal Checkout | Plausible goal when customer access the checkout. Leave empty to ignore. |
| Goal Order | Plausible goal name when customer completes an order. Leave empty to ignore. |
| Goal Product | Plausible goal name when customer visits a product page. Leave empty to ignore. |
| Goal Category | Plausible goal name when customer visits a category page. Leave empty to ignore. |

You need to add goal events in your Plausible website configuration:

Expand Down Expand Up @@ -154,8 +156,6 @@ When this controller is reached and the page displayed, the goal named "page_vie

The **send** method allows to send goals. The goal will persist until **send** method is requested for the current session.

**Note:** the page must be completely displayed before the goals are sent. The "plausible" section is refreshed when the customer data is reloaded.

Add custom properties if needed (Business Plan only):

```php
Expand All @@ -174,6 +174,20 @@ To send goals on a full cached page after any action, add the action in a `secti
</config>
```

To always send goal on a full cached page, add a child block to the native block `pixel_open_plausible_goals`:

```xml
<?xml version="1.0"?>
<!-- Vendor/MyModule/view/frontend/layout/my_fpc_page.xml -->
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceBlock name="pixel_open_plausible_goals">
<block name="pixel_open_plausible_goals_fpc" class="PixelOpen\Plausible\Block\Goals" template="PixelOpen_Plausible::luma/goals/fpc.phtml" />
</referenceBlock>
</body>
</page>
```

To send goals from a custom RequireJS script, ask to reload the **plausible** section:

```javascript
Expand Down
4 changes: 2 additions & 2 deletions Session/Goals.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function add(string $goal, array $properties = [], array $additional = []
$goals = $this->get();

$name = $this->config->getGoalName($goal);
if (! empty($name)) {
if (!empty($name)) {
$goals[$name] = array_merge([
'props' => $properties,
], $additional);
Expand Down Expand Up @@ -83,7 +83,7 @@ public function send(): Goals

public function needReload(): bool
{
return (bool) $this->session->getPlausibleReload();
return (bool)$this->session->getPlausibleReload();
}

public function reset(): Goals
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"magento/framework": "*"
},
"type": "magento2-module",
"version": "100.2.2",
"version": "100.3.0",
"autoload": {
"files": [
"registration.php"
Expand Down
2 changes: 1 addition & 1 deletion composer.json.ci
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"magento/framework": "*"
},
"type": "magento2-module",
"version": "100.2.1",
"version": "100.3.0",
"autoload": {
"files": [
"registration.php"
Expand Down
7 changes: 7 additions & 0 deletions ecs.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
use PhpCsFixer\Fixer\Import\NoUnusedImportsFixer;
use Symplify\EasyCodingStandard\Config\ECSConfig;
use Symplify\EasyCodingStandard\ValueObject\Set\SetList;
use PhpCsFixer\Fixer\Operator\NotOperatorWithSuccessorSpaceFixer;
use PhpCsFixer\Fixer\CastNotation\CastSpacesFixer;

return function (ECSConfig $ecsConfig): void {
$ecsConfig->paths([
Expand Down Expand Up @@ -32,4 +34,9 @@
SetList::PSR_12,
SetList::SYMPLIFY
]);

$ecsConfig->skip([
NotOperatorWithSuccessorSpaceFixer::class,
CastSpacesFixer::class
]);
};
16 changes: 15 additions & 1 deletion etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0"?>
<!--
/**
* Copyright (C) 2023 Pixel Développement
* Copyright (C) 2024 Pixel Développement
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand Down Expand Up @@ -89,6 +89,20 @@
<field id="*/goals/enabled">1</field>
</depends>
</field>
<field id="product" translate="comment" type="text" sortOrder="80" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Goal Product</label>
<comment>Plausible goal name when customer visits a product page. Leave empty to ignore.</comment>
<depends>
<field id="*/goals/enabled">1</field>
</depends>
</field>
<field id="category" translate="comment" type="text" sortOrder="80" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Goal Category</label>
<comment>Plausible goal name when customer visits a category page. Leave empty to ignore.</comment>
<depends>
<field id="*/goals/enabled">1</field>
</depends>
</field>
</group>
<group id="revenue_tracking" translate="label" type="text" sortOrder="40" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Revenue Tracking</label>
Expand Down
4 changes: 3 additions & 1 deletion etc/config.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0"?>
<!--
/**
* Copyright (C) 2023 Pixel Développement
* Copyright (C) 2024 Pixel Développement
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand All @@ -25,6 +25,8 @@
<cart>cart</cart>
<checkout>checkout</checkout>
<order>order</order>
<product />
<category />
</goals>
</pixel_open_plausible>
</default>
Expand Down
11 changes: 10 additions & 1 deletion etc/frontend/di.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0"?>
<!--
/**
* Copyright (C) 2023 Pixel Développement
* Copyright (C) 2024 Pixel Développement
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand All @@ -15,6 +15,9 @@
<plugin name="pixel_open_plausible_goal_register" type="PixelOpen\Plausible\Plugin\GoalRegister" />
<plugin name="pixel_open_plausible_goal_login" type="PixelOpen\Plausible\Plugin\GoalLogin" />
</type>
<type name="Magento\Customer\Controller\Ajax\Login">
<plugin name="pixel_open_plausible_goal_login_ajax" type="PixelOpen\Plausible\Plugin\GoalLoginAjax" />
</type>
<type name="Magento\Checkout\Controller\Cart\Index">
<plugin name="pixel_open_plausible_goal_cart" type="PixelOpen\Plausible\Plugin\GoalCart" />
</type>
Expand All @@ -24,6 +27,12 @@
<type name="Magento\Checkout\Controller\Onepage\Success">
<plugin name="pixel_open_plausible_goal_order" type="PixelOpen\Plausible\Plugin\GoalOrder" />
</type>
<type name="Magento\Catalog\Controller\Product\View">
<plugin name="pixel_open_plausible_goal_product" type="PixelOpen\Plausible\Plugin\GoalProduct" />
</type>
<type name="Magento\Catalog\Controller\Category\View">
<plugin name="pixel_open_plausible_goal_category" type="PixelOpen\Plausible\Plugin\GoalCategory" />
</type>
<type name="Magento\Customer\CustomerData\SectionPoolInterface">
<arguments>
<argument name="sectionSourceMap" xsi:type="array">
Expand Down
Loading

0 comments on commit 71cd260

Please sign in to comment.