Skip to content

Tag PID to BQ delivery metric #7788

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

Merged
merged 5 commits into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
12 changes: 9 additions & 3 deletions packages/messaging/src/helpers/externalizePayload.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ describe('externalizePayload', () => {
// eslint-disable-next-line camelcase
collapse_key: 'collapse',
// eslint-disable-next-line camelcase
fcmMessageId: 'mid'
fcmMessageId: 'mid',
// eslint-disable-next-line camelcase
productId: 123
};

const payload: MessagePayload = {
Expand Down Expand Up @@ -66,7 +68,9 @@ describe('externalizePayload', () => {
// eslint-disable-next-line camelcase
collapse_key: 'collapse',
// eslint-disable-next-line camelcase
fcmMessageId: 'mid'
fcmMessageId: 'mid',
// eslint-disable-next-line camelcase
productId: 123
};

const payload: MessagePayload = {
Expand Down Expand Up @@ -100,7 +104,9 @@ describe('externalizePayload', () => {
// eslint-disable-next-line camelcase
collapse_key: 'collapse',
// eslint-disable-next-line camelcase
fcmMessageId: 'mid'
fcmMessageId: 'mid',
// eslint-disable-next-line camelcase
productId: 123
};

const payload: MessagePayload = {
Expand Down
25 changes: 22 additions & 3 deletions packages/messaging/src/helpers/logToFirelog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ import {
FcmEvent,
LogEvent,
LogRequest,
LogResponse
LogResponse,
ComplianceData
} from '../interfaces/logging-types';

import { MessagePayloadInternal } from '../interfaces/internal-message-payload';
Expand Down Expand Up @@ -162,7 +163,8 @@ export async function stageLog(
await messaging.firebaseDependencies.installations.getId()
);

createAndEnqueueLogEvent(messaging, fcmEvent);

createAndEnqueueLogEvent(messaging, fcmEvent, internalPayload.productId);
}

function createFcmEvent(
Expand Down Expand Up @@ -208,18 +210,35 @@ function createFcmEvent(

function createAndEnqueueLogEvent(
messaging: MessagingService,
fcmEvent: FcmEvent
fcmEvent: FcmEvent,
productId: number
): void {
const logEvent = {} as LogEvent;

/* eslint-disable camelcase */
logEvent.event_time_ms = Math.floor(Date.now()).toString();
logEvent.source_extension_json_proto3 = JSON.stringify(fcmEvent);

if (!!productId) {
logEvent.compliance_data = buildComplianceData(productId);
}
// eslint-disable-next-line camelcase

messaging.logEvents.push(logEvent);
}

function buildComplianceData(productId: number): ComplianceData {
const complianceData: ComplianceData = {
privacy_context: {
prequest: {
origin_associated_product_id: productId,
},
},
};

return complianceData;
}

export function _createLogRequest(logEventQueue: LogEvent[]): LogRequest {
const logRequest = {} as LogRequest;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export interface MessagePayloadInternal {
isFirebaseMessaging?: boolean;
from: string;
fcmMessageId: string;
productId: number;
// eslint-disable-next-line camelcase
collapse_key: string;
}
Expand Down
15 changes: 15 additions & 0 deletions packages/messaging/src/interfaces/logging-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,21 @@ export interface LogEvent {

// A stringified json proto version of source_extension.
source_extension_json_proto3: string;

// The compliance data associated with this event.
compliance_data: ComplianceData;
}

export interface ComplianceData {
privacy_context: ExternalPrivacyContext;
}

export interface ExternalPrivacyContext {
prequest: ExternalPRequestContext;
}

export interface ExternalPRequestContext {
origin_associated_product_id: number;
}
/* eslint-enable camelcase */

Expand Down
3 changes: 2 additions & 1 deletion packages/messaging/src/listeners/sw-listeners.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ const DISPLAY_MESSAGE: MessagePayloadInternal = {
// eslint-disable-next-line camelcase
collapse_key: 'collapse',
// eslint-disable-next-line camelcase
fcmMessageId: 'mid'
fcmMessageId: 'mid',
productId: 123
};

// maxActions is an experimental property and not part of the official
Expand Down
20 changes: 18 additions & 2 deletions packages/messaging/src/testing/fakes/logging-object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,16 @@ import {
FcmEvent,
LogEvent,
LogResponse,
UserResponse
UserResponse,
ComplianceData
} from '../../interfaces/logging-types';

export function getFakeLogEvent(): LogEvent {
return {
/* eslint-disable camelcase */
event_time_ms: '0',
source_extension_json_proto3: JSON.stringify(getFakeFcmEvent())
source_extension_json_proto3: JSON.stringify(getFakeFcmEvent()),
compliance_data: getFakeComplianceData()
/* eslint-enable camelcase */
};
}
Expand All @@ -50,6 +52,20 @@ function getFakeFcmEvent(): FcmEvent {
};
}

function getFakeComplianceData(): ComplianceData {
const fakeComplianceData: ComplianceData = {
/* eslint-disable camelcase */
privacy_context: {
prequest: {
origin_associated_product_id: 123,
},
},
/* eslint-enable camelcase */
};

return fakeComplianceData;
}

export function getSuccessResponse(): LogResponse {
return Object.create({
nextRequestWaitMillis: 1000,
Expand Down