Conversation
#4107) Agent-Logs-Url: https://github.com/Parsely/wp-parsely/sessions/22d2bce4-6a8d-488c-b1b3-e3d432d609bd Co-authored-by: jblz <1587282+jblz@users.noreply.github.com>
|
@copilot let's only use the filter approach for now. Please remove the option mechanism for overriding the tracker URL and corresponding UI changes. Update tests as appropriate. |
…echanism Agent-Logs-Url: https://github.com/Parsely/wp-parsely/sessions/ca610bd9-6c90-41fb-a1c7-dd8800de6956 Co-authored-by: jblz <1587282+jblz@users.noreply.github.com>
Done in |
wp_parsely_tracker_url filter and Custom Tracker URL settingwp_parsely_tracker_url filter
|
I've switched Although this isn't a usage we expect, I've made the switch as a failsafe for any case. |
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
📝 WalkthroughWalkthroughThis PR adds a Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Suggested labels
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 PHPStan (2.1.46)Invalid configuration: Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
tests/Integration/OtherTest.php (1)
416-428: Strengthen the filter test by asserting input and removing the hook after assertion.This test proves override behavior, but it will be more deterministic if it also validates the incoming default URL and cleans up the callback.
Proposed test hardening patch.
public function test_get_tracker_url_filter(): void { self::set_options( array( 'apikey' => self::VALID_SITE_ID ) ); + $expected_default_url = 'https://cdn.parsely.com/keys/' . self::VALID_SITE_ID . '/p.js'; $custom_url = 'https://my-first-party-cdn.example.com/p.js'; + $callback = static function ( string $tracker_url ) use ( $custom_url, $expected_default_url ): string { + self::assertSame( $expected_default_url, $tracker_url ); + return $custom_url; + }; + add_filter( 'wp_parsely_tracker_url', - function () use ( $custom_url ): string { - return $custom_url; - } + $callback ); self::assertSame( $custom_url, self::$parsely->get_tracker_url() ); + remove_filter( 'wp_parsely_tracker_url', $callback ); }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@tests/Integration/OtherTest.php` around lines 416 - 428, The test test_get_tracker_url_filter should validate the default URL passed into the wp_parsely_tracker_url filter and clean up the hook afterwards: replace the simple add_filter callback with a closure that accepts the incoming $default (or $url) argument, assert that $default equals the expected default tracker URL (derived from using self::VALID_SITE_ID or by calling the code that produces the default), then return $custom_url; after calling self::$parsely->get_tracker_url(), remove the filter (remove_filter for 'wp_parsely_tracker_url' with the same closure or a named callback) so the filter does not leak into other tests.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@tests/Integration/OtherTest.php`:
- Around line 416-428: The test test_get_tracker_url_filter should validate the
default URL passed into the wp_parsely_tracker_url filter and clean up the hook
afterwards: replace the simple add_filter callback with a closure that accepts
the incoming $default (or $url) argument, assert that $default equals the
expected default tracker URL (derived from using self::VALID_SITE_ID or by
calling the code that produces the default), then return $custom_url; after
calling self::$parsely->get_tracker_url(), remove the filter (remove_filter for
'wp_parsely_tracker_url' with the same closure or a named callback) so the
filter does not leak into other tests.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 372e4cc2-3a92-43f6-88e0-26979e43ac1f
📒 Files selected for processing (2)
src/class-parsely.phptests/Integration/OtherTest.php
|
Thanks, @acicovic |
Description
Adds a
wp_parsely_tracker_urlfilter toget_tracker_url(), allowing publishers to programmatically override the Parse.ly tracker script URL.Changes
src/class-parsely.php: Updatedget_tracker_url()to apply thewp_parsely_tracker_urlfilter before returning the tracker URLtests/Integration/OtherTest.php: New integration test covering filter overrideUsage
Motivation and context
The tracker script URL is hardcoded to
https://cdn.parsely.com/keys/{site_id}/p.js. Publishers serving the tracker from a first-party domain had no clean override path — they had to suppress the built-in tracker viawp_parsely_load_js_trackerand re-enqueue manually (replicatingdata-parsely-site,id="parsely-cfg", and loader script), or use the fragilescript_loader_srcfilter.Fixes #4107.
How has this been tested?
test_get_tracker_url_filter) verifies the filter override works correctlytest_get_tracker_urlandtest_get_tracker_no_site_idremain unchanged and unaffectedSummary by CodeRabbit
New Features
Tests