diff --git a/client/lib/mobile-app/index.js b/client/lib/mobile-app/index.js index 5e6df8338bcdd..9732efa9ebd1b 100644 --- a/client/lib/mobile-app/index.js +++ b/client/lib/mobile-app/index.js @@ -21,3 +21,27 @@ export function isWcMobileApp() { } return navigator.userAgent && /wc-(android|ios)/.test( navigator.userAgent ); } + +const deviceUnknown = { + device: 'unknown', + version: 'unknown', +}; + +export function getMobileDeviceInfo() { + try { + const userAgent = navigator.userAgent.toLowerCase(); + const regex = /wp-(android|iphone)\/(\d+.\d+)/; + const match = userAgent.match( regex ); + + if ( ! match ) { + return deviceUnknown; + } + + return { + device: match[ 1 ], + version: match[ 2 ], + }; + } catch ( e ) { + return deviceUnknown; + } +} diff --git a/client/lib/promote-post/index.ts b/client/lib/promote-post/index.ts index ddfa357003d21..f95ba11fe0a8d 100644 --- a/client/lib/promote-post/index.ts +++ b/client/lib/promote-post/index.ts @@ -3,7 +3,7 @@ import { loadScript } from '@automattic/load-script'; import { __ } from '@wordpress/i18n'; import { translate } from 'i18n-calypso/types'; import { getHotjarSiteSettings, mayWeLoadHotJarScript } from 'calypso/lib/analytics/hotjar'; -import { isWpMobileApp } from 'calypso/lib/mobile-app'; +import { getMobileDeviceInfo, isWpMobileApp } from 'calypso/lib/mobile-app'; import wpcom from 'calypso/lib/wp'; import { useSelector } from 'calypso/state'; import { bumpStat, composeAnalytics, recordTracksEvent } from 'calypso/state/analytics/actions'; @@ -48,6 +48,7 @@ declare global { }; isV2?: boolean; hotjarSiteSettings?: object; + options?: object; } ) => void; strings: any; }; @@ -71,6 +72,28 @@ export async function loadDSPWidgetJS(): Promise< void > { await import( './string' ); } +const ANDROID_VERSION_HIDE_CAMPAIGNS_BUTTON = 22.9; + +type DeviceInfo = { + device: string; + version: string; +}; + +const shouldHideGoToCampaignButton = () => { + // Android versions higher or equal than 22.9 should hide the button + const deviceInfo = getMobileDeviceInfo() as DeviceInfo; + return ( + deviceInfo.device.includes( 'android' ) && + parseFloat( deviceInfo?.version ) >= ANDROID_VERSION_HIDE_CAMPAIGNS_BUTTON + ); +}; + +const getWidgetOptions = () => { + return { + hideGoToCampaignsButton: shouldHideGoToCampaignButton(), + }; +}; + export async function showDSP( siteSlug: string | null, siteId: number | string, @@ -121,6 +144,7 @@ export async function showDSP( : undefined, isV2, hotjarSiteSettings: { ...getHotjarSiteSettings(), isEnabled: mayWeLoadHotJarScript() }, + options: getWidgetOptions(), } ); } else { reject( false );