Skip to content

Commit

Permalink
Adds BYOP and Rewarded Ad impressions to prompt frequency capping flo…
Browse files Browse the repository at this point in the history
…w. (#3434)

* add byop impression to freq capping events

* add rewarded ad

* add test

* add imp_ad expectation

* fix unknown autoprompt type

* add coverage

* revert

* revert more

---------

Co-authored-by: justinchou-google <justinchou-google@users.noreply.github.com>
  • Loading branch information
justinchou-google and justinchou-google authored Feb 21, 2024
1 parent 67c849e commit be6ca6f
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 15 deletions.
47 changes: 32 additions & 15 deletions src/runtime/auto-prompt-manager-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -775,19 +775,27 @@ describes.realWin('AutoPromptManager', (env) => {

[
{
storageKey: ImpressionStorageKeys.NEWSLETTER_SIGNUP,
eventType: AnalyticsEvent.IMPRESSION_NEWSLETTER_OPT_IN,
storageKey: ImpressionStorageKeys.NEWSLETTER_SIGNUP,
},
{
eventType: AnalyticsEvent.IMPRESSION_BYOP_NEWSLETTER_OPT_IN,
storageKey: ImpressionStorageKeys.NEWSLETTER_SIGNUP,
},
{
storageKey: ImpressionStorageKeys.REGISTRATION_WALL,
eventType: AnalyticsEvent.IMPRESSION_REGWALL_OPT_IN,
storageKey: ImpressionStorageKeys.REGISTRATION_WALL,
},
{
storageKey: ImpressionStorageKeys.REWARDED_SURVEY,
eventType: AnalyticsEvent.IMPRESSION_SURVEY,
storageKey: ImpressionStorageKeys.REWARDED_SURVEY,
},
].forEach(({storageKey, eventType}) => {
it(`for storageKey=${storageKey} and eventType=${eventType}, should set frequency cap local storage if experiment is enabled`, async () => {
{
eventType: AnalyticsEvent.IMPRESSION_REWARDED_AD,
storageKey: ImpressionStorageKeys.REWARDED_AD,
},
].forEach(({eventType, storageKey}) => {
it(`for eventType=${eventType} and storageKey=${storageKey}, should set frequency cap timestamps via local storage if experiment is enabled`, async () => {
autoPromptManager.frequencyCappingLocalStorageEnabled_ = true;
autoPromptManager.isClosable_ = true;
storageMock
Expand Down Expand Up @@ -3469,7 +3477,7 @@ describes.realWin('AutoPromptManager', (env) => {
.once();

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

expect(logEventSpy).to.be.calledOnceWith({
eventType: AnalyticsEvent.EVENT_PROMPT_FREQUENCY_CAP_MET,
Expand Down Expand Up @@ -3611,7 +3619,7 @@ describes.realWin('AutoPromptManager', (env) => {
.once();

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

expect(logEventSpy).to.be.calledOnceWith({
eventType: AnalyticsEvent.EVENT_PROMPT_FREQUENCY_CAP_MET,
Expand Down Expand Up @@ -4047,7 +4055,7 @@ describes.realWin('AutoPromptManager', (env) => {
expect(actionFlowSpy).to.not.have.been.called;
});

it('should show the second dismissible prompt if the frequency cap for contributions is met on lock content', async () => {
it('should show the second dismissible prompt if the frequency cap for contributions is met on locked content', async () => {
sandbox.stub(pageConfig, 'isLocked').returns(true);
setupPreviousImpressionAndDismissals(
storageMock,
Expand Down Expand Up @@ -4082,7 +4090,7 @@ describes.realWin('AutoPromptManager', (env) => {
.once();

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

expect(logEventSpy).to.be.calledOnceWith({
eventType: AnalyticsEvent.EVENT_PROMPT_FREQUENCY_CAP_MET,
Expand Down Expand Up @@ -4293,7 +4301,7 @@ describes.realWin('AutoPromptManager', (env) => {
alwaysShow: false,
isClosable: true,
});
await tick(20);
await tick(25);

expect(autoPromptManager.promptFrequencyCappingEnabled_).to.equal(true);
expect(autoPromptManager.isClosable_).to.equal(true);
Expand Down Expand Up @@ -4389,7 +4397,7 @@ describes.realWin('AutoPromptManager', (env) => {
});
});

it('should not display a prompt for an unknown autoprompt type if the next action is a monetization prompt', async () => {
it('should display a monetization prompt for an unknown autoprompt type if the next action is a monetization prompt', async () => {
setupPreviousImpressionAndDismissals(
storageMock,
{
Expand All @@ -4412,11 +4420,11 @@ describes.realWin('AutoPromptManager', (env) => {
autoPromptType: 'unknown',
alwaysShow: false,
});
await tick(10);
await tick(25);

expect(autoPromptManager.promptFrequencyCappingEnabled_).to.equal(true);
expect(subscriptionPromptFnSpy).to.not.have.been.called;
expect(contributionPromptFnSpy).to.not.have.been.called;
expect(contributionPromptFnSpy).to.be.calledOnce;
expect(startSpy).to.not.have.been.called;
});

Expand Down Expand Up @@ -4457,7 +4465,7 @@ describes.realWin('AutoPromptManager', (env) => {
autoPromptType: 'unknown',
alwaysShow: false,
});
await tick(20);
await tick(25);

expect(autoPromptManager.promptFrequencyCappingEnabled_).to.equal(true);
expect(contributionPromptFnSpy).to.not.have.been.called;
Expand Down Expand Up @@ -4595,11 +4603,12 @@ describes.realWin('AutoPromptManager', (env) => {
storageMock,
impressions = {}
) {
const {contribution, newsletter, regwall, survey, subscription} = {
const {contribution, newsletter, regwall, survey, ad, subscription} = {
contribution: null,
newsletter: null,
regwall: null,
survey: null,
ad: null,
subscription: null,
...impressions,
};
Expand Down Expand Up @@ -4635,6 +4644,14 @@ describes.realWin('AutoPromptManager', (env) => {
)
.resolves(survey)
.once();
storageMock
.expects('get')
.withExactArgs(
ImpressionStorageKeys.REWARDED_AD,
/* useLocalStorage */ true
)
.resolves(ad)
.once();
storageMock
.expects('get')
.withExactArgs(
Expand Down
5 changes: 5 additions & 0 deletions src/runtime/auto-prompt-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,16 @@ const INTERVENTION_TO_STORAGE_KEY_MAP = new Map([
AnalyticsEvent.IMPRESSION_NEWSLETTER_OPT_IN,
ImpressionStorageKeys.NEWSLETTER_SIGNUP,
],
[
AnalyticsEvent.IMPRESSION_BYOP_NEWSLETTER_OPT_IN,
ImpressionStorageKeys.NEWSLETTER_SIGNUP,
],
[
AnalyticsEvent.IMPRESSION_REGWALL_OPT_IN,
ImpressionStorageKeys.REGISTRATION_WALL,
],
[AnalyticsEvent.IMPRESSION_SURVEY, ImpressionStorageKeys.REWARDED_SURVEY],
[AnalyticsEvent.IMPRESSION_REWARDED_AD, ImpressionStorageKeys.REWARDED_AD],
[
AnalyticsEvent.IMPRESSION_SWG_SUBSCRIPTION_MINI_PROMPT,
ImpressionStorageKeys.SUBSCRIPTION,
Expand Down

0 comments on commit be6ca6f

Please sign in to comment.