Wordpress LScache Plugin: tracking code cache question
Last Updated on: Wed, 15 Apr 2026 00:00:02 We use Matomo (Piwik) on site to track analytics. A provided WordPress plugin connects to the script and inserts inline js in each page of our site. You can see the js on the test page around line 313. Since installing LiteSpeed, Ive seen some inconsistent results. It appears the tracking code gets cached, at least sometimes. A few times, when logging into a site as a user (Chrome), when opening a completely separate browser (Firefox), I was able to see the users username in the tracking code when viewing the page source (inside Firefox). But, I dont always get this result. Any suggestion for insuring this Matomo tracking code doesnt get cached (for example, so different users dont register as the same username in the tracking script)? I can edit the js the plugin inserts into WordPress. Ive seen data-no-optimize, but this seems more geared towards optimazation and not cache issues? Thank you for any suggestions. The page I need help with: https://www.lifeleap.org/blank-test/ Hi @andrew55, Can you show a sample of Matomo generated js script with the username when login for us? As the blank-test page already cached with non-logged-in version. Also, may I know the js code is inserted by the plugin or on the theme? Thanks, Stanley Here is a sample of script taken from view source with username intact: var _paq = _paq || [] / tracker methods like setCustomDimension should be called before trackPageView / _paq.push([setUserId, testuser2]) _paq.push([trackPageView]) _paq.push([enableLinkTracking]) (function() var u=https://www.visionrise.com/matomo/ _paq.push([setTrackerUrl, u+piwik.php]) _paq.push([setSiteId, 2]) var d=document, g=d.createElement(script), s=d.getElementsByTagName(script)[0] g.type=text/javascript g.async=true g.defer=true g.src=u+piwik.js s.parentNode.insertBefore(g,s) )() Also, I believe the js code is inserted into the theme by the Piwik/Matomo plugin: https://wordpress.org/plugins/wp-piwik/ Thank you for any help with this. Hi @andrwe55, As the script needs to insert the username inline by the plugin, you can insert the shortcodes with ESI and Enable ESI in LiteSpeed > Setting > ESI (Advance options): Heres the guideline: https://blog.litespeedtech.com/2018/12/12/wordpress-shortcodes-esi-blocks/ Thanks, Stanley The analytics tracking plugin inserts the javascript directly into the theme, so Im thinking shortcodes wont work. I can edit code in plugin admin just as I posted it before (I can edit the raw javascript tracking code). No Cache Tags might work great at enclosing the script, but I havet been able to find these for LiteSpeed. On a different note, I can enable the analytics tracking plugin to stop auto-inserting javascript, giving me the option to manually insert it. 1. Using above method, would you suggest I put the tracking javascript in a widget, set the widget to no ESI cache, and insert the widget into theme using Widgets On Pages plugin (using Insert In Headers And Footers plugin)? Or, is there another preferred method? 2. Also, does ESI work at preventing cache with browser cache, page cache, or both? Im asking because Ive been testing it with a widget and setting the Widget ESI TTL to 0 and Public . But the dynamic contents in the widget are still getting cached when I test it. Thanks for any help with this. Hi @andrew55, yes you can try to us (1) method with TTL 0 private ESI cache. Please test to see is it working or not. Heres the detail setting for Enabling and Configuring ESI from the LiteSpeed Plugin: https://www.litespeedtech.com/support/wiki/doku.php/litespeed_wiki:cache:lscwp:esi#creating_new_widget_esi_blocks For 2. ESI work for preventing server cache but not browser cache(but usually the browser will not cache WordPress except you have another setting). You can check the debug log to see is the page serving private ESI block. If you have difficulty on this issue you can join our Slack channel or submit a ticket here to discuss with us.
LiteCache Rush: Speed comes from using less, not from doing it faster
Reference