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

FPA M0.5: Onsite Preview updates #3555

Merged
Merged
Show file tree
Hide file tree
Changes from 4 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
129 changes: 112 additions & 17 deletions src/runtime/auto-prompt-manager-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -924,9 +924,6 @@ describes.realWin('AutoPromptManager', (env) => {
],
engineId: '123',
},
experimentConfig: {
experimentFlags: ['onsite_preview_enabled'],
},
previewEnabled: true,
})
.once();
Expand Down Expand Up @@ -1559,9 +1556,6 @@ describes.realWin('AutoPromptManager', (env) => {
actions: [],
engineId: '123',
},
experimentConfig: {
experimentFlags: ['onsite_preview_enabled'],
},
previewEnabled: true,
})
.once();
Expand All @@ -1580,12 +1574,9 @@ describes.realWin('AutoPromptManager', (env) => {
getArticleExpectation
.resolves({
audienceActions: {
actions: [SURVEY_INTERVENTION, NEWSLETTER_INTERVENTION],
actions: [SURVEY_INTERVENTION],
engineId: '123',
},
experimentConfig: {
experimentFlags: ['onsite_preview_enabled'],
},
previewEnabled: true,
})
.once();
Expand Down Expand Up @@ -1614,6 +1605,56 @@ describes.realWin('AutoPromptManager', (env) => {
});
});

it('preview should show a dismissble prompt when isClosable', async () => {
getArticleExpectation
.resolves({
audienceActions: {
actions: [SURVEY_INTERVENTION],
engineId: '123',
},
previewEnabled: true,
})
.once();

await autoPromptManager.showAutoPrompt({isClosable: true});
await tick(20);

expect(startSpy).to.have.been.calledOnce;
expect(actionFlowSpy).to.have.been.calledWith(deps, {
action: 'TYPE_REWARDED_SURVEY',
configurationId: 'survey_config_id',
autoPromptType: undefined,
isClosable: true,
calledManually: false,
shouldRenderPreview: true,
});
});

it('preview should show a blocking prompt when not isClosable', async () => {
getArticleExpectation
.resolves({
audienceActions: {
actions: [SURVEY_INTERVENTION],
engineId: '123',
},
previewEnabled: true,
})
.once();

await autoPromptManager.showAutoPrompt({isClosable: false});
await tick(20);

expect(startSpy).to.have.been.calledOnce;
expect(actionFlowSpy).to.have.been.calledWith(deps, {
action: 'TYPE_REWARDED_SURVEY',
configurationId: 'survey_config_id',
autoPromptType: undefined,
isClosable: false,
calledManually: false,
shouldRenderPreview: true,
});
});

it('should show the first prompt if the frequency cap is not met', async () => {
expectFrequencyCappingTimestamps(storageMock, {
'TYPE_CONTRIBUTION': {
Expand Down Expand Up @@ -2940,7 +2981,7 @@ describes.realWin('AutoPromptManager', (env) => {
engineId: '123',
},
experimentConfig: {
experimentFlags: ['onsite_preview_enabled'],
experimentFlags: ['action_orchestration_experiment'],
},
previewEnabled: true,
})
Expand All @@ -2960,11 +3001,11 @@ describes.realWin('AutoPromptManager', (env) => {
getArticleExpectation
.resolves({
audienceActions: {
actions: [SURVEY_INTERVENTION, NEWSLETTER_INTERVENTION],
actions: [SURVEY_INTERVENTION],
engineId: '123',
},
experimentConfig: {
experimentFlags: ['onsite_preview_enabled'],
experimentFlags: ['action_orchestration_experiment'],
},
previewEnabled: true,
})
Expand All @@ -2979,7 +3020,7 @@ describes.realWin('AutoPromptManager', (env) => {
storageMock.expects('get').never();
storageMock.expects('set').never();

await autoPromptManager.showAutoPrompt({});
await autoPromptManager.showAutoPrompt({contentType: ContentType.OPEN});
await tick(20);

expect(startSpy).to.have.been.calledOnce;
Expand All @@ -2993,6 +3034,63 @@ describes.realWin('AutoPromptManager', (env) => {
});
});

it('preview should show a dismissble prompt when ContentType OPEN', async () => {
getArticleExpectation
.resolves({
audienceActions: {
actions: [SURVEY_INTERVENTION],
engineId: '123',
},
experimentConfig: {
experimentFlags: ['action_orchestration_experiment'],
},
previewEnabled: true,
})
.once();

await autoPromptManager.showAutoPrompt({contentType: ContentType.OPEN});
await tick(20);

expect(startSpy).to.have.been.calledOnce;
expect(actionFlowSpy).to.have.been.calledWith(deps, {
action: 'TYPE_REWARDED_SURVEY',
configurationId: 'survey_config_id',
autoPromptType: undefined,
isClosable: true,
calledManually: false,
shouldRenderPreview: true,
});
});

it('preview should show a blocking prompt when ContentType CLOSED', async () => {
getArticleExpectation
.resolves({
audienceActions: {
actions: [SURVEY_INTERVENTION],
engineId: '123',
},
experimentConfig: {
experimentFlags: ['action_orchestration_experiment'],
},

previewEnabled: true,
})
.once();

await autoPromptManager.showAutoPrompt({contentType: ContentType.CLOSED});
await tick(20);

expect(startSpy).to.have.been.calledOnce;
expect(actionFlowSpy).to.have.been.calledWith(deps, {
action: 'TYPE_REWARDED_SURVEY',
configurationId: 'survey_config_id',
autoPromptType: undefined,
isClosable: false,
calledManually: false,
shouldRenderPreview: true,
});
});

it('should show the first prompt for contentType CLOSED, despite past dismissals', async () => {
getArticleExpectation
.resolves({
Expand Down Expand Up @@ -4658,9 +4756,6 @@ describes.realWin('AutoPromptManager', (env) => {
],
engineId: '123',
},
experimentConfig: {
experimentFlags: ['onsite_preview_enabled'],
},
previewEnabled: true,
})
.once();
Expand Down
19 changes: 8 additions & 11 deletions src/runtime/auto-prompt-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ export class AutoPromptManager {
private lastAudienceActionFlow_: AudienceActionFlow | null = null;
private isClosable_: boolean | undefined;
private autoPromptType_: AutoPromptType | undefined;
private onsitePreviewEnabled_: boolean = false;
private shouldRenderOnsitePreview_: boolean = false;
private actionOrchestrationExperiment_: boolean = false;

Expand Down Expand Up @@ -216,8 +215,7 @@ export class AutoPromptManager {

this.setArticleExperimentFlags_(article);

this.shouldRenderOnsitePreview_ =
!!article && article.previewEnabled && this.onsitePreviewEnabled_;
this.shouldRenderOnsitePreview_ = !!article?.previewEnabled;

if (this.shouldRenderOnsitePreview_) {
this.showPreviewAutoPrompt_(article!, params);
Expand All @@ -234,10 +232,6 @@ export class AutoPromptManager {
return;
}
// Set experiment flags here.
this.onsitePreviewEnabled_ = this.isArticleExperimentEnabled_(
article,
ArticleExperimentFlags.ONSITE_PREVIEW_ENABLED
);
this.actionOrchestrationExperiment_ = this.isArticleExperimentEnabled_(
article,
ArticleExperimentFlags.ACTION_ORCHESTRATION_EXPERIMENT
Expand All @@ -262,10 +256,13 @@ export class AutoPromptManager {
params.autoPromptType
)!;

// Default isClosable to what is set in the page config.
// Otherwise, the prompt is blocking for publications with a
// subscription revenue model, while all others can be dismissed.
this.isClosable_ = params.isClosable ?? !this.isSubscription_();
// Default isClosable to what is set in the page config and fallback to
// if the prompt to preview is a subscription prompt.
// For FPA M0.5 - default to the contentType.
// TODO(b/364344782): Determine closability for FPA M1+.
this.isClosable_ = this.actionOrchestrationExperiment_
justinchou-google marked this conversation as resolved.
Show resolved Hide resolved
? params.contentType === ContentType.OPEN
: params.isClosable ?? !this.isSubscription_();

const previewAction = actions[0];

Expand Down
5 changes: 0 additions & 5 deletions src/runtime/experiment-flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,6 @@ export enum ArticleExperimentFlags {
*/
BACKGROUND_CLICK_BEHAVIOR_EXPERIMENT = 'background_click_behavior_experiment',

/**
* Experiment flag to enable onsite preview.
*/
ONSITE_PREVIEW_ENABLED = 'onsite_preview_enabled',

/**
* [FPA M0.5] Experiment flag to enable the new autoPromptManager flow to use
* actionOrchestration from the article response as the source of the
Expand Down
Loading