From 19da78ea204e7d1de2af5d7c005b37d99a6566c3 Mon Sep 17 00:00:00 2001 From: Anthony Shull Date: Fri, 25 Oct 2024 14:27:24 -0500 Subject: [PATCH] Show the ad for the mobile app to everyone not on an android (#2203) * check that user agent isnt android * add new pages * rework * remove commuter rail alerts * dont need to check for CR on schedule page --- assets/js/mobile-app-banner.js | 48 +++++++++++++++++++++++++--------- assets/package-lock.json | 8 +++--- assets/package.json | 2 +- mix.exs | 2 +- mix.lock | 2 +- 5 files changed, 43 insertions(+), 19 deletions(-) diff --git a/assets/js/mobile-app-banner.js b/assets/js/mobile-app-banner.js index 72e702221d..620397d7a0 100644 --- a/assets/js/mobile-app-banner.js +++ b/assets/js/mobile-app-banner.js @@ -1,28 +1,52 @@ -const isAlertsPage = () => { - const url = window.location.href; +const isNotAndroid = () => { + return !/Android/.test(navigator.userAgent); +}; - return /\/alerts\/[\w.-]+/.test(url); +const isNotCommuterRail = url => { + return !/\/schedules\/CR-/.test(url); }; -const isIPhone = () => { - return /iPhone/.test(navigator.userAgent); +const isNotFerry = url => { + return !/\/schedules\/Boat-/.test(url); }; -const isSchedulePage = () => { - const url = window.location.href; +const isAlertsPage = url => { + return isNotCommuterRail(url) && isNotFerry(url) && /\/alerts/.test(url); +}; + +const isSchedulePage = url => { + return ( + isNotCommuterRail(url) && + isNotFerry(url) && + /\/schedules\/[\w.-]+\//.test(url) + ); +}; - return /\/schedules\/[\w.-]+\/line/.test(url); +const isStopPage = url => { + return /\/stops\/[\w.-]+/.test(url); }; -const isStopPage = () => { +const isTransitNearMePage = url => { + return /\/transit-near-me/.test(url); +}; + +const isIncludedPage = () => { const url = window.location.href; - return /\/stops\/[\w.-]+/.test(url); + return [isAlertsPage, isSchedulePage, isStopPage, isTransitNearMePage].some( + fn => { + return fn(url); + } + ); }; -// Show the mobile app banner +/** + * If the page is one of the pages we want to show the banner on + * And the user is not on an Android device + * Show the banner + */ export default function mobileAppBanner() { - if (isIPhone() && (isAlertsPage() || isSchedulePage() || isStopPage())) { + if (isIncludedPage() && isNotAndroid()) { document.querySelector("#mobile-app-banner").style.display = "block"; } } diff --git a/assets/package-lock.json b/assets/package-lock.json index 0ecea486cf..52a96800a8 100644 --- a/assets/package-lock.json +++ b/assets/package-lock.json @@ -35,7 +35,7 @@ "leaflet": "^1.4.0", "leaflet-rotatedmarker": "^0.2.0", "lodash": "^4.17.21", - "mbta_metro": "^0.0.49", + "mbta_metro": "^0.0.50", "mobile-detect": "^1.4.5", "phoenix": "file:../deps/phoenix", "phoenix_html": "file:../deps/phoenix_html", @@ -16320,9 +16320,9 @@ } }, "node_modules/mbta_metro": { - "version": "0.0.49", - "resolved": "https://registry.npmjs.org/mbta_metro/-/mbta_metro-0.0.49.tgz", - "integrity": "sha512-Ll6b8L+Yg+aLOtD82L0vtHNf+QAQ345mEZpH1D77HGyI9oshAEfhKJQVIYAnGJgyX8nNnmkf9nRlZsH4hJWUQQ==", + "version": "0.0.50", + "resolved": "https://registry.npmjs.org/mbta_metro/-/mbta_metro-0.0.50.tgz", + "integrity": "sha512-GaVXvpMnD16gFlGuXUI21OEvnMwxqKYsr2zLD6srjS59oC2mlRtft3kz7bYhQ0zgo3tvQsqp1Qugu8aLAL+CwQ==", "dependencies": { "@tailwindcss/forms": "0.5.9", "camelcase-keys": "9.1.3", diff --git a/assets/package.json b/assets/package.json index 373aade220..cd074590d0 100644 --- a/assets/package.json +++ b/assets/package.json @@ -30,7 +30,7 @@ "leaflet": "^1.4.0", "leaflet-rotatedmarker": "^0.2.0", "lodash": "^4.17.21", - "mbta_metro": "^0.0.49", + "mbta_metro": "^0.0.50", "mobile-detect": "^1.4.5", "phoenix": "file:../deps/phoenix", "phoenix_html": "file:../deps/phoenix_html", diff --git a/mix.exs b/mix.exs index c7c3db84ad..c2a1e16d23 100644 --- a/mix.exs +++ b/mix.exs @@ -103,7 +103,7 @@ defmodule DotCom.Mixfile do {:jason, "1.4.4", override: true}, {:logster, "1.1.1"}, {:mail, "0.3.1"}, - {:mbta_metro, "0.0.49"}, + {:mbta_metro, "0.0.50"}, {:mock, "0.3.8", [only: :test]}, {:mox, "1.1.0", [only: :test]}, {:nebulex, "2.6.3"}, diff --git a/mix.lock b/mix.lock index 6a5cdf1cc2..6806457076 100644 --- a/mix.lock +++ b/mix.lock @@ -54,7 +54,7 @@ "makeup_elixir": {:hex, :makeup_elixir, "0.16.2", "627e84b8e8bf22e60a2579dad15067c755531fea049ae26ef1020cad58fe9578", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.2.3 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "41193978704763f6bbe6cc2758b84909e62984c7752b3784bd3c218bb341706b"}, "makeup_erlang": {:hex, :makeup_erlang, "1.0.1", "c7f58c120b2b5aa5fd80d540a89fdf866ed42f1f3994e4fe189abebeab610839", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "8a89a1eeccc2d798d6ea15496a6e4870b75e014d1af514b1b71fa33134f57814"}, "makeup_html": {:hex, :makeup_html, "0.1.1", "c3d4abd39d5f7e925faca72ada6e9cc5c6f5fa7cd5bc0158315832656cf14d7f", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "44f2a61bc5243645dd7fafeaa6cc28793cd22f3c76b861e066168f9a5b2c26a4"}, - "mbta_metro": {:hex, :mbta_metro, "0.0.49", "a2fc42c79ed3f6ca16c29c9b6fb254dff739ad3f4568a852d02dc93bc3b44f2f", [:mix], [{:heroicons, "0.5.6", [hex: :heroicons, repo: "hexpm", optional: true]}, {:jason, "1.4.4", [hex: :jason, repo: "hexpm", optional: false]}, {:phoenix, "1.7.14", [hex: :phoenix, repo: "hexpm", optional: false]}, {:phoenix_live_view, "1.0.0-rc.6", [hex: :phoenix_live_view, repo: "hexpm", optional: false]}, {:phoenix_storybook, "0.6.4", [hex: :phoenix_storybook, repo: "hexpm", optional: false]}, {:timex, "3.7.11", [hex: :timex, repo: "hexpm", optional: false]}], "hexpm", "fa1c321860d774445595be88b7b1d70ced29761181a3c5389f032df32c05aa34"}, + "mbta_metro": {:hex, :mbta_metro, "0.0.50", "26592935c4f2016d436ce277998e2ce67c0787cfd20b20e9bd5d5db1e57a2c10", [:mix], [{:heroicons, "0.5.6", [hex: :heroicons, repo: "hexpm", optional: true]}, {:jason, "1.4.4", [hex: :jason, repo: "hexpm", optional: false]}, {:phoenix, "1.7.14", [hex: :phoenix, repo: "hexpm", optional: false]}, {:phoenix_live_view, "1.0.0-rc.6", [hex: :phoenix_live_view, repo: "hexpm", optional: false]}, {:phoenix_storybook, "0.6.4", [hex: :phoenix_storybook, repo: "hexpm", optional: false]}, {:timex, "3.7.11", [hex: :timex, repo: "hexpm", optional: false]}], "hexpm", "ff5e9c3862556a3424f458a05e224fad7e634193bd75c1f1e24df9e01bdd2152"}, "meck": {:hex, :meck, "0.9.2", "85ccbab053f1db86c7ca240e9fc718170ee5bda03810a6292b5306bf31bae5f5", [:rebar3], [], "hexpm", "81344f561357dc40a8344afa53767c32669153355b626ea9fcbc8da6b3045826"}, "metrics": {:hex, :metrics, "1.0.1", "25f094dea2cda98213cecc3aeff09e940299d950904393b2a29d191c346a8486", [:rebar3], [], "hexpm", "69b09adddc4f74a40716ae54d140f93beb0fb8978d8636eaded0c31b6f099f16"}, "mime": {:hex, :mime, "2.0.6", "8f18486773d9b15f95f4f4f1e39b710045fa1de891fada4516559967276e4dc2", [:mix], [], "hexpm", "c9945363a6b26d747389aac3643f8e0e09d30499a138ad64fe8fd1d13d9b153e"},