如何通过Firebase在React JS Android应用中跟踪“按钮点击”?

huangapple go评论60阅读模式
英文:

How to Track "button clicks" in react js android application via Firebase?

问题

我是新手处理React Native应用程序,正在尝试找出如何跟踪我的Android应用程序上可用的几个按钮。

在我的React Native应用程序中,当注册应用时有一个"提交"按钮,我想通过Firebase跟踪该按钮,但不知道如何在Android Studio项目中为React Native应用程序执行此操作。尽管我知道需要放置类似的代码,但不确定如何在这里识别按钮类元素。

以下是我需要放置的类似代码:

Button b1 = findViewById(R.id.button2);
b1.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        Bundle bundle = new Bundle();
        bundle.putString("Button_text", "Sign_up");
        mFirebaseAnalytics.logEvent("Sign_up_button", bundle);
    }
});

这是我的React Native应用程序,我不知道正确的按钮在哪里,我正在尝试找出

英文:

I am new in dealing with react native apps and I am trying to find out how to track few buttons that is being available on my android application.

In my react native app, there is a "submit" button while signing up into the app and I want to track that button via Firebase, but have no idea on how to do that in android studio project for an react native application. Although I know the similar code which I need to put but not sure how to identify the button class element right here.

Here's the similar code what I need to put:

``
  Button b1= findViewById(R.id.button2);
            b1.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Bundle bundle= new Bundle();
                    bundle.putString("Button_text","Sign_up");
                    mFirebaseAnalytics.logEvent("Sign_up_button",bundle);
            }
``

This is my react native app, and I don't know where is the right button I am trying to find out

答案1

得分: 1

RNFirebase 应该集成到 React Native 项目中。

如文档中所解释,按钮操作的事件跟踪应该在 onPress 回调方法中处理。

import React, { useEffect } from 'react';
import { View, Button } from 'react-native';
import analytics from '@react-native-firebase/analytics';

function App() {
  return (
    <View>
      <Button
        title="添加到购物篮"
        onPress={async () =>
          await analytics().logEvent('事件名称', {
            数据对象
          })
        }
      />
    </View>
  );
}
英文:

RNFirebase should be integrated into the react-native project.

As explained in the document the event tracking for the button action should be handled in onPress callback method

import react, { useEffect } from &#39;react&#39;;
import { View, Button } from &#39;react-native&#39;;
import analytics from &#39;@react-native-firebase/analytics&#39;;

function App() {
  return (
    &lt;View&gt;
      &lt;Button
        title=&quot;Add To Basket&quot;
        onPress={async () =&gt;
          await analytics().logEvent(&#39;Event Name&#39;, {
            Data Object
          })
        }
      /&gt;
    &lt;/View&gt;
  );
}

huangapple
  • 本文由 发表于 2023年2月16日 12:39:08
  • 转载请务必保留本文链接:https://go.coder-hub.com/75467915.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定