From cf739335ae93c83875835e6387df07e42176558e Mon Sep 17 00:00:00 2001 From: magentix Date: Tue, 9 Apr 2024 23:04:10 +0200 Subject: [PATCH 1/4] Magento 2.4.7 CSP compatibility --- CHANGELOG.md | 4 ++++ composer.json | 2 +- view/frontend/templates/script.phtml | 8 +++++++- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5b65a14..26cf0eb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 100.2.2 + +- Magento 2.4.7 CSP compatibility + ## 100.2.1 - Revenue Tracking feature added diff --git a/composer.json b/composer.json index 989e439..3d99a8d 100644 --- a/composer.json +++ b/composer.json @@ -12,7 +12,7 @@ "magento/framework": "*" }, "type": "magento2-module", - "version": "100.2.1", + "version": "100.2.2", "autoload": { "files": [ "registration.php" diff --git a/view/frontend/templates/script.phtml b/view/frontend/templates/script.phtml index b6df4ed..b9e3ced 100644 --- a/view/frontend/templates/script.phtml +++ b/view/frontend/templates/script.phtml @@ -1,6 +1,12 @@ + isEnabled()): ?> - +renderTag('script', [], $script, false); +?> From d80dc40f637cf5db9a5a45988e5b558582f70d84 Mon Sep 17 00:00:00 2001 From: magentix Date: Sun, 9 Jun 2024 22:36:12 +0200 Subject: [PATCH 2/4] Allow to send a goal on a full cached page --- CHANGELOG.md | 6 ++++ Helper/Config.php | 10 ++++-- Plugin/GoalCategory.php | 36 +++++++++++++++++++ Plugin/GoalLoginAjax.php | 36 +++++++++++++++++++ Plugin/GoalOrder.php | 10 +++--- Plugin/GoalProduct.php | 36 +++++++++++++++++++ README.md | 18 ++++++++-- Session/Goals.php | 4 +-- composer.json | 2 +- etc/adminhtml/system.xml | 16 ++++++++- etc/config.xml | 4 ++- etc/frontend/di.xml | 11 +++++- etc/frontend/sections.xml | 7 ++-- .../frontend/layout/catalog_category_view.xml | 16 +++++++++ view/frontend/layout/catalog_product_view.xml | 16 +++++++++ view/frontend/templates/luma/goals.phtml | 2 ++ view/frontend/templates/luma/goals/fpc.phtml | 7 ++++ 17 files changed, 219 insertions(+), 18 deletions(-) create mode 100644 Plugin/GoalCategory.php create mode 100644 Plugin/GoalLoginAjax.php create mode 100644 Plugin/GoalProduct.php create mode 100644 view/frontend/layout/catalog_category_view.xml create mode 100644 view/frontend/layout/catalog_product_view.xml create mode 100644 view/frontend/templates/luma/goals/fpc.phtml diff --git a/CHANGELOG.md b/CHANGELOG.md index 26cf0eb..f69dbbc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/Helper/Config.php b/Helper/Config.php index 8f1b6ea..0cea824 100644 --- a/Helper/Config.php +++ b/Helper/Config.php @@ -1,6 +1,6 @@ scopeConfig->getValue(self::PLAUSIBLE_TRACKING_INSTANCE_URL, ScopeInterface::SCOPE_STORE); - if (! $url) { + if (!$url) { $url = self::PLAUSIBLE_SAAS_INSTANCE_URL; } @@ -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 ''; } diff --git a/Plugin/GoalCategory.php b/Plugin/GoalCategory.php new file mode 100644 index 0000000..f9d3627 --- /dev/null +++ b/Plugin/GoalCategory.php @@ -0,0 +1,36 @@ +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; + } +} diff --git a/Plugin/GoalLoginAjax.php b/Plugin/GoalLoginAjax.php new file mode 100644 index 0000000..3a87a4d --- /dev/null +++ b/Plugin/GoalLoginAjax.php @@ -0,0 +1,36 @@ +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; + } +} diff --git a/Plugin/GoalOrder.php b/Plugin/GoalOrder.php index 192b734..20b7567 100644 --- a/Plugin/GoalOrder.php +++ b/Plugin/GoalOrder.php @@ -1,6 +1,6 @@ successValidator->isValid()) { + if (!$this->successValidator->isValid()) { return null; } @@ -53,7 +53,7 @@ public function beforeExecute(Success $subject) ->getCheckout() ->getLastRealOrder(); - if (! $order) { + if (!$order) { return null; } @@ -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(), ], ]; } diff --git a/Plugin/GoalProduct.php b/Plugin/GoalProduct.php new file mode 100644 index 0000000..47a9c4e --- /dev/null +++ b/Plugin/GoalProduct.php @@ -0,0 +1,36 @@ +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; + } +} diff --git a/README.md b/README.md index 201899c..5d77726 100644 --- a/README.md +++ b/README.md @@ -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: @@ -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 @@ -174,6 +174,20 @@ To send goals on a full cached page after any action, add the action in a `secti ``` +To always send goal on a full cached page, add a child block to the native block `pixel_open_plausible_goals`: + +```xml + + + + + + + + + +``` + To send goals from a custom RequireJS script, ask to reload the **plausible** section: ```javascript diff --git a/Session/Goals.php b/Session/Goals.php index f7a46e9..9d6e3cc 100644 --- a/Session/Goals.php +++ b/Session/Goals.php @@ -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); @@ -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 diff --git a/composer.json b/composer.json index 3d99a8d..095e1de 100644 --- a/composer.json +++ b/composer.json @@ -12,7 +12,7 @@ "magento/framework": "*" }, "type": "magento2-module", - "version": "100.2.2", + "version": "100.3.0", "autoload": { "files": [ "registration.php" diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml index 34a1d90..8b4e852 100644 --- a/etc/adminhtml/system.xml +++ b/etc/adminhtml/system.xml @@ -1,7 +1,7 @@ + + + + + + + diff --git a/view/frontend/layout/catalog_product_view.xml b/view/frontend/layout/catalog_product_view.xml new file mode 100644 index 0000000..71b7691 --- /dev/null +++ b/view/frontend/layout/catalog_product_view.xml @@ -0,0 +1,16 @@ + + + + + + + + + diff --git a/view/frontend/templates/luma/goals.phtml b/view/frontend/templates/luma/goals.phtml index 457e7aa..d46c19a 100644 --- a/view/frontend/templates/luma/goals.phtml +++ b/view/frontend/templates/luma/goals.phtml @@ -1,4 +1,5 @@ + isEnabled()): ?> +getChildHtml('pixel_open_plausible_goals_fpc') ?> diff --git a/view/frontend/templates/luma/goals/fpc.phtml b/view/frontend/templates/luma/goals/fpc.phtml new file mode 100644 index 0000000..b98deb1 --- /dev/null +++ b/view/frontend/templates/luma/goals/fpc.phtml @@ -0,0 +1,7 @@ + + + From 9b9e776aea8b496f56f310eea5269d729fa4cfd4 Mon Sep 17 00:00:00 2001 From: magentix Date: Mon, 10 Jun 2024 09:32:18 +0200 Subject: [PATCH 3/4] Skip ECS space fixer rules --- composer.json.ci | 2 +- ecs.php | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/composer.json.ci b/composer.json.ci index b8b4840..4fd7310 100644 --- a/composer.json.ci +++ b/composer.json.ci @@ -12,7 +12,7 @@ "magento/framework": "*" }, "type": "magento2-module", - "version": "100.2.1", + "version": "100.3.0", "autoload": { "files": [ "registration.php" diff --git a/ecs.php b/ecs.php index a618e62..a827fd9 100644 --- a/ecs.php +++ b/ecs.php @@ -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([ @@ -32,4 +34,9 @@ SetList::PSR_12, SetList::SYMPLIFY ]); + + $ecsConfig->skip([ + NotOperatorWithSuccessorSpaceFixer::class, + CastSpacesFixer::class + ]); }; From 81676a298c03af21f044cf37467485b0e8ef61d8 Mon Sep 17 00:00:00 2001 From: magentix Date: Mon, 10 Jun 2024 09:36:13 +0200 Subject: [PATCH 4/4] GitHub actions updated --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 62ceff9..6e79d3d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 @@ -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') }}