Skip to content

Commit d0710d5

Browse files
authored
Create a logging service with flagsetDeliveryMetricsExportedToBigQueryEnabled to enable/disable (#5139)
1 parent f825b1d commit d0710d5

27 files changed

+909
-124
lines changed

.changeset/bright-clouds-pretend.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@firebase/messaging': minor
3+
'firebase': minor
4+
---
5+
6+
Allows retrieval of `messageId` from `MessagePayload`.

.vscode/settings.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@
1111
},
1212
"typescript.tsdk": "node_modules/typescript/lib",
1313
"files.associations": { "*.json": "jsonc" }
14-
}
14+
}
+69-68
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,69 @@
1-
## API Report File for "@firebase/messaging-exp"
2-
3-
> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).
4-
5-
```ts
6-
7-
import { FirebaseApp } from '@firebase/app-exp';
8-
import { NextFn } from '@firebase/util';
9-
import { Observer } from '@firebase/util';
10-
import { Unsubscribe } from '@firebase/util';
11-
12-
// @public
13-
export function deleteToken(messaging: Messaging): Promise<boolean>;
14-
15-
// @public
16-
export interface FcmOptions {
17-
analyticsLabel?: string;
18-
link?: string;
19-
}
20-
21-
// @public
22-
export function getMessaging(app?: FirebaseApp): Messaging;
23-
24-
// @public
25-
export function getToken(messaging: Messaging, options?: GetTokenOptions): Promise<string>;
26-
27-
// @public
28-
export interface GetTokenOptions {
29-
serviceWorkerRegistration?: ServiceWorkerRegistration;
30-
vapidKey?: string;
31-
}
32-
33-
// @public
34-
export function isSupported(): Promise<boolean>;
35-
36-
// @public
37-
export interface MessagePayload {
38-
collapseKey: string;
39-
data?: {
40-
[key: string]: string;
41-
};
42-
fcmOptions?: FcmOptions;
43-
from: string;
44-
notification?: NotificationPayload;
45-
}
46-
47-
// @public
48-
export interface Messaging {
49-
}
50-
51-
export { NextFn }
52-
53-
// @public
54-
export interface NotificationPayload {
55-
body?: string;
56-
image?: string;
57-
title?: string;
58-
}
59-
60-
export { Observer }
61-
62-
// @public
63-
export function onMessage(messaging: Messaging, nextOrObserver: NextFn<MessagePayload> | Observer<MessagePayload>): Unsubscribe;
64-
65-
export { Unsubscribe }
66-
67-
68-
```
1+
## API Report File for "@firebase/messaging-exp"
2+
3+
> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).
4+
5+
```ts
6+
7+
import { FirebaseApp } from '@firebase/app-exp';
8+
import { NextFn } from '@firebase/util';
9+
import { Observer } from '@firebase/util';
10+
import { Unsubscribe } from '@firebase/util';
11+
12+
// @public
13+
export function deleteToken(messaging: Messaging): Promise<boolean>;
14+
15+
// @public
16+
export interface FcmOptions {
17+
analyticsLabel?: string;
18+
link?: string;
19+
}
20+
21+
// @public
22+
export function getMessaging(app?: FirebaseApp): Messaging;
23+
24+
// @public
25+
export function getToken(messaging: Messaging, options?: GetTokenOptions): Promise<string>;
26+
27+
// @public
28+
export interface GetTokenOptions {
29+
serviceWorkerRegistration?: ServiceWorkerRegistration;
30+
vapidKey?: string;
31+
}
32+
33+
// @public
34+
export function isSupported(): Promise<boolean>;
35+
36+
// @public
37+
export interface MessagePayload {
38+
collapseKey: string;
39+
data?: {
40+
[key: string]: string;
41+
};
42+
fcmOptions?: FcmOptions;
43+
from: string;
44+
messageId: string;
45+
notification?: NotificationPayload;
46+
}
47+
48+
// @public
49+
export interface Messaging {
50+
}
51+
52+
export { NextFn }
53+
54+
// @public
55+
export interface NotificationPayload {
56+
body?: string;
57+
image?: string;
58+
title?: string;
59+
}
60+
61+
export { Observer }
62+
63+
// @public
64+
export function onMessage(messaging: Messaging, nextOrObserver: NextFn<MessagePayload> | Observer<MessagePayload>): Unsubscribe;
65+
66+
export { Unsubscribe }
67+
68+
69+
```

packages-exp/messaging-exp/src/api.ts

+22-2
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717

1818
import { FirebaseApp, _getProvider, getApp } from '@firebase/app-exp';
1919
import {
20-
Messaging,
2120
GetTokenOptions,
22-
MessagePayload
21+
MessagePayload,
22+
Messaging
2323
} from './interfaces/public-types';
2424
import {
2525
NextFn,
@@ -33,6 +33,7 @@ import { deleteToken as _deleteToken } from './api/deleteToken';
3333
import { getToken as _getToken } from './api/getToken';
3434
import { onBackgroundMessage as _onBackgroundMessage } from './api/onBackgroundMessage';
3535
import { onMessage as _onMessage } from './api/onMessage';
36+
import { _setDeliveryMetricsExportedToBigQueryEnabled } from './api/setDeliveryMetricsExportedToBigQueryEnabled';
3637

3738
/**
3839
* Retrieves a Firebase Cloud Messaging instance.
@@ -137,3 +138,22 @@ export function onBackgroundMessage(
137138
messaging = getModularInstance(messaging);
138139
return _onBackgroundMessage(messaging as MessagingService, nextOrObserver);
139140
}
141+
142+
/**
143+
* Enables or disables Firebase Cloud Messaging message delivery metrics export to BigQuery. By
144+
* default, message delivery metrics are not exported to BigQuery. Use this method to enable or
145+
* disable the export at runtime.
146+
*
147+
* @param messaging - The `FirebaseMessaging` instance.
148+
* @param enable - Whether Firebase Cloud Messaging should export message delivery metrics to
149+
* BigQuery.
150+
*
151+
* @public
152+
*/
153+
export function setDeliveryMetricsExportedToBigQueryEnabled(
154+
messaging: Messaging,
155+
enable: boolean
156+
): void {
157+
messaging = getModularInstance(messaging);
158+
return _setDeliveryMetricsExportedToBigQueryEnabled(messaging, enable);
159+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* @license
3+
* Copyright 2020 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
import { Messaging } from '../interfaces/public-types';
19+
import { MessagingService } from '../messaging-service';
20+
21+
export function _setDeliveryMetricsExportedToBigQueryEnabled(
22+
messaging: Messaging,
23+
enable: boolean
24+
): void {
25+
(messaging as MessagingService).deliveryMetricsExportedToBigQueryEnabled =
26+
enable;
27+
}

packages-exp/messaging-exp/src/helpers/externalizePayload.test.ts

+15-6
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,16 @@ describe('externalizePayload', () => {
3030
},
3131
from: 'from',
3232
// eslint-disable-next-line camelcase
33-
collapse_key: 'collapse'
33+
collapse_key: 'collapse',
34+
// eslint-disable-next-line camelcase
35+
fcm_message_id: 'mid'
3436
};
3537

3638
const payload: MessagePayload = {
3739
notification: { title: 'title', body: 'body', image: 'image' },
3840
from: 'from',
39-
collapseKey: 'collapse'
41+
collapseKey: 'collapse',
42+
messageId: 'mid'
4043
};
4144
expect(externalizePayload(internalPayload)).to.deep.equal(payload);
4245
});
@@ -50,13 +53,16 @@ describe('externalizePayload', () => {
5053
},
5154
from: 'from',
5255
// eslint-disable-next-line camelcase
53-
collapse_key: 'collapse'
56+
collapse_key: 'collapse',
57+
// eslint-disable-next-line camelcase
58+
fcm_message_id: 'mid'
5459
};
5560

5661
const payload: MessagePayload = {
5762
data: { foo: 'foo', bar: 'bar', baz: 'baz' },
5863
from: 'from',
59-
collapseKey: 'collapse'
64+
collapseKey: 'collapse',
65+
messageId: 'mid'
6066
};
6167
expect(externalizePayload(internalPayload)).to.deep.equal(payload);
6268
});
@@ -80,7 +86,9 @@ describe('externalizePayload', () => {
8086
},
8187
from: 'from',
8288
// eslint-disable-next-line camelcase
83-
collapse_key: 'collapse'
89+
collapse_key: 'collapse',
90+
// eslint-disable-next-line camelcase
91+
fcm_message_id: 'mid'
8492
};
8593

8694
const payload: MessagePayload = {
@@ -99,7 +107,8 @@ describe('externalizePayload', () => {
99107
analyticsLabel: 'label'
100108
},
101109
from: 'from',
102-
collapseKey: 'collapse'
110+
collapseKey: 'collapse',
111+
messageId: 'mid'
103112
};
104113
expect(externalizePayload(internalPayload)).to.deep.equal(payload);
105114
});

packages-exp/messaging-exp/src/helpers/externalizePayload.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ export function externalizePayload(
2424
const payload: MessagePayload = {
2525
from: internalPayload.from,
2626
// eslint-disable-next-line camelcase
27-
collapseKey: internalPayload.collapse_key
27+
collapseKey: internalPayload.collapse_key,
28+
// eslint-disable-next-line camelcase
29+
messageId: internalPayload.fcm_message_id
2830
} as MessagePayload;
2931

3032
propagateNotificationPayload(payload, internalPayload);

0 commit comments

Comments
 (0)