Problem/Motivation

The Umami tracking script is currently loaded with async defer attributes directly in the HTML. While this is non-blocking, the browser still discovers and fetches the script during parsing, which means it appears in the critical request chain and can negatively impact page speed scores (e.g. Lighthouse, PageSpeed Insights).

Proposed resolution

Add a configurable "Script loading method" setting with two options:

  • Deferred (default) — Injects the tracking script dynamically via window.addEventListener('load', ...), so the script is only fetched after all page resources have finished loading. This keeps analytics completely out of the critical rendering path.
  • Async — Preserves the current async defer behavior for sites that prefer it.

Remaining tasks

  • New script_mode config key (default: onload)
  • Config schema and install config updated
  • Settings form: radio buttons with per-option descriptions
  • hook_page_attachments: conditional logic based on the selected mode
Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

pivica created an issue. See original summary.

pivica changed the visibility of the branch 3578404-add-configurable-script to hidden.

pivica changed the visibility of the branch 3578404-add-configurable-script to active.

  • pivica committed b6007883 on 2.x
    feat: #3578404 Add configurable script loading method to keep tracking...

  • pivica committed da62edd3 on 1.x
    feat: #3578404 Add configurable script loading method to keep tracking...
pivica’s picture

Status: Active » Fixed

Merged to both 2.x and 1.x.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.