Skip to content

Feature Request: Add filter to load tracker from an alternative URL #4107

@jblz

Description

@jblz

Is your feature request related to a problem?

The tracker script URL is currently hardcoded in Parsely::get_tracker_url():

$tracker_url = 'https://cdn.parsely.com/keys/' . $this->get_site_id() . '/p.js';

There is no supported way to override this URL. Publishers who serve the Parse.ly tracker in a non-standard manner currently have no clean option — they must either suppress the built-in tracker entirely via wp_parsely_load_js_tracker and re-enqueue it manually, or use the generic WordPress script_loader_src filter as a workaround. Neither is a great solution.

Describe the solution you'd like

GUI

Add a text box on the Advanced tab of the settings page. It's used instead of the default if specified.
Include appropriately prominent disclaimers.

Code-based

Add a wp_parsely_tracker_url filter to get_tracker_url(), consistent with the plugin's existing filter conventions:

public function get_tracker_url(): string {
    if ( $this->site_id_is_set() ) {
        $tracker_url = 'https://cdn.parsely.com/keys/' . $this->get_site_id() . '/p.js';

        /**
         * Filters the URL of the Parse.ly tracker script.
         *
         * @since TBD
         *
         * @param string $tracker_url The URL of the tracker script.
         */
        return esc_url( apply_filters( 'wp_parsely_tracker_url', $tracker_url ) );
    }
    return '';
}

This would allow publishers to override the URL cleanly:

add_filter( 'wp_parsely_tracker_url', function( string $url ): string {
    return 'https://my-first-party-cdn.example.com/p.js';
} );

The filter, if added, takes precedence over the option set by the GUI

Describe alternatives you've considered

  • Using script_loader_src to intercept the registered script — works but is indirect and fragile.
  • Using wp_parsely_load_js_tracker to suppress the built-in tracker and re-enqueuing manually — works but requires the implementor to also replicate the data-parsely-site attribute and id="parsely-cfg" tag mutations, as well as re-enqueuing wp-parsely-loader.

Metadata

Metadata

Assignees

Labels

EnhancementTicket that requests an enhancement to an existing featurewp-parselyRequired label for all issues

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions