https://github.com/pixel-open/magento-plausible
Add Plausible Analytics to Magento
https://github.com/pixel-open/magento-plausible
adobe-commerce analytics magento magento2 magento2-module module plausible plausible-analytics
Last synced: 3 months ago
JSON representation
Add Plausible Analytics to Magento
- Host: GitHub
- URL: https://github.com/pixel-open/magento-plausible
- Owner: Pixel-Open
- License: mit
- Created: 2023-04-13T09:23:11.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-06-10T07:44:07.000Z (over 1 year ago)
- Last Synced: 2024-10-31T13:09:19.005Z (11 months ago)
- Topics: adobe-commerce, analytics, magento, magento2, magento2-module, module, plausible, plausible-analytics
- Language: PHP
- Homepage: https://pixel-open.org/projects/plausible-analytics-for-magento-2
- Size: 148 KB
- Stars: 6
- Watchers: 3
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
# Magento Plausible
[](https://php.net/)
[](https://business.adobe.com/products/magento/magento-commerce.html)
[](https://github.com/Pixel-Open/magento-plausible/releases)
[](https://sonarcloud.io/summary/new_code?id=Pixel-Open_magento-plausible)## Presentation
Add Plausible Analytics to Magento.
- Save visited pages
- Access Analytics in Magento Admin with Plausible Shared Link
- Manage goals on specific actions (contact, register, checkout, order...)
- Allow use of your own Plausible instance
- Compatible with multiple websites
- Compatible with Magento OpenSource, Mage-OS and Adobe Commerce
- Compatible with Hyvä theme
## Requirements
- Magento >= 2.4.4
- PHP >= 8.0.0## Installation
```
composer require pixelopen/magento-plausible
```## Configuration
*Stores > Configuration > Services > Plausible*
### Tracking
| Option | Description |
|--------------|------------------------------------------------------------------------------|
| Enabled | Add tracking script on frontend and start recording visited pages. |
| Instance URL | Plausible instance URL. Allow to use a custom domain for dedicated instance. |**Note:** For custom domain with Magento CSP Module, remember to add your instance URL in CSP whitelist for *frame-src*, *connect-src* and *script-src*.
### Admin
| Option | Description |
|-------------|---------------------------------------------------------------------------------------------------------|
| Enabled | Display stats in the "Marketing > Plausible > Analytics" menu (refresh cache when option is updated). |
| Shared Link | Create the shared link in your Plausible instance site settings: Visibility > Shared links > + New link |### Goals
The module includes goal events when enabled in module configuration.
- Contact message sent
- Account registration
- Customer has logged in
- Cart view
- Checkout
- Order complete| Option | Description |
|---------------|----------------------------------------------------------------------------------|
| Enabled | Allow to track actions. |
| Goal Contact | Plausible goal name when customer send a contact message. Leave empty to ignore. |
| Goal Register | Plausible goal name when creating the customer account. Leave empty to ignore. |
| Goal Login | Plausible goal name when customer was connected. Leave empty to ignore. |
| 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:

The Plausible goal name must be the same as the name in the module configuration.
Default goal names are:
- contact
- register
- login
- cart
- checkout
- order### Revenue Tracking
With the goal "order", the "revenue tracking" is sent. This feature is only available with Plausible business plan.
When you add the "order" goal, you need to enable the "Revenue Tracking":

### Custom Goal
In a module, declare the new goals in the `config.xml` file:
```xml
page_view_goal
form_post_goal
```
From anywhere (like a controller action), add a new Plausible goal:
```php
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;
}
}
```When this controller is reached and the page displayed, the goal named "page_view_goal" (according the config for "my_page_view_action") is sent to Plausible.
The **send** method allows to send goals. The goal will persist until **send** method is requested for the current session.
Add custom properties if needed (Business Plan only):
```php
$this->goals->add('my_page_view_action', ['foo' => 'bar'])->send();
```To send goals on a full cached page after any action, add the action in a `sections.xml` file in `etc/frontend` directory.
```xml
```
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
define(
[
'uiComponent',
'Magento_Customer/js/customer-data'
],
function (Component, customerData) {
'use strict';return Component.extend({
initialize: function () {
this._super();
customerData.reload(['plausible'], false);
}});
}
);
```To simply send a goal in JavaScript, use the **plausible** method:
```javascript
plausible('goalName', {'props': {'foo': 'bar'}});
```