Skip to content

Commit 552f5d1

Browse files
jeffreyvrclaude
andcommitted
Match result clicks by rank map, guard empty permalinks
Result clicks are attributed via the interceptor's permalink→rank map rather than a guessed results container, so themes that render links outside #primary/main still report. Skips permalinks that come back empty/non-string when building the map. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent e212605 commit 552f5d1

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

src/Search/ClickTracking.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
* results; events go straight to the Datalumo API through the SDK,
1212
* tagged with the search session the interceptor's API call returned so
1313
* each click ties back to the query that produced it.
14+
*
15+
* Result clicks are matched against the interceptor's permalink→rank map
16+
* (not a guessed results container), so theme markup that puts links
17+
* outside #primary / main still reports.
1418
*/
1519
class ClickTracking
1620
{

src/Search/Interceptor.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,17 @@ public function intercept(?array $posts, WP_Query $query): ?array
7777
$pool = $this->reorder($pool, $query);
7878

7979
// Zero-based, matching the widget SDK's wire convention — the
80-
// dashboard renders ranks as #rank+1.
80+
// dashboard renders ranks as #rank+1. Keys are the absolute
81+
// permalinks themes render; the browser-side matcher normalises
82+
// trailing slashes / encoding before comparing.
8183
$ranks = [];
8284

8385
foreach ($pool as $index => $post) {
84-
$ranks[get_permalink($post)] = $index;
86+
$permalink = get_permalink($post);
87+
88+
if (is_string($permalink) && $permalink !== '') {
89+
$ranks[$permalink] = $index;
90+
}
8591
}
8692

8793
self::$lastSearch = [

0 commit comments

Comments
 (0)