Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
732b463
Fixed: translation loaded too early in some configurations.
Dan0sz Mar 6, 2025
2861484
Updated tested with tag.
Dan0sz Mar 7, 2025
9cfa977
Updated Tested Up To and Requires PHP tag.
Dan0sz Mar 7, 2025
a418ecc
Added: support for add to cart tracking through direct links.
Dan0sz Mar 11, 2025
44f3dea
Improved: if $url isn't set, and no referer is found, attempt to fall…
Dan0sz Mar 11, 2025
6ceaf40
Minor re-factor to Cron label.
Dan0sz Mar 13, 2025
30e5769
Fixed: cron is now registered properly upon plugin activation.
Dan0sz Mar 13, 2025
18888d0
PHPDoc.
Dan0sz Mar 13, 2025
c9fb615
Merge pull request #245 from plausible/cron_fix
Dan0sz Mar 13, 2025
1a3d1a6
Merge branch 'develop' into direct_links_support
Dan0sz Mar 13, 2025
8eb13c9
Ignore this function, because we can't test XHR requests here.
Dan0sz Mar 13, 2025
5701c27
Added testGenerateEventUrl and refactored code for readability.
Dan0sz Mar 13, 2025
1b86992
Moved ClientFactoryTest to Integration tests and removed Unit tests dir.
Dan0sz Mar 13, 2025
199e89a
Merge pull request #244 from plausible/direct_links_support
Dan0sz Mar 13, 2025
56e7b49
Improved: added Gravity Forms compatibility for Form Completions.
Dan0sz Mar 13, 2025
8a8d705
Ignore code.
Dan0sz Mar 13, 2025
012f40e
Merge pull request #247 from plausible/gravity_forms_compatibility
Dan0sz Mar 13, 2025
64d505e
Added: upgrade script for 2.3.1 and tests.
Dan0sz Mar 13, 2025
e1b25a1
Update readme.txt
metmarkosaric Mar 14, 2025
4adfa52
Fixed: run track_direct_add_to_cart before WC's add to cart action in…
Dan0sz Mar 14, 2025
ca23f2f
Only change JS ID if IE compatibility is enabled.
Dan0sz Mar 14, 2025
08f583a
Updated FiltersTest
Dan0sz Mar 14, 2025
a7d6b18
Merge pull request #248 from plausible/ie_compatibility
Dan0sz Mar 14, 2025
5a9340f
Merge pull request #249 from plausible/track_wc_direct_link_add_to_cart
Dan0sz Mar 14, 2025
c4e0839
Removed unused code.
Dan0sz Mar 19, 2025
e8c614f
Improved: Enhanced Measurements of which the required capabilities ar…
Dan0sz Mar 19, 2025
f13c088
Improved: capabilities are refreshed when clicking "Connect" and opti…
Dan0sz Mar 19, 2025
fa8c0ec
Added: auto-enable customer user role for EDD/WC.
Dan0sz Mar 19, 2025
330b66d
Added: auto-enable customer user role for EDD/WC.
Dan0sz Mar 19, 2025
9536e4f
Added: tests
Dan0sz Mar 19, 2025
05cd003
Merge pull request #251 from plausible/auto_enable_customer_role
Dan0sz Mar 19, 2025
b353482
Merge branch 'develop' into disable_options_not_in_plan
Dan0sz Mar 19, 2025
fe05b83
Improved: capabilities are now updated when an option is toggled.
Dan0sz Mar 19, 2025
274f79f
Fixed: capabilities of Form completions and Custom Events.
Dan0sz Mar 19, 2025
b216a31
Minor refactor.
Dan0sz Mar 19, 2025
83711d9
Nothing to test here.
Dan0sz Mar 19, 2025
2283ede
Merge pull request #250 from plausible/disable_options_not_in_plan
Dan0sz Mar 19, 2025
005e849
2.3.1
Dan0sz Mar 20, 2025
7465e3b
Update WooCommerce.php
pau1phi11ips Mar 27, 2025
086b4ab
Fixed: Call to a member function get_data on bool.
Dan0sz Apr 4, 2025
f91546f
Tested with WP 6.8
Dan0sz Apr 16, 2025
1140b07
Improved: store token caps in DB during validation.
Dan0sz Apr 16, 2025
a901c6e
Added: Search queries can now be enabled for Growth plans.
Dan0sz Apr 16, 2025
fbc934c
Ignore this line.
Dan0sz Apr 16, 2025
47a835a
Merge pull request #253 from plausible/fix_search_queries
Dan0sz Apr 16, 2025
df661b9
Fixed: Function _load_textdomain_just_in_time was called incorrectly …
Dan0sz Apr 18, 2025
999eab3
Improved: is_wc_active and is_edd_active methods did too much.
Dan0sz Apr 18, 2025
3183e2b
Fixed: Translation loading for the plausible-analytics domain was tri…
Dan0sz Apr 18, 2025
b9329b1
Ignore this code, because there's nothing to test.
Dan0sz Apr 18, 2025
84e2340
is_edd_recurring_active did too much.
Dan0sz Apr 18, 2025
f423fcf
Minor refactor.
Dan0sz Apr 18, 2025
0f10d0a
Merge pull request #254 from plausible/load_textdomain_fix
Dan0sz Apr 18, 2025
d92d44e
Merge branch 'develop' into patch-2
Dan0sz Apr 22, 2025
d773b57
Merge pull request #252 from pau1phi11ips/patch-2
Dan0sz Apr 22, 2025
ac593a3
v2.3.2
Dan0sz Apr 22, 2025
41cd238
Merge branch 'load_textdomain_fix' into develop
Dan0sz Apr 22, 2025
b1a3f72
Fixed: exclude our loaded JS from WP Rocket's delay JS setting.
Dan0sz Apr 24, 2025
4fa1490
Merge pull request #255 from plausible/fix_wp_rocket_delay_js
Dan0sz Apr 24, 2025
a4ddc1d
Added: W3 Total Cache compatibility
Dan0sz Apr 24, 2025
2438940
Merge pull request #256 from plausible/w3tc_compatibility
Dan0sz Apr 24, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 49 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,45 @@

[![Github CI](https://github.com/plausible/wordpress/actions/workflows/push.yml/badge.svg)](https://github.com/plausible/wordpress/actions/workflows/push.yml) ![WordPress version](https://img.shields.io/wordpress/plugin/v/plausible-analytics.svg) ![WordPress Rating](https://img.shields.io/wordpress/plugin/r/plausible-analytics.svg) ![WordPress Downloads](https://img.shields.io/wordpress/plugin/dt/plausible-analytics.svg)

Welcome to the Plausible Analytics WordPress Plugin GitHub repository. This is the code source and the center of active development. Here you can
Welcome to the Plausible Analytics WordPress Plugin GitHub repository. This is the code source and the center of active
development. Here you can
browse the source, look at open issues, and contribute to the project.

## Getting Started

If you're looking to contribute or actively develop on Plausible Analytics then skip ahead to
the [Local Development](https://github.com/plausible/wordpress/#local-development) section below. The following is if you're looking to actively use
the [Local Development](https://github.com/plausible/wordpress/#local-development) section below. The following is if
you're looking to actively use
the plugin on your WordPress site.

### Minimum Requirements

* WordPress 5.3 or greater
* WordPress 5.9 or greater
* PHP version 7.4 or greater
* MySQL version 5.5 or greater

### Automatic installation

Automatic installation is the easiest option as WordPress handles the file transfers itself, and you don't need to leave your web browser. To do an
automatic installation of Plausible Analytics, log in to your WordPress dashboard, navigate to the Plugins menu and click "Add New".
Automatic installation is the easiest option as WordPress handles the file transfers itself, and you don't need to leave
your web browser. To do an
automatic installation of Plausible Analytics, log in to your WordPress dashboard, navigate to the Plugins menu and
click "Add New".

In the search field type "Plausible Analytics" and click Search Plugins. Once you have found the plugin you can view details about it such as the
In the search field type "Plausible Analytics" and click Search Plugins. Once you have found the plugin you can view
details about it such as the
point release, rating and description. Most importantly of course, you can install it by simply clicking "Install Now".

### Manual installation

The manual installation method involves downloading our plugin and uploading it to your server via your favorite FTP application. The
WordPress codex contains [instructions on how to do this](https://codex.wordpress.org/Managing_Plugins#Manual_Plugin_Installation).
The manual installation method involves downloading our plugin and uploading it to your server via your favorite FTP
application. The
WordPress codex
contains [instructions on how to do this](https://codex.wordpress.org/Managing_Plugins#Manual_Plugin_Installation).

### Support

This repository is not suitable for support. Please don't use GitHub issues for support requests. To get support please use the following channels:
This repository is not suitable for support. Please don't use GitHub issues for support requests. To get support please
use the following channels:

* [WP.org Support Forums](https://wordpress.org/support/plugin/plausible-analytics) - for all users

Expand All @@ -45,25 +53,33 @@ This repository is not suitable for support. Please don't use GitHub issues for
- `plausible_analytics_settings`: Allows you to modify and/or force values for each of the plugin's settings.
- `plausible_load_js_in_footer`: Allows you to load the JS code snippet in the footer.
- `plausible_analytics_script_params`: Allows you to modify the `script` element, loading the Plausible JS library.
- Example: using this filter and the `file-types` attribute will allow you to track downloads of certain file types when File Downloads tracking is
- Example: using this filter and the `file-types` attribute will allow you to track downloads of certain file types
when File Downloads tracking is
enabled.
- `plausible_analytics_pageview_properties`: Allows you to add custom pageview properties when the Pageview Properties option is enabled under
Enhanced Measurements. For examples, read the [documentation on Pageview Properties](https://plausible.io/docs/custom-props/for-pageviews).
- `plausible_analytics_pageview_properties`: Allows you to add custom pageview properties when the Pageview Properties
option is enabled under
Enhanced Measurements. For examples, read
the [documentation on Pageview Properties](https://plausible.io/docs/custom-props/for-pageviews).

### Actions

- `plausible_analytics_settings_saved`: Trigger additional tasks directly after settings are saved.
- `plausible_analytics_after_register_assets`: This action allows you to trigger additional tasks or add custom JS (e.g. events) to the tracking code.
- `plausible_analytics_after_register_assets`: This action allows you to trigger additional tasks or add custom JS (e.g.
events) to the tracking code.

### Toggles

Using constants, you can modify the behavior of the plugin. `wp-config.php` is the best place to define constants. If you're using a custom plugin,
Using constants, you can modify the behavior of the plugin. `wp-config.php` is the best place to define constants. If
you're using a custom plugin,
make sure its code is loaded before this plugin.

- `PLAUSIBLE_SELF_HOSTED_DOMAIN`: Especially useful for Multisite instances using the self-hosted version of Plausible, this constant allows you to
specify the Self-Hosted Domain for all subsites at once. **IMPORTANT**: this constant takes precedence over the plugin's setting. So, if this
- `PLAUSIBLE_SELF_HOSTED_DOMAIN`: Especially useful for Multisite instances using the self-hosted version of Plausible,
this constant allows you to
specify the Self-Hosted Domain for all subsites at once. **IMPORTANT**: this constant takes precedence over the
plugin's setting. So, if this
constant is defined, changing the setting won't have any effect.
- `plausible_proxy`: Appending this `GET`-parameter will force enable the proxy on the page you\'re calling it. This will allow you to test your proxy
- `plausible_proxy`: Appending this `GET`-parameter will force enable the proxy on the page you\'re calling it. This
will allow you to test your proxy
in the frontend, before enabling the option.

## Local Development
Expand All @@ -83,15 +99,17 @@ That's it. You're now ready to start development.

Plausible Analytics relies on several npm commands to get you started:

* `npm run watch` - Live reloads JS and SASS files. Typically, you'll run this command before you start development. It's necessary to build the
* `npm run watch` - Live reloads JS and SASS files. Typically, you'll run this command before you start development.
It's necessary to build the
JS/CSS
however if you're working strictly within PHP it may not be necessary to run.
* `npm run dev` - Runs a one time build for development. No production files are created.
* `npm run production` - Builds the minified production files for release.

### Development Notes

* Ensure that you have `SCRIPT_DEBUG` enabled within your wp-config.php file. Here's a good example of wp-config.php for debugging:
* Ensure that you have `SCRIPT_DEBUG` enabled within your wp-config.php file. Here's a good example of wp-config.php for
debugging:
```
// Enable WP_DEBUG mode
define( 'WP_DEBUG', true );
Expand All @@ -103,21 +121,27 @@ Plausible Analytics relies on several npm commands to get you started:
define( 'SCRIPT_DEBUG', true );
```
* Commit the `package.lock` file. Read more about why [here](https://docs.npmjs.com/files/package-lock.json).
* Your editor should recognize the `.eslintrc` and `.editorconfig` files within the Repo's root directory. Please only submit PRs following those
* Your editor should recognize the `.eslintrc` and `.editorconfig` files within the Repo's root directory. Please only
submit PRs following those
coding style rulesets.

### Regenerating the OpenAPI PHP Client

This plugin uses a OpenAPI PHP Client which is autogenerated by the OpenAPI generator to reduce contract violations, etc. to a minimum. But, since
this is a WordPress plugin, some manual modifications need to be done to make sure it doesn't conflict with other plugins:
This plugin uses a OpenAPI PHP Client which is autogenerated by the OpenAPI generator to reduce contract violations,
etc. to a minimum. But, since
this is a WordPress plugin, some manual modifications need to be done to make sure it doesn't conflict with other
plugins:

- (Re)generate the PHP client using the following command (trigger it from the Plugin's root dir as output will be saved to `src/Client`):
- (Re)generate the PHP client using the following command (trigger it from the Plugin's root dir as output will be saved
to `src/Client`):
`openapi-generator-cli generate -i https://plausible.io/api/plugins/spec/openapi -g php -o src/Client --additional-properties=identifierNamingConvention=snake_case,invokerPackage="Plausible\\Analytics\\WP\\Client" --global-property=apis,models,supportingFiles,modelDocs=false,modelTests=false,apiDocs=false,apiTests=false`
- (When regenerating the PHP client this step can be skipped) Navigate to the `src/Client` director and install Composer
dependencies: `composer install --no-dev`
- (When regenerating the PHP client this step can be skipped) Run `mozart compose` from the `src/Client` directory (Make sure Mozart is installed
- (When regenerating the PHP client this step can be skipped) Run `mozart compose` from the `src/Client` directory (Make
sure Mozart is installed
globally)
- In the `src/Client/lib` directory, replace all occurrences of ` GuzzleHttp` (mind the space) with ` Plausible\Analytics\WP\Client\Lib\GuzzleHttp` (
- In the `src/Client/lib` directory, replace all occurrences of ` GuzzleHttp` (mind the space) with
` Plausible\Analytics\WP\Client\Lib\GuzzleHttp` (
again, mind the space at the beginning)
- In the same directory, replace all occurrences of ` \GuzzleHttp` (mind the space and backslash)
with ` \Plausible\Analytics\WP\Client\Lib\GuzzleHttp`.
Expand Down
43 changes: 40 additions & 3 deletions assets/src/js/admin/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ document.addEventListener('DOMContentLoaded', () => {
*
* @param e
*/
toggleOption: function (e) {
toggleOption: async function (e) {
/**
* Make sure event target is a toggle.
*/
Expand All @@ -109,11 +109,13 @@ document.addEventListener('DOMContentLoaded', () => {
// Toggle: off
button.classList.replace('bg-indigo-600', 'bg-gray-200');
toggle.classList.replace('translate-x-5', 'translate-x-0');
button.dataset.status = 'off';
toggleStatus = '';
} else {
// Toggle: on
button.classList.replace('bg-gray-200', 'bg-indigo-600');
toggle.classList.replace('translate-x-0', 'translate-x-5');
button.dataset.status = 'on';
toggleStatus = 'on';
}

Expand All @@ -126,7 +128,13 @@ document.addEventListener('DOMContentLoaded', () => {
form.append('is_list', button.dataset.list);
form.append('_nonce', plausible.nonce);

plausible.ajax(form);
let data = await plausible.ajax(form);

if (data.capabilities === undefined) {
return;
}

plausible.maybeDisableOptions(data.capabilities);
},

/**
Expand Down Expand Up @@ -160,6 +168,33 @@ document.addEventListener('DOMContentLoaded', () => {
plausible.ajax(form, button);
},

/**
* Disable options based on the capabilities retrieved from the API.
*
* @param capabilities
*/
maybeDisableOptions: function (capabilities) {
let options = document.querySelectorAll('button[data-caps]');

options.forEach(function (option) {
let caps = option.dataset.caps.split(',');
let disable = false;

caps.forEach(function (cap) {
if (capabilities[cap] === false) {
disable = true;
}
});

if (disable === true) {
// Trigger a click to make sure the option is disabled.
if (option.dataset.status === 'on') {
option.dispatchEvent(new Event('click', {bubbles: true}));
}
}
});
},

/**
* Currently only validates the domain_name input, but can be used in the future for other custom input validations.
*
Expand Down Expand Up @@ -375,7 +410,8 @@ document.addEventListener('DOMContentLoaded', () => {
}
}

if (response.status === 200) {
// We still want the data, if it's a Payment Required error.
if (response.status === 200 || response.status === 402) {
return response.json();
}

Expand Down Expand Up @@ -478,6 +514,7 @@ document.addEventListener('DOMContentLoaded', () => {
}, 2000);
}
},

/**
* Renders a HTML box containing additional information about the enabled option.
*
Expand Down
Loading