From 303feb491a45d817eacef1ee615abcd05c8d054f Mon Sep 17 00:00:00 2001 From: vshnosngh Date: Tue, 17 Nov 2026 18:52:24 +0530 Subject: [PATCH] feat(apps): update mobile app store links and implement unified device-detecting QR code --- .env.example | 6 ++ content/collections/apps/bg-cleaner-app.json | 12 ++-- .../collections/apps/photo-enhancer-pro.json | 12 ++-- .../apps/bg-cleaner-app/app.config.json | 12 ++-- .../apps/photo-enhancer-pro/app.config.json | 12 ++-- src/app/go/[tool]/[app]/route.ts | 71 +++++++++--------- src/components/sections/AppHandoffSection.tsx | 40 +++++++---- .../sections/RecommendedAppsSection.tsx | 4 +- src/components/tools/PostResultAppHandoff.tsx | 50 +++++++------ tests/goRoute.test.ts | 72 +++++++++++++++++++ 10 files changed, 199 insertions(+), 92 deletions(-) create mode 100644 tests/goRoute.test.ts diff --git a/.env.example b/.env.example index f493284..6aac49a 100644 --- a/.env.example +++ b/.env.example @@ -38,3 +38,9 @@ ALLOWED_ORIGIN=http://localhost:3000 # --------------------------------------------------------------------------- NEXT_PUBLIC_TURNSTILE_SITE_KEY=your_cloudflare_turnstile_site_key CLOUDFLARE_TURNSTILE_SECRET_KEY=your_cloudflare_turnstile_secret_key + +# --------------------------------------------------------------------------- +# Mobile App Redirect Host override (optional - defaults to current origin / SITE_URL) +# Used for single smart QR code device routing to Google Play & App Store +# --------------------------------------------------------------------------- +# NEXT_PUBLIC_APP_REDIRECT_HOST=https://your-public-domain.com diff --git a/content/collections/apps/bg-cleaner-app.json b/content/collections/apps/bg-cleaner-app.json index 8a89ece..ad6aa9b 100644 --- a/content/collections/apps/bg-cleaner-app.json +++ b/content/collections/apps/bg-cleaner-app.json @@ -3,8 +3,8 @@ "slug": "bg-cleaner-app", "status": "published", "name": { - "en": "Magic Cutout & Erase Studio", - "hi": "मैजिक कटआउट और इरेज़ स्टूडियो" + "en": "BG Remove: Background Editor", + "hi": "BG Remove: Background Editor" }, "tagline": { "en": "Cut out any subject, erase photobombers, and design product shots", @@ -16,12 +16,12 @@ }, "stores": { "android": { - "packageId": "com.creinnovations.bgcleaner", - "url": "https://play.google.com/store/apps/details?id=com.creinnovations.bgcleaner" + "packageId": "com.me2creative.AiDressChanger", + "url": "https://play.google.com/store/apps/details?id=com.me2creative.AiDressChanger&pcampaignid=web_share" }, "ios": { - "appId": "1672384912", - "url": "https://apps.apple.com/app/id1672384912" + "appId": "1497878283", + "url": "https://apps.apple.com/bn/app/bg-remove-background-editor/id1497878283" } }, "deepLink": { diff --git a/content/collections/apps/photo-enhancer-pro.json b/content/collections/apps/photo-enhancer-pro.json index 50536ff..37e596a 100644 --- a/content/collections/apps/photo-enhancer-pro.json +++ b/content/collections/apps/photo-enhancer-pro.json @@ -3,8 +3,8 @@ "slug": "photo-enhancer-pro", "status": "published", "name": { - "en": "Enhance Ultra AI", - "hi": "एन्हांस अल्ट्रा एआई" + "en": "Enhance Photo Quality", + "hi": "Enhance Photo Quality" }, "tagline": { "en": "Turn blurry or aged photos into crystal clear 4K masterpieces", @@ -16,12 +16,12 @@ }, "stores": { "android": { - "packageId": "com.creinnovations.photoenhancer", - "url": "https://play.google.com/store/apps/details?id=com.creinnovations.photoenhancer" + "packageId": "com.smartworld.enhancephotoquality", + "url": "https://play.google.com/store/apps/details?id=com.smartworld.enhancephotoquality&pcampaignid=web_share" }, "ios": { - "appId": "1672384911", - "url": "https://apps.apple.com/app/id1672384911" + "appId": "1587310121", + "url": "https://apps.apple.com/mm/app/enhance-photo-quality/id1587310121" } }, "deepLink": { diff --git a/management/apps/bg-cleaner-app/app.config.json b/management/apps/bg-cleaner-app/app.config.json index cd8d25f..83a5a06 100644 --- a/management/apps/bg-cleaner-app/app.config.json +++ b/management/apps/bg-cleaner-app/app.config.json @@ -3,8 +3,8 @@ "slug": "bg-cleaner-app", "status": "published", "name": { - "en": "Magic Cutout & Erase Studio", - "hi": "\u092e\u0948\u091c\u093f\u0915 \u0915\u091f\u0906\u0909\u091f \u0914\u0930 \u0907\u0930\u0947\u091c\u093c \u0938\u094d\u091f\u0942\u0921\u093f\u092f\u094b" + "en": "BG Remove: Background Editor", + "hi": "BG Remove: Background Editor" }, "tagline": { "en": "Cut out any subject, erase photobombers, and design product shots", @@ -16,12 +16,12 @@ }, "stores": { "android": { - "packageId": "com.creinnovations.bgcleaner", - "url": "https://play.google.com/store/apps/details?id=com.creinnovations.bgcleaner" + "packageId": "com.me2creative.AiDressChanger", + "url": "https://play.google.com/store/apps/details?id=com.me2creative.AiDressChanger&pcampaignid=web_share" }, "ios": { - "appId": "1672384912", - "url": "https://apps.apple.com/app/id1672384912" + "appId": "1497878283", + "url": "https://apps.apple.com/bn/app/bg-remove-background-editor/id1497878283" } }, "deepLink": { diff --git a/management/apps/photo-enhancer-pro/app.config.json b/management/apps/photo-enhancer-pro/app.config.json index 62fbf8f..43bffe4 100644 --- a/management/apps/photo-enhancer-pro/app.config.json +++ b/management/apps/photo-enhancer-pro/app.config.json @@ -3,8 +3,8 @@ "slug": "photo-enhancer-pro", "status": "published", "name": { - "en": "Enhance Ultra AI", - "hi": "\u090f\u0928\u094d\u0939\u093e\u0902\u0938 \u0905\u0932\u094d\u091f\u094d\u0930\u093e \u090f\u0906\u0908" + "en": "Enhance Photo Quality", + "hi": "Enhance Photo Quality" }, "tagline": { "en": "Turn blurry or aged photos into crystal clear 4K masterpieces", @@ -16,12 +16,12 @@ }, "stores": { "android": { - "packageId": "com.creinnovations.photoenhancer", - "url": "https://play.google.com/store/apps/details?id=com.creinnovations.photoenhancer" + "packageId": "com.smartworld.enhancephotoquality", + "url": "https://play.google.com/store/apps/details?id=com.smartworld.enhancephotoquality&pcampaignid=web_share" }, "ios": { - "appId": "1672384911", - "url": "https://apps.apple.com/app/id1672384911" + "appId": "1587310121", + "url": "https://apps.apple.com/mm/app/enhance-photo-quality/id1587310121" } }, "deepLink": { diff --git a/src/app/go/[tool]/[app]/route.ts b/src/app/go/[tool]/[app]/route.ts index 1c5d82e..bc697ad 100644 --- a/src/app/go/[tool]/[app]/route.ts +++ b/src/app/go/[tool]/[app]/route.ts @@ -7,39 +7,44 @@ export async function GET( req: NextRequest, { params }: { params: { tool: string; app: string } } ) { - const tool = getToolBySlug(params.tool) || getToolById(params.tool); - const app = getAppBySlug(params.app) || getAppById(params.app); + try { + const tool = getToolBySlug(params.tool) || getToolById(params.tool); + const app = getAppBySlug(params.app) || getAppById(params.app); - if (!app) { - return NextResponse.redirect(new URL('/apps', req.url)); + if (!app) { + return NextResponse.redirect(new URL('/apps', req.url)); + } + + const userAgent = req.headers.get('user-agent') || ''; + const isAndroid = /android/i.test(userAgent); + const isIOS = /ipad|iphone|ipod/i.test(userAgent); + + const searchParams = req.nextUrl.searchParams; + const source = searchParams.get('utm_source') || 'web_try'; + const campaign = searchParams.get('utm_campaign') || (tool ? tool.slug : 'general'); + + if (isAndroid) { + const playUrl = app.stores.android?.url || 'https://play.google.com'; + const finalUrl = new URL(playUrl); + finalUrl.searchParams.set('referrer', `utm_source=${source}&utm_campaign=${campaign}`); + return NextResponse.redirect(finalUrl.toString()); + } + + if (isIOS) { + const iosUrl = app.stores.ios?.url || 'https://apps.apple.com'; + const finalUrl = new URL(iosUrl); + finalUrl.searchParams.set('pt', '123456'); + finalUrl.searchParams.set('ct', `${source}_${campaign}`); + return NextResponse.redirect(finalUrl.toString()); + } + + // Desktop visitor -> Redirect to app page with QR code & deep link info + const desktopUrl = new URL(`/apps/${app.slug}`, req.url); + desktopUrl.searchParams.set('src', source); + desktopUrl.searchParams.set('tool', tool ? tool.slug : ''); + return NextResponse.redirect(desktopUrl.toString()); + } catch (err: any) { + console.error('[go route error]', err); + return NextResponse.json({ error: err?.message || String(err) }, { status: 500 }); } - - const userAgent = req.headers.get('user-agent') || ''; - const isAndroid = /android/i.test(userAgent); - const isIOS = /ipad|iphone|ipod/i.test(userAgent); - - const searchParams = req.nextUrl.searchParams; - const source = searchParams.get('utm_source') || 'web_try'; - const campaign = searchParams.get('utm_campaign') || (tool ? tool.slug : 'general'); - - if (isAndroid) { - const playUrl = app.stores.android?.url || 'https://play.google.com'; - const finalUrl = new URL(playUrl); - finalUrl.searchParams.set('referrer', `utm_source=${source}&utm_campaign=${campaign}`); - return NextResponse.redirect(finalUrl.toString()); - } - - if (isIOS) { - const iosUrl = app.stores.ios?.url || 'https://apps.apple.com'; - const finalUrl = new URL(iosUrl); - finalUrl.searchParams.set('pt', '123456'); - finalUrl.searchParams.set('ct', `${source}_${campaign}`); - return NextResponse.redirect(finalUrl.toString()); - } - - // Desktop visitor -> Redirect to app page with QR code & deep link info - const desktopUrl = new URL(`/apps/${app.slug}`, req.url); - desktopUrl.searchParams.set('src', source); - desktopUrl.searchParams.set('tool', tool ? tool.slug : ''); - return NextResponse.redirect(desktopUrl.toString()); } diff --git a/src/components/sections/AppHandoffSection.tsx b/src/components/sections/AppHandoffSection.tsx index add34cd..e60e1c2 100644 --- a/src/components/sections/AppHandoffSection.tsx +++ b/src/components/sections/AppHandoffSection.tsx @@ -40,13 +40,21 @@ export function AppHandoffSection({ if (!app) return null; - const baseHost = origin || 'http://localhost:3000'; + const androidUrl = app.stores?.android?.url || 'https://play.google.com'; + const iosUrl = app.stores?.ios?.url || 'https://apps.apple.com'; + + const redirectHost = + process.env.NEXT_PUBLIC_APP_REDIRECT_HOST || + process.env.NEXT_PUBLIC_SITE_URL || + origin || + 'http://localhost:3000'; + const targetUrl = tool - ? `${baseHost}/go/${tool.slug}/${app.slug}` - : `${baseHost}/apps/${app.slug}`; + ? `${redirectHost}/go/${tool.slug}/${app.slug}` + : `${redirectHost}/go/explore/${app.slug}`; useEffect(() => { - if (showQr) { + if (showQr && targetUrl) { QRCode.toDataURL(targetUrl, { width: 220, margin: 1, @@ -132,7 +140,7 @@ export function AppHandoffSection({ Direct store installation
{copiedLink ?
- {/* Right Column: Clean QR Code Card */} + {/* Right Column: Single Smart QR Code Card */} {showQr && qrDataUrl && (
- Scan with phone camera + + Scan with Phone Camera +
{`Scan
-
-

Instant mobile handoff

-

Directs to App Store or Google Play for instantaneous installation.

+
+

+ ⚡ Automatic Store Detection +

+

+ Single QR code — automatically opens Google Play on Android or Apple App Store on iPhone. +

)} diff --git a/src/components/sections/RecommendedAppsSection.tsx b/src/components/sections/RecommendedAppsSection.tsx index 44b9eb7..69cdb87 100644 --- a/src/components/sections/RecommendedAppsSection.tsx +++ b/src/components/sections/RecommendedAppsSection.tsx @@ -94,7 +94,7 @@ const DEFAULT_RECOMMENDED_APPS = [ { id: 'app-enhancer', slug: 'photo-enhancer-pro', - name: 'Enhance Ultra AI', + name: 'Enhance Photo Quality', tagline: 'Generative 4K super-resolution and archival restoration', category: 'Super resolution', platforms: ['iOS 17+', 'Android 14+'], @@ -104,7 +104,7 @@ const DEFAULT_RECOMMENDED_APPS = [ { id: 'app-cutout', slug: 'bg-cleaner-app', - name: 'Magic Cutout Studio', + name: 'BG Remove: Background Editor', tagline: 'Sub-pixel P3M alpha matting and background removal', category: 'Background cutout', platforms: ['iOS 17+', 'Android 14+'], diff --git a/src/components/tools/PostResultAppHandoff.tsx b/src/components/tools/PostResultAppHandoff.tsx index 1b48077..d11e40b 100644 --- a/src/components/tools/PostResultAppHandoff.tsx +++ b/src/components/tools/PostResultAppHandoff.tsx @@ -77,23 +77,33 @@ export function PostResultAppHandoff({ const appName = resolveLocalised(appData.name, locale); const toolName = tool.name ? resolveLocalised(tool.name, locale) : 'Photo Tools'; - const baseHost = origin || 'http://localhost:3000'; - const targetUrl = `${baseHost}/go/${tool.slug}/${appData.slug}?src=${variant}`; - const iosUrl = appData.stores?.ios?.url || `/go/${tool.slug}/${appData.slug}?src=ios`; - const androidUrl = appData.stores?.android?.url || `/go/${tool.slug}/${appData.slug}?src=android`; + const redirectHost = + process.env.NEXT_PUBLIC_APP_REDIRECT_HOST || + process.env.NEXT_PUBLIC_SITE_URL || + origin || + 'http://localhost:3000'; + + const targetUrl = tool + ? `${redirectHost}/go/${tool.slug}/${appData.slug}?src=${variant}` + : `${redirectHost}/go/explore/${appData.slug}?src=${variant}`; + + const iosUrl = appData.stores?.ios?.url || 'https://apps.apple.com'; + const androidUrl = appData.stores?.android?.url || 'https://play.google.com'; // Generate dynamic QR Code for instant phone handoff useEffect(() => { - QRCode.toDataURL(targetUrl, { - width: 240, - margin: 1, - color: { - dark: '#0f172a', - light: '#ffffff', - }, - }) - .then((url) => setQrDataUrl(url)) - .catch((err) => console.error('Failed to generate QR code:', err)); + if (targetUrl) { + QRCode.toDataURL(targetUrl, { + width: 240, + margin: 1, + color: { + dark: '#0f172a', + light: '#ffffff', + }, + }) + .then((url) => setQrDataUrl(url)) + .catch((err) => console.error('Failed to generate QR code:', err)); + } }, [targetUrl]); const handleCopyLink = (e: React.MouseEvent) => { @@ -315,7 +325,7 @@ export function PostResultAppHandoff({ // eslint-disable-next-line @next/next/no-img-element {`Scan ) : ( @@ -326,12 +336,12 @@ export function PostResultAppHandoff({
-

- Instantly opens App Store or Google Play directly on your phone. +

+ ⚡ Automatic Store Detection +

+

+ Automatically opens Google Play on Android or App Store on iPhone.

- - Works on iOS 15+ and Android 9+ -
diff --git a/tests/goRoute.test.ts b/tests/goRoute.test.ts new file mode 100644 index 0000000..be91ed2 --- /dev/null +++ b/tests/goRoute.test.ts @@ -0,0 +1,72 @@ +import { describe, it, expect } from 'vitest'; +import { NextRequest } from 'next/server'; +import { GET } from '@/app/go/[tool]/[app]/route'; + +describe('/go/[tool]/[app] dynamic redirect route', () => { + it('redirects Android user to Enhance Photo Quality on Google Play', async () => { + const req = new NextRequest('http://localhost:3000/go/photo-enhancer/photo-enhancer-pro', { + headers: { + 'user-agent': 'Mozilla/5.0 (Linux; Android 14; Pixel 8) AppleWebKit/537.36 Chrome/120.0.0.0 Mobile Safari/537.36', + }, + }); + + const res = await GET(req, { + params: { tool: 'photo-enhancer', app: 'photo-enhancer-pro' }, + }); + + expect(res.status).toBe(307); + const location = res.headers.get('location'); + expect(location).toContain('play.google.com/store/apps/details?id=com.smartworld.enhancephotoquality'); + expect(location).toContain('pcampaignid=web_share'); + expect(location).toContain('referrer=utm_source'); + }); + + it('redirects iOS user to Enhance Photo Quality on Apple App Store', async () => { + const req = new NextRequest('http://localhost:3000/go/photo-enhancer/photo-enhancer-pro', { + headers: { + 'user-agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 17_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.0 Mobile/15E148 Safari/604.1', + }, + }); + + const res = await GET(req, { + params: { tool: 'photo-enhancer', app: 'photo-enhancer-pro' }, + }); + + expect(res.status).toBe(307); + const location = res.headers.get('location'); + expect(location).toContain('apps.apple.com/mm/app/enhance-photo-quality/id1587310121'); + }); + + it('redirects Android user to BG Remove / Dress Changer on Google Play', async () => { + const req = new NextRequest('http://localhost:3000/go/background-remover/bg-cleaner-app', { + headers: { + 'user-agent': 'Mozilla/5.0 (Linux; Android 14; Samsung Galaxy S24) AppleWebKit/537.36', + }, + }); + + const res = await GET(req, { + params: { tool: 'background-remover', app: 'bg-cleaner-app' }, + }); + + expect(res.status).toBe(307); + const location = res.headers.get('location'); + expect(location).toContain('play.google.com/store/apps/details?id=com.me2creative.AiDressChanger'); + expect(location).toContain('pcampaignid=web_share'); + }); + + it('redirects iOS user to BG Remove: Background Editor on Apple App Store', async () => { + const req = new NextRequest('http://localhost:3000/go/background-remover/bg-cleaner-app', { + headers: { + 'user-agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 17_2 like Mac OS X) AppleWebKit/605.1.15', + }, + }); + + const res = await GET(req, { + params: { tool: 'background-remover', app: 'bg-cleaner-app' }, + }); + + expect(res.status).toBe(307); + const location = res.headers.get('location'); + expect(location).toContain('apps.apple.com/bn/app/bg-remove-background-editor/id1497878283'); + }); +});