Skip to content

fix(analytics, android, ios): cast item INDEX param to integer#8964

Open
brojor wants to merge 1 commit intoinvertase:mainfrom
brojor:fix/analytics-item-index-integer-cast
Open

fix(analytics, android, ios): cast item INDEX param to integer#8964
brojor wants to merge 1 commit intoinvertase:mainfrom
brojor:fix/analytics-item-index-integer-cast

Conversation

@brojor
Copy link
Copy Markdown

@brojor brojor commented Apr 8, 2026

Description

The React Native bridge converts all JS numbers to double, but the native Firebase SDK expects FirebaseAnalytics.Param.INDEX (which maps to item_list_index) as an integer/long. When a double is forwarded, Firebase does not recognise it as the standard ecommerce parameter — item_list_index ends up as (not set) in GA4 / BigQuery, breaking attribution of clicks/views to list positions.

The library already handles this exact problem for Param.QUANTITY in both native modules. This PR mirrors that conversion for Param.INDEX:

  • Android (ReactNativeFirebaseAnalyticsModule.java): putLong(FirebaseAnalytics.Param.INDEX, (long) number)
  • iOS (RNFBAnalyticsModule.m): item[kFIRParameterIndex] = @([item[kFIRParameterIndex] integerValue])

No JS / TS changes — the public API already accepts index: number, only the native coercion was missing.

Related issues

None filed upstream; happy to open one if preferred.

Release Summary

Fix item_list_index showing as (not set) in GA4 / BigQuery when index is provided on items[].

Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
    • Yes
  • My change supports the following platforms;
    • Android
    • iOS
    • Other (macOS, web)
  • My change includes tests;
    • e2e tests added or updated in packages/**/e2e
    • jest tests added or updated in packages/**/__tests__
  • I have updated TypeScript types that are affected by my change.
  • This is a breaking change;
    • Yes
    • No

No tests added — the existing QUANTITY conversion (the precedent this PR follows) is also not covered by jest/e2e tests, since the coercion happens in the native modules below the JS bridge and there is no native test infra in the analytics package. Happy to add coverage if maintainers point me at the right place.

Test Plan

Verified in production via `patch-package` against `@react-native-firebase/analytics@22.3.0` in a live e-commerce app:

  • Before: `item_list_index` arrives as `(not set)` in GA4 / BigQuery despite `index` being set on every item.
  • After: `item_list_index` is populated with the correct integer position for `view_item_list`, `select_item`, and related ecommerce events.

Note

Low Risk
Small, localized change to native parameter coercion for analytics events; low risk aside from potential truncation if callers pass non-integer index values.

Overview
Ensures Firebase ecommerce items[] event params send INDEX/item_list_index as an integer type instead of a JS-bridge double.

On Android, ReactNativeFirebaseAnalyticsModule.toBundle now casts FirebaseAnalytics.Param.INDEX to long; on iOS, cleanJavascriptParams now coerces kFIRParameterIndex to an integerValue, mirroring existing QUANTITY handling.

Reviewed by Cursor Bugbot for commit 77c898a. Bugbot is set up for automated code reviews on this repo. Configure here.

🔥

The React Native bridge converts all JS numbers to double, but the
native Firebase SDK expects FirebaseAnalytics.Param.INDEX as an
integer/long. When a double is passed, Firebase does not recognise it
as the standard ecommerce parameter and item_list_index ends up as
(not set) in GA4 / BigQuery.

Mirror the existing QUANTITY conversion for INDEX in both native
modules so that JS numbers are coerced to integer before being
forwarded to Firebase.
@vercel
Copy link
Copy Markdown

vercel bot commented Apr 8, 2026

@brojor is attempting to deploy a commit to the Invertase Team on Vercel.

A member of the Team first needs to authorize it.

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Apr 8, 2026

CLA assistant check
All committers have signed the CLA.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds support for the INDEX parameter in Firebase Analytics for both Android and iOS platforms. On Android, the parameter is converted from a double to a long, while on iOS, it is converted to an integer. A review comment suggests improving variable naming for better readability and notes a potential inconsistency in how numeric parameters are typed compared to the Firebase SDK expectations.

Comment on lines +214 to +217
if (itemBundle.containsKey(FirebaseAnalytics.Param.INDEX)) {
double number = itemBundle.getDouble(FirebaseAnalytics.Param.INDEX);
itemBundle.putLong(FirebaseAnalytics.Param.INDEX, (long) number);
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

There's an inconsistency in how numeric parameters are handled. The existing code for QUANTITY uses putInt, while this change uses putLong for INDEX. According to the Firebase SDK documentation, both parameters are expected to be of type long. For correctness and consistency, QUANTITY should also be handled as a long.

Additionally, using a more descriptive variable name instead of number would improve readability.

Suggested change
if (itemBundle.containsKey(FirebaseAnalytics.Param.INDEX)) {
double number = itemBundle.getDouble(FirebaseAnalytics.Param.INDEX);
itemBundle.putLong(FirebaseAnalytics.Param.INDEX, (long) number);
}
if (itemBundle.containsKey(FirebaseAnalytics.Param.INDEX)) {
double index = itemBundle.getDouble(FirebaseAnalytics.Param.INDEX);
itemBundle.putLong(FirebaseAnalytics.Param.INDEX, (long) index);
}

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regarding the QUANTITY inconsistency — I'd prefer to keep that out of this PR to stay focused on the INDEX fix. If QUANTITY should indeed be a long per the Firebase SDK, that's a pre-existing issue and deserves its own PR so it can be reviewed and reverted independently.

For the variable naming, I intentionally kept number to stay consistent with the existing QUANTITY block right above, which uses the same pattern. Renaming only the new lines would introduce inconsistency within the same method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants