Skip to content

Support global config object as alternative to data-* attributes #4177

@julianwitzel

Description

@julianwitzel

Feature Request: Global Config Object for Tracker Configuration

Summary

Add support for a global JavaScript configuration object (e.g. window.umamiConfig) as an alternative to data-* attributes for configuring the Umami tracker script.

Motivation

We are building a Google Tag Manager (GTM) Custom Template for Umami Analytics to make it easier for non-technical users to install and configure Umami via GTM.

However, GTM's sandboxed template environment strips custom data-* attributes from injected script tags. This is a known GTM limitation and the reason why Umami's own documentation already recommends using document.createElement with setAttribute as a workaround for GTM Custom HTML Tags.

While this works for Custom HTML Tags, it is not possible in GTM Custom Templates due to sandbox restrictions. GTM Templates have access to setInWindow which can set global variables before a script loads – but only if the tracker reads its configuration from a global object.

Proposed Solution

Support a global config object that the tracker reads on initialization, for example:

window.umamiConfig = {
  websiteId: '94db1cb1-74f4-4a40-ad6c-962362670409',
  hostUrl: 'https://stats.mywebsite.com',
  autoTrack: true,
  domains: ['mywebsite.com'],
  tag: 'homepage-layout-a'
};

The tracker would check for window.umamiConfig on load and use these values as fallbacks or overrides for data-* attributes.

Impact

This would enable a fully functional GTM Custom Template for Umami, making it significantly easier to:

  • Install Umami via GTM without touching the site's HTML
  • Configure all tracker options through the GTM UI
  • Support self-hosted Umami instances with dynamic URLs

Alternative Considered

Using data-* attributes directly – not possible in GTM Custom Templates due to sandbox restrictions.

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions