Skip to content

Commit ce87d25

Browse files
Adding a new API that allows iOS users to log notification delivery signal that exports to BigQuery. (#6181)
1 parent a0f054e commit ce87d25

25 files changed

+1098
-51
lines changed

FirebaseMessaging.podspec

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ device, and it is completely free.
3535

3636
base_dir = "FirebaseMessaging/"
3737
s.source_files = [
38-
base_dir + 'Sources/**/*.[mh]',
38+
base_dir + 'Sources/**/*',
39+
base_dir + 'Sources/Protogen/nanopb/*.h',
3940
'Interop/Analytics/Public/*.h',
4041
'FirebaseCore/Sources/Private/*.h',
4142
'FirebaseInstallations/Source/Library/Private/*.h',
@@ -44,9 +45,12 @@ device, and it is completely free.
4445
s.library = 'sqlite3'
4546
s.pod_target_xcconfig = {
4647
'GCC_C_LANGUAGE_STANDARD' => 'c99',
48+
'GCC_PREPROCESSOR_DEFINITIONS' =>
49+
# for nanopb:
50+
'PB_FIELD_32BIT=1 PB_NO_PACKED_STRUCTS=1 PB_ENABLE_MALLOC=1',
4751
# Unit tests do library imports using repo-root relative paths.
4852
'HEADER_SEARCH_PATHS' => '"${PODS_TARGET_SRCROOT}"',
49-
}
53+
}
5054
s.ios.framework = 'SystemConfiguration'
5155
s.tvos.framework = 'SystemConfiguration'
5256
s.osx.framework = 'SystemConfiguration'
@@ -57,6 +61,8 @@ device, and it is completely free.
5761
s.dependency 'GoogleUtilities/Reachability', '~> 7.4'
5862
s.dependency 'GoogleUtilities/Environment', '~> 7.4'
5963
s.dependency 'GoogleUtilities/UserDefaults', '~> 7.4'
64+
s.dependency 'GoogleDataTransport', '~> 9.0'
65+
s.dependency 'nanopb', '~> 2.30908.0'
6066

6167
s.test_spec 'unit' do |unit_tests|
6268
unit_tests.scheme = { :code_coverage => true }

FirebaseMessaging/Apps/AdvancedSample/AdvancedSample.xcodeproj/project.pbxproj

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,14 @@
3131
5194496E258AF2D000297021 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 5194496D258AF2D000297021 /* Preview Assets.xcassets */; };
3232
51944B28258B091A00297021 /* GoogleService-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 51944B27258B091A00297021 /* GoogleService-Info.plist */; };
3333
51944B9D258B136000297021 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 51944B9C258B136000297021 /* Assets.xcassets */; };
34-
51944BE1258BE42F00297021 /* GoogleService-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 51944BE0258BE42F00297021 /* GoogleService-Info.plist */; };
3534
51A1F3A525883DCF0025932B /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 51A1F3A425883DCF0025932B /* Preview Assets.xcassets */; };
3635
51A1F3B125883E370025932B /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51A1F3B025883E370025932B /* AppDelegate.swift */; };
3736
51A1F3B525883E630025932B /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51A1F3B425883E630025932B /* SceneDelegate.swift */; };
3837
51A1F3B825883E810025932B /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51A1F3B725883E810025932B /* ContentView.swift */; };
3938
51A1F3C625883EF60025932B /* Identity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51A1F3C525883EF60025932B /* Identity.swift */; };
4039
51A1F3CA25883EFF0025932B /* UserSettings.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51A1F3C825883EFF0025932B /* UserSettings.swift */; };
4140
51A1F3CB25883EFF0025932B /* TopicView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51A1F3C925883EFF0025932B /* TopicView.swift */; };
42-
51A1F3CE25883FAD0025932B /* GoogleService-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 51A1F3CD25883FAD0025932B /* GoogleService-Info.plist */; };
41+
51C21D212667FBCE0079AEEE /* GoogleService-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 51C21D202667FBCE0079AEEE /* GoogleService-Info.plist */; };
4342
51C24C622589603800236F25 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 51C24C602589603800236F25 /* LaunchScreen.storyboard */; };
4443
51C24C652589606B00236F25 /* logo.png in Resources */ = {isa = PBXBuildFile; fileRef = 51C24C642589606B00236F25 /* logo.png */; };
4544
/* End PBXBuildFile section */
@@ -149,7 +148,6 @@
149148
51944A86258B012A00297021 /* SampleWatchWatchKitExtension.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = SampleWatchWatchKitExtension.entitlements; sourceTree = "<group>"; };
150149
51944B27258B091A00297021 /* GoogleService-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "GoogleService-Info.plist"; sourceTree = "<group>"; };
151150
51944B9C258B136000297021 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; name = Assets.xcassets; path = ../../Shared/Assets.xcassets; sourceTree = "<group>"; };
152-
51944BE0258BE42F00297021 /* GoogleService-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "GoogleService-Info.plist"; sourceTree = "<group>"; };
153151
51A1F39825883DCE0025932B /* AdvancedSample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = AdvancedSample.app; sourceTree = BUILT_PRODUCTS_DIR; };
154152
51A1F3A425883DCF0025932B /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = "<group>"; };
155153
51A1F3A925883DCF0025932B /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
@@ -159,7 +157,7 @@
159157
51A1F3C525883EF60025932B /* Identity.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Identity.swift; path = ../../Shared/Identity.swift; sourceTree = "<group>"; };
160158
51A1F3C825883EFF0025932B /* UserSettings.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = UserSettings.swift; path = ../../Shared/UserSettings.swift; sourceTree = "<group>"; };
161159
51A1F3C925883EFF0025932B /* TopicView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = TopicView.swift; path = ../../Shared/TopicView.swift; sourceTree = "<group>"; };
162-
51A1F3CD25883FAD0025932B /* GoogleService-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = "GoogleService-Info.plist"; path = "../../Shared/GoogleService-Info.plist"; sourceTree = "<group>"; };
160+
51C21D202667FBCE0079AEEE /* GoogleService-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = "GoogleService-Info.plist"; path = "../../Shared/GoogleService-Info.plist"; sourceTree = "<group>"; };
163161
51C24C612589603800236F25 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = ../../Shared/Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
164162
51C24C642589606B00236F25 /* logo.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = logo.png; path = ../../Shared/logo.png; sourceTree = "<group>"; };
165163
/* End PBXFileReference section */
@@ -253,7 +251,6 @@
253251
51944961258AF2D000297021 /* SampleWatchWatchKitExtension */ = {
254252
isa = PBXGroup;
255253
children = (
256-
51944BE0258BE42F00297021 /* GoogleService-Info.plist */,
257254
51944A86258B012A00297021 /* SampleWatchWatchKitExtension.entitlements */,
258255
51944962258AF2D000297021 /* HostingController.swift */,
259256
51944964258AF2D000297021 /* ContentView.swift */,
@@ -303,10 +300,10 @@
303300
51A1F39A25883DCE0025932B /* AdvancedSample */ = {
304301
isa = PBXGroup;
305302
children = (
303+
51C21D202667FBCE0079AEEE /* GoogleService-Info.plist */,
306304
519448DE2589900400297021 /* AdvancedSample.entitlements */,
307305
51C24C642589606B00236F25 /* logo.png */,
308306
51C24C602589603800236F25 /* LaunchScreen.storyboard */,
309-
51A1F3CD25883FAD0025932B /* GoogleService-Info.plist */,
310307
51A1F3C925883EFF0025932B /* TopicView.swift */,
311308
51A1F3C825883EFF0025932B /* UserSettings.swift */,
312309
51A1F3C525883EF60025932B /* Identity.swift */,
@@ -539,17 +536,16 @@
539536
files = (
540537
5194496E258AF2D000297021 /* Preview Assets.xcassets in Resources */,
541538
5194496B258AF2D000297021 /* Assets.xcassets in Resources */,
542-
51944BE1258BE42F00297021 /* GoogleService-Info.plist in Resources */,
543539
);
544540
runOnlyForDeploymentPostprocessing = 0;
545541
};
546542
51A1F39625883DCE0025932B /* Resources */ = {
547543
isa = PBXResourcesBuildPhase;
548544
buildActionMask = 2147483647;
549545
files = (
550-
51A1F3CE25883FAD0025932B /* GoogleService-Info.plist in Resources */,
551546
51C24C652589606B00236F25 /* logo.png in Resources */,
552547
51C24C622589603800236F25 /* LaunchScreen.storyboard in Resources */,
548+
51C21D212667FBCE0079AEEE /* GoogleService-Info.plist in Resources */,
553549
51A1F3A525883DCF0025932B /* Preview Assets.xcassets in Resources */,
554550
51944B9D258B136000297021 /* Assets.xcassets in Resources */,
555551
);

FirebaseMessaging/Apps/AdvancedSample/NotificationServiceExtension/NotificationService.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ class NotificationService: UNNotificationServiceExtension {
2929
// Modify the notification content here...
3030
bestAttemptContent.title = "\(bestAttemptContent.title) 👩🏻‍💻"
3131

32+
// Log Delivery signals and export to BigQuery.
33+
Messaging.serviceExtension()
34+
.exportDeliveryMetricsToBigQuery(withMessageInfo: request.content.userInfo)
35+
36+
// Add image, call this last to finish with the content handler.
3237
Messaging.serviceExtension()
3338
.populateNotificationContent(bestAttemptContent, withContentHandler: contentHandler)
3439
}

FirebaseMessaging/Apps/AdvancedSample/Podfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ def shared_pods
99
pod 'FirebaseMessaging', :path => '../../../'
1010
pod 'FirebaseCoreDiagnostics', :path => '../../../'
1111
pod 'FirebaseInstallations', :path => '../../../'
12+
pod 'GoogleDataTransport'
1213
end
1314

1415
target 'AdvancedSample' do

FirebaseMessaging/Apps/Sample/Sample.xcodeproj/project.pbxproj

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
archiveVersion = 1;
44
classes = {
55
};
6-
objectVersion = 51;
6+
objectVersion = 50;
77
objects = {
88

99
/* Begin PBXBuildFile section */
@@ -15,7 +15,6 @@
1515
51A1F3DB2588405A0025932B /* TopicView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51A1F3D72588405A0025932B /* TopicView.swift */; };
1616
51A1F3DC2588405A0025932B /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51A1F3D82588405A0025932B /* SceneDelegate.swift */; };
1717
51A1F3E12588406A0025932B /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51A1F3DE2588406A0025932B /* AppDelegate.swift */; };
18-
51A1F3E22588406A0025932B /* GoogleService-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 51A1F3DF2588406A0025932B /* GoogleService-Info.plist */; };
1918
51A1F3E32588406A0025932B /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51A1F3E02588406A0025932B /* ContentView.swift */; };
2019
51C24C5225894EDB00236F25 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 51C24C5025894EDB00236F25 /* LaunchScreen.storyboard */; };
2120
51C24C742589614800236F25 /* logo.png in Resources */ = {isa = PBXBuildFile; fileRef = 51C24C732589614800236F25 /* logo.png */; };
@@ -33,7 +32,6 @@
3332
51A1F3D72588405A0025932B /* TopicView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = TopicView.swift; path = ../../Shared/TopicView.swift; sourceTree = "<group>"; };
3433
51A1F3D82588405A0025932B /* SceneDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SceneDelegate.swift; path = ../../Shared/SceneDelegate.swift; sourceTree = "<group>"; };
3534
51A1F3DE2588406A0025932B /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = AppDelegate.swift; path = ../../Shared/AppDelegate.swift; sourceTree = "<group>"; };
36-
51A1F3DF2588406A0025932B /* GoogleService-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = "GoogleService-Info.plist"; path = "../../Shared/GoogleService-Info.plist"; sourceTree = "<group>"; };
3735
51A1F3E02588406A0025932B /* ContentView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ContentView.swift; path = ../../Shared/ContentView.swift; sourceTree = "<group>"; };
3836
51C24C5125894EDB00236F25 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = ../../Shared/Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
3937
51C24C732589614800236F25 /* logo.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = logo.png; path = ../../Shared/logo.png; sourceTree = "<group>"; };
@@ -81,7 +79,6 @@
8179
51C24C5025894EDB00236F25 /* LaunchScreen.storyboard */,
8280
51A1F3DE2588406A0025932B /* AppDelegate.swift */,
8381
51A1F3E02588406A0025932B /* ContentView.swift */,
84-
51A1F3DF2588406A0025932B /* GoogleService-Info.plist */,
8582
51A1F3D52588405A0025932B /* Identity.swift */,
8683
51A1F3D82588405A0025932B /* SceneDelegate.swift */,
8784
51A1F3D72588405A0025932B /* TopicView.swift */,
@@ -162,7 +159,6 @@
162159
isa = PBXResourcesBuildPhase;
163160
buildActionMask = 2147483647;
164161
files = (
165-
51A1F3E22588406A0025932B /* GoogleService-Info.plist in Resources */,
166162
51C24C742589614800236F25 /* logo.png in Resources */,
167163
5125CCA92437F472006CA5D0 /* Preview Assets.xcassets in Resources */,
168164
51C24C5225894EDB00236F25 /* LaunchScreen.storyboard in Resources */,

FirebaseMessaging/Apps/Sample/Sample/Info.plist

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@
3737
</array>
3838
</dict>
3939
</dict>
40+
<key>UIBackgroundModes</key>
41+
<array>
42+
<string>remote-notification</string>
43+
</array>
4044
<key>UILaunchStoryboardName</key>
4145
<string>LaunchScreen</string>
4246
<key>UIRequiredDeviceCapabilities</key>

FirebaseMessaging/Apps/Shared/AppDelegate.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
import UIKit
1616
import FirebaseCore
17+
import FirebaseMessaging
1718
import FirebaseAnalytics
1819

1920
@UIApplicationMain
@@ -22,6 +23,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
2223
didFinishLaunchingWithOptions launchOptions: [UIApplication
2324
.LaunchOptionsKey: Any]?) -> Bool {
2425
FirebaseApp.configure()
26+
application.delegate = self
2527
FirebaseAnalytics.Analytics.logEvent("test", parameters: nil)
2628

2729
let center = UNUserNotificationCenter.current()
@@ -33,6 +35,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
3335
}
3436
}
3537
application.registerForRemoteNotifications()
38+
3639
return true
3740
}
3841

@@ -49,4 +52,14 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
4952
withCompletionHandler completionHandler: @escaping () -> Void) {
5053
completionHandler()
5154
}
55+
56+
func application(_ application: UIApplication,
57+
didReceiveRemoteNotification userInfo: [AnyHashable: Any],
58+
fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult)
59+
-> Void) {
60+
print("Hidden message arrived:\n" + userInfo.debugDescription)
61+
// Log delivery signal for data/hidden/background messages
62+
Messaging.serviceExtension().exportDeliveryMetricsToBigQuery(withMessageInfo: userInfo)
63+
completionHandler(.newData)
64+
}
5265
}

FirebaseMessaging/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# unreleased
2+
- [added] Added new API `FIRMessagingExtensionHelper exportDeliveryMetricsToBigQuery` that allows developers to enable notification delivery metrics to BigQuery. (#6181)
3+
14
# 2021-06 -- v8.2.0
25
- [fixed] Fixed an issue that local scheduled notification is not set correctly due to sound type. (#8172)
36

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Copyright 2021 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
#
15+
16+
# Options for mee.protos
17+
fm.MessagingClientEvent.message_id type:FT_POINTER
18+
fm.MessagingClientEvent.instance_id type:FT_POINTER
19+
fm.MessagingClientEvent.package_name type:FT_POINTER
20+
fm.MessagingClientEvent.analytics_label type:FT_POINTER
21+
fm.MessagingClientEvent.composer_label type:FT_POINTER
22+
fm.MessagingClientEventExtension.messaging_client_event type:FT_POINTER
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
//
2+
// Copyright 2020 Google LLC.
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
//
16+
17+
syntax = "proto3";
18+
19+
package fm;
20+
21+
message MessagingClientEvent {
22+
23+
int64 project_number = 1;
24+
25+
string message_id = 2;
26+
27+
string instance_id = 3;
28+
29+
enum MessageType {
30+
UNKNOWN = 0;
31+
DATA_MESSAGE = 1;
32+
TOPIC = 2;
33+
DISPLAY_NOTIFICATION = 3;
34+
}
35+
36+
MessageType message_type = 4;
37+
38+
enum SDKPlatform {
39+
UNKNOWN_OS = 0;
40+
ANDROID = 1;
41+
IOS = 2;
42+
WEB = 3;
43+
}
44+
45+
SDKPlatform sdk_platform = 5;
46+
47+
string package_name = 6;
48+
49+
enum Event {
50+
UNKNOWN_EVENT = 0;
51+
MESSAGE_DELIVERED = 1;
52+
MESSAGE_OPEN = 2;
53+
}
54+
55+
Event event = 12;
56+
57+
string analytics_label = 13;
58+
59+
int64 campaign_id = 14;
60+
61+
string composer_label = 15;
62+
}
63+
64+
message MessagingClientEventExtension {
65+
MessagingClientEvent messaging_client_event = 1;
66+
}

0 commit comments

Comments
 (0)