Skip to content

Commit 4fa5141

Browse files
committed
fix(firestore): set firestore client language attribution to react-native
1 parent acc665c commit 4fa5141

File tree

5 files changed

+61
-2
lines changed

5 files changed

+61
-2
lines changed

packages/firestore/RNFBFirestore.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Pod::Spec.new do |s|
2727
s.ios.deployment_target = firebase_ios_target
2828
s.macos.deployment_target = firebase_macos_target
2929
s.tvos.deployment_target = firebase_tvos_target
30-
s.source_files = 'ios/**/*.{h,m}'
30+
s.source_files = 'ios/**/*.{h,m,mm}'
3131

3232
# React Native dependencies
3333
s.dependency 'React-Core'

packages/firestore/android/src/main/java/io/invertase/firebase/firestore/UniversalFirebaseFirestoreCommon.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
import com.google.firebase.firestore.FirebaseFirestore;
2323
import com.google.firebase.firestore.FirebaseFirestoreSettings;
2424
import com.google.firebase.firestore.Query;
25+
import com.google.firebase.firestore.remote.FirestoreChannel;
26+
import io.invertase.firebase.app.ReactNativeFirebaseVersion;
2527
import io.invertase.firebase.common.UniversalFirebasePreferences;
2628
import java.lang.ref.WeakReference;
2729
import java.util.WeakHashMap;
@@ -42,6 +44,7 @@ static FirebaseFirestore getFirestoreForApp(String appName, String databaseId) {
4244
}
4345

4446
FirebaseApp firebaseApp = FirebaseApp.getInstance(appName);
47+
FirestoreChannel.setClientLanguage("gl-rn/" + ReactNativeFirebaseVersion.VERSION);
4548

4649
FirebaseFirestore instance = FirebaseFirestore.getInstance(firebaseApp, databaseId);
4750

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/**
2+
* Copyright (c) 2025-present Invertase Limited & Contributors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this library 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+
18+
#import <Foundation/Foundation.h>
19+
#import <string>
20+
21+
namespace firebase {
22+
namespace firestore {
23+
namespace api {
24+
25+
class Firestore {
26+
public:
27+
static void SetClientLanguage(std::string language_token);
28+
};
29+
30+
} // namespace api
31+
} // namespace firestore
32+
} // namespace firebase
33+
34+
@interface RNFBFirestoreClientLanguage : NSObject
35+
+ (void)setClientLanguage:(NSString *)language;
36+
@end
37+
38+
@implementation RNFBFirestoreClientLanguage
39+
+ (void)setClientLanguage:(NSString *)language {
40+
if (language == nil) {
41+
return;
42+
}
43+
std::string token = std::string([language UTF8String]);
44+
firebase::firestore::api::Firestore::SetClientLanguage(token);
45+
}
46+
@end

packages/firestore/ios/RNFBFirestore/RNFBFirestoreCommon.m

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
#import "RNFBFirestoreCommon.h"
1919
#import <RNFBApp/RNFBSharedUtils.h>
20+
#import <RNFBApp/RNFBVersion.h>
2021
#import "RNFBPreferences.h"
2122

2223
NSString *const FIRESTORE_CACHE_SIZE = @"firebase_firestore_cache_size";
@@ -28,6 +29,10 @@
2829

2930
NSMutableDictionary *instanceCache;
3031

32+
@interface RNFBFirestoreClientLanguage : NSObject
33+
+ (void)setClientLanguage:(NSString *)language;
34+
@end
35+
3136
@implementation RNFBFirestoreCommon
3237
+ (FIRFirestore *)getFirestoreForApp:(FIRApp *)app databaseId:(NSString *)databaseId {
3338
if (instanceCache == nil) {
@@ -43,6 +48,11 @@ + (FIRFirestore *)getFirestoreForApp:(FIRApp *)app databaseId:(NSString *)databa
4348

4449
FIRFirestore *instance = [FIRFirestore firestoreForApp:app database:databaseId];
4550

51+
#if TARGET_OS_IPHONE
52+
[RNFBFirestoreClientLanguage
53+
setClientLanguage:[NSString stringWithFormat:@"gl-rn/%@", RNFBVersionString]];
54+
#endif
55+
4656
[self setFirestoreSettings:instance
4757
appName:[RNFBSharedUtils getAppJavaScriptName:app.name]
4858
databaseId:databaseId];

tests/ios/Podfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2303,7 +2303,7 @@ SPEC CHECKSUMS:
23032303
RNFBAuth: 712e85c69a1f5b6d9c624eca9f92831976016a5e
23042304
RNFBCrashlytics: 7ba5fb1d27ae0019c9c0a46a0111758d9a7d0b0f
23052305
RNFBDatabase: 13814bc51ebf8af459d248dde4c0f0216a3bf486
2306-
RNFBFirestore: 6390b16301f1841ad57907f101103cbf6317f131
2306+
RNFBFirestore: a7c57bc634607929418b29b744be49897ae0ce1d
23072307
RNFBFunctions: 914a518d87227e0c5b3beb91789e0a2325dfb5dd
23082308
RNFBInAppMessaging: ca3a4590b39dd196751e3e70d938c7aa37a19409
23092309
RNFBInstallations: c85e437fa09155df6ed4947c37f44abeead104c2

0 commit comments

Comments
 (0)