We are designing a PWA install funnel. The funnel needs to be optimized for:
Android mini-CTA (likely a small call-to-action button, maybe in the browser UI)
iOS share sheet (since iOS doesn't support PWA install prompts natively in the same way; we need to use the share sheet to guide users to "Add to Home Screen")
Desktop prompts (likely using the beforeinstallprompt event)
Additionally, we need to instrument analytics to track the funnel steps.
We need to consider the user journey:
User visits site.
Site determines if PWA is installable (using beforeinstallprompt event for Android/desktop, and for iOS we check if it's Safari and not already installed).
Then we show appropriate prompts (mini-CTA for Android, share sheet instruction for iOS, and a custom prompt for desktop if needed).
Track events: prompt shown, prompt accepted, prompt dismissed, and also eventual installation (maybe via appinstalled event).
We need to design the funnel, meaning we need to think about the timing, the UI components, and the fallback mechanisms.
Let's outline:
Detection:
Use window.matchMedia('(display-mode: standalone)') to check if already installed.
For Android/desktop: listen to beforeinstallprompt event. When fired, we can set a flag that the app is installable. We should also check for navigator.serviceWorker and other criteria.
For iOS: We can't detect installability natively. We might use heuristics: user agent is iOS Safari, and we are not in standalone mode, and maybe some other conditions (like if the user has visited before? But not reliable). Typically for iOS, we show a custom "Add to Home Screen" prompt (like a banner) after some user engagement (e.g., after 2-3 visits or a certain time on site). Or we can show it always but not too intrusive. We need to decide.
Prompt UI:
Android mini-CTA: This is a small button, maybe in the navigation bar or floating. We want to show it when installable and not dismissed. It could say "Install App" or use an icon. The mini-CTA should be dismissible.
iOS share sheet instruction: On iOS, we need to instruct the user to use the share button and then "Add to Home Screen". This might be a modal or a banner that explains with steps. Since iOS doesn't have a native install prompt, we have to guide manually. We can also have a mini-CTA (like a button) that says "Add to Home Screen" and when clicked, shows the instructions. Or we could show a full-screen overlay after some delay.
Desktop prompts: For desktop, we can use the native prompt triggered from beforeinstallprompt.prompt(). But we want to control when to show it. Typically we show a custom UI first (like a banner) and then when user clicks a button, we call prompt(). Alternatively, we could auto-show after some engagement, but that might be annoying. Better to have a trigger.
However, the problem says "optimized for Android mini-CTA, iOS share sheet, and desktop prompts". This suggests that for Android we want a mini-CTA (small persistent element), for iOS we want to leverage the share sheet (maybe we can't do a mini-CTA? Actually iOS Safari has a share button anyway, so we want to tell users to use it). For desktop, we want to use the native prompt (which is a modal dialog). But we also need to have a way to trigger it (maybe via a button as well). But the "desktop prompts" might refer to the native prompt that appears automatically? Actually the beforeinstallprompt event can be prevented from showing automatically, and we can show our own custom prompt then call prompt(). But the native prompt is browser UI, not ours. So we can't control its appearance entirely. However, we can choose to not use the native prompt and just rely on our custom UI? But that might not be as effective. The specification might be: on Android, show a mini-CTA that triggers the native prompt (by calling prompt()). On iOS, show a share sheet instruction (because there is no native prompt). On desktop, show a custom prompt that triggers the native prompt? Wait, on desktop (Chrome, Edge, etc.) there is a native install prompt that appears in the address bar (omnibox). That's not something we can control directly; it appears automatically when criteria are met and if the user interacts with the page? Actually the beforeinstallprompt event fires when the app is installable, but the default behavior is suppressed. We can call prompt() to show the native prompt. But we might also want to show our own custom UI to encourage installation, and then when user clicks our button, we call prompt(). That is typical.
So funnel steps:
Detection phase: determine installability.
Engagement trigger: wait for some user action (like clicking a button, or after some time on site, or after certain pages visited) before showing any prompt. This improves conversion.
pwa_prompt_accepted (user clicked install in the prompt or followed instructions)
pwa_prompt_dismissed
pwa_installed (via appinstalled event)
Also maybe track engagement triggers.
We should use a common analytics tool like Google Analytics, or custom events. But the design just needs to specify what to track.
Implementation considerations:
We need to handle multiple platforms: Android (Chrome), iOS (Safari), Desktop (Chrome, Edge, etc.). We need to detect the platform and conditionally show UI.
For iOS, we may need to display instructions on how to add to home screen. There are known patterns: a modal with an arrow pointing to the share button, and step-by-step.
We need to consider that iOS 11.3+ supports "Add to Home Screen" but the process is via share sheet. And also note that iOS does not fire beforeinstallprompt and does not support the PWA install prompt API. So we must have a fallback.
For Android, the beforeinstallprompt event is supported. We can use that to show the native prompt after user interaction.
For desktop, same.
But also we need to consider that some browsers on Android might be other than Chrome (like Samsung Internet) which may have their own behavior. But the mini-CTA likely targets Chrome on Android.
Mini-CTA design:
Small button, maybe fixed to bottom right or top right. Could be icon plus text. Should be dismissible (so it doesn't annoy returning users who don't want to install).
We need to store dismissal in local storage or cookie to not show again for a while (maybe 30 days).
The mini-CTA should only appear when the app is installable (for Android/desktop). For iOS, we might show a different CTA (maybe "Add to Home Screen" button) that triggers the instructions.
But the problem says "Android mini-CTA", implying a specific UI component for Android. For iOS it says "iOS share sheet" which is not a UI we design; it's the system UI we want to direct users to. So our iOS UI is an instruction that leads to the share sheet. For desktop it says "desktop prompts" which likely means the native prompt (which we trigger after user interaction). But we may also have a custom prompt UI on desktop if we want to show before the native prompt? Possibly we could have a custom banner that says "Install our app" and when clicked, triggers the native prompt. That is common on desktop too.
Let's define:
Android: We show a mini-CTA (persistent small button). When clicked, we call event.prompt() from the stored beforeinstallprompt event. This shows the native install prompt.
iOS: We show a banner/CTA that says "Add to Home Screen" or maybe an icon. When clicked, we show a modal with instructions on how to use the share sheet to add. Alternatively, we could show the instructions directly without a click? But typically you show an instructional popup after some trigger. We might also make the iOS CTA dismissible.
Desktop: We could show a similar mini-CTA or a larger custom prompt? The phrase "desktop prompts" might mean we use the native prompt directly? But we can't show the native prompt without a user gesture (like a click). So we need a UI element that the user clicks to trigger the native prompt. That could be a mini-CTA as well. But maybe on desktop we show a more prominent banner at the top of the page? It depends. Since desktop screens are larger, we could show a top banner. But the problem says "optimized for ... desktop prompts" meaning we want to use the prompt mechanism effectively. We could have a button that says "Install App" and when clicked, we call prompt(). That's analogous to Android mini-CTA but maybe larger.
However, the problem might be asking to design the funnel itself, not the pixel-level UI. So we can describe the components.
We also need to handle the case where the user has already installed the app. We should not show prompts if display-mode: standalone is true. Also, if they have dismissed the prompt, we should respect that for some time.
Funnel steps in order:
User arrives, page loads.
Script checks if already installed (via display-mode). If yes, skip prompts.
Script sets up event listeners for beforeinstallprompt (for browsers that support it) and maybe also checks user agent for iOS.
If beforeinstallprompt fires, we save the event (so we can prompt later) and set a flag that installable.
If iOS and not installed, we might start a timer (e.g., after 30 seconds or after 2 pageviews) and then show iOS CTA.
We also track engagement: maybe wait for a user interaction (click, scroll) before showing any prompt. This is best practice to increase conversion. So we might have a trigger: after first user interaction (or after 5 seconds?) and if installable, show the appropriate prompt.
When showing the prompt:
For Android/desktop: if we have a saved beforeinstallprompt event, we call prompt() and then handle the outcome. But note: the native prompt appears in its own UI; we don't control it. But we might want to first show our own UI explaining why they should install, then after they click our button, we trigger the native prompt. That is typical: we have a custom "Install" button that calls prompt(). So the mini-CTA is that button. We might also show the native prompt automatically when the event fires? No, we must wait for user gesture. So we must have a button. So the funnel: user sees mini-CTA, clicks it, then native prompt appears. Then they accept or dismiss.
For iOS: we show a modal/banner with instructions. That's our custom UI. Then the user follows the instructions manually (opens share sheet, taps "Add to Home Screen"). There is no programmatic way to know when they actually install. However, we can detect if the app is launched in standalone mode on next visit. So we can infer installation.
Track events: when mini-CTA shown, when clicked, when native prompt accepted/dismissed, when iOS instructions shown, when maybe user clicks "I've added it" button (we could have a "Got it" button to close instructions). But we can't directly know if they installed from iOS instructions. We can only infer on subsequent visits.
Analytics instrumentation details:
Use dataLayer for Google Tag Manager or direct GA events.
pwa_native_prompt_shown (platform - for Android/desktop, but this is after we call prompt; the native prompt is shown by browser, we might not have an event for that, but we can assume after we call prompt, the prompt is shown. However we can listen to beforeinstallprompt event: when we call prompt(), it returns a promise that resolves with an outcome. So we can track the outcome.
Actually the beforeinstallprompt event object has a prompt() method which returns a promise that resolves with an outcome object: { outcome: 'accepted' | 'dismissed' }. So we can track that.
For iOS: we can track pwa_ios_instructions_shown, pwa_ios_instructions_dismissed (if they close without following), maybe pwa_ios_instructions_cta_clicked (if we have a button that says "Open Share Sheet" which would focus on the share button? Actually we can't open share sheet programmatically; we just instruct. So we might have a button that says "Next" to go through steps, and finally a "Done" button. We can track completion of the instruction flow. But actual install detection is tricky.
pwa_app_installed event: This is fired by the browser when the app is installed (both on Android/desktop via the appinstalled event, and on iOS? I think iOS does not fire appinstalled because it's not a standard event. But we can detect on next visit via display-mode. So we might set a flag in localStorage that on next load, if standalone, we know they installed. But that's not immediate.
We should design a consistent analytics model:
Funnel steps:
Installable detected: We know the app can be installed.
Prompt shown: The user is presented with an install opportunity (either native prompt or our custom UI).
User action: The user accepts (installs) or dismisses (declines).
Installed: We confirm installation (either via appinstalled event or on subsequent visit in standalone mode).
For iOS, step 3 might be ambiguous if they install later. We could track the instructions shown and then on next visit, if we see standalone mode and we had shown instructions previously, we could deduce they installed from those instructions. But we need to have some linkage: we can store in sessionStorage that we showed instructions, and then on the next visit, if standalone, fire an event with source="ios_instructions". However, that's not guaranteed because they might have installed from elsewhere. But it's okay.
Platform detection:
We need robust detection. Use user agent? But that's messy. Better to use feature detection for the beforeinstallprompt event, and for iOS we know it's not supported. So:
If window.navigator.standalone (iOS) or window.matchMedia('(display-mode: standalone)') matches, we are already installed.
If window.addEventListener('beforeinstallprompt') works, we are in a browser that supports it (Android Chrome, Desktop Chrome/Edge). Then we set installable flag when event fires.
If iOS Safari (user agent includes iPhone/iPad and Safari and not Chrome) and not in standalone, we treat as iOS.
But note: iOS Safari supports PWA via "Add to Home Screen" but not the install prompt API. So we need to detect iOS. We can use user agent regex: /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream. Also check for Safari: navigator.vendor includes 'Apple' and maybe not Chrome. But simpler: if it's iOS and not in standalone, we consider iOS PWA installable if the site meets criteria (has manifest, service worker, etc). But we cannot easily detect if it meets criteria without trying to add? However, we could check if manifest has display: standalone or display: fullscreen and service worker is active. But on iOS, even if those are present, the "Add to Home Screen" option is always available in share sheet? Actually Apple has some requirements: the site must be launched from home screen after being added? But the share sheet option appears if the site is a PWA? I think if the site has a manifest with display: standalone and is served over HTTPS and has an apple-touch-icon, Safari shows the "Add to Home Screen" option in the share sheet. So we can check those conditions. But it's okay to assume that if we are in iOS Safari and not standalone, we can show the instructions. However, there is a nuance: if the site is not yet a certified PWA (like missing icons), the share sheet option might not appear. But we can still instruct; if it doesn't appear, the instruction might confuse. But we can't detect perfectly. So we might just show instructions regardless, or only show if we detect the necessary PWA assets. That's an extra check.
For simplicity in design, we'll assume we show iOS instructions if:
User is on iOS Safari (UA detection)
Not in standalone mode
The site has a manifest with display: standalone or fullscreen (we can check via document.querySelector('link[rel="manifest"]') and fetch? Not necessary at design level)
Service worker is active? Not strictly needed for iOS? Actually iOS requires service worker for offline? I think it's recommended but not mandatory for adding to home screen. But we can assume our PWA meets requirements.
Trigger timing:
We want to avoid showing prompts too early. Best practice: after a certain amount of engagement (e.g., 30 seconds on site, or after they've visited 3 pages, or after they've clicked something). We can implement a simple heuristic: after 30 seconds and after the user has performed at least one click or scroll. Or we could rely on our own custom trigger: we show the mini-CTA but we might only show it after the user has been on the site for 10 seconds, or we could show it immediately but then they might be annoyed. Usually we wait a bit.
We'll design a "trigger manager" that tracks user engagement and then signals that it's time to show the prompt.
UI components:
Mini-CTA for Android/desktop: A fixed-position element (bottom-right or top-right). Content: icon (e.g., download arrow or plus) and text "Install App". It should have a close button (×). On click (except close), we trigger the native prompt.
iOS CTA: Could be similar mini-CTA but with text "Add to Home Screen". When clicked, it opens a modal with instructions. The modal could have screenshots or illustrations showing the share button and the "Add to Home Screen" option. Include a "Got it" or "Close" button.
Desktop alternative prompt: Some sites show a top banner that says "Install our app for a better experience" with buttons "Install" and "Not now". That could be used for desktop as well. But since we already have mini-CTA, we could use the same mini-CTA for all platforms but change the behavior? For iOS, clicking the iOS mini-CTA opens instructions; for Android/desktop, clicking triggers native prompt. So we could have a unified CTA that adapts to platform. But the problem says "Android mini-CTA" maybe implying a specific small CTA, and for iOS it's share sheet instruction, and for desktop it's prompts (maybe the native ones). However, we could still have a CTA. We'll design as: on Android and desktop, show a mini-CTA that triggers native prompt; on iOS, show a CTA that triggers instructions.
But we need to be careful: on desktop, the native prompt is triggered only after a user gesture. So the mini-CTA click qualifies.
Edge cases:
User already installed: don't show.
User dismissed: don't show for a period (e.g., 30 days). Store dismissal timestamp in localStorage.
Prompt already shown but not dismissed? We might show it only once per session? Or we could show the mini-CTA persistently if installable and not dismissed.
If beforeinstallprompt event fires, we should store the event. But if the user doesn't click the mini-CTA for a while, the event might become stale? Actually the event remains valid until we call prompt() or the page reloads. But if the user navigates to another page, we might lose the event if we don't persist? The beforeinstallprompt is per page load. So we need to store it in a variable and if the user navigates, we might need to re-listen. Typically you handle it on the page where you want to prompt. But if they navigate away, you might lose the event. So we need to either keep the same page or re-detect on each page. The common pattern is to capture the event on page load and then show the mini-CTA on subsequent pages as well? But the event is only fired on the page that is the PWA scope? Actually the beforeinstallprompt event is fired at the window object when the app is installable. It might fire on every page within the scope? Not sure. Typically you add the event listener on every page. But if the user navigates to a new page, you might get the event again. So we can handle it per page.
However, we want a consistent experience across the site. So we could store a flag in sessionStorage that the app is installable, and then show the mini-CTA on all pages. But we need to have the beforeinstallprompt event to call prompt(). If the event hasn't fired on a particular page, we might not be able to trigger the native prompt because we need that event. So we must ensure that the page where we intend to trigger the prompt has received the beforeinstallprompt event. That is likely the root of the PWA scope. If the user navigates to another page that is outside the scope, the event may not fire. So the prompt should be triggered only on pages that are within the PWA scope. Usually the scope is set in manifest. So we need to restrict the mini-CTA to pages within that scope. That's a design detail.
We might assume our entire site is within the PWA scope (if set to "/"). So all pages would get the event. Good.
Analytics event naming:
Use a consistent naming convention, prefix with 'pwa_'.
pwa_native_prompt_shown (platform) - maybe we can combine with above? Actually clicking mini-CTA triggers native prompt, so we could track that click as leading to prompt. But we also might want to track if the native prompt is actually shown? The prompt() method shows it immediately, but we might not know if the browser actually displayed it? Actually it will display; but we can track the outcome later.
pwa_install_prompt_outcome (outcome: 'accepted'|'dismissed', platform) - from the promise.
pwa_ios_instructions_shown (platform: 'ios')
pwa_ios_instructions_completed (if they go through all steps and close with "Got it"? We can track that.)
pwa_installed (platform, source: 'native_prompt'|'manual_add'|'browser_ui', etc.) - from appinstalled event or inferred.
Also track:
pwa_mini_cta_dismissed (platform)
pwa_ios_instructions_dismissed
Implementation outline:
HTML:
We'll have a container for the mini-CTA (hidden by default) and a container for iOS instructions modal (hidden).
CSS:
Style the mini-CTA: fixed position, z-index, etc.
Style the modal.
JS:
Feature detection: check if already in standalone mode.
Define variables:
installPromptEvent to store the beforeinstallprompt event.
isInstallable flag.
platform: 'android', 'ios', 'desktop'.
Setup:
Add event listener for beforeinstallprompt. When fired, prevent default (to stop automatic prompt), store event, set isInstallable=true, and maybe fire analytics pwa_installable with platform='android' or 'desktop'? Actually the event fires on both Android and desktop browsers that support it. We can differentiate by user agent if needed, but maybe we just call it 'android' for mobile and 'desktop' for desktop? We could detect via navigator.userAgent or window.innerWidth? Better to use navigator.userAgent to distinguish. Or we can simply mark platform as 'beforeinstallprompt' and then when we show UI we assign platform. But we need platform for analytics. We'll detect platform at start.
Platform detection function:
code
function getPlatform() {
const ua = navigator.userAgent;
if (/iPad|iPhone|iPod/.test(ua) && !window.MSStream) {
return 'ios';
}
if (/Android/.test(ua)) {
return 'android';
}
return 'desktop';
}
But note: on Android, the beforeinstallprompt event might fire on Chrome. On iOS, it never fires. On desktop, it fires on Chrome/Edge. So we can set platform based on that detection.
Then:
For iOS: we don't have beforeinstallprompt. We'll rely on UA detection and check if not standalone. We'll also need to check if the site meets PWA criteria (manifest, service worker). We can assume so if we have those. But we can also try to check: if manifest exists and has display: standalone, and service worker is active. We'll implement a function isIosPwaInstallable() that returns true if conditions are met. This might be async because we need to fetch manifest? We can parse the link element without fetching? We can read document.querySelector('link[rel="manifest"]').href and then fetch it? But that's extra network. Maybe we skip strict check and just show instructions for all iOS Safari non-standalone visits after engagement. That's simpler.
We'll have an EngagementTracker that tracks time on page, scroll depth, clicks. When the user has met criteria (e.g., 30 seconds elapsed and at least one click), we set engagementMet flag. Then we show the appropriate prompt.
Show prompt logic:
code
if (isInstallable && engagementMet) {
if (platform === 'ios') {
showIosInstructions();
} else {
showMiniCta();
}
}
But we might show mini-CTA only when installable and after engagement. The mini-CTA is a persistent UI; we could show it after engagement and keep it until dismissed or installed. For iOS, we show the instructions modal after engagement (maybe automatically or via a button). The problem says "iOS share sheet" meaning we want to guide to share sheet, not necessarily a modal. But we need to show something. We can design a non-intrusive banner at the top with "Install our app" and a down-arrow icon? When clicked, it opens a small popover with steps. That's acceptable.
For Android/desktop: show mini-CTA. When clicked, if we have installPromptEvent, we call installPromptEvent.prompt(). Then we handle the result: installPromptEvent.userChoice returns a promise? Actually prompt() returns a promise that resolves with { outcome: 'accepted' | 'dismissed' }. Wait, the spec: prompt() returns a promise that resolves when the user has made a choice. So we can do:
code
installPromptEvent.prompt().then(outcome => {
track('pwa_install_prompt_outcome', {outcome: outcome.outcome});
if (outcome.outcome === 'accepted') {
// maybe user will install soon
}
// Reset the prompt event because it can only be used once.
installPromptEvent = null;
});
After calling prompt, we should hide the mini-CTA (since the native prompt is shown, we don't need our CTA until next time we get a new event). But the native prompt might not lead to immediate install; if they accept, the install happens, and we get appinstalled event. If dismissed, we might show the mini-CTA again later? Possibly after some time. But we can decide to hide it for this session, or respect dismissal and not show again for 30 days.
For iOS: show instructions modal. When user closes the modal (by clicking "Got it" or close button), we track dismissal. We can also offer a button "I've added it" which would then reload the page in standalone? Actually we could have a button that says "Check if installed" which reloads the page and if in standalone, we fire installed event. But we can't programmatically add to home screen. So we can just close. On next visit, if standalone, we'll detect and track install.
Dismissal handling: if user closes the mini-CTA or iOS modal, store a timestamp in localStorage with key like pwa_mini_cta_dismissed_<platform> and value = Date.now(). Then don't show again for X days (e.g., 30). Also, if they installed, we should stop showing.
After installation: we listen to window.addEventListener('appinstalled', (e) => { track('pwa_installed', {platform: currentPlatform, source: 'native_prompt'}); }). For iOS, as described, we can infer on next load.
Analytics instrumentation in code:
We'll have a track(eventName, params) function that sends data to analytics (e.g., Google Analytics). We'll assume we have a global window.gtag or similar. For design, we can abstract it.
Putting together:
Steps:
a. On page load:
Check if already in standalone mode. If true, maybe we are installed, so do nothing (or track as pwa_installed on first load? But we wouldn't know if it's fresh install. Could use session flag to avoid double count). But we can skip prompts.
Detect platform.
If platform is 'ios':
Set up engagement tracking.
If not standalone, start timer to maybe show iOS CTA after engagement criteria.
Else (android/desktop):
Add beforeinstallprompt listener. When fires, store event, set isInstallable = true, track pwa_installable.
Also start engagement tracking.
When engagement met and isInstallable, show mini-CTA (unless dismissed recently or already installed).
For iOS, we also need to check if installable (manifest etc). But for simplicity, assume installable always on iOS Safari if not standalone and we are a PWA. We'll have a function checkIosInstallability that returns a promise that resolves to true if manifest exists and has standalone display. We could fetch the manifest and check. But maybe we skip that and just show instructions. For a robust design, we might want to check. We can attempt to fetch manifest and parse.
b. Engagement tracking:
- Track time on page (e.g., after 30 seconds).
- Track user interactions: clicks, scrolls. After first interaction, set engaged = true.
- Could also track pageviews (if SPA, after certain routes). But for simplicity: after either 30 seconds or after any click (whichever comes later? Or both). We'll set a condition: if (elapsedTime >= 30 seconds && userInteracted) OR if visited >= 2 pages? We can implement a simple heuristic: after 30 seconds of page load and at least one click or scroll event, set engagementMet = true. Also, if the user navigates to a second page (if SPA, route change), we could set engagementMet as well. But we'll keep it simple.
c. Show mini-CTA function:
- Create element if not exists, add to DOM.
- Track shown.
- When clicked, if we have installPromptEvent, call installPromptEvent.prompt().
- Then handle outcome.
d. Show iOS instructions function:
- Create modal element if not exists, add to DOM.
- Track shown.
- When user clicks "Close" or "Got it", track dismissed.
- When user clicks "Done" we could check if now in standalone? Not necessary.
Now, we need to produce a "design" - likely a technical design document. The user said "Design a PWA install funnel optimized for Android mini-CTA, iOS share sheet, and desktop prompts with analytics instrumentation." So we need to output a design specification, possibly including code snippets? Or a description? The user didn't specify the format. We can provide a high-level design with pseudocode, and include the key components and analytics events. Since it's a "design", we can produce a structured document.
Possible structure:
Overview
Goals
Platform-specific strategies
Android: mini-CTA approach
iOS: share sheet guidance
Desktop: native prompt trigger
Funnel stages and flow diagram (maybe text description)
Implementation details
a. Detection
b. Engagement trigger
c. UI components
d. Event handling
e. Analytics events
f. Storage and cooldowns
Code structure (class design)
Edge cases and considerations
Configuration options
Testing plan
We'll produce that.
But the user may expect code? The instruction "Design a PWA install funnel..." could be for a technical interview, expecting a design description, maybe with pseudo-code. I'll produce a comprehensive answer with explanation and key code snippets.
I'll write it in a clear, organized manner.
Let's start.
Answer:
Design: PWA Install Funnel
1. Objectives
Increase PWA install rates by providing platform-appropriate install prompts.
Track the entire funnel: detection, prompt shown, user action, installation.
Respect user experience: avoid premature prompts, respect dismissals.
2. Platform Strategies
Android (Chrome): Use the beforeinstallprompt event to show a miniaturized, persistent call-to-action (mini-CTA) on the page. The CTA triggers the native install prompt when clicked.
iOS (Safari): Since iOS does not support the beforeinstallprompt API, guide users via the share sheet. Show an instructional modal that explains the "Add to Home Screen" steps. Include a button that reloads the page to check if the user successfully added the app.
Desktop (Chrome/Edge): Similar to Android, use the beforeinstallprompt event to show a mini-CTA that triggers the native prompt.
3. Funnel Flow
code
[Page Load]
|
v
[Check if already in standalone mode] -> Yes -> Exit funnel (app installed)
|
No
|
v
[Detect Platform] --> iOS --> iOS path
| |
| v
| [Check iOS installability (manifest, etc.)? optional]
| |
| v
| [Start engagement tracker]
| |
| v
| [Engagement met?] --No--> wait
| |
| Yes
| |
| v
| [Show iOS instructions modal]
| |
| /------------\
| | |
| Click "I've added" Click "Maybe later" / dismiss
| | |
| v v
| [Reload page] [Set dismiss cooldown, hide modal]
| |
| v
| [On reload: if standalone -> Track install (ios_instructions)]
| |
| No (still not standalone) -> Respect cooldown, do not show modal soon
|
v (Android/Desktop)
[Add beforeinstallprompt listener]
|
v (event fires)
[Save event, set installable = true]
|
v
[Start engagement tracker]
|
v
[Engagement met?] --No--> wait
|
Yes
|
v
[Show mini-CTA] (if not dismissed recently)
|
| (click on mini-CTA)
v
[Call event.prompt()] -> shows native prompt
|
v
[Track native prompt shown]
|
v
[Wait for outcome via promise]
| |
| outcome = 'accepted' -> wait for appinstalled
| |
| outcome = 'dismissed' -> set dismiss cooldown
|
v (appinstalled event)
[Track pwa_installed with source = 'native_prompt']
[Clear dismissal flags, hide mini-CTA]
4. Engagement Trigger
To avoid annoying users, the prompt (CTA or modal) is only shown after a minimum engagement. We define engagement as:
At least 30 seconds of page time, AND
At least one user interaction (click, scroll, keypress).
Alternatively, if the user navigates to a second page (in a SPA) we may count that as engagement.
We implement an EngagementTracker that:
Starts a timer on page load.
Listens for interaction events (click, scroll, keydown).
When both conditions are satisfied, sets engagementMet = true and triggers a check to possibly show the prompt.
5. UI Components
Mini-CTA (for Android/desktop):
Fixed position (bottom-right on mobile, top-right on desktop).
Contains an icon (e.g., download arrow) and text "Install App".
Close button (×) to dismiss.
On click (except close), triggers the native prompt.
Hidden by default; shown only when installable && engagementMet && !dismissed.
Dismissal: clicking close stores a timestamp in localStorage under key pwa_mini_cta_dismissed_<platform>. The CTA will not reappear for 30 days.
iOS Instructions Modal:
Full-screen overlay with semi-transparent background.
Centered box with step-by-step instructions (text and optional visual aid).
Buttons: Primary "I've added it", Secondary "Maybe later", and a close icon.
Shown after engagement and if not dismissed.
Dismissal: clicking "Maybe later" or close sets pwa_ios_modal_dismissed in localStorage (30 days).
"I've added it": sets pwa_ios_attempted timestamp, reloads the page.
Top Banner Alternative: For desktop, one could also consider a top banner instead of a mini-CTA, but the design uses a consistent mini-CTA across Android and desktop.
6. Analytics Instrumentation
We track these events (with suggested parameters):
Confirmed installation (via appinstalled event or standalone detection).
Implementation: use a tracking function that sends to Google Analytics (gtag) or other analytics. Example:
code
function track(event, params = {}) {
if (window.gtag) {
gtag('event', event, params);
} else if (window.dataLayer) {
dataLayer.push({ event, ...params });
} else {
console.log('[PWA Analytics]', event, params);
}
}
7. Storage and Cooldowns
Keys in localStorage (prefix pwa_):
pwa_mini_cta_dismissed_<platform>: timestamp of last dismissal (for mini-CTA). Cooldown: 30 days.
pwa_ios_modal_dismissed: timestamp of last iOS modal dismissal. Cooldown: 30 days.
pwa_ios_attempted: timestamp when user clicked "I've added it" on iOS. Used to attribute install and to avoid showing the modal again soon (cooldown 7 days). Cleared after install detection.
Also, we may want to use sessionStorage for temporary flags (like engagementMet) but that's in memory.
8. Implementation Class Structure
We propose a PWAInstallFunnel class that encapsulates all logic. It should be instantiated once (maybe as a singleton) and initialized on page load.
Pseudo-code skeleton:
javascript
9. CSS Styling
Add minimal CSS for the CTA and modal. The site can override.
iOS PWA Criteria: The iOS instructions modal assumes the site qualifies for "Add to Home Screen". If the manifest lacks display: standalone or the site lacks required icons, the option may not appear. To be robust, we could attempt to fetch the manifest and verify display property, and also check if a service worker is active. If not, skip iOS modal. Implementation omitted for brevity but can be added.
Multiple Instances: Ensure the class is instantiated only once to avoid duplicate listeners.
Page Visibility: If the page is hidden (e.g., user switches tabs), we might pause the engagement timer? Not necessary but could be optimized.
Hardware Back Button: On Android, if the native prompt is showing, it handles its own UI. No interference.
iOS "I've added it" detection: The reload method is reliable because after adding to home screen and launching, navigator.standalone will be true. However, if the user reloads from within Safari (without adding), they will still be in Safari and standalone false. They might then see the modal again if not dismissed. Our cooldown (7 days after attempt) prevents immediate annoyance.
Desktop Native Prompt: On desktop, the native prompt may appear as a small infobar or modal depending on the browser. Our mini-CTA triggers it.
Beforeinstallprompt event persistence: If the user navigates away before interacting with the mini-CTA, the stored installPromptEvent may become stale (the event can only be used once). On navigating to a new page, we'll get a new event (if still installable) or not. So it's fine.
11. Configuration Options
The constructor accepts an optional config object to override defaults:
engagementTimeMs: Time (ms) before engagement considered met (default 30000).
trackingFunction: Custom analytics function instead of built-in gtag/dataLayer.
12. Testing
Test on:
Android Chrome (APIs supported)
iOS Safari (instructions flow)
Desktop Chrome/Edge (prompt flow)
Already installed scenarios (should not show prompt)
Dismissal flows (cooldown should suppress)
Reload after iOS "I've added it" to see install detection.
Simulate beforeinstallprompt event via DevTools > Application > Manifest > "Add to home screen" test.
13. Conclusion
This design provides a tailored install funnel for the three major environments, with robust analytics to measure conversion at each step, while respecting user experience with cooldowns and engagement gating.
PWA Install Funnel Design
1. Goals
Maximize PWA installs by delivering platform‑appropriate prompts.
Track every funnel step: detection → prompt shown → user action → installation.
Avoid user frustration with intelligent gating and cooldowns.
2. Platform‑Specific Strategies
Platform
Mechanism
UI Component
Android (Chrome)
beforeinstallprompt event → native install dialog
Mini‑CTA (small persistent button)
iOS (Safari)
No beforeinstallprompt; rely on Share Sheet → “Add to Home Screen”
Instructional modal (steps + “I’ve added”)
Desktop (Chrome/Edge)
beforeinstallprompt event → native install dialog
Mini‑CTA (same as Android)
3. Funnel Flow
code
[Page Load]
↓
[Already in standalone?] → Yes → Exit (app installed)
↓ No
[Detect platform]
↓
[Check installability]
• Android/Desktop: wait for beforeinstallprompt event
• iOS: assume installable if not standalone (manifest ok)
↓
[Start engagement tracker] → (30s + user interaction)
↓
[Engagement met?] → No → keep waiting
↓ Yes
[Show platform‑specific prompt]
├─ Android/Desktop → Show mini‑CTA
│ ├─ Click → trigger native prompt → track outcome (accepted/dismissed)
│ └─ Dismiss (×) → set cooldown
└─ iOS → Show instructions modal
├─ “I’ve added it” → reload → if standalone → track install
└─ “Maybe later”/close → set cooldown
↓
[Installation confirmed]
• Android/Desktop: `appinstalled` event
• iOS: on reload, `navigator.standalone` true
↓
[Track install, clear dismissal flags]
4. Engagement Trigger
To prevent premature prompts, the UI appears only after:
Time: ≥ 30 seconds on the page, and
Interaction: at least one click/scroll/keypress.
Implementation uses a simple tracker that listens for interaction events and a timeout.
iOS PWA eligibility: Before showing iOS modal, optionally verify manifest contains display: standalone and a service worker is active. If not, skip.
SPA navigation: The funnel lives on the global object; it will survive route changes. Ensure re‑checking of beforeinstallprompt if needed (event may fire on new navigation within scope).
Cooldown tuning: Cooldowns (30 d mini‑CTA, 30 d iOS modal, 7 d iOS attempt) are defaults; adjust based on product needs.
Testing: Use Chrome DevTools → Application → “Add to home screen” test to fire beforeinstallprompt. Test iOS by adding to home screen manually and checking navigator.standalone.
11. Conclusion
This design delivers a cohesive, analytics‑driven install funnel tailored to Android, iOS, and desktop platforms. It respects user experience with engagement gating and dismissal cooldowns while providing full visibility into conversion via standardized events. The modular class can be dropped into any PWA with minimal configuration.
pwa_installed
Alternatively, we can track only what we can directly observe: for iOS, we can't really track install conversion reliably. We can track the instruction flow completion and assume some conversion. But maybe we can track the share sheet open? There is no API to detect that. So best we can do is track the instruction shown and then on subsequent visits, if they are in standalone, we mark them as converted from iOS. But we need to link the user across sessions, so we could use a cookie or localStorage with a session id? But without a login, it's hard. However, we can set a flag in localStorage when we show instructions, and then on subsequent loads check if standalone and that flag exists, then we can infer and fire an install event, and then clear the flag. That would work if they install within the same browser and don't clear storage. That's acceptable.
So plan:
localStorage key: pwa_ios_shown_instructions with timestamp.
On page load: if display-mode: standalone and that key exists, then fire pwa_installed with platform='ios' and source='instructions', and remove key.
Also, if they installed via native methods on Android/desktop, appinstalled event fires, we track that.
But note: the appinstalled event fires when the PWA is installed from either the prompt or the browser menu. So it's good.
So we can detect iOS conditionally.
e. Dismissal persistence:
- Use localStorage with key: pwa_prompt_dismissed_<platform> and value = timestamp. When showing, check if exists and if within cooldown period (e.g., 30 days), don't show. If dismissed, respect cooldown.
- When user dismisses, set localStorage key with current timestamp.
- When user installs (via appinstalled or inferred on iOS), clear any dismissal keys (since they installed, no need to show again).
f. appinstalled event listener:
- Track pwa_installed with platform and source.
- Hide any prompts (remove mini-CTA, close modals).
- Clear dismissal storage.
g. iOS inference:
- On page load (for iOS), after checking not in standalone, check localStorage for pwa_ios_shown_instructions (set when we showed instructions). If it exists, we don't show again (cooldown). But we also need to detect if they installed in the meantime: On each load, if display-mode: standalone is true, we track install and clear flags.
- If they had instructions shown in this session (maybe we set a session flag), and they later load in standalone, we can fire install event with source='ios_instructions'. But we need to persist across sessions: we could set a localStorage item pwa_ios_last_instruction_shown with a timestamp. Then on a subsequent visit (not same session), if standalone and that timestamp is recent (e.g., within last 7 days), we infer they installed from instructions. But careful: they might have installed without instructions. But it's okay; we'll attribute to instructions. Or we could not attribute; just record install. We'll simplify: when we detect standalone, we fire pwa_installed with platform 'ios' and source 'standalone_detected' (or manual). We can also try to differentiate if we had shown instructions before: if localStorage.getItem('pwa_ios_instructions_shown') is not null and within last X days, we set source='ios_instructions'. That's a heuristic.
Alternatively, we could provide a way for iOS users to manually indicate they installed: a button "I've added to Home Screen" that they click after adding, and then we reload the page and check if standalone, then attribute. That would be more reliable. But that adds friction. Many implementations use that. They show instructions with a button "Continue" that reloads the page and if still not standalone, they keep showing; if standalone, they close. That's common. Let's adopt that: In the iOS instructions modal, we have a button "I've added it to Home Screen". When clicked, we reload the page. On reload, if in standalone, we consider installed and fire event. If not, we might show the modal again? Or we could wait a bit. This gives a more direct conversion tracking.
So iOS flow:
After engagement, show modal with steps.
Modal includes: "Follow these steps to add to Home Screen: 1. Tap Share button. 2. Scroll down and tap 'Add to Home Screen'. 3. Done."
Also include a button "I've added it". When clicked, we reload the page.
On reload, check if standalone. If yes, fire pwa_installed with source='ios_instructions'. Also hide modal. If not, maybe keep showing modal? But we might want to not annoy; we can keep the modal open but with a "Maybe later" option. We'll have a close button as well.
This also allows us to track the conversion directly.
This is a good pattern.
So iOS instructions modal:
Shows steps.
Has three buttons: "I've added it" (reload), "Maybe later" (close, track dismissal, set dismissal cooldown), and maybe "Learn more" link.
When "I've added it" is clicked, we reload and then on next load, if standalone, we'll fire install event. If not, we could show again? Possibly after some time. We could also check if after reload they are still not standalone; maybe they haven't succeeded, so we might not show the modal again if they dismiss? We'll store that they attempted (e.g., localStorage set pwa_ios_attempted with timestamp). Then we won't show again for a while (like 7 days) to avoid annoyance. If they eventually become standalone, we clear that flag on detection.
This seems solid.
Code structure:
We'll create a class PWAInstallFunnel that handles everything.
Methods:
init(): sets up detection, events, engagement.
detectPlatform()
checkInstallability(): runs checks.
setupEventListeners()
track(event, params)
showMiniCTA()
hideMiniCTA()
showIosInstructions()
hideIosInstructions()
handleNativePrompt(): for Android/desktop, trigger prompt and handle outcome.
handleAppInstalled(e)
handleIosInstructionComplete(): called when user clicks "I've added".
isDismissed(): check localStorage.
dismiss(): set localStorage.
clearDismissal(): on install.
We'll need to be careful with scope: if using a module pattern.
Detailed design for each platform:
Android/desktop mini-CTA:
Appears after engagement is met and installable.
Design: fixed to bottom-right (mobile) or top-right (desktop). Small rectangular button with icon and text.
Dismissible with an "x" icon. Dismissal sets localStorage and hides.
When clicked (except x), we call prompt() on the stored event. We also track that the prompt is being shown? Actually the native prompt appears; we might want to track that we triggered it. So we can track pwa_native_prompt_shown at the moment we call prompt(). Then we wait for outcome.
After the outcome (from the promise), we hide the mini-CTA? We could hide it regardless of outcome, because the prompt is now shown and we don't want to show again until next install opportunity (maybe after a while). Typically, after prompting, the browser might not fire another beforeinstallprompt event until next visit or some conditions. So we can hide the mini-CTA and wait for appinstalled or dismissal. If dismissed, we could show again after a long time? Maybe we hide until next page load? Actually the beforeinstallprompt event can only be used once per page. So after calling prompt(), the event is consumed. We set installPromptEvent = null. The mini-CTA should be hidden. On a new page (if we navigate within same SPA), we might not get a new event immediately. So the mini-CTA would reappear only if we get a new beforeinstallprompt event on that page. So we need to re-listen on each page. That's fine.
So after calling prompt, we hide mini-CTA. If the outcome is 'accepted', we expect appinstalled soon. If dismissed, we might want to set a dismissal so we don't show again soon. But note: the dismissal by the native prompt might be considered a user choice not to install now. We might want to treat that as a dismissal and set a cooldown. So we can call dismiss() with a longer cooldown (e.g., 90 days). But we can also not; some implementations show again after some time. We'll set cooldown on dismissal from native prompt as well. That seems user-friendly.
When the user clicks the x on mini-CTA (without triggering prompt), that's a direct dismissal, set cooldown.
iOS instructions modal:
Appears after engagement and not in standalone. Could be a modal overlay with a semi-transparent backdrop.
Content: title "Add to Home Screen", step-by-step instructions (maybe with an image of iPhone showing share button). Buttons: "I've added it" (primary), "Maybe later" (secondary). Also close "x" at top right.
Set a flag in localStorage: pwa_ios_attempted = Date.now() (to avoid showing again soon if they didn't succeed).
Then reload the page.
On reload, check if standalone: if yes, track pwa_installed with source='ios_instructions', clear any dismissal flags, and hide modal (if present). If not standalone, we could show the modal again? But we set the attempted flag, so we won't show again for a cooldown (e.g., 7 days). That's sensible.
When "Maybe later" or close is clicked: track pwa_ios_instructions_dismissed, set dismissal cooldown (e.g., 30 days) via localStorage, and hide modal.
Installation detection on iOS after reload:
On page load (iOS), after checking not standalone? Actually we will check if window.navigator.standalone is true (iOS specific) or display-mode includes 'standalone'. So we can check:
On iOS, navigator.standalone is true if launched from home screen. On other platforms, display-mode is used. So we can check both.
If isStandalone is true, we track pwa_installed with appropriate source. But we need to determine source: if we have pwa_ios_attempted flag, we can attribute to ios_instructions. Else, maybe natural install (user added manually without our instructions). So we could set source: 'ios_manual'. Then we clear pwa_ios_attempted if present? Actually if they installed after our instructions, the reload that shows standalone will happen; we should clear the attempted flag to avoid re-attributing. So we do:
if (isStandalone) {
const source = localStorage.getItem('pwa_ios_attempted') ? 'ios_instructions' : 'ios_manual';
track('pwa_installed', { platform: 'ios', source });
localStorage.removeItem('pwa_ios_attempted');
// Also maybe clear other flags.
}
Integration with SPAs:
Since we're designing for any site, we need to consider if the site is a single-page app (like React, Vue). The funnel should work across route changes. So we need to re-run detection on route changes? Actually some things (like beforeinstallprompt) might fire only on initial load? In a SPA, if the initial page is within the scope, the event might fire on load. But navigating to a new route might not re-fire. However, we only need to show the prompt once per install opportunity. So we can handle on initial load. But if the user navigates to a new route, the mini-CTA should persist if already shown. We'll attach the mini-CTA to the body and it remains. So it's okay.
However, if the user navigates to a route outside the PWA scope (unlikely if scope is "/"), we might want to hide the CTA because the native prompt might not work. So we could check window.location against the scope. But we can assume all pages are within scope.
Privacy and GDPR:
Since we are storing local storage and tracking events, we should ensure we have user consent if needed. But that's beyond design scope.
CSS styling:
Provide basic styling for mini-CTA and modal. We can keep it minimal and customizable.
Analytics payload:
We'll define events with parameters.
Summary of funnel:
Step 1: Page load.
Step 2: Detect platform and installability.
Step 3: Start engagement tracking.
Step 4: Once engagement threshold met (e.g., 30 seconds & interact) and installable:
- If Android/desktop: show mini-CTA.
- If iOS: show instructions modal.
Step 5: User interacts with CTA:
- Android/desktop: Click mini-CTA -> trigger native prompt -> track outcome (accepted/dismissed). If dismissed, set cooldown. If accepted, wait for appinstalled event.
- iOS: Click "I've added it" -> reload page -> if standalone, track install; else cooldown. Click "Maybe later" -> dismiss modal, set cooldown.
Step 6: On install (appinstalled event or standalone detection), track install and clear flags.
Additionally, we track:
Installable detected.
Mini-CTA shown/dismissed.
Native prompt outcome.
iOS instructions shown/completed/dismissed.
App installed.
We also respect cooldowns to avoid spamming.
Implementation details: We'll produce a self-contained JavaScript module that can be included in the page. We'll assume a global analytics function like window.dataLayer.push or gtag. We'll abstract tracking: if window.gtag exists, use it; else if window.dataLayer exists, use that; else console.log. Or we can just dispatch custom events for the site to handle. We'll design a simple tracking interface: this.track(eventName, params).
We'll also have configuration: cooldown periods, engagement time, etc. We can set defaults.
Testing notes: We should test on Android Chrome, iOS Safari, desktop Chrome/Edge.
class PWAInstallFunnel {
constructor(config = {}) {
this.config = {
engagementTimeMs: 30000,
miniCtaCooldownMs: 30 * 24 * 60 * 60 * 1000,
iosModalCooldownMs: 30 * 24 * 60 * 60 * 1000,
iosAttemptCooldownMs: 7 * 24 * 60 * 60 * 1000,
...config
};
this.platform = this.detectPlatform();
this.installable = false;
this.installPromptEvent = null;
this.engagementMet = false;
this.miniCtaElement = null;
this.iosModalElement = null;
this.userInteracted = false;
this.init();
}
detectPlatform() {
const ua = navigator.userAgent;
if (/iPad|iPhone|iPod/.test(ua) && !window.MSStream) return 'ios';
if (/Android/.test(ua)) return 'android';
return 'desktop';
}
isStandalone() {
return window.navigator.standalone || window.matchMedia('(display-mode: standalone)').matches;
}
init() {
// If already installed, exit
if (this.isStandalone()) {
this.track('pwa_app_installed', { platform: this.platform, source: 'existing' });
return;
}
// Setup event listeners
this.setupBeforeInstallPrompt();
this.setupAppInstalled();
this.startEngagementTracker();
// For iOS, we may also check manifest availability? Optional.
if (this.platform === 'ios') {
// We could optionally check manifest
// but we'll assume installable.
this.installable = true; // simplistic
} else {
// installable will be set when beforeinstallprompt fires
}
// After engagement, conditionally show UI
this.maybeShowPrompt();
}
setupBeforeInstallPrompt() {
if (this.platform === 'ios') return;
window.addEventListener('beforeinstallprompt', (e) => {
e.preventDefault();
this.installPromptEvent = e;
this.installable = true;
this.track('pwa_installable', { platform: this.platform, reason: 'beforeinstallprompt' });
this.maybeShowPrompt();
});
}
setupAppInstalled() {
window.addEventListener('appinstalled', () => {
this.track('pwa_app_installed', { platform: this.platform, source: 'native_prompt' });
this.clearDismissalFlags();
this.hideMiniCTA();
});
}
startEngagementTracker() {
const checkEngagement = () => {
const timeExceeded = Date.now() - this.pageLoadTime >= this.config.engagementTimeMs;
if (timeExceeded && this.userInteracted) {
this.engagementMet = true;
this.maybeShowPrompt();
}
};
this.pageLoadTime = Date.now();
window.addEventListener('click', this.markInteracted, { once: true });
window.addEventListener('scroll', this.markInteracted, { once: true });
window.addEventListener('keydown', this.markInteracted, { once: true });
// Also fallback timer: after long time even without interaction? Maybe not.
setTimeout(checkEngagement, this.config.engagementTimeMs + 1000);
}
markInteracted = () => {
this.userInteracted = true;
// Also check immediately if time already met
if (Date.now() - this.pageLoadTime >= this.config.engagementTimeMs) {
this.engagementMet = true;
this.maybeShowPrompt();
}
}
maybeShowPrompt() {
if (!this.engagementMet || !this.installable) return;
// Check dismissal cooldown
if (this.isDismissed()) return;
if (this.platform === 'ios') {
this.showIosInstructions();
} else {
this.showMiniCTA();
}
}
isDismissed() {
const key = this.getDismissalKey();
const dismissed = localStorage.getItem(key);
if (dismissed) {
const dismissedTime = parseInt(dismissed, 10);
const cooldown = this.platform === 'ios' ? this.config.iosModalCooldownMs : this.config.miniCtaCooldownMs;
if (Date.now() - dismissedTime < cooldown) {
return true;
}
}
return false;
}
getDismissalKey() {
if (this.platform === 'ios') return 'pwa_ios_modal_dismissed';
return `pwa_mini_cta_dismissed_${this.platform}`;
}
dismiss() {
const key = this.getDismissalKey();
localStorage.setItem(key, Date.now());
this.hideMiniCTA();
this.hideIosInstructions();
}
clearDismissalFlags() {
if (this.platform === 'ios') {
localStorage.removeItem('pwa_ios_modal_dismissed');
localStorage.removeItem('pwa_ios_attempted');
} else {
localStorage.removeItem(`pwa_mini_cta_dismissed_${this.platform}`);
}
}
showMiniCTA() {
if (this.miniCtaElement) return;
// Create element
this.miniCtaElement = document.createElement('div');
this.miniCtaElement.className = 'pwa-mini-cta';
this.miniCtaElement.innerHTML = `
<button class="pwa-mini-cta-button">Install App</button>
<button class="pwa-mini-cta-close">×</button>
`;
document.body.appendChild(this.miniCtaElement);
this.track('pwa_mini_cta_shown', { platform: this.platform });
this.miniCtaElement.querySelector('.pwa-mini-cta-button').addEventListener('click', () => {
this.handleMiniCtaClick();
});
this.miniCtaElement.querySelector('.pwa-mini-cta-close').addEventListener('click', () => {
this.dismiss();
this.track('pwa_mini_cta_dismissed', { platform: this.platform });
});
}
hideMiniCTA() {
if (this.miniCtaElement) {
this.miniCtaElement.remove();
this.miniCtaElement = null;
}
}
handleMiniCtaClick() {
if (!this.installPromptEvent) return;
this.track('pwa_native_prompt_shown', { platform: this.platform });
this.installPromptEvent.prompt().then(outcome => {
this.track('pwa_install_prompt_outcome', { platform: this.platform, outcome: outcome.outcome });
if (outcome.outcome === 'dismissed') {
this.dismiss(); // set cooldown
this.track('pwa_mini_cta_dismissed', { platform: this.platform });
}
// If accepted, we'll hear appinstalled later
});
this.installPromptEvent = null; // consumed
this.hideMiniCTA(); // hide now that prompt is shown
}
showIosInstructions() {
if (this.iosModalElement) return;
this.iosModalElement = document.createElement('div');
this.iosModalElement.className = 'pwa-ios-modal';
this.iosModalElement.innerHTML = `
<div class="pwa-ios-modal-content">
<button class="pwa-ios-close">×</button>
<h2>Add to Home Screen</h2>
<ol>
<li>Tap the Share button <span class="icon-share"></span> in the toolbar.</li>
<li>Scroll down and tap "Add to Home Screen".</li>
<li>Open the app from your home screen.</li>
</ol>
<div class="pwa-ios-actions">
<button class="pwa-ios-done">I've added it</button>
<button class="pwa-ios-later">Maybe later</button>
</div>
</div>
`;
document.body.appendChild(this.iosModalElement);
this.track('pwa_ios_instructions_shown');
this.iosModalElement.querySelector('.pwa-ios-close').addEventListener('click', () => {
this.dismissIos();
});
this.iosModalElement.querySelector('.pwa-ios-later').addEventListener('click', () => {
this.dismissIos();
});
this.iosModalElement.querySelector('.pwa-ios-done').addEventListener('click', () => {
this.handleIosInstructionComplete();
});
}
hideIosInstructions() {
if (this.iosModalElement) {
this.iosModalElement.remove();
this.iosModalElement = null;
}
}
dismissIos() {
this.hideIosInstructions();
this.dismiss(); // sets dismissal cooldown
this.track('pwa_ios_instructions_dismissed');
}
handleIosInstructionComplete() {
this.hideIosInstructions();
this.track('pwa_ios_instruction_complete');
// Mark that user attempted installation via instructions
localStorage.setItem('pwa_ios_attempted', Date.now());
// Reload to check if now in standalone mode
window.location.reload();
}
track(event, params = {}) {
// Simple proxy to analytics
if (typeof window.gtag === 'function') {
window.gtag('event', event, params);
} else if (window.dataLayer && typeof window.dataLayer.push === 'function') {
window.dataLayer.push({ event, ...params });
} else {
console.log('[PWA Funnel]', event, params);
}
}
}
// Initialize
document.addEventListener('DOMContentLoaded', () => {
window.pwaFunnel = new PWAInstallFunnel();
});