Support » Plugin: Site Kit by Google - Analytics, Search Console, AdSense, Speed » Conflict for logged-in users on front end: loader.js

  • Site Kit loads your loader.js script for logged-in users viewing their front end. This creates a conflict if the user’s page also needs loader.js to display a Google Chart viz. In my case calling loader.js twice prevents my Google Chart from displaying. (Note: This happens for logged-in users only, so not a problem for regular site-viewers. But not helpful for people composing posts who can’t see the charts.)

    Tested by removing my script call (while logged in) so only oe loader.js call (by Site Keit: Chart displays.

    Does Site Kit needs loader.js on the front end? If not, perhaps put the script call inside an is_admin().

    However, another potential conflict would be with plugins that use Google Charts (so call loader.js).

    In any case, stellar work on Site Kit. Many thanks.

    Your code that refers to loader.js is in the get_assets() method in /Core/Assets/Assets.php. And the output is:
    <script src='https://www.gstatic.com/charts/loader.js?ver=1.30.0' id='googlesitekit-google-charts-js'></script>

    The page I need help with: [log in to see the link]

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Support James Osborne

    (@jamesosborne)

    Hi there,

    Many thanks for the detailed support topic and valuable suggestions. While the loader.js file is requested via the Google charts library for logged in users this is used to display information based on the current active URL. It provide insights to administrators without having to visit your Site Kit dashboard, from the admin panel toolbar.

    You can also ensure these scripts don’t run by removing the Site Kit tab from the admin toolbar, using the below filter:
    add_filter( 'googlesitekit_show_admin_bar_menu', '__return_false', 1000 );

    Logged in users should also ideally have the “administrator” role in order for the Site Kit admin toolbar menu item to appear. From my testing since you opened this support topic I do see this toolbar appearing for the “Editor” role. I’ve therefore added this to the below GitHub issue, which we’re working on in relation to the editor role.
    https://github.com/google/site-kit-wp/issues/2938

    I’ll also pass your feedback on to the team in relation to this based on your analysis and report back to you here. Many thanks for your contributions! I’ll hopefully have some additional insights for you after discussing this with the team. Out of curiously what roles are you encountering these resources being loaded for, I assume editor roles?

    Thread Starter Barrett Golding

    (@hearvox)

    The filter works great, thx. I forgot about that nice Site Kit in-page/active-URL data feature: makes sense you need loader.js for that.

    To answer your question, I was in Admin and Editor roles when observing the issue. Removing the script for Editor role (but leaving for Admin) would work well for me and, I suspect, most WP sites.

    As a more comprehensive fix: I wonder if there’s some very uniquely named var in loader.js which I, or maybe Site Kit, could test for in a wrapper that calls loader.js in? Similar to other libraries, like if (window.jQuery). (Come to think of it: if your loader.js uses the WP enqueue, I can use its handle to test whether it’s loaded.)

    Plugin Support James Osborne

    (@jamesosborne)

    No problem at all. If you want to fork the Site Kit plugin to test any changes feel free to do so from the plugins GitHub repository. I believe the loader.js is added via wp_add_inline_script, which you’ll find here. I’m happy to follow up with the team if you wish for any questions on this.

    Note that once #2938 has been released this will ensure Site Kit resources are loaded for admin roles only. Apologies I never got back to you on this sooner. Mode details within the same GitHub issue.

    Plugin Support James Osborne

    (@jamesosborne)

    @hearvox Just to let you know we’ve release the latest version of Site Kit, 1.32.0. This release will ensure the resources you referenced load for admin only.

    Many thanks for bringing this to our attention, your contribution will benefit other non administrator users checking their site while logged in.

    Thread Starter Barrett Golding

    (@hearvox)

    Working, thanks. Resolved.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Conflict for logged-in users on front end: loader.js’ is closed to new replies.