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

Cleanup DISABLE_DESKTOP_MINIPROMPT experiment flag #3497

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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
12 changes: 3 additions & 9 deletions src/runtime/auto-prompt-manager-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,13 @@ import {ClientEventManager} from './client-event-manager';
import {ConfiguredRuntime} from './runtime';
import {Entitlements} from '../api/entitlements';
import {EntitlementsManager} from './entitlements-manager';
import {ExperimentFlags} from './experiment-flags';
import {GlobalDoc} from '../model/doc';
import {MiniPromptApi} from './mini-prompt-api';
import {MockDeps} from '../../test/mock-deps';
import {PageConfig} from '../model/page-config';
import {Storage} from './storage';
import {StorageKeys} from '../utils/constants';
import {XhrFetcher} from './fetcher';
import {setExperiment} from './experiments';
import {tick} from '../../test/tick';

const CURRENT_TIME = 1615416442; // GMT: Wednesday, March 10, 2021 10:47:22 PM
Expand Down Expand Up @@ -1142,7 +1140,6 @@ describes.realWin('AutoPromptManager', (env) => {

it('should log events when a large prompt overrides the miniprompt', async () => {
win./*OK*/ innerWidth = 500;
setExperiment(win, ExperimentFlags.DISABLE_DESKTOP_MINIPROMPT, true);
const expectedEvent = {
eventType: AnalyticsEvent.EVENT_DISABLE_MINIPROMPT_DESKTOP,
eventOriginator: EventOriginator.SWG_CLIENT,
Expand All @@ -1163,9 +1160,8 @@ describes.realWin('AutoPromptManager', (env) => {
expect(logEventSpy).to.be.calledOnceWith(expectedEvent);
});

it('should replace the contribution miniprompt with a large prompt if DISABLE_DESKTOP_MINIPROMPT is enabled and viewport is wider than 480px', async () => {
it('should replace the contribution miniprompt with a large prompt if viewport is wider than 480px', async () => {
win./*OK*/ innerWidth = 500;
setExperiment(win, ExperimentFlags.DISABLE_DESKTOP_MINIPROMPT, true);
miniPromptApiMock.expects('create').never();

await autoPromptManager.showAutoPrompt({
Expand All @@ -1177,9 +1173,8 @@ describes.realWin('AutoPromptManager', (env) => {
expect(contributionPromptFnSpy).to.be.calledOnce;
});

it('should replace the subscription miniprompt with a large prompt if DISABLE_DESKTOP_MINIPROMPT is enabled and viewport is wider than 480px', async () => {
it('should replace the subscription miniprompt with a large prompt if viewport is wider than 480px', async () => {
win./*OK*/ innerWidth = 500;
setExperiment(win, ExperimentFlags.DISABLE_DESKTOP_MINIPROMPT, true);
miniPromptApiMock.expects('create').never();

await autoPromptManager.showAutoPrompt({
Expand All @@ -1191,9 +1186,8 @@ describes.realWin('AutoPromptManager', (env) => {
expect(subscriptionPromptFnSpy).to.be.calledOnce;
});

it('should not replace the miniprompt with a large prompt when DISABLE_DESKTOP_MINIPROMPT is enabled but the viewport is narrower than 480px', async () => {
it('should not replace the miniprompt with a large prompt when the viewport is narrower than 480px', async () => {
win./*OK*/ innerWidth = 450;
setExperiment(win, ExperimentFlags.DISABLE_DESKTOP_MINIPROMPT, true);
const expectedEvent = {
eventType: AnalyticsEvent.EVENT_DISABLE_MINIPROMPT_DESKTOP,
eventOriginator: EventOriginator.SWG_CLIENT,
Expand Down
20 changes: 5 additions & 15 deletions src/runtime/auto-prompt-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,13 @@ import {Deps} from './deps';
import {Doc} from '../model/doc';
import {Duration, FrequencyCapConfig} from '../model/auto-prompt-config';
import {Entitlements} from '../api/entitlements';
import {ExperimentFlags} from './experiment-flags';
import {GoogleAnalyticsEventListener} from './google-analytics-event-listener';
import {MiniPromptApi} from './mini-prompt-api';
import {OffersRequest} from '../api/subscriptions';
import {PageConfig} from '../model/page-config';
import {Storage, pruneTimestamps} from './storage';
import {StorageKeys} from '../utils/constants';
import {assert} from '../utils/log';
import {isExperimentOn} from './experiments';

const TYPE_CONTRIBUTION = 'TYPE_CONTRIBUTION';
const TYPE_SUBSCRIPTION = 'TYPE_SUBSCRIPTION';
Expand Down Expand Up @@ -543,24 +541,16 @@ export class AutoPromptManager {
}

/**
* Returns which type of prompt to display based on the type specified,
* the viewport width, and whether the disableDesktopMiniprompt experiment
* is enabled.
*
* If the disableDesktopMiniprompt experiment is enabled and the desktop is
* wider than 480px then the large prompt type will be substituted for the mini
* prompt. The original promptType will be returned as-is in all other cases.
* Returns which type of prompt to display based on the type specified and
* the viewport width. If the desktop is wider than 480px, then the large
* prompt type will be substituted for the miniprompt. The original
* promptType will be returned as-is in all other cases.
*/
private getPromptTypeToDisplay_(
promptType?: AutoPromptType
): AutoPromptType | undefined {
const disableDesktopMiniprompt = isExperimentOn(
this.doc_.getWin(),
ExperimentFlags.DISABLE_DESKTOP_MINIPROMPT
);
const isWideDesktop = this.getInnerWidth_() > 480;

if (disableDesktopMiniprompt && isWideDesktop) {
if (isWideDesktop) {
if (promptType === AutoPromptType.SUBSCRIPTION) {
this.logDisableMinipromptEvent_(promptType);
return AutoPromptType.SUBSCRIPTION_LARGE;
Expand Down
9 changes: 2 additions & 7 deletions src/runtime/basic-runtime-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import {ClientTheme} from '../api/subscriptions';
import {ContributionsFlow} from './contributions-flow';
import {Entitlements} from '../api/entitlements';
import {EntitlementsManager} from './entitlements-manager';
import {ExperimentFlags} from './experiment-flags';
import {GlobalDoc} from '../model/doc';
import {MiniPromptApi} from './mini-prompt-api';
import {MockActivityPort} from '../../test/mock-activity-port';
Expand All @@ -46,7 +45,6 @@ import {UiPredicates} from '../model/client-config';
import {acceptPortResultData} from './../utils/activity-utils';
import {analyticsEventToGoogleAnalyticsEvent} from './event-type-mapping';
import {createElement} from '../utils/dom';
import {setExperiment, setExperimentsStringForTesting} from './experiments';
import {tick} from '../../test/tick';

describes.realWin('installBasicRuntime', (env) => {
Expand Down Expand Up @@ -148,7 +146,6 @@ describes.realWin('BasicRuntime', (env) => {
doc = new GlobalDoc(win);
configuredRuntimeSpy = sandbox.spy(runtime, 'ConfiguredRuntime');
basicRuntime = new BasicRuntime(win);
setExperimentsStringForTesting('');
});

describe('initialization', () => {
Expand Down Expand Up @@ -803,8 +800,7 @@ describes.realWin('BasicConfiguredRuntime', (env) => {
});
});

it('should configure subscription auto prompts to show offers for paygated content when disable desktop miniprompt experiment is enabled', async () => {
setExperiment(win, ExperimentFlags.DISABLE_DESKTOP_MINIPROMPT, true);
it('should configure subscription auto prompts to show offers for paygated content when the desktop viewport is large', async () => {
autoPromptManagerMock.expects('getInnerWidth_').returns(500).once();
sandbox.stub(pageConfig, 'isLocked').returns(true);
entitlementsManagerMock
Expand Down Expand Up @@ -891,8 +887,7 @@ describes.realWin('BasicConfiguredRuntime', (env) => {
});
});

it('should configure contribution auto prompts to show contribution options for paygated content when disable desktop miniprompt experiment is enabled', async () => {
setExperiment(win, ExperimentFlags.DISABLE_DESKTOP_MINIPROMPT, true);
it('should configure contribution auto prompts to show contribution options for paygated content when the desktop viewport is large', async () => {
autoPromptManagerMock.expects('getInnerWidth_').returns(500).once();
sandbox.stub(pageConfig, 'isLocked').returns(true);
entitlementsManagerMock
Expand Down
8 changes: 1 addition & 7 deletions src/runtime/experiment-flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,7 @@
* IMPORTANT: All flags should also be added to the e2e test configuration in
* nightwatch.conf.js.
*/
export enum ExperimentFlags {
/**
* Experiment flag for disabling the miniprompt icon on desktop screens wider
* than 480px.
*/
DISABLE_DESKTOP_MINIPROMPT = 'disable-desktop-miniprompt',
}
export enum ExperimentFlags {}

/**
* Experiment flags within article experiment config.
Expand Down
Loading