@ amplitude/plugin- engagement- react- native
原生反应的振幅插件
安装
要安装 :
- 添加
@amplitude/analytics-react-native财务报告和审定财务报表@amplitude/plugin-engagement-react-native - 添加
@react-native-async-storage/async-storage- 为什么? 此为
engagement本地模块, 但 CLI 只将您在应用程序中直接依赖的本地模块自动链接package.json
- 为什么? 此为
npm install @amplitude/analytics-react-native
npm install @react-native-async-storage/async-storage
npm install @amplitude/plugin-engagement-react-native
重新运行 pod install 输入 ios 目录 :
$ cd ios
$ bundle exec pod install
使用量
设置代码
通过添加插件并按常态调用“ init” 设置 :
// index.js
import {Linking} from 'react-native';
import { init, add } from '@amplitude/analytics-react-native';
import { getPlugin, handleURL } from '@amplitude/plugin-engagement-react-native';
init('<<< YOUR API KEY HERE >>>');
add(getPlugin());
Linking.getInitialURL().then(async (url) => {
if (url) {
const didHandleURL = await handleURL(url);
if (didHandleURL) { return; }
// Handle a non-Amplitude SDK URL
}
});
Linking.addEventListener('url', async ({ url }) => {
const didHandleURL = await handleURL(url);
if (didHandleURL) { return; }
// Handle a non-Amplitude SDK URL
});
连接设置
如果您尚未设置, 请遵循此指南, 除了添加上述链接代码外, 在您的 React Industrial app 中启用深链接支持 : https://reactnative.dev/docs/linking#enabling-deep-links 页面存档备份,存于互联网档案馆
然后,遵循阿尔法登机指南,为您Android和iOS项目中的深层链接设置"计划".
启动
最后,用用户的ID“启动”插件;SDK“启动”使指南和调查能够显示:
import {
setDeviceId,
setUserId,
} from '@amplitude/analytics-react-native';
import { useEffect } from 'react';
import { getPlugin } from '@amplitude/plugin-engagement-react-native';
export default function App() {
useEffect(() => {
//
// NOTE: setting the User ID in @amplitude/analytics-react-native
// --and-- passing it to boot() is necessary for now, but in a
// future version will not be necessary
//
setUserId('rn-test-user-1');
setDeviceId('test-device-1');
getPlugin().boot('rn-test-user-1', 'test-device-1');
}, []);
一体化
将《指南》和《调查》跟踪的活动转交分析提供者
非振幅分析,通过 integrations 改为 boot()每一个
集成是接收事件类型和事件属性的回调
每个跟踪事件:
getPlugin().boot({
user: { user_id: 'rn-test-user-1', device_id: 'test-device-1' },
integrations: [
(eventType, eventProperties) => {
// e.g. forward to your third-party analytics provider
thirdPartyAnalytics.track(eventType, eventProperties);
},
],
});
许可证
麻省理工学院