Skip to content

Commit

Permalink
Hide the go to campaign button if android version >= 22.9 (#79966)
Browse files Browse the repository at this point in the history
* Hide the go to campaign button if android version >= 22.9

* Change the way we obtain device info
  • Loading branch information
jjolmo authored Aug 1, 2023
1 parent a445c3d commit 7fa254a
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
24 changes: 24 additions & 0 deletions client/lib/mobile-app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
26 changes: 25 additions & 1 deletion client/lib/promote-post/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -48,6 +48,7 @@ declare global {
};
isV2?: boolean;
hotjarSiteSettings?: object;
options?: object;
} ) => void;
strings: any;
};
Expand All @@ -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,
Expand Down Expand Up @@ -121,6 +144,7 @@ export async function showDSP(
: undefined,
isV2,
hotjarSiteSettings: { ...getHotjarSiteSettings(), isEnabled: mayWeLoadHotJarScript() },
options: getWidgetOptions(),
} );
} else {
reject( false );
Expand Down

0 comments on commit 7fa254a

Please sign in to comment.