Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add mobile app store redirector (Issue #14172) #14208

Merged
merged 1 commit into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 34 additions & 1 deletion bedrock/firefox/redirects.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at https://mozilla.org/MPL/2.0/.

from bedrock.redirects.util import no_redirect, platform_redirector, redirect
from bedrock.redirects.util import mobile_app_redirector, no_redirect, platform_redirector, redirect


def firefox_mobile_faq(request, *args, **kwargs):
Expand All @@ -17,6 +17,37 @@ def firefox_channel(*args, **kwargs):
return platform_redirector("firefox.channel.desktop", "firefox.channel.android", "firefox.channel.ios")


def mobile_app(request, *args, **kwargs):
qs = request.META.get("QUERY_STRING", "")
campaign = None
product = "firefox"

product_options = ["firefox", "focus", "klar"]

campaign_options = [
"firefox-whatsnew",
"firefox-whatsnew-120",
"firefox-whatsnew-122",
"firefox-welcome-4",
"firefox-welcome-6",
"firefox-welcome-17",
"firefox-browsers-mobile-get-app",
"firefox-browsers-mobile-android",
"firefox-browsers-mobile-ios",
"firefox-browsers-mobile-focus",
]

for p in product_options:
if f"product={p}" in qs:
product = p

for c in campaign_options:
if f"campaign={c}" in qs:
campaign = c

stevejalim marked this conversation as resolved.
Show resolved Hide resolved
return mobile_app_redirector(request, product, campaign)


redirectpatterns = (
# overrides
# issue 8096
Expand Down Expand Up @@ -562,4 +593,6 @@ def firefox_channel(*args, **kwargs):
# issue 13732
redirect(r"^firefox/welcome/3/?$", "firefox.accounts"),
redirect(r"^firefox/mobile/get-app/?$", "firefox.browsers.mobile.get-app"),
# issue 14172
redirect(r"^firefox/browsers/mobile/app/?$", mobile_app, cache_timeout=0, query=False),
)
18 changes: 18 additions & 0 deletions bedrock/redirects/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from collections import defaultdict
from urllib.parse import parse_qs, urlencode

from django.conf import settings
from django.http import (
HttpResponseGone,
HttpResponsePermanentRedirect,
Expand Down Expand Up @@ -86,6 +87,23 @@ def decider(request, *args, **kwargs):
return decider


def mobile_app_redirector(request, product, campaign):
android_re = re.compile(r"\bAndroid\b", flags=re.I)
value = request.headers.get("User-Agent", "")

if android_re.search(value):
base_url = getattr(settings, f"GOOGLE_PLAY_{product.upper()}_LINK")
params = "&referrer=utm_source%3Dwww.mozilla.org%26utm_medium%3Dreferral%26utm_campaign%3D{cmp}"
else:
base_url = getattr(settings, f"APPLE_APPSTORE_{product.upper()}_LINK").replace("/{country}/", "/")
params = "?pt=373246&ct={cmp}&mt=8"

if campaign:
return base_url + params.format(cmp=campaign)
else:
return base_url


def no_redirect(pattern, locale_prefix=True, re_flags=None):
"""
Return a url matcher that will stop the redirect middleware and force
Expand Down
49 changes: 49 additions & 0 deletions tests/redirects/map_globalconf.py
Original file line number Diff line number Diff line change
Expand Up @@ -1231,5 +1231,54 @@
url_test("/foundation/annualreport/{,2022/}", "https://stateof.mozilla.org/"),
# Issue 14186
url_test("/privacy/firefox-monitor/", "/privacy/subscription-services/"),
# Issue 14172
url_test(
"/firefox/browsers/mobile/app/?product=firefox",
"https://play.google.com/store/apps/details?id=org.mozilla.firefox",
req_headers=UA_ANDROID,
resp_headers={"Cache-Control": "max-age=0"},
),
url_test(
"/firefox/browsers/mobile/app/?product=firefox",
"https://apps.apple.com/app/apple-store/id989804926",
req_headers=UA_IOS,
resp_headers={"Cache-Control": "max-age=0"},
),
url_test(
"/firefox/browsers/mobile/app/?product=firefox&campaign=firefox-whatsnew",
"https://play.google.com/store/apps/details?id=org.mozilla.firefox&referrer=utm_source%3Dwww.mozilla.org%26utm_medium%3Dreferral%26utm_campaign%3Dfirefox-whatsnew",
req_headers=UA_ANDROID,
resp_headers={"Cache-Control": "max-age=0"},
),
url_test(
"/firefox/browsers/mobile/app/?product=firefox&campaign=firefox-whatsnew",
"https://apps.apple.com/app/apple-store/id989804926?pt=373246&ct=firefox-whatsnew&mt=8",
req_headers=UA_IOS,
resp_headers={"Cache-Control": "max-age=0"},
),
url_test(
"/firefox/browsers/mobile/app/?product=focus&campaign=firefox-browsers-mobile-focus",
"https://play.google.com/store/apps/details?id=org.mozilla.focus&referrer=utm_source%3Dwww.mozilla.org%26utm_medium%3Dreferral%26utm_campaign%3Dfirefox-browsers-mobile-focus",
req_headers=UA_ANDROID,
resp_headers={"Cache-Control": "max-age=0"},
),
url_test(
"/firefox/browsers/mobile/app/?product=focus&campaign=firefox-browsers-mobile-focus",
"https://apps.apple.com/app/apple-store/id1055677337?pt=373246&ct=firefox-browsers-mobile-focus&mt=8",
req_headers=UA_IOS,
resp_headers={"Cache-Control": "max-age=0"},
),
url_test(
"/firefox/browsers/mobile/app/?product=klar&campaign=firefox-browsers-mobile-focus",
"https://play.google.com/store/apps/details?id=org.mozilla.klar&referrer=utm_source%3Dwww.mozilla.org%26utm_medium%3Dreferral%26utm_campaign%3Dfirefox-browsers-mobile-focus",
req_headers=UA_ANDROID,
resp_headers={"Cache-Control": "max-age=0"},
),
url_test(
"/firefox/browsers/mobile/app/?product=klar&campaign=firefox-browsers-mobile-focus",
"https://apps.apple.com/app/apple-store/id1073435754?pt=373246&ct=firefox-browsers-mobile-focus&mt=8",
req_headers=UA_IOS,
resp_headers={"Cache-Control": "max-age=0"},
),
)
)
Loading