• Resolved Ov3rfly

    (@ov3rfly)


    During testing with targeted loading feature enabled sometimes the JavaScript would not load on the Chat URL page.

    After a lot of investigation we found that in all those cases the page was called from external sites (social media, adwords etc.) with query parameters like utm_source or utm_campaign or similar.

    https://example.com/chat/ – JavaScript loads.

    https://example.com/chat/?utm_source=google – JavaScript does not load.

    Reason is in simple-ajax-chat.php in sac_enqueue_scripts():

    $current_url = esc_url_raw($protocol . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
    

    To decide about enqueuing $current_url is compared to targeted loading url(s). Problem is that $_SERVER['REQUEST_URI'] also contains the query string.

    We added some code (found at stackoverflow) to cut off the query string:

    $current_url = esc_url_raw($protocol . $_SERVER['HTTP_HOST'] . strtok( $_SERVER['REQUEST_URI'], '?' ) );
    

    Now targeted loading works as expected.

    Thanks for great plugin.

Viewing 1 replies (of 1 total)
  • Plugin Author Jeff Starr

    (@specialk)

    This bug is resolved in the upcoming version of the plugin, should be available before the WP v5.4 release. Thanks for reporting.

Viewing 1 replies (of 1 total)
  • The topic ‘Bug: Targeted loading of JavaScript fails if query params are present’ is closed to new replies.