Skip to content

Commit

Permalink
[FPA M0.5] Error logging for Repeatability (#3586)
Browse files Browse the repository at this point in the history
* add error event logging for missing number of completions

* format test file

* remove unhelpful comment

---------

Co-authored-by: justinchou-google <justinchou-google@users.noreply.github.com>
  • Loading branch information
justinchou-google and justinchou-google authored Oct 21, 2024
1 parent f74fc70 commit a0852b9
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 9 deletions.
3 changes: 3 additions & 0 deletions src/proto/api_messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ export enum AnalyticsEvent {
IMPRESSION_HOSTED_PAGE_SUBSCRIPTION_OFFERS_ERROR = 54,
IMPRESSION_HOSTED_PAGE_CONTRIBUTION_OFFERS_ERROR = 55,
IMPRESSION_BYO_CTA = 56,
IMPRESSION_BYO_CTA_ERROR = 57,
ACTION_SUBSCRIBE = 1000,
ACTION_PAYMENT_COMPLETE = 1001,
ACTION_ACCOUNT_CREATED = 1002,
Expand Down Expand Up @@ -200,6 +201,7 @@ export enum AnalyticsEvent {
EVENT_SURVEY_ALREADY_SUBMITTED = 2006,
EVENT_SURVEY_COMPLETION_RECORD_FAILED = 2007,
EVENT_SURVEY_DATA_TRANSFER_FAILED = 2008,
EVENT_BYO_CTA_COMPLETION_RECORD_FAILED = 2009,
EVENT_CUSTOM = 3000,
EVENT_CONFIRM_TX_ID = 3001,
EVENT_CHANGED_TX_ID = 3002,
Expand Down Expand Up @@ -256,6 +258,7 @@ export enum AnalyticsEvent {
EVENT_CONTRIBUTION_PAYMENT_COMPLETE = 3051,
EVENT_HOSTED_PAGE_SUBSCRIPTION_PAYMENT_COMPLETE = 3054,
EVENT_HOSTED_PAGE_CONTRIBUTION_PAYMENT_COMPLETE = 3055,
EVENT_COMPLETION_COUNT_FOR_REPEATABLE_ACTION_MISSING_ERROR = 3056,
EVENT_SUBSCRIPTION_STATE = 4000,
}

Expand Down
23 changes: 23 additions & 0 deletions src/runtime/auto-prompt-manager-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5012,6 +5012,29 @@ describes.realWin('AutoPromptManager', (env) => {
});
expect(action).to.equal(CONTRIBUTION_INTERVENTION);
});

it('checkOrchestrationEligibility_ should log an error if completion count is missing for a repeatable action', async () => {
const isEligible = autoPromptManager.checkOrchestrationEligibility_(
{
configId: 'action_id',
type: 'TYPE_REWARDED_AD',
repeatability: {type: 'FINITE', count: 1},
},
new Set(['action_id']),
new Map()
);

expect(logEventSpy).to.be.calledOnceWith({
eventType:
AnalyticsEvent.EVENT_COMPLETION_COUNT_FOR_REPEATABLE_ACTION_MISSING_ERROR,
eventOriginator: EventOriginator.SWG_CLIENT,
isFromUserAction: false,
additionalParameters: null,
timestamp: sandbox.match.number,
configurationId: null,
});
expect(isEligible).to.equal(true);
});
});

describe('AudienceActionLocalFlow', () => {
Expand Down
29 changes: 20 additions & 9 deletions src/runtime/auto-prompt-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -532,10 +532,11 @@ export class AutoPromptManager {

// Filter the funnel of interventions by eligibility.
const numberOfCompletionsMap = new Map(
article.audienceActions!.actions!.map((action) => [
action.configurationId!,
action.numberOfCompletions ?? 0,
])
article
.audienceActions!.actions!.filter(
(action) => !!action.numberOfCompletions
)
.map((action) => [action.configurationId!, action.numberOfCompletions!])
);
interventionOrchestration = interventionOrchestration.filter(
(intervention) =>
Expand Down Expand Up @@ -1011,11 +1012,21 @@ export class AutoPromptManager {
!orchestration.repeatability.type ||
RepeatabilityType.UNSPECIFIED === orchestration.repeatability.type
? 1
: orchestration.repeatability.count; // TODO(justinchou) handle bad number of completions.
if (
numberOfCompletionsMap.get(orchestration.configId)! >=
maximumNumberOfCompletions
) {
: orchestration.repeatability.count;
let numberOfCompletions;
if (!numberOfCompletionsMap.has(orchestration.configId)) {
if (RepeatabilityType.FINITE === orchestration.repeatability.type) {
this.eventManager_.logSwgEvent(
AnalyticsEvent.EVENT_COMPLETION_COUNT_FOR_REPEATABLE_ACTION_MISSING_ERROR
);
}
numberOfCompletions = 0;
} else {
numberOfCompletions = numberOfCompletionsMap.get(
orchestration.configId
)!;
}
if (numberOfCompletions! >= maximumNumberOfCompletions) {
return false;
}
}
Expand Down

0 comments on commit a0852b9

Please sign in to comment.