Install
The Install controller handles the installation flow of a Progressive Web App (PWA). It listens for browser installation events, detects if the app is already installed, and provides an easy way to trigger the "Add to Home Screen" prompt when supported.
This component is essential for:
Providing a custom install button or banner
Detecting whether the app is already installed
Tracking installation events and user behavior
Creating a seamless installation experience
Showing/hiding install prompts based on installation status
Browser Support
The installation prompt API (beforeinstallprompt event) is supported in Chromium-based browsers (Chrome, Edge, Opera). Other browsers may use different installation mechanisms. The controller gracefully handles all scenarios.
Usage
Basic Install Button
<div {{ stimulus_controller('@pwa/install') }}>
<button
id="install-btn"
{{ stimulus_action('@pwa/install', 'install', 'click') }}
style="display:none;"
>
Install App
</button>
</div>
<script>
document.addEventListener('pwa--install:not-installed', () => {
document.getElementById('install-btn').style.display = 'block';
});
document.addEventListener('pwa--install:installed', () => {
document.getElementById('install-btn').style.display = 'none';
});
</script>Install Banner with Animation
Install Card in App Settings
Smart Install Prompt with User Tracking
Parameters
None
Actions
install
Triggers the PWA installation prompt. This action will:
Show the browser's native "Add to Home Screen" dialog
Emit the
installingevent when the prompt is shownEmit either
installedorcancelledbased on user choice
This action only works if the browser supports installation prompts and the PWA meets all installation criteria.
Targets
None
Events
pwa--install:not-installed
Dispatched when the PWA is not currently installed but can potentially be installed.
No payload
Use this event to show install buttons or banners:
pwa--install:installed
Dispatched when the PWA is detected as already installed or running in standalone mode.
No payload
This event is emitted:
On page load if the app is running in standalone mode
After a successful installation
Use this to hide install prompts and show thank you messages:
pwa--install:installing
Dispatched when the user triggers the install() action and the installation prompt is shown.
No payload
Use this to track when users see the install prompt:
pwa--install:cancelled
Dispatched when the user dismisses the install prompt or an error occurs during installation.
No payload
Use this to handle installation cancellation:
Best Practices
Don't be pushy: Show install prompts after users have engaged with your app
Provide value: Explain benefits of installation (offline access, faster loading, etc.)
Respect dismissals: Track how many times users dismiss the prompt and back off
Check installation status: Always listen for the
installedevent to hide promptsUse appropriate timing: Show install prompts at natural break points in the user journey
Make it optional: Never force installation; let users discover and install when ready
Track metrics: Monitor installation rates and prompt dismissals to optimize your approach
Detection of Already Installed Apps
The controller automatically detects if your PWA is already installed by checking if the app is running in standalone mode. This detection happens immediately on page load, so you can hide install buttons for users who have already installed your app.
Common Scenarios
E-commerce Site
Show install prompt after user adds first item to cart:
Content Site
Show install prompt after user reads 3 articles:
Gaming App
Show install prompt after first game completed:
Last updated
Was this helpful?