Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🔥 [🐛] Event Attribution Discrepancy between Firebase and Google Ads in React Native Firebase SDK #8108

Open
2 of 10 tasks
ajouve opened this issue Nov 1, 2024 · 3 comments
Labels

Comments

@ajouve
Copy link

ajouve commented Nov 1, 2024

Issue

Description:

Hello React Native Firebase team,

We’re experiencing a significant data discrepancy between Firebase and Google Ads for specific conversion events in our app, built with the React Native Firebase SDK. We have thoroughly reviewed our integration, followed the documentation meticulously, and ensured our events are set up correctly. Despite this, only about 30% of our conversion events are reflected in Google Ads reporting compared to Firebase.

Event Details:

The specific events affected are:

in_app_purchase

  • app_store_subscription_renew
  • app_store_subscription_convert
    All our traffic originates from Google Ads, so we expect near-perfect alignment between Firebase and Google Ads data. However, approximately 70% of our events appear unattributed.

Background from Google Analytics and Firebase Support:

We have reached out to both Google Analytics and Firebase Support, who have reviewed our setup and provided the following insights:

Google Analytics Feedback:
According to Google Analytics, many pings are "unattributed" in Firebase, suggesting potential issues with SDK implementation. They recommended consulting the Firebase support team or React Native Firebase community due to limited expertise with React Native SDKs.

Firebase Support Feedback:
Firebase Support confirmed our Google Ads and Firebase are correctly linked, and our events show a "google" source, indicating they should be attributed to Google Ads. They noted that React Native Firebase is not an official Firebase SDK, so issues could stem from its external nature. They suggested exploring attribution nuances or consulting Google Analytics further for historical data and configuration details.

Request:

Could you provide any guidance or insights into what might cause these unattributed pings in the React Native Firebase SDK? Is there anything specific to this SDK that could result in this significant data drop-off or the unattribution issue?

We appreciate any assistance or advice on resolving this discrepancy. Thank you for your support and for providing a fantastic tool for integrating Firebase with React Native!

Additional Context:

We have confirmed that our setup aligns with all provided documentation, and we haven't omitted any configuration steps.
At the moment most of our users are on Android, we are not able to confirm if the issue is also on iOS


Project Files

Javascript

Click To Expand

package.json:

{
  "name": "***",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "android": "react-native run-android",
    "ios": "react-native run-ios",
    "start": "react-native start",
    "test": "jest",
    "lint": "eslint .",
    "build:android": "(cd android;./gradlew clean) && (cd android;./gradlew bundleRelease)",
    "pod": "(cd ios;bundle install && bundle exec pod install --repo-update)",
    "plateform-version": "node bin/plateformVersion.js"
  },
  "dependencies": {
    "@react-native-async-storage/async-storage": "^1.23.1",
    "@react-native-community/checkbox": "^0.5.17",
    "@react-native-firebase/analytics": "^21.3.0",
    "@react-native-firebase/app": "^21.3.0",
    "@react-native-firebase/crashlytics": "^21.3.0",
    "@react-navigation/native": "^6.1.18",
    "@react-navigation/native-stack": "^6.10.1",
    "@rneui/base": "^4.0.0-rc.7",
    "@rneui/themed": "^4.0.0-rc.8",
    "@sentry/react-native": "^5.24.1",
    "@shopify/flash-list": "^1.6.3",
    "country-telephone-data": "^0.6.3",
    "fetch-retry": "^6.0.0",
    "i18next": "^23.2.8",
    "moment": "^2.29.4",
    "phone": "^3.1.37",
    "react": "18.3.1",
    "react-i18next": "^13.0.2",
    "react-native": "0.75.2",
    "react-native-actions-sheet": "^0.9.3",
    "react-native-background-fetch": "^4.2.3",
    "react-native-contacts": "^7.0.8",
    "react-native-device-info": "^10.7.0",
    "react-native-fs": "^2.20.0",
    "react-native-geolocation-service": "^5.3.1",
    "react-native-gesture-handler": "^2.14.0",
    "react-native-image-crop-picker": "^0.41.2",
    "react-native-localize": "^3.0.6",
    "react-native-maps": "1.18.0",
    "react-native-onesignal": "^5.2.4",
    "react-native-open-maps": "^0.4.3",
    "react-native-permissions": "^4.1.5",
    "react-native-purchases": "^8.2.3",
    "react-native-rate": "^1.2.12",
    "react-native-safe-area-context": "^4.6.4",
    "react-native-screens": "^3.22.1",
    "react-native-svg": "^13.10.0",
    "yargs": "^17.7.2"
  },
  "devDependencies": {
    "@babel/core": "^7.20.0",
    "@babel/preset-env": "^7.20.0",
    "@babel/runtime": "^7.20.0",
    "@react-native/babel-preset": "0.75.2",
    "@react-native/eslint-config": "0.75.2",
    "@react-native/metro-config": "0.75.2",
    "@react-native/typescript-config": "0.75.2",
    "@types/react": "^18.2.6",
    "@types/react-test-renderer": "^18.0.0",
    "babel-jest": "^29.6.3",
    "eslint": "^8.19.0",
    "jest": "^29.6.3",
    "prettier": "2.8.8",
    "react-test-renderer": "18.3.1",
    "typescript": "5.0.4"
  },
  "engines": {
    "node": ">=18"
  },
  "packageManager": "yarn@3.6.4"
}

firebase.json for react-native-firebase v6:

# N/A

iOS

Click To Expand

ios/Podfile:

  • I'm not using Pods
  • I'm using Pods and my Podfile looks like:
# Resolve react_native_pods.rb with node to allow for hoisting
def node_require(script)
  # Resolve script with node to allow for hoisting
  require Pod::Executable.execute_command('node', ['-p',
    "require.resolve(
      '#{script}',
      {paths: [process.argv[1]]},
    )", __dir__]).strip
end

node_require('react-native/scripts/react_native_pods.rb')
node_require('react-native-permissions/scripts/setup.rb')


platform :ios, 14
prepare_react_native_project!

setup_permissions([
  # 'AppTrackingTransparency',
  # 'Bluetooth',
  # 'Calendars',
  # 'CalendarsWriteOnly',
   'Camera',
   'Contacts',
  # 'FaceID',
   'LocationAccuracy',
   'LocationAlways',
   'LocationWhenInUse',
   'MediaLibrary',
  # 'Microphone',
  # 'Motion',
   'Notifications',
   'PhotoLibrary',
  # 'PhotoLibraryAddOnly',
  # 'Reminders',
  # 'Siri',
  # 'SpeechRecognition',
  # 'StoreKit',
])

linkage = ENV['USE_FRAMEWORKS']
if linkage != nil
  Pod::UI.puts "Configuring Pod with #{linkage}ally linked Frameworks".green
  use_frameworks! :linkage => linkage.to_sym
end

target 'AppGeolocNative' do

  # React Native Maps dependencies
  rn_maps_path = '../node_modules/react-native-maps'
  pod 'react-native-google-maps', :path => rn_maps_path

  config = use_native_modules!

  # https://rnfirebase.io/
  use_frameworks! :linkage => :static
  $RNFirebaseAsStaticFramework = true
  $RNFirebaseAnalyticsEnableAdSupport = true

  use_react_native!(
    :path => config[:reactNativePath],
    # An absolute path to your application root.
    :app_path => "#{Pod::Config.instance.installation_root}/.."
  )

  target 'AppGeolocNativeTests' do
    inherit! :complete
    # Pods for testing
  end

  post_install do |installer|
    # https://github.com/facebook/react-native/blob/main/packages/react-native/scripts/react_native_pods.rb#L197-L202
    react_native_post_install(
      installer,
      config[:reactNativePath],
      :mac_catalyst_enabled => false,
      # :ccache_enabled => true
    )
  end
end

target 'OneSignalNotificationServiceExtension' do
  # https://rnfirebase.io/
  use_frameworks! :linkage => :static
  $RNFirebaseAsStaticFramework = true

  pod 'OneSignalXCFramework', '>= 5.0.0', '< 6.0'
end

AppDelegate.m:

#import "AppDelegate.h"

#import <GoogleMaps/GoogleMaps.h>
#import <Firebase.h>
#import <React/RCTBundleURLProvider.h>
#import <TSBackgroundFetch/TSBackgroundFetch.h>

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  [FIRApp configure];
  [GMSServices provideAPIKey:@"xxx"];

  NSURL *jsCodeLocation;
  
  // [REQUIRED] Register BackgroundFetch
  [[TSBackgroundFetch sharedInstance] didFinishLaunching];
  
  [UIDevice currentDevice].batteryMonitoringEnabled = true;

  self.moduleName = @"AppGeolocNative";
  // You can add your custom initial props in the dictionary below.
  // They will be passed down to the ViewController used by React Native.
  self.initialProps = @{};

  return [super application:application didFinishLaunchingWithOptions:launchOptions];
}

- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
{
  return [self bundleURL];
}
 
- (NSURL *)bundleURL
{
#if DEBUG
  return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index"];
#else
  return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
#endif
}

@end


Android

Click To Expand

Have you converted to AndroidX?

  • my application is an AndroidX application?
  • I am using android/gradle.settings jetifier=true for Android compatibility?
  • I am using the NPM package jetifier for react-native compatibility?

android/build.gradle:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    ext {
        buildToolsVersion = "34.0.0"
        minSdkVersion = 23
        compileSdkVersion = 34
        targetSdkVersion = 34
        ndkVersion = "26.1.10909125"
        kotlinVersion = "1.9.24"

        // https://stackoverflow.com/questions/77274148/could-not-invoke-rnfusedlocation-getcurrentposition-react-native-geolocation-s
        playServicesLocationVersion = "21.0.1"
    }
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath("com.android.tools.build:gradle")
        classpath("com.facebook.react:react-native-gradle-plugin")
        classpath("org.jetbrains.kotlin:kotlin-gradle-plugin")
        // https://rnfirebase.io/
        classpath 'com.google.gms:google-services:4.4.2'
        // https://rnfirebase.io/crashlytics/android-setup
        classpath 'com.google.firebase:firebase-crashlytics-gradle:2.9.9'
    }
}

// react-native-background-fetch
allprojects {
    repositories {
         maven {
            url("${project(':react-native-background-fetch').projectDir}/libs")
        }
    }
}

apply plugin: "com.facebook.react.rootproject"

android/app/build.gradle:

apply plugin: "com.android.application"

// https://rnfirebase.io/
apply plugin: 'com.google.gms.google-services'

apply plugin: "org.jetbrains.kotlin.android"
apply plugin: "com.facebook.react"

// https://rnfirebase.io/crashlytics/android-setup
apply plugin: 'com.google.firebase.crashlytics'

/**
 * This is the configuration block to customize your React Native Android app.
 * By default you don't need to apply any configuration, just uncomment the lines you need.
 */
react {
    /* Folders */
    //   The root of your project, i.e. where "package.json" lives. Default is '../..'
    // root = file("../../")
    //   The folder where the react-native NPM package is. Default is ../../node_modules/react-native
    // reactNativeDir = file("../../node_modules/react-native")
    //   The folder where the react-native Codegen package is. Default is ../../node_modules/@react-native/codegen
    // codegenDir = file("../../node_modules/@react-native/codegen")
    //   The cli.js file which is the React Native CLI entrypoint. Default is ../../node_modules/react-native/cli.js
    // cliFile = file("../../node_modules/react-native/cli.js")

    /* Variants */
    //   The list of variants to that are debuggable. For those we're going to
    //   skip the bundling of the JS bundle and the assets. By default is just 'debug'.
    //   If you add flavors like lite, prod, etc. you'll have to list your debuggableVariants.
    // debuggableVariants = ["liteDebug", "prodDebug"]

    /* Bundling */
    //   A list containing the node command and its flags. Default is just 'node'.
    // nodeExecutableAndArgs = ["node"]
    //
    //   The command to run when bundling. By default is 'bundle'
    // bundleCommand = "ram-bundle"
    //
    //   The path to the CLI configuration file. Default is empty.
    // bundleConfig = file(../rn-cli.config.js)
    //
    //   The name of the generated asset file containing your JS bundle
    // bundleAssetName = "MyApplication.android.bundle"
    //
    //   The entry file for bundle generation. Default is 'index.android.js' or 'index.js'
    // entryFile = file("../js/MyApplication.android.js")
    //
    //   A list of extra flags to pass to the 'bundle' commands.
    //   See https://github.com/react-native-community/cli/blob/main/docs/commands.md#bundle
    // extraPackagerArgs = []

    /* Hermes Commands */
    //   The hermes compiler command to run. By default it is 'hermesc'
    // hermesCommand = "$rootDir/my-custom-hermesc/bin/hermesc"
    //
    //   The list of flags to pass to the Hermes compiler. By default is "-O", "-output-source-map"
    // hermesFlags = ["-O", "-output-source-map"]

    /* Autolinking */
    autolinkLibrariesWithApp()
}

/**
 * Set this to true to create four separate APKs instead of one,
 * one for each native architecture. This is useful if you don't
 * use App Bundles (https://developer.android.com/guide/app-bundle/)
 * and want to have separate APKs to upload to the Play Store.
 */
def enableSeparateBuildPerCPUArchitecture = false

/**
 * Set this to true to Run Proguard on Release builds to minify the Java bytecode.
 */
def enableProguardInReleaseBuilds = false

/**
 * The preferred build flavor of JavaScriptCore (JSC)
 *
 * For example, to use the international variant, you can use:
 * `def jscFlavor = 'org.webkit:android-jsc-intl:+'`
 *
 * The international variant includes ICU i18n library and necessary data
 * allowing to use e.g. `Date.toLocaleString` and `String.localeCompare` that
 * give correct results when using with locales other than en-US. Note that
 * this variant is about 6MiB larger per architecture than default.
 */
def jscFlavor = 'org.webkit:android-jsc:+'

/**
 * Private function to get the list of Native Architectures you want to build.
 * This reads the value from reactNativeArchitectures in your gradle.properties
 * file and works together with the --active-arch-only flag of react-native run-android.
 */
def reactNativeArchitectures() {
    def value = project.getProperties().get("reactNativeArchitectures")
    return value ? value.split(",") : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"]
}

android {
    ndkVersion rootProject.ext.ndkVersion

    buildToolsVersion rootProject.ext.buildToolsVersion
    compileSdk rootProject.ext.compileSdkVersion

    namespace "com.majx.geoloc"
    defaultConfig {
        applicationId "com.majx.geoloc"
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        versionCode 182
        versionName "2.0.4"
        missingDimensionStrategy "store", "play"
        vectorDrawables.useSupportLibrary = true
    }

    splits {
        abi {
            reset()
            enable enableSeparateBuildPerCPUArchitecture
            universalApk false  // If true, also generate a universal APK
            include (*reactNativeArchitectures())
        }
    }
    signingConfigs {
        release {
            if (project.hasProperty('MYAPP_UPLOAD_STORE_FILE')) {
                storeFile file(MYAPP_UPLOAD_STORE_FILE)
                storePassword MYAPP_UPLOAD_STORE_PASSWORD
                keyAlias MYAPP_UPLOAD_KEY_ALIAS
                keyPassword MYAPP_UPLOAD_KEY_PASSWORD
            }
        }
        debug {
            storeFile file('debug.keystore')
            storePassword 'android'
            keyAlias 'androiddebugkey'
            keyPassword 'android'
        }
    }
    buildTypes {
        debug {
            signingConfig signingConfigs.debug
        }
        release {
            // Caution! In production, you need to generate your own keystore file.
            // see https://reactnative.dev/docs/signed-apk-android.
            signingConfig signingConfigs.release
            minifyEnabled enableProguardInReleaseBuilds
            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
        }
    }

    // applicationVariants are e.g. debug, release
    applicationVariants.all { variant ->
        variant.outputs.each { output ->
            // For each separate APK per architecture, set a unique version code as described here:
            // https://developer.android.com/studio/build/configure-apk-splits.html
            // Example: versionCode 1 will generate 1001 for armeabi-v7a, 1002 for x86, etc.
            def versionCodes = ["armeabi-v7a": 1, "x86": 2, "arm64-v8a": 3, "x86_64": 4]
            def abi = output.getFilter(com.android.build.OutputFile.ABI)
            if (abi != null) {  // null for the universal-debug, universal-release variants
                output.versionCodeOverride =
                        defaultConfig.versionCode * 1000 + versionCodes.get(abi)
            }

        }
    }
}

dependencies {
    // The version of react-native is set by the React Native Gradle Plugin
    implementation("com.facebook.react:react-android")

    if (hermesEnabled.toBoolean()) {
        implementation("com.facebook.react:hermes-android")
    } else {
        implementation jscFlavor
    }
}

android/settings.gradle:

pluginManagement { includeBuild("../node_modules/@react-native/gradle-plugin") }
plugins { id("com.facebook.react.settings") }
extensions.configure(com.facebook.react.ReactSettingsExtension){ ex -> ex.autolinkLibrariesFromCommand() }
rootProject.name = 'xxx'
include ':app'
includeBuild('../node_modules/@react-native/gradle-plugin')

MainApplication.kt:

package com.company.project

import android.app.Application
import com.facebook.react.PackageList
import com.facebook.react.ReactApplication
import com.facebook.react.ReactHost
import com.facebook.react.ReactNativeHost
import com.facebook.react.ReactPackage
import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint.load
import com.facebook.react.defaults.DefaultReactHost.getDefaultReactHost
import com.facebook.react.defaults.DefaultReactNativeHost
import com.facebook.soloader.SoLoader

class MainApplication : Application(), ReactApplication {

  override val reactNativeHost: ReactNativeHost =
      object : DefaultReactNativeHost(this) {
        override fun getPackages(): List<ReactPackage> =
            PackageList(this).packages.apply {
              // Packages that cannot be autolinked yet can be added manually here, for example:
              // add(MyReactNativePackage())
            }

        override fun getJSMainModuleName(): String = "index"

        override fun getUseDeveloperSupport(): Boolean = BuildConfig.DEBUG

        override val isNewArchEnabled: Boolean = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED
        override val isHermesEnabled: Boolean = BuildConfig.IS_HERMES_ENABLED
      }

  override val reactHost: ReactHost
    get() = getDefaultReactHost(applicationContext, reactNativeHost)

  override fun onCreate() {
    super.onCreate()
    SoLoader.init(this, false)
    if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) {
      // If you opted-in for the New Architecture, we load the native entry point for this app.
      load()
    }
  }
}

AndroidManifest.xml:

<manifest xmlns:android="http://schemas.android.com/apk/res/android">

  <uses-permission android:name="android.permission.INTERNET" />
  <uses-permission android:name="com.android.vending.BILLING" />
  <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
  <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
  <uses-permission android:name="android.permission.READ_CONTACTS" />
  <uses-permission android:name="com.google.android.gms.permission.AD_ID" />
  <uses-permission android:name="android.permission.CAMERA" />
  <uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
  <uses-permission android:name="android.permission.ACCESS_MEDIA_LOCATION" />
  <uses-permission android:name="android.permission.READ_PROFILE" />
  <uses-permission android:name="android.permission.POST_NOTIFICATIONS"/> 

  <application android:name=".MainApplication" android:label="@string/app_name" android:icon="@mipmap/ic_launcher" android:roundIcon="@mipmap/ic_launcher_round" android:allowBackup="false" android:theme="@style/AppTheme" android:supportsRtl="true">
    <activity android:name=".MainActivity" android:label="@string/app_name" android:screenOrientation="portrait" android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|screenSize|smallestScreenSize|uiMode" android:launchMode="singleTask" android:windowSoftInputMode="adjustResize" android:exported="true">
      <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
      </intent-filter>
    </activity>
    <meta-data android:name="com.google.android.geo.API_KEY" android:value="xxx"/>
  </application>
</manifest>


Environment

Click To Expand

react-native info output:

System:
  OS: macOS 14.6.1
  CPU: (12) arm64 Apple M2 Max
  Memory: 3.66 GB / 64.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 20.11.1
    path: /opt/homebrew/opt/node@20/bin/node
  Yarn: Not Found
  npm:
    version: 10.2.4
    path: /opt/homebrew/opt/node@20/bin/npm
  Watchman:
    version: 2024.05.06.00
    path: /opt/homebrew/bin/watchman
Managers:
  CocoaPods:
    version: 1.14.3
    path: /Users/ajouve/.rvm/gems/ruby-2.7.5/bin/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 24.1
      - iOS 18.1
      - macOS 15.1
      - tvOS 18.1
      - visionOS 2.1
      - watchOS 11.1
  Android SDK: Not Found
IDEs:
  Android Studio: 2022.3 AI-223.8836.35.2231.10671973
  Xcode:
    version: 16.1/16B40
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 22.0.1
    path: /opt/homebrew/opt/openjdk/bin/javac
  Ruby:
    version: 2.7.5
    path: /Users/ajouve/.rvm/rubies/ruby-2.7.5/bin/ruby
npmPackages:
  "@react-native-community/cli":
    installed: 15.0.1
    wanted: ^15.0.1
  react:
    installed: 18.3.1
    wanted: 18.3.1
  react-native:
    installed: 0.75.2
    wanted: 0.75.2
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: Not found
  newArchEnabled: Not found
iOS:
  hermesEnabled: Not found
  newArchEnabled: Not found
  • Platform that you're experiencing the issue on:
    • iOS
    • Android
    • iOS but have not tested behavior on Android
    • Android but have not tested behavior on iOS
    • Both
  • react-native-firebase version you're using that has this issue:
    • 21.3.0
  • Firebase module(s) you're using that has the issue:
    • analytics
  • Are you using TypeScript?
    • N


@mikehardy
Copy link
Collaborator

🤔 Hmm, going to be quite the run-around on this one unfortunately, since we're comparing two cloud-based + different google services (google ads, firebase analytics) and it's wrapped by this library which both of them are suspicious of since they don't control it.

Here's what I know based on your helpful information - those two events are marked as reserved for us - that is no user may use an analytics API here which attempts to manually log them:

'app_store_refund',
'app_store_subscription_cancel',
'app_store_subscription_convert',
'app_store_subscription_renew',

logEvent(name, params = {}, options = {}) {
if (!isString(name)) {
throw new Error("firebase.analytics().logEvent(*) 'name' expected a string value.");
}
if (!isUndefined(params) && !isObject(params)) {
throw new Error("firebase.analytics().logEvent(_, *) 'params' expected an object value.");
}
// check name is not a reserved event name
if (isOneOf(name, ReservedEventNames)) {
throw new Error(
`firebase.analytics().logEvent(*) 'name' the event name '${name}' is reserved and can not be used.`,
);
}

So, we do not even let users log those events, full stop. Nothing in this library allows for those events to be used, they are off-limits.

In a full-repo search, the app_store_subscription_convert event is not used in any other spot:

https://github.com/search?q=repo%3Ainvertase%2Freact-native-firebase%20app_store_subscription_convert&type=code

My informed hypothesis is that this library is not involved in sending that conversion information to google servers at all.

To explore this a bit more - looking more widely for the words convert or conversion do not yield anything analytics related either:

https://github.com/search?q=repo%3Ainvertase%2Freact-native-firebase+convert+language%3AJava&type=code&l=Java
https://github.com/search?q=repo%3Ainvertase%2Freact-native-firebase+conversion+language%3AJava&type=code&l=Java

Looking upstream, these are classed as "automatically collected events", and they have had problems before:

firebase/firebase-android-sdk#2179

Indeed these are marked as automatically collected:
https://support.google.com/analytics/answer/9234069?hl=en&visit_id=638660672837317251-375485086&rd=2

That is, the SDKs under us - firebase-android-sdk in this case - are doing it for us with no part of this repository doing anything

So I don't think this is a problem here

However, this tidbit is interesting:

According to Google Analytics, many pings are "unattributed" in Firebase, suggesting potential issues with SDK implementation

The more (and more technical) information we could get about that, the more it would help determine what this means, and whether we could influence it. Unfortunately I'm not even sure what it means at a technical level at the moment

Possible ways forward:
1- get that technical info - as specific as possible - about unattributed pings
2- construct reproduction rig that is firebase-android-sdk only, removing this layer, to inspect attribution. Can be done with fresh app + fresh cloud accounts and products that are very low-cost or zero I hope - allowing for clean + focused reproduction without the finger-pointing that is unfortunately inevitable when those teams here "react-native"

Of the 2 - 1 is of interest here but I don't think will actually resolve your issue. I think 2 is the real way forward

This may be the best skeleton to begin with:
https://github.com/firebase/quickstart-android/blob/master/analytics/README.md

then just hack in (the most rapid way possible) buttons that subscribe and cancel ?

@ajouve
Copy link
Author

ajouve commented Nov 3, 2024

Thank you for your response and the insights provided.

We’ve reached out to Google Analytics and Firebase support for further clarification on the attribution issues. They are currently reviewing the setup but haven’t identified a conclusive reason for the event discrepancy.

We have one additional question regarding user consent for analytics and ad tracking. Currently, we are not requesting explicit user consent for analytics data collection. Could the absence of consent handling be a potential cause of these unattributed pings?

If consent could be impacting event attribution, we’re considering implementing the following code after obtaining user consent:

import { firebase } from '@react-native-firebase/analytics';
// ...
await firebase.analytics().setConsent({
  analytics_storage: true,
  ad_storage: true,
  ad_user_data: true,
  ad_personalization: true,
});

Would you recommend this approach, or is there additional guidance on handling consent to improve data attribution? Any advice on this front would be greatly appreciated.

Thank you again for your assistance!

@mikehardy
Copy link
Collaborator

With sincere apologies - as soon as the conversation tracks into user consent flows I have to bow out - this is a specific area that requires correct answers for legal reasons and not only am I not an expert I haven't done more than implement the react-native APIs (that is: I have not actually used them) so I don't even have the experience, must less the actual required expertise. I don't want to lead anyone astray.

That said, if you look at the setConsent code where we make the javascript bindings you'll see that this one is also just a pure / boring wrapper - there's nothing to the react-native layer. That means two things, it shouldn't be "us" (react-native-firebase) with an error if there is one, but also if you attempted a native reproduction directly with a quickstart from firebase-android-sdk, it should be trivial as the APIs are also trivial

The javascript - some validation, then a native call:

setConsent(consentSettings) {
if (!isObject(consentSettings)) {
throw new Error(
'firebase.analytics().setConsent(*): The supplied arg must be an object of key/values.',
);
}
const entries = Object.entries(consentSettings);
for (let i = 0; i < entries.length; i++) {
const [key, value] = entries[i];
if (!isBoolean(value)) {
throw new Error(
`firebase.analytics().setConsent(*) 'consentSettings' value for parameter '${key}' is invalid, expected a boolean.`,
);
}
}
return this.native.setConsent(consentSettings);
}

The native call - mostly just type conversion from what comes in from javascript to native types, then the firebase-android-sdk call:

Task<Void> setConsent(Bundle consentSettings) {
return Tasks.call(
() -> {
boolean analyticsStorage = consentSettings.getBoolean("analytics_storage");
boolean adStorage = consentSettings.getBoolean("ad_storage");
boolean adUserData = consentSettings.getBoolean("ad_user_data");
boolean adPersonalization = consentSettings.getBoolean("ad_personalization");
Map<ConsentType, ConsentStatus> consentMap = new EnumMap<>(ConsentType.class);
consentMap.put(
ConsentType.ANALYTICS_STORAGE,
analyticsStorage ? ConsentStatus.GRANTED : ConsentStatus.DENIED);
consentMap.put(
ConsentType.AD_STORAGE, adStorage ? ConsentStatus.GRANTED : ConsentStatus.DENIED);
consentMap.put(
ConsentType.AD_USER_DATA, adUserData ? ConsentStatus.GRANTED : ConsentStatus.DENIED);
consentMap.put(
ConsentType.AD_PERSONALIZATION,
adPersonalization ? ConsentStatus.GRANTED : ConsentStatus.DENIED);
FirebaseAnalytics.getInstance(getContext()).setConsent(consentMap);
return null;
});

Not much to it?

It could work, it may work, but I can't say either way, sorry

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants