From 295523457fdc982b9ef2dc96aa454d27e9e8174d Mon Sep 17 00:00:00 2001 From: Jari Turkia Date: Mon, 3 Jun 2024 21:52:50 +0300 Subject: [PATCH] bugfix: When not adding tracking counters, return a proper link --- .../serendipity_event_google_analytics.php | 23 ++++++++++++++----- 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/serendipity_event_google_analytics/serendipity_event_google_analytics.php b/serendipity_event_google_analytics/serendipity_event_google_analytics.php index c27596733..8e6666eb8 100644 --- a/serendipity_event_google_analytics/serendipity_event_google_analytics.php +++ b/serendipity_event_google_analytics/serendipity_event_google_analytics.php @@ -154,7 +154,7 @@ function gtag() { !$markupDisabledConfig && !$markupDisabledPost) { $element = $element['element']; $eventData[$element] = preg_replace_callback( - "#]*)>#isUm", + "#]*)>#isUm", array($this, 'analytics_tracker_callback'), $eventData[$element] ); @@ -162,21 +162,32 @@ function gtag() { } return true; - default : + default: return false; } // end switch ($event) { } + /** + * matches: + * 0 = entire regexp match + * 1 = anything between "" + */ function analytics_tracker_callback($matches) { - $parsed_url = parse_url($matches[3].$matches[4]); + $parsed_url = parse_url($matches[2].$matches[3]); + + // Skip tracking for local URLs without scheme, or unknown scheme. if (!isset($parsed_url["scheme"])) - return; + return $matches[0]; if (!in_array($parsed_url["scheme"], array("http", "https"))) - return; + return $matches[0]; + // Note: Assume, there is no second onclick-event in substr($matches[0], 2) return '