• Resolved Ivan Privalov

    (@ivanpr)


    I attempted to use the new caos_local_file_url filter, but it only changes the URL of the GA JavaScript in the code and does not affect where the GA file is downloaded. This makes the filter useless.

    We need a way to manually specify the path and the constant filename of the downloaded script.

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author DaanvandenBergh

    (@daanvandenbergh)

    I’m guessing what you need is the cache directory option under Advanced Settings?

    Thread Starter Ivan Privalov

    (@ivanpr)

    We need a way to manually specify the path and the constant filename of the downloaded script.

    Plugin Author DaanvandenBergh

    (@daanvandenbergh)

    Thanks for repeating your last sentence.

    Can you share a use case with me, so I can come up with a proper solution?

    Thread Starter Ivan Privalov

    (@ivanpr)

    Currently the caos_local_file_url filter only changes the URL of the GA JavaScript’s path+filename in the output code but does not affect where the downloaded GA file is actually stored [why would I want to modify the path+filename if it is never created there].

    I would expect to be able to specify the stable [non-dynamic] path+filename of the CAOS-updated GA library with this filter:

    add_filter(‘caos_local_file_url’, ‘caos_local_file_url’);
    function caos_local_file_url($url) {
    return content_url() . ‘/uploads/caos/ga4.js’;
    }

    In this case this downloaded GA is then used by the other local products outside the WordPress.

    Plugin Author DaanvandenBergh

    (@daanvandenbergh)

    Hi again,

    You can try this beta: https://we.tl/t-0xzUQtOPPX

    It contains two new filters:

    • caos_local_dir: which allows you to set the absolute path to CAOS local dir.
    • caos_file_alias: which allows you to set the filename. It’s applied globally.

    This is untested, so if you run into anything, let me know!

    Thread Starter Ivan Privalov

    (@ivanpr)

    Hello Daan, the add_filter(‘caos_local_dir’, ‘theme_caos_local_dir’); creates no folder and even if the folder was manually created, the filter does not save the file if I set it to, say:
    function wpo_caos_local_dir($path) {
    return content_url() . ‘/ga4/’;
    }

    At the same it does shoot an error if I miss the ending slash with:
    return content_url() . ‘/ga4’;


    BUT since this filter actually duplicates the ‘Cache directory for Gtag.js’ plugin setting I see no reason to use it anyway.


    I therefore specified the directory path using the plugin’s settings and simply used the following filter to manually and permanently specify the filename of the downloaded library that is then served in the code and used by subdomains:

    add_filter(‘caos_file_alias’, ‘wpo_caos_file_alias’);
    function wpo_caos_file_alias($filename) {
    ? return ‘ga4.js’;
    }

    Thread Starter Ivan Privalov

    (@ivanpr)

    One other thing, I expected those filters to affect the output out of the box and did not know I was supposed to Save the plugin settings OR Regenerate Alias(es) in order to generate the script’s copy with the new filename.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘caos_local_file_url filter’ is closed to new replies.