=== Interaction-Delayed Scripts ===
Contributors: contentpowered
Author: Content Powered
Author URI: https://www.contentpowered.com/wordpress-plugins/
Plugin URI: https://www.contentpowered.com
Tags: delay javascript, pagespeed, performance, google analytics, third-party scripts
Requires at least: 5.8
Tested up to: 7.1
Requires PHP: 7.2
License: GPL-2.0-or-later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Holds back the third-party scripts you choose (analytics, pixels, chat widgets) until a visitor scrolls, clicks, taps or types, so pages load faster.

== Description ==

Analytics, ad pixels, chat widgets and embeds are some of the heaviest things on a page, and most of them don't need to load until someone actually uses the page. Interaction-Delayed Scripts holds back the scripts you choose until the visitor scrolls, clicks, taps, types or moves the mouse, then runs them in their original order. Pages load and become usable sooner, and PageSpeed Insights stops counting those scripts against you.

There are two ways to choose what waits:

* **Paste a snippet.** Paste the code a service gives you (Google Analytics, Google Tag Manager, Meta Pixel, Hotjar, Microsoft Clarity, a chat widget) into the Snippets tab, script tags and all. It's added to every page and held back until the visitor interacts.
* **Pick from your site.** Click Scan page and the plugin lists every script on that page, from other websites and from your theme and plugins, each with a Delay switch. Known services are labeled, and scripts that should load right away (cookie consent, payments, captchas, jQuery) carry a warning.

You can also add keywords: any script whose address or code contains one is delayed too, on every page.

= Features =

* Delayed scripts run one at a time in page order, so a script that needs another one still finds it.
* A WordPress script is delayed together with its settings and with the scripts that depend on it.
* Scripts that wait for the page to finish loading still get their "ready" and "load" events.
* Test mode: only logged-in administrators get delayed scripts, until you're happy.
* An optional timeout loads everything anyway a few seconds after the page loads, so analytics still count visitors who never interact.
* Skip pages such as the checkout, with * for "anything".
* Add ?nodelay to any address to see the page without delays.
* Cookie consent tools, JSON-LD and other non-JavaScript scripts are never touched.
* Saving clears your page cache (WP Rocket, LiteSpeed, W3 Total Cache, WP Super Cache, SiteGround and more).
* Nothing is delayed in the admin, the Customizer, page builder editors, AMP pages or feeds.

Find it under Content Powered > Interaction-Delayed Scripts in the admin menu.

Found a bug or have an idea? Use Content Powered > Report a Bug or Content Powered > Submit Feedback to send it straight to us.

= Credits =

* Icons by [Lucide](https://lucide.dev), used under the ISC License. Icons derived from [Feather](https://feathericons.com) are under the MIT License. The full license text is in `icons/LICENSE`.
* Updates delivered by [Plugin Update Checker](https://github.com/YahnisElsts/plugin-update-checker) by Janis Elsts, MIT License.

== Installation ==

1. Upload the `interaction-delayed-scripts` folder to `/wp-content/plugins/`.
2. Activate the plugin through the Plugins screen in WordPress.
3. Go to Content Powered > Interaction-Delayed Scripts. Paste your tracking snippets under Snippets, or click Scan page under Scripts and switch on the scripts that can wait.
4. Check your site, then test it with PageSpeed Insights. Test mode under Settings lets you try it as an administrator first.

Updates arrive through the normal WordPress Updates screen, and you can turn on auto-updates from the Plugins screen.

== Frequently Asked Questions ==

= Which scripts should I delay? =

Scripts from other websites that nobody needs the moment the page appears: analytics, ad and social pixels, heatmaps, chat widgets, video and social embeds, review widgets. Leave cookie consent, payment forms, captchas and your site's own menus and sliders alone unless you've tested them delayed. The scan marks the risky ones.

= Will my analytics still count visitors? =

A visit counts once the analytics script runs, which is the first time the visitor scrolls, taps, clicks, types or moves the mouse. Almost every real visitor does. Visitors who leave without touching the page aren't counted; set "Load anyway after" under Settings to catch them too.

= How is this different from defer or async? =

Deferred and async scripts still download and run while the page loads, and PageSpeed Insights counts them. Delayed scripts don't download or run at all until the visitor interacts, which PageSpeed Insights never does.

= Does it work with WP Rocket, LiteSpeed Cache and other caching plugins? =

Yes. Page caches store the page with the scripts already delayed, and saving the plugin's settings clears them. If another plugin is set to delay JavaScript too, the plugin's page says so: they can run side by side, as long as the same script isn't delayed in both.

= How do I check it's working? =

Open your site in a private window and look at the page source: delayed scripts have type="interaction-delayed". Or open the browser's developer tools, watch the Network tab, and move the mouse. Add ?nodelay to the address to compare with the page as it was.

= Something stopped working. What do I do? =

Switch that script off under Scripts (or remove the keyword that matches it) and save. If you're not sure which one it is, turn Delaying off under Settings: everything loads straight away again, and your choices are kept.

== Changelog ==

See https://github.com/jmsprsns/interaction-delayed-scripts/releases for the full release history.
