Auto-detection uses a MutationObserver to watch the DOM for newly added widget elements. When a widget element is added dynamically — for example, by a SPA router, a content management system rendering blocks on the fly, or an AJAX request — the SDK automatically detects it and loads the corresponding widget bundle without any extra code on your part.Documentation Index
Fetch the complete documentation index at: https://docs.tally.site/llms.txt
Use this file to discover all available pages before exploring further.
When to use auto-detection
Auto-detection is most useful when:- Your page is a single-page application built with React, Vue, Angular, or a similar framework, and widget elements are injected by the router or component lifecycle.
- Content is loaded dynamically via AJAX after the initial page render.
- A CMS or page builder injects widget elements asynchronously.
Enable auto-detection
You can enable auto-detection in three ways.Method 1: Script tag attribute
Adddata-tallysight-observer="true" to the SDK <script> tag. This enables the MutationObserver immediately when the SDK initializes.
Method 2: enableAutoDetection()
Call Tallysight.enableAutoDetection() after the SDK is ready. This returns the Tallysight object so you can chain additional calls.
Method 3: Tallysight.configure()
Pass autoDetect: true via configure(). This is useful when you want to configure multiple settings together.
Disable auto-detection
To stop watching for new widget elements, calldisableAutoDetection(). This removes the MutationObserver and stops the SDK from automatically loading any widgets added to the DOM after the call.
Example: adding a widget element dynamically
The following example creates a widget element with JavaScript, adds it to the DOM, and lets auto-detection handle loading the bundle. No manual call toscan() or loadWidget() is needed.
Alternative: manual scan
If auto-detection is not enabled, you can trigger widget loading manually by callingTallysight.scan() after adding widget elements to the DOM. Pass a CSS selector to limit the scan to a specific container and avoid re-scanning the entire document.