英文:
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 'react';
import { View, Button } from 'react-native';
import analytics from '@react-native-firebase/analytics';
function App() {
return (
<View>
<Button
title="Add To Basket"
onPress={async () =>
await analytics().logEvent('Event Name', {
Data Object
})
}
/>
</View>
);
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论