Skip to content

Commit 14c26bb

Browse files
authored
fix(analytics): long/double handling for android (#225)
1 parent 843ffef commit 14c26bb

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

packages/firebase-analytics/index.android.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@ Object.defineProperty(fb, 'analytics', {
1515
writable: false,
1616
});
1717

18-
function serialize(data) {
19-
let store;
18+
function numberHasDecimals(item: number) {
19+
return !(item % 1 === 0);
20+
}
2021

22+
function serialize(data) {
2123
switch (typeof data) {
2224
case 'string':
2325
case 'boolean':
@@ -31,7 +33,7 @@ function serialize(data) {
3133
}
3234

3335
if (Array.isArray(data)) {
34-
store = new java.util.ArrayList();
36+
const store = new java.util.ArrayList();
3537
data.forEach((item) => {
3638
const value = serialize(item);
3739
switch (typeof value) {
@@ -49,15 +51,19 @@ function serialize(data) {
4951
return store;
5052
}
5153

52-
store = new android.os.Bundle();
54+
const store = new android.os.Bundle();
5355
Object.keys(data).forEach((key) => {
5456
const value = serialize(data[key]);
5557
switch (typeof value) {
5658
case 'boolean':
5759
store.putBoolean(key, value);
5860
break;
5961
case 'number':
60-
store.putInt(key, value);
62+
if (numberHasDecimals(value)) {
63+
store.putDouble(key, value);
64+
} else {
65+
store.putLong(key, value);
66+
}
6167
break;
6268
case 'string':
6369
store.putString(key, value);

0 commit comments

Comments
 (0)