From d0168b290ba6e0691cb447a56f01a4bfcf22f6fd Mon Sep 17 00:00:00 2001
From: Daan van den Bergh <18595395+Dan0sz@users.noreply.github.com>
Date: Mon, 8 Dec 2025 13:47:14 +0100
Subject: [PATCH 1/7] Added: track query params enhanced measurement option.
---
src/Admin/Settings/Page.php | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)
diff --git a/src/Admin/Settings/Page.php b/src/Admin/Settings/Page.php
index 8515f9b..cbe2f9b 100644
--- a/src/Admin/Settings/Page.php
+++ b/src/Admin/Settings/Page.php
@@ -221,6 +221,28 @@ public function __construct() {
'value' => 'user-logged-in',
'caps' => [ self::CAP_PROPS ],
],
+ 'query-params' => [
+ 'label' => esc_html__( 'Query parameters', 'plausible-analytics' ),
+ 'docs' => 'https://plausible.io/wordpress-analytics-plugin#how-to-track-query-parameters',
+ 'slug' => 'enhanced_measurements',
+ 'type' => 'checkbox',
+ 'value' => 'query-params',
+ 'addtl_opts' => true,
+ 'caps' => [ self::CAP_PROPS ],
+ ],
+ 'query-params-patterns' => [
+ 'slug' => 'query_params',
+ 'description' => sprintf(
+ __(
+ 'Enter the query parameters you\'d like to track. E.g. enter lang if you want to track %s.',
+ 'plausible-analytics'
+ ),
+ get_home_url() . '?lang=en'
+ ),
+ 'type' => 'clonable_text',
+ 'value' => Helpers::get_settings()['query-params'] ?? [],
+ 'hidden' => ! Helpers::is_enhanced_measurement_enabled( 'query-params' ),
+ ],
'search' => [
'label' => esc_html__( 'Search queries', 'plausible-analytics' ),
'docs' => 'https://plausible.io/wordpress-analytics-plugin#how-to-enable-site-search-tracking',
From 19f8b003e6798c7806b5ade1ceca973cf0b3a275 Mon Sep 17 00:00:00 2001
From: Daan van den Bergh <18595395+Dan0sz@users.noreply.github.com>
Date: Mon, 8 Dec 2025 14:03:12 +0100
Subject: [PATCH 2/7] Updated link.
---
src/Admin/Settings/Page.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/Admin/Settings/Page.php b/src/Admin/Settings/Page.php
index cbe2f9b..ed86c69 100644
--- a/src/Admin/Settings/Page.php
+++ b/src/Admin/Settings/Page.php
@@ -223,7 +223,7 @@ public function __construct() {
],
'query-params' => [
'label' => esc_html__( 'Query parameters', 'plausible-analytics' ),
- 'docs' => 'https://plausible.io/wordpress-analytics-plugin#how-to-track-query-parameters',
+ 'docs' => 'https://plausible.io/wordpress-analytics-plugin#how-to-track-custom-query-parameters',
'slug' => 'enhanced_measurements',
'type' => 'checkbox',
'value' => 'query-params',
From 014598b6dee72bcc503904097b0dae2b4f55ac7d Mon Sep 17 00:00:00 2001
From: Daan van den Bergh <18595395+Dan0sz@users.noreply.github.com>
Date: Mon, 8 Dec 2025 14:19:17 +0100
Subject: [PATCH 3/7] Typo.
---
src/Admin/Settings/Page.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/Admin/Settings/Page.php b/src/Admin/Settings/Page.php
index ed86c69..6a612ee 100644
--- a/src/Admin/Settings/Page.php
+++ b/src/Admin/Settings/Page.php
@@ -240,7 +240,7 @@ public function __construct() {
get_home_url() . '?lang=en'
),
'type' => 'clonable_text',
- 'value' => Helpers::get_settings()['query-params'] ?? [],
+ 'value' => Helpers::get_settings()['query_params'] ?? [],
'hidden' => ! Helpers::is_enhanced_measurement_enabled( 'query-params' ),
],
'search' => [
From 84a1daae628b274f3dc6ae440b8553998258adb0 Mon Sep 17 00:00:00 2001
From: Daan van den Bergh <18595395+Dan0sz@users.noreply.github.com>
Date: Mon, 8 Dec 2025 15:05:52 +0100
Subject: [PATCH 4/7] Added auto provisioning for Query Params option.
---
src/Actions.php | 28 +++++++++++++++++++++++++++-
src/Admin/Provisioning.php | 13 ++++++++++++-
2 files changed, 39 insertions(+), 2 deletions(-)
diff --git a/src/Actions.php b/src/Actions.php
index 36d8648..addd219 100644
--- a/src/Actions.php
+++ b/src/Actions.php
@@ -130,6 +130,32 @@ public function maybe_register_assets() {
);
}
+ if ( Helpers::is_enhanced_measurement_enabled( 'query-params' ) ) {
+ $query_params = Helpers::get_settings()['query_params'] ?? [];
+ $props = [];
+
+ foreach ( $query_params as $query_param ) {
+ if ( isset( $_REQUEST[ $query_param ] ) ) {
+ $props[ $query_param ] = $_REQUEST[ $query_param ];
+ }
+ }
+
+ if ( ! empty( $props ) ) {
+ $data = wp_json_encode(
+ [
+ 'props' => $props,
+ ]
+ );
+
+ $script = "plausible('Query Parameters', $data );";
+
+ wp_add_inline_script(
+ 'plausible-analytics',
+ "document.addEventListener('DOMContentLoaded', function() {\n$script\n});"
+ );
+ }
+ }
+
// Track search results. Tracks a search event with the search term and the number of results, and a pageview with the site's search URL.
if ( Helpers::is_enhanced_measurement_enabled( 'search' ) && is_search() ) {
global $wp_query;
@@ -138,7 +164,7 @@ public function maybe_register_assets() {
$data = wp_json_encode(
[
'props' => [
- // convert queries to lowercase and remove trailing whitespace to ensure same terms are grouped together
+ // convert queries to lowercase and remove trailing whitespace to ensure the same terms are grouped together
'search_query' => strtolower( trim( get_search_query() ) ),
'result_count' => $wp_query->found_posts,
'search_source' => $search_source,
diff --git a/src/Admin/Provisioning.php b/src/Admin/Provisioning.php
index 112889b..e06d8fb 100644
--- a/src/Admin/Provisioning.php
+++ b/src/Admin/Provisioning.php
@@ -91,6 +91,7 @@ public function __construct( $client = null ) {
'file-downloads' => __( 'File Download', 'plausible-analytics' ),
'form-completions' => __( 'WP Form Completions', 'plausible-analytics' ),
'outbound-links' => __( 'Outbound Link: Click', 'plausible-analytics' ),
+ 'query-params' => __( 'Query Parameters', 'plausible-analytics' ),
'search' => __( 'WP Search Queries', 'plausible-analytics' ),
];
@@ -334,7 +335,8 @@ public function maybe_create_custom_properties( $old_settings, $settings ) {
if ( ! Helpers::is_enhanced_measurement_enabled( 'pageview-props', $enhanced_measurements ) &&
! Helpers::is_enhanced_measurement_enabled( 'revenue', $enhanced_measurements ) &&
- ! Helpers::is_enhanced_measurement_enabled( 'search', $enhanced_measurements ) ) {
+ ! Helpers::is_enhanced_measurement_enabled( 'search', $enhanced_measurements ) &&
+ ! Helpers::is_enhanced_measurement_enabled( 'query-params', $enhanced_measurements ) ) {
return; // @codeCoverageIgnore
}
@@ -359,6 +361,15 @@ public function maybe_create_custom_properties( $old_settings, $settings ) {
}
}
+ /**
+ * Create Custom Properties for Query Parameters option.
+ */
+ if ( Helpers::is_enhanced_measurement_enabled( 'query-params', $enhanced_measurements ) ) {
+ foreach ( Helpers::get_settings()['query_params'] ?? [] as $query_param ) {
+ $properties[] = new Client\Model\CustomProp( [ 'custom_prop' => [ 'key' => $query_param ] ] );
+ }
+ }
+
/**
* Create Custom Properties for Search Queries option.
*/
From 62dd6422502b6154df94a58be30744db755bbbb0 Mon Sep 17 00:00:00 2001
From: Daan van den Bergh <18595395+Dan0sz@users.noreply.github.com>
Date: Mon, 8 Dec 2025 15:27:34 +0100
Subject: [PATCH 5/7] Renamed event to WP Query Parameters.
---
src/Admin/Provisioning.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/Admin/Provisioning.php b/src/Admin/Provisioning.php
index e06d8fb..367f5be 100644
--- a/src/Admin/Provisioning.php
+++ b/src/Admin/Provisioning.php
@@ -91,7 +91,7 @@ public function __construct( $client = null ) {
'file-downloads' => __( 'File Download', 'plausible-analytics' ),
'form-completions' => __( 'WP Form Completions', 'plausible-analytics' ),
'outbound-links' => __( 'Outbound Link: Click', 'plausible-analytics' ),
- 'query-params' => __( 'Query Parameters', 'plausible-analytics' ),
+ 'query-params' => __( 'WP Query Parameters', 'plausible-analytics' ),
'search' => __( 'WP Search Queries', 'plausible-analytics' ),
];
From 1784b429c7510178e981f610010a147a784e8bb1 Mon Sep 17 00:00:00 2001
From: Daan van den Bergh <18595395+Dan0sz@users.noreply.github.com>
Date: Mon, 8 Dec 2025 16:01:18 +0100
Subject: [PATCH 6/7] Renamed event to WP Query Parameters.
---
src/Actions.php | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/src/Actions.php b/src/Actions.php
index addd219..0c2bcae 100644
--- a/src/Actions.php
+++ b/src/Actions.php
@@ -130,6 +130,7 @@ public function maybe_register_assets() {
);
}
+ // Track query parameters (if enabled and set)
if ( Helpers::is_enhanced_measurement_enabled( 'query-params' ) ) {
$query_params = Helpers::get_settings()['query_params'] ?? [];
$props = [];
@@ -147,7 +148,7 @@ public function maybe_register_assets() {
]
);
- $script = "plausible('Query Parameters', $data );";
+ $script = "plausible('WP Query Parameters', $data );";
wp_add_inline_script(
'plausible-analytics',
From eb0c6ff5c5dfcc44df1a0c970c9991b8f6e9ca3e Mon Sep 17 00:00:00 2001
From: Daan van den Bergh <18595395+Dan0sz@users.noreply.github.com>
Date: Mon, 8 Dec 2025 16:01:40 +0100
Subject: [PATCH 7/7] Typo.
---
src/Actions.php | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/Actions.php b/src/Actions.php
index 0c2bcae..2e9dbf4 100644
--- a/src/Actions.php
+++ b/src/Actions.php
@@ -152,7 +152,7 @@ public function maybe_register_assets() {
wp_add_inline_script(
'plausible-analytics',
- "document.addEventListener('DOMContentLoaded', function() {\n$script\n});"
+ "document.addEventListener('DOMContentLoaded', function () {\n$script\n});"
);
}
}
@@ -176,7 +176,7 @@ public function maybe_register_assets() {
wp_add_inline_script(
'plausible-analytics',
- "document.addEventListener('DOMContentLoaded', function() {\n$script\n});"
+ "document.addEventListener('DOMContentLoaded', function () {\n$script\n});"
);
}